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 artifact tarball when spec.ignore changes #712

Closed
wants to merge 5 commits into from

Conversation

angelokurtis
Copy link

This commit adds a new field status.artifact.excludedPatternsChecksum which is used to detect changes on spec.ignore, that controls the exclusions for the object's status.artifact.

Fix: #704

@darkowlzz
Copy link
Contributor

Hi, thanks for proposing this solution. Sharing a few thoughts about it:

  • Maybe it'd be better to not mix the terms. The spec has it as ignore, it'd be better to call the new field with the same name.
  • Ignore is an attribute of GitRepo and Bucket only. Adding the checksum field as part of artifact exposes it to all the other source types. Maybe it'd be better to introduce it in the status of GitRepo and Bucket only. There's already status.includedArtifacts in GitRepo. Maybe we could have ignored informtion there as well.

@hiddeco
Copy link
Member

hiddeco commented May 9, 2022

@darkowlzz you are pretty much reflecting my thoughts in #710 :-)

@angelokurtis
Copy link
Author

Hey everyone! Thanks for the feedback!
I updated the PR with your suggestions. Please let me know if you see any other improvements.

Copy link
Contributor

@darkowlzz darkowlzz left a comment

Choose a reason for hiding this comment

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

Thanks for updating the implementation.
Left some inline comments.
The test failure seems to be unrelated.

api/v1beta2/bucket_types.go Outdated Show resolved Hide resolved
api/v1beta2/bucket_types.go Outdated Show resolved Hide resolved
controllers/gitrepository_controller.go Outdated Show resolved Hide resolved
@stefanprodan
Copy link
Member

Please rebase with upstream main, we've fixed the e2e tests.

@angelokurtis angelokurtis force-pushed the fix-excluded-patterns branch 2 times, most recently from 03b53dd to 8f4462f Compare May 10, 2022 21:10
assertConditions: []metav1.Condition{
*conditions.TrueCondition(sourcev1.ArtifactInStorageCondition, meta.SucceededReason, "stored artifact for revision 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'"),
},
},
Copy link
Contributor

@darkowlzz darkowlzz May 11, 2022

Choose a reason for hiding this comment

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

Nice tests.
In the above, we test for cases where ignore is added and removed. Let's also test for the case where the existing value of ignore is updated, would result in a different checksum, not empty.

Same for the GitRepo tests.

Copy link
Author

Choose a reason for hiding this comment

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

Done!

r.eventLogf(ctx, obj, events.EventTypeTrace, sourcev1.ArtifactUpToDateReason, "artifact up-to-date with remote revision: '%s'", artifact.Revision)
return sreconcile.ResultSuccess, nil
}

// Ensure .spec.ignore checksum is up-to-date
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe

Suggested change
// Ensure .spec.ignore checksum is up-to-date
// Ensure .status.ignoreChecksum is up-to-date with .spec.ignore.

Same for the Bucket code.

Copy link
Author

Choose a reason for hiding this comment

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

Done!

@darkowlzz
Copy link
Contributor

Could you also update the spec docs in https://github.com/fluxcd/source-controller/tree/main/docs/spec/v1beta2 for both GitRepo and Bucket in the Status section towards the bottom of the docs with some documentation for the checksum field?

