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: retain count and order of revisions for multi source apps (#14108) #14113

Merged
merged 4 commits into from
Jun 20, 2023

Conversation

woehrl01
Copy link
Contributor

@woehrl01 woehrl01 commented Jun 18, 2023

Fixes #14108
Fixes #14109

Supersedes #14081

Note on DCO:

If the DCO action in the integration test fails, one or more of your commits are not signed off. Please click on the Details link next to the DCO action for instructions on how to resolve this.

Checklist:

  • Either (a) I've created an enhancement proposal and discussed it with the community, (b) this is a bug fix, or (c) this does not need to be in the release notes.
  • The title of the PR states what changed and the related issues number (used for the release note).
  • The title of the PR conforms to the Toolchain Guide
  • I've included "Closes [ISSUE #]" or "Fixes [ISSUE #]" in the description to automatically close the associated issue.
  • I've updated both the CLI and UI to expose my feature, or I plan to submit a second PR with them.
  • Does this PR require documentation updates?
  • I've updated documentation as required by this PR.
  • Optional. My organization is added to USERS.md.
  • I have signed off all my commits as required by DCO
  • I have written unit and/or e2e tests for my change. PRs without these are unlikely to be merged.
  • My build is green (troubleshooting builds).
  • My new feature complies with the feature status guidelines.
  • I have added a brief description of why this PR is necessary and/or what this PR solves.

Please see Contribution FAQs if you have questions about your pull-request.

@woehrl01 woehrl01 force-pushed the fix_revision_order branch from f876ebe to 7519ed6 Compare June 18, 2023 11:26
@codecov
Copy link

codecov bot commented Jun 18, 2023

Codecov Report

Patch coverage: 100.00% and project coverage change: -0.01 ⚠️

Comparison is base (8f63ba3) 49.61% compared to head (189952f) 49.61%.

❗ Current head 189952f differs from pull request most recent head 0a7837a. Consider uploading reports for the commit 0a7837a to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #14113      +/-   ##
==========================================
- Coverage   49.61%   49.61%   -0.01%     
==========================================
  Files         256      256              
  Lines       43934    43924      -10     
==========================================
- Hits        21800    21795       -5     
+ Misses      19975    19972       -3     
+ Partials     2159     2157       -2     
Impacted Files Coverage Δ
controller/state.go 71.78% <100.00%> (+0.35%) ⬆️

... and 1 file with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@ishitasequeira
Copy link
Member

ishitasequeira commented Jun 20, 2023

One thing to note is that, for the repo used just as a reference to values files (e.g. In below example, ref-repo), we do not generate any manifests and thus do not end up printing revision for the same. This leads to not mentioning the revision of the referenced repository used for external values files.

See below example,

spec:
  sources:
  - helm:
      valueFiles:
      - $values_test/values.yaml
    path: helm-guestbook
    repoURL: https://github.com/argoproj/argocd-example-apps.git
    targetRevision: HEAD
  - ref: values_test                          <--------------------------------- ref-Repo
    repoURL: https://github.com/ishitasequeira/values-test.git
    targetRevision: HEAD
status:
    revisions:
    - 53e28ff20cc530b9ada2173fbbd64d48338583ba

Also, if there are more than one repositories, it is difficult to associate which revision belongs to which repository. (below example)

spec:
  sources:
  - helm:
      valueFiles:
      - $values_test/values.yaml
    path: helm-guestbook
    repoURL: https://github.com/argoproj/argocd-example-apps.git
    targetRevision: HEAD
  - ref: values_test
    repoURL: https://github.com/ishitasequeira/values-test.git
    targetRevision: HEAD
  - path: guestbook
    repoURL: https://github.com/ishitasequeira/argocd-example-apps.git
    targetRevision: HEAD
status:
      revisions:
      - 53e28ff20cc530b9ada2173fbbd64d48338583ba
      - 86f65c1eacddba892814445f88631101b55f4bcf

In my opinion, it was okay to show revision directly earlier when we had only one source. But with multiple sources, we should add source to the revision as well (only for status.revisions). Something like below:

status:
      revisions:
      - repoUrl: https://github.com/argoproj/argocd-example-apps.git
        revision: 53e28ff20cc530b9ada2173fbbd64d48338583ba
      - repoUrl: https://github.com/ishitasequeira/argocd-example-apps.git
        revision: 86f65c1eacddba892814445f88631101b55f4bcf

Let me know what do you think.

cc: @crenshaw-dev

@woehrl01
Copy link
Contributor Author

@ishitasequeira there is a place in the code with skips the revision if there is no manifest, I suggest removing that case for the revision output. Then the revisions always align up by index.

@woehrl01
Copy link
Contributor Author

woehrl01 commented Jun 20, 2023

I just pushed the changes. This will also directly fix a recurring cache invalidation bug, where the results would never be cached in the mentioned case of @ishitasequeira , because the length of the array will never be the same.

argo-cd/controller/state.go

Lines 532 to 536 in b392917

revisionChanged := len(manifestInfoMap) != len(sources) || !reflect.DeepEqual(app.Status.Sync.Revisions, manifestRevisions)
specChanged := !reflect.DeepEqual(app.Status.Sync.ComparedTo, v1alpha1.ComparedTo{Source: app.Spec.GetSource(), Destination: app.Spec.Destination, Sources: sources})
_, refreshRequested := app.IsRefreshRequested()
noCache = noCache || refreshRequested || app.Status.Expired(m.statusRefreshTimeout) || specChanged || revisionChanged

@crenshaw-dev
Copy link
Member

I think listing all revisions and using the index as key is fine, as long as the change doesn't have any unfortunate side-effects (looking at the PR, I don't think it does).

