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

Update to allowing building and publishing images in hashrelease #9429

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

radTuti
Copy link
Contributor

@radTuti radTuti commented Nov 1, 2024

Description

This allows building and publishing images in hashreleases.

Semaphore allows the ability to distinguish how a workflow is started using SEMAPHORE_WORKFLOW_TRIGGERED_BY_SCHEDULE environment variable.

This allow cleans up some of the hashrelease tasks and move into calico manager or build/main.go

Related issues/PRs

Todos

  • Tests
  • Documentation
  • Release note

Release Note

TBD

Reminder for the reviewer

Make sure that this PR has the correct labels and milestone set.

Every PR needs one docs-* label.

  • docs-pr-required: This change requires a change to the documentation that has not been completed yet.
  • docs-completed: This change has all necessary documentation completed.
  • docs-not-required: This change has no user-facing impact and requires no docs.

Every PR needs one release-note-* label.

  • release-note-required: This PR has user-facing changes. Most PRs should have this label.
  • release-note-not-required: This PR has no user-facing changes.

Other optional labels:

  • cherry-pick-candidate: This PR should be cherry-picked to an earlier release. For bug fixes only.
  • needs-operator-pr: This PR is related to install and requires a corresponding change to the operator.

@radTuti radTuti requested a review from a team as a code owner November 1, 2024 20:08
@marvin-tigera marvin-tigera added this to the Calico v3.30.0 milestone Nov 1, 2024
@marvin-tigera marvin-tigera added release-note-required Change has user-facing impact (no matter how small) docs-pr-required Change is not yet documented labels Nov 1, 2024
@radTuti radTuti added docs-not-required Docs not required for this change release-note-not-required Change has no user-facing impact labels Nov 4, 2024
@marvin-tigera marvin-tigera removed release-note-required Change has user-facing impact (no matter how small) docs-pr-required Change is not yet documented labels Nov 4, 2024
release/Makefile Outdated
@@ -26,8 +26,8 @@ ci: static-checks
###############################################################################
.PHONY: hashrelease
hashrelease: bin/release var-require-all-GITHUB_TOKEN
@bin/release hashrelease build
@bin/release hashrelease publish
@bin/release hashrelease build ${BUILD_ARGS}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we just decouple the hashrelease.yml Semaphore file from the Makefile? I don't think there's any reason it needs to do this complicated passthrough of CLI flags via env vars.

It can just call bin/release directly, passing the arguments that it wants.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively, we can add ENV equivalents for all of the CLI args like we have done for some, and then we can completely configure the CLI arguments via env vars when running in CI.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will switch to ENV.

I am using the make target make hashrelease so that the variables from metdata.mk file gets used

@@ -160,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.", Value: false},
&cli.StringFlag{Name: imageRegistryFlag, Usage: "Specify image registry to use", Value: ""},
&cli.StringFlag{Name: imageRegistryFlag, Usage: "Specify image registry to use", EnvVars: []string{"REGISTRIES", "DEV_REGISTRIES"}, Value: ""},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need DEV_REGISTRIES? I think if nobody is using it we can just have a single env var for this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will switch to just REGISTRIES

return fmt.Sprintf("https://%s.%s", h.Name, BaseDomain)
}

func (h *Hashrelease) AsLatest() *Hashrelease {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This functions seems unnecessary to me - we already have a public Latest field on the struct, so the calling code can just do hr.Latest = true which is much easier to read.

@@ -63,11 +66,41 @@ func WithOutputDir(outputDir string) Option {
}
}

func WithPublishOptions(images, tag, github bool) Option {
func WithPublishOptions(opt ...PublishOptions) Option {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think I like this pattern of nested options. We should just define Option options for all of the things that we want to make configurable. We don't need an option to specify multiple other options. Or do we? Is there something I'm missing?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this makes the configuration a bit more versatile across hashrelease and release. As well as it works better for close source.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As well as it works better for close source.

Could you explain this a bit more? It's not obvious to me how this is better for closed source code.

}
}

func PublishImages() PublishOptions {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
func PublishImages() PublishOptions {
func PublishImages() Option {

if err != nil {
return fmt.Errorf("failed to get tag for checked-out commit, is there one? %s", err)
}
func (r *CalicoManager) publishToHashreleaseServer() error {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it makes sense to do this degree of wrapping - either we make the CalicoManager truly responsible for publishing hashreleases and get rid of hashreleaseserver.PublishHashrelease, or we leave them separate.

I think it's confusing if we're passing configuration to the CalicoManager, just for it to turn around and call the task-based functions in the hashreleaseserver package.

@@ -48,10 +49,6 @@ func NewManager(opts ...Option) *CalicoManager {
b := &CalicoManager{
runner: &command.RealCommandRunner{},
validate: true,
buildImages: true,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these should stay the default for a real release. Hashrelease can override them, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the options only allow setting true.
With release we already pass the value as true

@@ -477,6 +468,9 @@ func (r *CalicoManager) releasePrereqs() error {

// Prerequisites specific to publishing a release.
func (r *CalicoManager) publishPrereqs() error {
if r.isHashRelease {
return nil
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we not have any other hashrelease prereqs? e.g., if it already exists on the server?

I think we're checking that elsewhere, but why not here? Seems better to consolidate into one location. As it stands, it's not obvious when something belongs in the CalicoManager vs. when it just goes into main.go.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can add the check here. However it is in main so that operator images do not get pushed if the hashrelease already exist

@@ -708,7 +708,8 @@ func (r *CalicoManager) buildContainerImages(ver string) error {
return nil
}

func (r *CalicoManager) publishGithubRelease(ver string) error {
func (r *CalicoManager) publishGithubRelease() error {
ver := r.calicoVersion
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should just swap ver for r.calicoVersion instead of using a local variable.

release/pkg/manager/calico/manager.go Show resolved Hide resolved
- key-cert-provisioner: add release-build and release-publish targets
- add ability to skip release notes
- allow changing registry in pinnedversion
- allowing skipping validation for publish
- move hashrelease validation to calico manager
- update .gitignore to ignore publishing identifier files
- fix key-cert-provisioner publishing
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs-not-required Docs not required for this change release-note-not-required Change has no user-facing impact
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants