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

Calculate Clusters resourceCount from BundleDeployments instead of GitRepos #3102

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

aruiz14
Copy link
Contributor

@aruiz14 aruiz14 commented Nov 27, 2024

Refers to rancher/rancher#46916

Description

status.resourceCounts for cluster.fleet.cattle.io is calculated from GitRepos statuses (which include an equivalent resourceCounts field. This causes the count to be incorrect, since a GitRepo could deploy resources to different Clusters.

How to reproduce the issue

  1. Setup Rancher/Fleet with more than 1 downstream clusters
  2. Add a GitRepo that deploys to all downstream clusters
  3. Describe the status of any of the clusters and observe that status.resourceCounts is wrong, since it also includes resources deployed to other namespaces.

Description of the fix

This can be fixed by populating Clusters' status.resourceCounts from their respective BundleDeployments, similarly to how it's calculated for GitRepos. In order to do this in a clean way, I had to move that code out of the gitops reconciler to its own package.

In addition, I've added some changes to make the existing code a bit more efficient:

  • Filter bundleDeployment.Items while it's being modified, removing the need to keep a separate map of deleted objects.
  • Create an index (map) of bundles to be deleted, instead of having a double for loop.
  • Removed duplicity of repoKey type, which was the same as types.NamespacedKey.

@aruiz14 aruiz14 requested a review from a team as a code owner November 27, 2024 11:03
@aruiz14 aruiz14 changed the title Calculate resourceCount from BundleDeployments instead of GitRepos Calculate Clusters resourceCount from BundleDeployments instead of GitRepos Nov 27, 2024
Comment on lines +167 to +170
// Omit fleet-agent bundle deployments from resource counts
if strings.HasPrefix(bd.Name, "fleet-agent") {
return true
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This has an effect on the calculations performed later, since fleet-agent bundles (and its k8s resources) will be omitted from any calculations and display. This is also reflected in the e2e that started failing:

Checks status updates happen for a simple deployment when deployment is successful [It] correctly sets the status values for Clusters
...
  Expected
      <string>: '1/1'
  to equal
      <string>: '2/2'

However, the actual test expectation would not be obvious if you don't know that fleet-agents are deployed using bundles (e.g. why it expects 2 ready bundles if I only deployed 1?).
I thought users may have the same confusion, and I added this for that reason, but happy to revert if if you think otherwise.

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.

1 participant