@crenshaw-dev crenshaw-dev changed the title fix: retain order of revisions for multi source apps (#14108) fix: retain count and order of revisions for multi source apps (#14108) Jun 20, 2023
@crenshaw-dev
Copy link
Member

The second revision is appearing as an empty string for me.

image

@woehrl01
Copy link
Contributor Author

woehrl01 commented Jun 20, 2023

@crenshaw-dev Looks like this is related to the following condition:

if hasMultipleSources && source.Path == "" && source.Chart == "" {
log.WithFields(map[string]interface{}{
"source": source,
}).Debugf("not generating manifests as path and chart fields are empty")
return nil
}

I currently don't see a reason for having this check in place?

@ishitasequeira
Copy link
Member

@crenshaw-dev Looks like this is related to the following condition:

if hasMultipleSources && source.Path == "" && source.Chart == "" {
log.WithFields(map[string]interface{}{
"source": source,
}).Debugf("not generating manifests as path and chart fields are empty")
return nil
}

That is the expected condition and we would not want to remove that as we are not generating manifests for the specific scenarios when the source does not have a path / chart in the repo. The source can be used only for external values files.

@woehrl01
Copy link
Contributor Author

@ishitasequeira I see. But we still have to process this method to return the resolving of the ref (e.g. HEAD) to commit hash, don't we?

@woehrl01
Copy link
Contributor Author

@ishitasequeira after looking at the code, and getting a bit familiar with it, my suggestion would be to slightly modify this part:

operation := func(repoRoot, commitSHA, cacheKey string, ctxSrc operationContextSrc) error {
promise = s.runManifestGen(ctx, repoRoot, commitSHA, cacheKey, ctxSrc, q)
// The fist channel to send the message will resume this operation.
// The main purpose for using channels here is to be able to unlock
// the repository as soon as the lock in not required anymore. In
// case of CMP the repo is compressed (tgz) and sent to the cmp-server
// for manifest generation.
select {
case err := <-promise.errCh:
return err
case resp := <-promise.responseCh:
res = resp
case tarDone := <-promise.tarDoneCh:
tarConcluded = tarDone
}
return nil
}

So that it has a new argument to not generate a manifest, but it returns the correct "ManifestResponse", instead of this:

if q.HasMultipleSources && err == nil && res == nil {
res = &apiclient.ManifestResponse{}
}

Thoughts?

@woehrl01
Copy link
Contributor Author

like this 93b0273 @ishitasequeira CC: @crenshaw-dev

Created that in my fork, to get your opinion.

@ishitasequeira
Copy link
Member

I think that should work.. Thanks @woehrl01 !!

@crenshaw-dev
Copy link
Member

@woehrl01 how do you feel about this slightly simplified version? woehrl01#1

@woehrl01
Copy link
Contributor Author

woehrl01 commented Jun 20, 2023

Looks great, I'll pick that.

@woehrl01 woehrl01 force-pushed the fix_revision_order branch from b9f9521 to 7519ed6 Compare June 20, 2023 15:01
@crenshaw-dev
Copy link
Member

One downside of my change is that we'll be running some unnecessary manifest-generation-related operations for ref sources (e.g. checking for out-of-bounds symlinks) which could be skipped. But for now I think the performance hit is worth it for a relatively simple fix.

@crenshaw-dev
Copy link
Member

/cherry-pick release-2.6

@crenshaw-dev
Copy link
Member

/cherry-pick release-2.7

@woehrl01
Copy link
Contributor Author

@crenshaw-dev we also have to handle

opContext, err := ctxSrc()

Do you have an idea what would be the best behaviour here? Should we just duplicate the check and return nil?

Copy link
Member

@ishitasequeira ishitasequeira left a comment

Choose a reason for hiding this comment

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

LGTM!!

@crenshaw-dev
Copy link
Member

@woehrl01 I don't think the UI currently hits that endpoint for multi-source apps, precisely because it's not equipped to handle stuff like the ref-only sources. I think it's safe to ignore until someone starts working on multi-source UI support.

@crenshaw-dev crenshaw-dev merged commit 59e6f2c into argoproj:master Jun 20, 2023
@gcp-cherry-pick-bot
Copy link

Cherry-pick failed with Merge error 59e6f2c3ac5029e018cae7bb8f08204597fae773 into temp-cherry-pick-60e3a3-release-2.6

@gcp-cherry-pick-bot
Copy link

Cherry-pick failed with Merge error 59e6f2c3ac5029e018cae7bb8f08204597fae773 into temp-cherry-pick-60e3a3-release-2.7

crenshaw-dev added a commit to crenshaw-dev/argo-cd that referenced this pull request Jun 20, 2023
…roj#14108) (argoproj#14113)

* fix: retain order of revisions for multi source apps (argoproj#14108)

Signed-off-by: Lukas Wöhrl <[email protected]>

* fix: retain revision for multi source app with ref-repos

Signed-off-by: Lukas Wöhrl <[email protected]>

* calculate commitSHA before quitting manifest generation

Signed-off-by: Michael Crenshaw <[email protected]>

---------

Signed-off-by: Lukas Wöhrl <[email protected]>
Signed-off-by: Michael Crenshaw <[email protected]>
Co-authored-by: Michael Crenshaw <[email protected]>
crenshaw-dev added a commit to crenshaw-dev/argo-cd that referenced this pull request Jun 20, 2023
…roj#14108) (argoproj#14113)

* fix: retain order of revisions for multi source apps (argoproj#14108)

Signed-off-by: Lukas Wöhrl <[email protected]>

* fix: retain revision for multi source app with ref-repos

Signed-off-by: Lukas Wöhrl <[email protected]>

* calculate commitSHA before quitting manifest generation

Signed-off-by: Michael Crenshaw <[email protected]>

---------

Signed-off-by: Lukas Wöhrl <[email protected]>
Signed-off-by: Michael Crenshaw <[email protected]>
Co-authored-by: Michael Crenshaw <[email protected]>
@crenshaw-dev
Copy link
Member

Fixes will be in 2.6.11 and 2.7.6.

crenshaw-dev added a commit that referenced this pull request Jun 20, 2023
… (#14113) (#14136)

* fix: retain order of revisions for multi source apps (#14108)



* fix: retain revision for multi source app with ref-repos



* calculate commitSHA before quitting manifest generation



---------

Signed-off-by: Lukas Wöhrl <[email protected]>
Signed-off-by: Michael Crenshaw <[email protected]>
Co-authored-by: Lukas Wöhrl <[email protected]>
crenshaw-dev added a commit that referenced this pull request Jun 20, 2023
… (#14113) (#14135)

* fix: retain order of revisions for multi source apps (#14108)



* fix: retain revision for multi source app with ref-repos



* calculate commitSHA before quitting manifest generation



---------

Signed-off-by: Lukas Wöhrl <[email protected]>
Signed-off-by: Michael Crenshaw <[email protected]>
Co-authored-by: Lukas Wöhrl <[email protected]>
schakrad pushed a commit to schakrad/argo-cd that referenced this pull request Jul 24, 2023
…roj#14108) (argoproj#14113) (argoproj#14135)

* fix: retain order of revisions for multi source apps (argoproj#14108)

* fix: retain revision for multi source app with ref-repos

* calculate commitSHA before quitting manifest generation

---------

Signed-off-by: Lukas Wöhrl <[email protected]>
Signed-off-by: Michael Crenshaw <[email protected]>
Co-authored-by: Lukas Wöhrl <[email protected]>
Signed-off-by: schakrad <[email protected]>
yyzxw pushed a commit to yyzxw/argo-cd that referenced this pull request Aug 9, 2023
…roj#14108) (argoproj#14113)

* fix: retain order of revisions for multi source apps (argoproj#14108)

Signed-off-by: Lukas Wöhrl <[email protected]>

* fix: retain revision for multi source app with ref-repos

Signed-off-by: Lukas Wöhrl <[email protected]>

* calculate commitSHA before quitting manifest generation

Signed-off-by: Michael Crenshaw <[email protected]>

---------

Signed-off-by: Lukas Wöhrl <[email protected]>
Signed-off-by: Michael Crenshaw <[email protected]>
Co-authored-by: Michael Crenshaw <[email protected]>
tesla59 pushed a commit to tesla59/argo-cd that referenced this pull request Dec 16, 2023
…roj#14108) (argoproj#14113)

* fix: retain order of revisions for multi source apps (argoproj#14108)

Signed-off-by: Lukas Wöhrl <[email protected]>

* fix: retain revision for multi source app with ref-repos

Signed-off-by: Lukas Wöhrl <[email protected]>

* calculate commitSHA before quitting manifest generation

Signed-off-by: Michael Crenshaw <[email protected]>

---------

Signed-off-by: Lukas Wöhrl <[email protected]>
Signed-off-by: Michael Crenshaw <[email protected]>
Co-authored-by: Michael Crenshaw <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants