Skip to content

Commit

Permalink
address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
radTuti committed Nov 22, 2024
1 parent 8006abf commit a1cae27
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 34 deletions.
3 changes: 1 addition & 2 deletions .semaphore/release/hashrelease.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ blocks:
jobs:
- name: Build and publish hashrelease
commands:
- |
if [[ ${SEMAPHORE_PIPELINE_PROMOTION} == "true" ]]; then export BUILD_IMAGES=true; export SKIP_PUBLISH_IMAGES=false; fi
- if [[ ${SEMAPHORE_PIPELINE_PROMOTION} == "true" ]]; then export BUILD_IMAGES=true; export SKIP_PUBLISH_IMAGES=false; fi
- make hashrelease
prologue:
commands:
Expand Down
32 changes: 16 additions & 16 deletions release/build/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ func hashreleaseSubCommands(cfg *config.Config) []*cli.Command {
&cli.BoolFlag{Name: skipValidationFlag, Usage: "Skip all pre-build validation", Value: false},
&cli.BoolFlag{Name: skipBranchCheckFlag, Usage: "Skip check that this is a valid release branch.", Value: false},
&cli.BoolFlag{Name: buildImagesFlag, Usage: "Build images from local codebase. If false, will use images from CI instead.", EnvVars: []string{"BUILD_IMAGES"}, Value: false},
&cli.StringFlag{Name: imageRegistryFlag, Usage: "Specify image registry to use", EnvVars: []string{"REGISTRIES"}, Value: ""},
&cli.StringSliceFlag{Name: imageRegistryFlag, Usage: "Specify image registry or registries to use", EnvVars: []string{"REGISTRIES"}, Value: &cli.StringSlice{}},
&cli.StringFlag{Name: operatorOrgFlag, Usage: "Operator git organization", EnvVars: []string{"OPERATOR_GIT_ORGANIZATION"}, Value: config.OperatorDefaultOrg},
&cli.StringFlag{Name: operatorRepoFlag, Usage: "Operator git repository", EnvVars: []string{"OPERATOR_GIT_REPO"}, Value: config.OperatorDefaultRepo},
&cli.StringFlag{Name: operatorImageFlag, Usage: "Specify the operator image to use", EnvVars: []string{"OPERATOR_IMAGE"}, Value: config.OperatorDefaultImage},
Expand All @@ -173,7 +173,7 @@ func hashreleaseSubCommands(cfg *config.Config) []*cli.Command {
if c.Bool(skipValidationFlag) && !c.Bool(skipBranchCheckFlag) {
return fmt.Errorf("%s must be set if %s is set", skipBranchCheckFlag, skipValidationFlag)
}
if c.String(imageRegistryFlag) != "" && c.String(operatorRegistryFlag) == "" {
if len(c.StringSlice(imageRegistryFlag)) > 0 && c.String(operatorRegistryFlag) == "" {
return fmt.Errorf("%s must be set if %s is set", operatorRegistryFlag, imageRegistryFlag)
}
if c.String(operatorImageFlag) != "" && c.String(operatorRegistryFlag) == "" {
Expand All @@ -182,7 +182,7 @@ func hashreleaseSubCommands(cfg *config.Config) []*cli.Command {
return fmt.Errorf("%s must be set if %s is set", operatorImageFlag, operatorRegistryFlag)
}
if !cfg.CI.IsCI {
if c.String(imageRegistryFlag) == "" && c.Bool(buildImagesFlag) {
if len(c.StringSlice(imageRegistryFlag)) == 0 && c.Bool(buildImagesFlag) {
logrus.Warn("Local builds should specify an image registry using the --dev-registry flag")
}
if c.String(operatorRegistryFlag) == registry.QuayRegistry && c.String(operatorImageFlag) == config.OperatorDefaultImage {
Expand Down Expand Up @@ -262,8 +262,8 @@ func hashreleaseSubCommands(cfg *config.Config) []*cli.Command {
calico.WithRepoRemote(cfg.GitRemote),
calico.WithArchitectures(cfg.Arches),
}
if reg := c.String(imageRegistryFlag); reg != "" {
opts = append(opts, calico.WithImageRegistries([]string{reg}))
if reg := c.StringSlice(imageRegistryFlag); len(reg) > 0 {
opts = append(opts, calico.WithImageRegistries(reg))
}

r := calico.NewManager(opts...)
Expand Down Expand Up @@ -293,8 +293,8 @@ func hashreleaseSubCommands(cfg *config.Config) []*cli.Command {
Flags: []cli.Flag{
&cli.StringFlag{Name: orgFlag, Usage: "Git organization", EnvVars: []string{"ORGANIZATION"}, Value: config.DefaultOrg},
&cli.StringFlag{Name: repoFlag, Usage: "Git repository", EnvVars: []string{"GIT_REPO"}, Value: config.DefaultRepo},
&cli.StringFlag{Name: imageRegistryFlag, Usage: "Specify image registry to use", EnvVars: []string{"REGISTRIES"}, Value: ""},
&cli.BoolFlag{Name: skipPublishImagesFlag, Usage: "Skip publishing of container images to registry", EnvVars: []string{"SKIP_PUBLISH_IMAGES"}, Value: true},
&cli.StringSliceFlag{Name: imageRegistryFlag, Usage: "Specify image registry or registries to use", EnvVars: []string{"REGISTRIES"}, Value: &cli.StringSlice{}},
&cli.BoolFlag{Name: skipPublishImagesFlag, Usage: "Skip publishing of container images to registry/registries", EnvVars: []string{"PUBLISH_IMAGES"}, Value: false},
&cli.BoolFlag{Name: skipPublishHashreleaseFlag, Usage: "Skip publishing to hashrelease server", Value: false},
&cli.BoolFlag{Name: latestFlag, Usage: "Promote this release as the latest for this stream", Value: true},
&cli.BoolFlag{Name: skipValidationFlag, Usage: "Skip pre-build validation", Value: false},
Expand All @@ -304,7 +304,7 @@ func hashreleaseSubCommands(cfg *config.Config) []*cli.Command {
configureLogging("hashrelease-publish.log")

// If using a custom registry, do not set the hashrelease as latest
if c.String(imageRegistryFlag) != "" && c.Bool(latestFlag) {
if len(c.StringSlice(imageRegistryFlag)) > 0 && c.Bool(latestFlag) {
return fmt.Errorf("cannot set hashrelease as latest when using a custom registry")
}

Expand Down Expand Up @@ -359,8 +359,8 @@ func hashreleaseSubCommands(cfg *config.Config) []*cli.Command {
calico.WithPublishHashrelease(!c.Bool(skipPublishHashreleaseFlag)),
calico.WithImageScanning(!c.Bool(skipImageScanFlag), cfg.ImageScannerConfig),
}
if reg := c.String(imageRegistryFlag); reg != "" {
opts = append(opts, calico.WithImageRegistries([]string{reg}))
if reg := c.StringSlice(imageRegistryFlag); len(reg) > 0 {
opts = append(opts, calico.WithImageRegistries(reg))
}
r := calico.NewManager(opts...)
if err := r.PublishRelease(); err != nil {
Expand Down Expand Up @@ -425,7 +425,7 @@ func releaseSubCommands(cfg *config.Config) []*cli.Command {
&cli.StringFlag{Name: repoFlag, Usage: "Git repository", EnvVars: []string{"GIT_REPO"}, Value: config.DefaultRepo},
&cli.BoolFlag{Name: buildImagesFlag, Usage: "Build images from local codebase. If false, will use images from CI instead.", EnvVars: []string{"BUILD_IMAGES"}, Value: true},
&cli.BoolFlag{Name: skipValidationFlag, Usage: "Skip pre-build validation", Value: false},
&cli.StringFlag{Name: imageRegistryFlag, Usage: "Specify image registry to use", Value: ""},
&cli.StringSliceFlag{Name: imageRegistryFlag, Usage: "Specify image registry or registries to use", EnvVars: []string{"REGISTRIES"}, Value: &cli.StringSlice{}},
},
Action: func(c *cli.Context) error {
configureLogging("release-build.log")
Expand Down Expand Up @@ -458,8 +458,8 @@ func releaseSubCommands(cfg *config.Config) []*cli.Command {
if c.Bool(skipValidationFlag) {
opts = append(opts, calico.WithValidate(false))
}
if reg := c.String(imageRegistryFlag); reg != "" {
opts = append(opts, calico.WithImageRegistries([]string{reg}))
if reg := c.StringSlice(imageRegistryFlag); len(reg) > 0 {
opts = append(opts, calico.WithImageRegistries(reg))
}
r := calico.NewManager(opts...)
return r.Build()
Expand All @@ -476,7 +476,7 @@ func releaseSubCommands(cfg *config.Config) []*cli.Command {
&cli.BoolFlag{Name: skipPublishImagesFlag, Usage: "Skip publishing of container images to registry", EnvVars: []string{"SKIP_PUBLISH_IMAGES"}, Value: false},
&cli.BoolFlag{Name: skipPublishGitTagFlag, Usage: "Skip publishing of tag to git repository", Value: false},
&cli.BoolFlag{Name: skipPublishGithubReleaseFlag, Usage: "Skip publishing of release to Github", Value: false},
&cli.StringFlag{Name: imageRegistryFlag, Usage: "Specify image registry to use", Value: ""},
&cli.StringSliceFlag{Name: imageRegistryFlag, Usage: "Specify image registry or registries to use", EnvVars: []string{"REGISTRIES"}, Value: &cli.StringSlice{}},
},
Action: func(c *cli.Context) error {
configureLogging("release-publish.log")
Expand All @@ -499,8 +499,8 @@ func releaseSubCommands(cfg *config.Config) []*cli.Command {
calico.WithPublishGitTag(!c.Bool(skipPublishGitTagFlag)),
calico.WithPublishGithubRelease(!c.Bool(skipPublishGithubReleaseFlag)),
}
if reg := c.String(imageRegistryFlag); reg != "" {
opts = append(opts, calico.WithImageRegistries([]string{reg}))
if reg := c.StringSlice(imageRegistryFlag); len(reg) > 0 {
opts = append(opts, calico.WithImageRegistries(reg))
}
r := calico.NewManager(opts...)
return r.PublishRelease()
Expand Down
54 changes: 38 additions & 16 deletions release/pkg/manager/calico/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -611,38 +611,50 @@ func (r *CalicoManager) assertImageVersions() error {
switch img {
case "calico/apiserver":
for _, reg := range r.imageRegistries {
out, _ := r.runner.Run("docker", []string{"run", "--rm", fmt.Sprintf("%s/%s:%s", reg, imageName, r.calicoVersion)}, nil)
out, err := r.runner.Run("docker", []string{"run", "--rm", fmt.Sprintf("%s/%s:%s", reg, imageName, r.calicoVersion)}, nil)
// apiserver always returns an error because there is no kubeconfig, log and ignore it.
if err != nil {
logrus.WithError(err).WithField("image", img).Warn("error getting version from image")
}
if !strings.Contains(out, r.calicoVersion) {
return fmt.Errorf("version does not match for image %s/%s:%s", reg, imageName, r.calicoVersion)
}
}
case "calico/cni": // cni-plugin
case "calico/cni":
for _, reg := range r.imageRegistries {
for _, cmd := range []string{"calico", "calico-ipam"} {
out, err := r.runner.Run("docker", []string{"run", "--rm", fmt.Sprintf("%s/%s:%s", reg, imageName, r.calicoVersion), cmd, "-v"}, nil)
if err != nil || !strings.Contains(out, r.calicoVersion) {
if err != nil {
return fmt.Errorf("failed to run get version from %s image: %s", cmd, err)
} else if !strings.Contains(out, r.calicoVersion) {
return fmt.Errorf("version does not match for image %s/%s:%s", reg, imageName, r.calicoVersion)
}
}
}
case "calico/csi": // pod2daemon
case "calico/csi":
for _, reg := range r.imageRegistries {
out, err := r.runner.Run("docker", []string{"inspect", `--format='{{ index .Config.Labels "version" }}'`, fmt.Sprintf("%s/%s:%s", reg, imageName, r.calicoVersion)}, nil)
if err != nil || !strings.Contains(out, r.calicoVersion) {
if err != nil {
return fmt.Errorf("failed to run get version from %s image: %s", imageName, err)
} else if !strings.Contains(out, r.calicoVersion) {
return fmt.Errorf("version does not match for image %s/%s:%s", reg, imageName, r.calicoVersion)
}
}
case "calico/ctl":
for _, reg := range r.imageRegistries {
out, err := r.runner.Run("docker", []string{"run", "--rm", fmt.Sprintf("%s/%s:%s", reg, imageName, r.calicoVersion), "version"}, nil)
if err != nil || !strings.Contains(out, r.calicoVersion) {
if err != nil {
return fmt.Errorf("failed to run get version from %s image: %s", imageName, err)
} else if !strings.Contains(out, r.calicoVersion) {
return fmt.Errorf("version does not match for image %s/%s:%s", reg, imageName, r.calicoVersion)
}
}
case "calico/dikastes": // app-policy
case "calico/dikastes":
for _, reg := range r.imageRegistries {
out, err := r.runner.Run("docker", []string{"inspect", `--format='{{ index .Config.Labels "version" }}'`, fmt.Sprintf("%s/%s:%s", reg, imageName, r.calicoVersion)}, nil)
if err != nil || !strings.Contains(out, r.calicoVersion) {
if err != nil {
return fmt.Errorf("failed to run get version from %s image: %s", imageName, err)
} else if !strings.Contains(out, r.calicoVersion) {
return fmt.Errorf("version does not match for image %s/%s:%s", reg, imageName, r.calicoVersion)
}
}
Expand All @@ -651,37 +663,47 @@ func (r *CalicoManager) assertImageVersions() error {
case "calico/kube-controllers":
for _, reg := range r.imageRegistries {
out, err := r.runner.Run("docker", []string{"run", "--rm", fmt.Sprintf("%s/%s:%s", reg, imageName, r.calicoVersion), "--version"}, nil)
if err != nil || !strings.Contains(out, r.calicoVersion) {
if err != nil {
return fmt.Errorf("failed to run get version from %s image: %s", imageName, err)
} else if !strings.Contains(out, r.calicoVersion) {
return fmt.Errorf("version does not match for image %s/%s:%s", reg, imageName, r.calicoVersion)
}
}
case "calico/node":
for _, reg := range r.imageRegistries {
out, err := r.runner.Run("docker", []string{"run", "--rm", fmt.Sprintf("%s/%s:%s", reg, imageName, r.calicoVersion), "versions"}, nil)
if err != nil || !strings.Contains(out, r.calicoVersion) {
if err != nil {
return fmt.Errorf("failed to run get version from %s image: %s", imageName, err)
} else if !strings.Contains(out, r.calicoVersion) {
return fmt.Errorf("version does not match for image %s/%s:%s", reg, imageName, r.calicoVersion)
}
}
case "calico/node-driver-registrar": // pod2daemon
case "calico/node-driver-registrar":
for _, reg := range r.imageRegistries {
out, err := r.runner.Run("docker", []string{"inspect", `--format='{{ index .Config.Labels "version" }}'`, fmt.Sprintf("%s/%s:%s", reg, imageName, r.calicoVersion)}, nil)
if err != nil || !strings.Contains(out, r.calicoVersion) {
if err != nil {
return fmt.Errorf("failed to run get version from %s image: %s", imageName, err)
} else if !strings.Contains(out, r.calicoVersion) {
return fmt.Errorf("version does not match for image %s/%s:%s", reg, imageName, r.calicoVersion)
}
}
case "calico/pod2daemon-flexvol": // pod2daemon
case "calico/pod2daemon-flexvol":
for _, reg := range r.imageRegistries {
out, err := r.runner.Run("docker", []string{"inspect", `--format='{{ index .Config.Labels "version" }}'`, fmt.Sprintf("%s/%s:%s", reg, imageName, r.calicoVersion)}, nil)
if err != nil || !strings.Contains(out, r.calicoVersion) {
if err != nil {
return fmt.Errorf("failed to run get version from %s image: %s", imageName, err)
} else if !strings.Contains(out, r.calicoVersion) {
return fmt.Errorf("version does not match for image %s/%s:%s", reg, imageName, r.calicoVersion)
}
}
case "calico/test-signer": // key-cert-provisioner
case "calico/test-signer":
// test-signer does not have version information in the image.
case "calico/typha":
for _, reg := range r.imageRegistries {
out, err := r.runner.Run("docker", []string{"run", "--rm", fmt.Sprintf("%s/%s:%s", reg, imageName, r.calicoVersion), "calico-typha", "--version"}, nil)
if err != nil || !strings.Contains(out, r.calicoVersion) {
if err != nil {
return fmt.Errorf("failed to run get version from %s image: %s", imageName, err)
} else if !strings.Contains(out, r.calicoVersion) {
return fmt.Errorf("version does not match for image %s/%s:%s", reg, imageName, r.calicoVersion)
}
}
Expand Down

0 comments on commit a1cae27

Please sign in to comment.