Skip to content

Commit

Permalink
Allow string slices as krel obs arguments
Browse files Browse the repository at this point in the history
This fixes the usage of packages and architectures as mentioned in
#3224 by using a custom
separator.

We cannot use the GCB separator substitution (see `gcloud topic
escaping`) because GCB complains that a 'build tag must match format
"^[\\w][\\w.-]{0,127}$"'.

Signed-off-by: Sascha Grunert <sgrunert@redhat.com>
  • Loading branch information
saschagrunert committed Sep 13, 2023
1 parent a92f4f2 commit dae6097
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
17 changes: 15 additions & 2 deletions cmd/krel/cmd/obs_stage.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"

"k8s.io/release/pkg/gcp/gcb"
"k8s.io/release/pkg/obs"
"k8s.io/release/pkg/release"
)
Expand Down Expand Up @@ -115,15 +116,15 @@ func init() {
)

obsStageCmd.PersistentFlags().
StringArrayVar(
StringSliceVar(
&obsStageOptions.Packages,
obsPackagesFlag,
obsStageOptions.Packages,
"List of packages to build",
)

obsStageCmd.PersistentFlags().
StringArrayVar(
StringSliceVar(
&obsStageOptions.Architectures,
obsArchitecturesFlag,
obsStageOptions.Architectures,
Expand Down Expand Up @@ -181,6 +182,18 @@ func init() {

func runOBSStage(options *obs.StageOptions) error {
options.NoMock = rootOpts.nomock

// Allow submitting packages and architectures separated by the string slice separator.
archSplit := strings.Split(options.Architectures[0], gcb.StringSliceSeparator)
if len(archSplit) > 1 {
options.Architectures = archSplit
}

packageSplit := strings.Split(options.Packages[0], gcb.StringSliceSeparator)
if len(packageSplit) > 1 {
options.Packages = packageSplit
}

stage := obs.NewStage(options)
if submitJob {
// Perform a local check of the specified options before launching a
Expand Down
4 changes: 2 additions & 2 deletions gcb/obs-stage/cloudbuild.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,7 @@ steps:
- "--log-level=${_LOG_LEVEL}"
- "--template-dir=${_SPEC_TEMPLATE_PATH}"
- "--packages=${_PACKAGES}"
# TODO(xmudrii) - followup: solve problem with delimiter
# - "--architectures=${_ARCHITECTURES}"
- "--architectures=${_ARCHITECTURES}"
- "--version=${_VERSION}"
- "--project=${_OBS_PROJECT}"
- "--source=${_PACKAGE_SOURCE}"
Expand All @@ -97,6 +96,7 @@ tags:
- ${_TYPE_TAG}
- ${_TYPE}
- ${_PACKAGES}
- ${_ARCHITECTURES}
- ${_VERSION}
- ${_OBS_PROJECT_TAG}

Expand Down
11 changes: 7 additions & 4 deletions pkg/gcp/gcb/gcb.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ import (
"sigs.k8s.io/release-utils/util"
)

// StringSliceSeparator is the separator used for passing string slices as GCB
// substitutions.
const StringSliceSeparator = "..."

// GCB is the main structure of this package.
type GCB struct {
options *Options
Expand Down Expand Up @@ -391,9 +395,8 @@ func (g *GCB) SetGCBSubstitutions(toolOrg, toolRepo, toolRef, gcsBucket string)
switch {
case g.options.OBSStage:
gcbSubs["SPEC_TEMPLATE_PATH"] = g.options.SpecTemplatePath
gcbSubs["PACKAGES"] = strings.Join(g.options.Packages, ",")
//nolint:gocritic // This needs some fixes that will be done in a follow-up
// gcbSubs["ARCHITECTURES"] = strings.Join(g.options.Architectures, ",")
gcbSubs["PACKAGES"] = strings.Join(g.options.Packages, StringSliceSeparator)
gcbSubs["ARCHITECTURES"] = strings.Join(g.options.Architectures, StringSliceSeparator)
gcbSubs["VERSION"] = g.options.Version
gcbSubs["OBS_PROJECT"] = g.options.OBSProject
gcbSubs["OBS_PROJECT_TAG"] = strings.ReplaceAll(g.options.OBSProject, ":", "-")
Expand All @@ -402,7 +405,7 @@ func (g *GCB) SetGCBSubstitutions(toolOrg, toolRepo, toolRef, gcsBucket string)
// Stop here when doing OBS stage
return gcbSubs, nil
case g.options.OBSRelease:
gcbSubs["PACKAGES"] = strings.Join(g.options.Packages, ",")
gcbSubs["PACKAGES"] = strings.Join(g.options.Packages, StringSliceSeparator)
gcbSubs["OBS_PROJECT"] = g.options.OBSProject
gcbSubs["OBS_PROJECT_TAG"] = strings.ReplaceAll(g.options.OBSProject, ":", "-")

Expand Down

0 comments on commit dae6097

Please sign in to comment.