@darkowlzz darkowlzz added enhancement New feature or request area/docs Documentation related issues and pull requests labels May 11, 2022
@@ -211,6 +211,12 @@ type GitRepositoryStatus struct {
// +optional
IncludedArtifacts []*Artifact `json:"includedArtifacts,omitempty"`

// IgnoreChecksum is a checksum of .spec.ignore in .status.observedGeneration
// version of the object.
// It is formatted as `<algo>:<checksum>`. For example: `sha256:<checksum>`.
Copy link
Member

Choose a reason for hiding this comment

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

Same comment.

Copy link
Author

Choose a reason for hiding this comment

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

Done!

@@ -124,6 +124,12 @@ type BucketStatus struct {
// +optional
Artifact *Artifact `json:"artifact,omitempty"`

// IgnoreChecksum is a checksum of .spec.ignore in .status.observedGeneration
// version of the object.
// It is formatted as `<algo>:<checksum>`. For example: `sha256:<checksum>`.
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
// It is formatted as `<algo>:<checksum>`. For example: `sha256:<checksum>`.
// It has the format of `<algo>:<checksum>`, for example: `sha256:<checksum>`.

Copy link
Author

Choose a reason for hiding this comment

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

Done!

@@ -42,6 +41,8 @@ import (
"sigs.k8s.io/controller-runtime/pkg/predicate"
"sigs.k8s.io/controller-runtime/pkg/ratelimiter"

"github.com/fluxcd/source-controller/pkg/azure"
Copy link
Member

Choose a reason for hiding this comment

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

This should be moved to block on L53.

Copy link
Author

Choose a reason for hiding this comment

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

Done!

@hiddeco hiddeco added area/git Git related issues and pull requests area/bucket Bucket related issues and pull requests labels May 11, 2022
This commit adds a new field `status.ignoreChecksum` which is used to detect changes on `spec.ignore`, that controls the exclusions for the object's `status.artifact`

Signed-off-by: Tiago Angelo <kurtis.angelo@gmail.com>
Signed-off-by: Tiago Angelo <kurtis.angelo@gmail.com>
Signed-off-by: Tiago Angelo <kurtis.angelo@gmail.com>
Signed-off-by: Tiago Angelo <kurtis.angelo@gmail.com>
Copy link
Member

@hiddeco hiddeco left a comment

Choose a reason for hiding this comment

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

This is code-wise looking picture perfect to me, thank you very much for being patient with our feedback 💯

One last request: could you add the fields to the spec documentation for both object kinds? A tiny description in the Status section about what it is, and what it triggers is sufficient. 🙇

Signed-off-by: Tiago Angelo <kurtis.angelo@gmail.com>
@angelokurtis
Copy link
Author

Hi guys, thanks for the support!
Please, let me know if you see any other improvements.

Comment on lines +949 to +951
The source-controller calculates the SHA256 checksum of the last Bucket's
[`.spec.ignore` field](#ignore) and record it in the `.status.ignoreChecksum` field. This field
is used to detect `.spec.ignore` updates to allow artifact changes.
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
The source-controller calculates the SHA256 checksum of the last Bucket's
[`.spec.ignore` field](#ignore) and record it in the `.status.ignoreChecksum` field. This field
is used to detect `.spec.ignore` updates to allow artifact changes.
The source-controller calculates the SHA256 checksum Bucket's [`.spec.ignore` field](#ignore),
and records it in `.status.ignoreChecksum`. This field is used to detect `.spec.ignore` changes to
trigger an Artifact update.

@@ -838,6 +838,12 @@ Note that a GitRepository can be [reconciling](#reconciling-gitrepository)
while failing at the same time, for example due to a newly introduced
configuration issue in the GitRepository spec.

### Ignore Checksum

The source-controller calculates the SHA256 checksum of the last GitRepository's
Copy link
Member

Choose a reason for hiding this comment

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

Same suggestion applies here.

@darkowlzz
Copy link
Contributor

Hi, due to some recent changes in the main branch, we had to restructure a lot of the code in GitRepo reconciler. A rough work on fixing that is in https://github.com/fluxcd/source-controller/compare/gitrepo-rec-fixes . It changes how we figure out if the source needs to be reconciled completely or not, similar to detecting changes to spec.ignore in this PR. The new work introduces a contentConfigChecksum field in the API, which includes the ignore value and many other fields that contribute to a new artifact to be built https://github.com/fluxcd/source-controller/compare/gitrepo-rec-fixes?expand=1#diff-4472354d9c6813ee6537b2625d7aa7eef2522f48bc45548c1397f207ff85cbc9R214-R223 .
I'd recommend to wait for that change to be finalized and merged first, and then based on those changes, add a similar change for the Bucket reconciler for detecting ignore + all other config changes.
Sorry for this. It wasn't planned before but the solution to fixing other stuff covers the issue that this PR tries to fix.

@darkowlzz
Copy link
Contributor

darkowlzz commented Jun 6, 2022

@angelokurtis flux v0.31.0 was just released with the aforementioned improvements in the GitRepo reconciler. Your initial issue #704 is closed. But you can still add a similar change in the Bucket reconciler based on the GitRepo reconcile change in 581695b. We can introduce the same field contentConfigChecksum in the status of a Bucket object and use it to detect changes. This may also result in restructuring some parts of the Bucket reconciler, but I think that's okay. Feel free to ask any questions about it that you may have.

@stefanprodan
Copy link
Member

Superseded by #926

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/bucket Bucket related issues and pull requests area/docs Documentation related issues and pull requests area/git Git related issues and pull requests enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Updating the spec.ignore field of a GitRepository has no effect
4 participants