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

Support pre-sync annotations #1433

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

tiffanny29631
Copy link
Contributor

No description provided.

Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please ask for approval from tiffanny29631. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

pkg/parse/run.go Outdated Show resolved Hide resolved
pkg/parse/run.go Outdated Show resolved Hide resolved
return status.APIServerError(err, "failed to get RootSync for parser")
}
existing := rs.DeepCopy()
core.SetAnnotation(rs, metadata.SourceCommitAnnotationKey, commit)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggest checking the existing annotations to avoid unnecessary updates if they're the same.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added check. Also added similar check in resetSourceAnnotations when removing the annotations when sourceType switched or set to Git.

pkg/parse/root.go Outdated Show resolved Hide resolved
Copy link
Contributor

@sdowell sdowell left a comment

Choose a reason for hiding this comment

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

Please add context to the commit message and PR description


// ImageURLAnnotationKey is the annotation key applied to R*Sync objects
// when pre-sync is either disabled or successfully completed.
// This annotation stores the Git commit hash or image digest.
Copy link
Contributor

Choose a reason for hiding this comment

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

This is misleading, it looks like this never maps to a Git commit hash. It's currently only set if the sourceType != git, i.e. for oci or helm. Is this behavior intentional?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just modified the comment to align with behavior.

@@ -261,6 +261,38 @@ func setSourceStatusFields(source *v1beta1.SourceStatus, newStatus *SourceStatus
source.LastUpdate = newStatus.LastUpdate
}

func (p *root) setSourceAnnotations(ctx context.Context, commit string) error {
rs := &v1beta1.RootSync{}
if err := p.Client.Get(ctx, rootsync.ObjectKey(p.SyncName), rs); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the get necessary? Seems like this patch does not require a get

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It compares the annotations with the new values to avoid unnecessary patching.

Copy link
Contributor

Choose a reason for hiding this comment

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

Alternatively, instead of merging from existing object, we can patch directly with the raw patch data, client.RawPatch. With that, we don't need to GET and check for changes.

err = p.setSourceAnnotations(ctx, gs.Commit)
}
if err != nil {
gs.Errs = status.Append(gs.Errs, status.SourceError.Wrap(err).Build())
Copy link
Contributor

Choose a reason for hiding this comment

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

There are no test cases which cover this scenario

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For now, setting or removing annotations should always succeed since the end-to-end test involving the webhook check has not been implemented yet. In the future, when the webhook service that verifies image signatures is in place, we will be able to simulate error scenarios where patching (setting annotations) fails, and then validate the source errors accordingly.

Copy link
Contributor

Choose a reason for hiding this comment

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

IMO that functionality is fundamental to this feature and the feature should not be submitted without test coverage for it. What's the motivation for submitting this feature before validating the webhook user journey?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fair, I could keep this open until the commit for the full user journey is ready. The original intention was to keep the steps small and make this change only adds the annotations, maybe I can leave the part of returning the SourceError out from this PR for now?

pkg/parse/run.go Outdated
if gs.Errs == nil {
var err error
if opts.SourceType == "git" {
err = p.resetSourceAnnotations(ctx)
Copy link
Contributor

@nan-yu nan-yu Sep 18, 2024

Choose a reason for hiding this comment

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

Suggest merging resetSourceAnnotations and setSourceAnnotations.

The consolidated setSourceAnnotations function should

  1. always set the source-commit annotation.
  2. Do not set the image-url annotation for Git sources, while set it to p.Options.SourceRepo for OCI and Helm.

Copy link
Contributor

Choose a reason for hiding this comment

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

For future-proofing, let's rename image-url to source-url, but still keep it unset for the Git source.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done with the latest patch, the source-commit is no longer removed when switching back to git. Modified the tests to reflect that.

pkg/metadata/annotations.go Outdated Show resolved Hide resolved
pkg/metadata/annotations.go Outdated Show resolved Hide resolved
@tiffanny29631 tiffanny29631 force-pushed the oci-reconciler-change branch 4 times, most recently from cd2f486 to dcfca04 Compare September 19, 2024 17:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants