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

fix(k8s): compareDeployedResources & manifest hash annotations #3386

Closed
wants to merge 2 commits into from

Conversation

stefreak
Copy link
Member

@stefreak stefreak commented Nov 25, 2022

What this PR does / why we need it:

  • fix(k8s): compareDeployedResources should not ignore manifest hash

compareDeployedResources actually just skipped isSubset check in case
the manifest hash was present.

Now it actually returns "outdated" when manifest hash differs.

This is necessary if the manifest removes annotations that are
present in the deployed manifest.

E.g.:

  1. upsert annotations: {"some-annotation": "present"}
  2. upsert annotations: {}

before this change, compareDeployedResources just returned "ready"
even though the deployedManifest was actually outdated (the annotation
needed to be removed)

This commit fixes that

  • fix(k8s): add manifest-hash annotations also for upsert operations

previously we added garden manifest-hash only for kubectl apply ops.

This commit makes sure to add the manifest-hash also for upserts.

This enables for more accurate (and quicker) comparison results in
compareDeployedResources for the affected resources.

Which issue(s) this PR fixes:

Fixes #

Special notes for your reviewer:

compareDeployedResources actually just skipped isSubset check in case
the manifest hash was present.

Now it actually returns "outdated" when manifest hash differs.

This is necessary if the manifest removes annotations that are
present in the deployed manifest.

E.g.:

1. upsert annotations: {"some-annotation": "present"}
2. upsert annotations: {}

before this change, compareDeployedResources just returned "ready"
even though the deployedManifest was actually outdated (the annotation
needed to be removed)

This commit fixes that
previously we added garden manifest-hash only for kubectl apply ops.

This commit makes sure to add the manifest-hash also for upserts.

This enables for more accurate (and quicker) comparison results in
compareDeployedResources for the affected resources.
@stefreak stefreak force-pushed the fix-compareDeployedResources branch from e12d77a to 10b2d1c Compare November 25, 2022 18:09
continue
if (lastAppliedHashed) {
const calculated = await hashManifest(manifest)
if (calculated !== lastAppliedHashed) {
Copy link
Member Author

@stefreak stefreak Nov 25, 2022

Choose a reason for hiding this comment

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

Probably we should keep the continue if it's equal – that way we are saving some cpu cycles.

Copy link
Member Author

@stefreak stefreak Nov 25, 2022

Choose a reason for hiding this comment

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

Suggested change
if (calculated !== lastAppliedHashed) {
if (calculated === lastAppliedHashed) {
continue
} else {

@@ -597,6 +597,17 @@ export class KubeApi {
obj: O
log: LogEntry
}) {
// Hash the raw input and add as an annotation on each manifest (this is helpful beyond kubectl's own annotation,
Copy link
Member Author

Choose a reason for hiding this comment

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

this code block is copied from apply() and should be extracted to a helper method

@vvagaytsev
Copy link
Collaborator

There are some test failures. I'll convert this to a draft, and will try to take a look later this week.

@vvagaytsev vvagaytsev marked this pull request as draft November 29, 2022 10:03
@stefreak stefreak closed this Jan 30, 2023
@vvagaytsev vvagaytsev deleted the fix-compareDeployedResources branch June 11, 2024 06:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants