Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow string slices as krel obs arguments #3267

Merged
merged 1 commit into from
Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 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,23 @@ func init() {

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

// Allow submitting packages and architectures separated by the string
// slice separator. This allows us to pass the GCB substitution, which
// already uses comma as default 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}$"'.
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
}
saschagrunert marked this conversation as resolved.
Show resolved Hide resolved

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
Loading