fleet: [SURE-8849] fleet incorrectly reports pre-existing resources as missing when setting helm.takeOwnership: true
Is there an existing issue for this?
- I have searched the existing issues
Current Behavior
When settings helm.takeOwernship: true , the chart deployment will add the standard helm labels and annotations to an existing object. E.g.:
apiVersion: ceph.rook.io/v1
kind: CephFilesystem
metadata:
annotations:
meta.helm.sh/release-name: rook-ceph-conf
meta.helm.sh/release-namespace: rook-ceph
...
labels:
app.kubernetes.io/managed-by: Helm
However, fleet-agent will complain about missing resources:
time="2024-02-07T23:16:25Z" level=error msg="bundle kueyen-only-kueyen-fleet-rook-ceph-conf: cephfilesystem.ceph.rook.io rook-ceph/obs-env missing"
As will the bundle and bundleDeployment resources:
NAME DEPLOYED MONITORED STATUS
kueyen-only-kueyen-fleet-rook-ceph-conf True True cephfilesystem.ceph.rook.io rook-ceph/obs-env missing
NAME BUNDLEDEPLOYMENTS-READY STATUS
kueyen-only-kueyen-fleet-rook-ceph-conf 0/1 Modified(1) [Cluster fleet-default/kueyen]; cephfilesystem.ceph.rook.io rook-ceph/obs-env missing; cephnfs.ceph.rook.io rook-ceph/obs-env missing; cephobjectstore.ceph.rook.io rook-ceph/lfa missing
Expected Behavior
I expect that “fleet” takes ownership of existing resources and does not report them as missing (when they exists!).
The resource is reported as missing because the pre-existing resources do not have the objectset.rio.cattle.io/hash label and objectset.rio.cattle.io/id annotation set. E.g.:
annotations:
objectset.rio.cattle.io/id: default-kueyen-only-kueyen-fleet-rook-ceph-conf
...
labels:
app.kubernetes.io/managed-by: Helm
objectset.rio.cattle.io/hash: 563cb3553e5fba84eee5ba3054b9b537c653465a
...
Manually copying the value of objectset.rio.cattle.io/hash from another resource resolves the “missing” resource warning.
Steps To Reproduce
- Manually create a resource
- Create a fleet bundle with
helm.takeOwnership: truewith a duplicate of that resource - Observe warnings on the
bundle,bundleDeploymentresources and in thefleet-agentlogs.
Environment
- Architecture: x86-64
- Fleet Version: 0.9.0 (rancher 2.8.1)
- Cluster:
- Provider: RKE1
- Kubernetes Version: v1.25.9
Logs
No response
Anything else?
No response
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 21 (15 by maintainers)
Commits related to this issue
- BundleDeployment error message improvement When a resource of a BundleDeployment is removed after the Bundle has been created, the BundleDeployment says it is missing. This is also the case if the re... — committed to p-se/fleet by p-se 2 years ago
- BundleDeployment error message improvement When a resource of a BundleDeployment is removed after the Bundle has been created, the BundleDeployment says it is missing. This is also the case if the re... — committed to p-se/fleet by p-se 2 years ago
- BundleDeployment error message improvement When a resource of a BundleDeployment is removed after the Bundle has been created, the BundleDeployment says it is missing. This is also the case if the re... — committed to p-se/fleet by p-se 2 years ago
- BundleDeployment error message improvement When a resource of a BundleDeployment is removed after the Bundle has been created, the BundleDeployment says it is missing. This is also the case if the re... — committed to p-se/fleet by p-se 2 years ago
- BundleDeployment error message improvement When a resource of a BundleDeployment is removed after the Bundle has been created, the BundleDeployment says it is missing. This is also the case if the re... — committed to p-se/fleet by p-se 2 years ago
- BundleDeployment error message improvement When a resource of a BundleDeployment is removed after the Bundle has been created, the BundleDeployment says it is missing. This is also the case if the re... — committed to p-se/fleet by p-se 2 years ago
- BundleDeployment error message improvement When a resource of a BundleDeployment is removed after the Bundle has been created, the BundleDeployment says it is missing. This is also the case if the re... — committed to p-se/fleet by p-se 2 years ago
Our contribution to helm to fix this issue has been merged. Also, the contribution has already been backported to the v3 branch, which means that we expect the next helm v3 release, which, according to the last release notes is going to be 3.18.0, to contain the fix. We will then update the helm version we use in Fleet, which will resolve this issue. The next helm release is scheduled for May 14, 2025.
As it turns out, the issue occurs because of custom resources. This does not happen with native resources. The culprit here is that helm treats native resources differently. Adoption (as in setting takeOwnership to true) of resources internally works like a
helm update.Updating native resources with helm is done in a three-way-merge, that means the current release is compared to what it is supposed to become, but the current state of the object in the cluster is also considered.
For custom resources helm only does a two-way merge and only considers the current release and the state to be updated to. The current implementation of fleet does not differentiate between native or custom resources.
When fleet adopts resources, no (helm) release exists. But to be able to perform an update, it needs to pretend it does. The “current” release is set to the same version of the resource as the desired state. Only due to the fact that the actual state of the resource in the cluster is considered, the patch creation, and therefore the adoption, works properly.
However, when fleet adopts a custom resource, only the “current” release and desired state are considered to create the patch, not the actual state of the object in the cluster. This leads the patch creation logic to return an empty patch and explains why the adoption of custom resources appears to succeed while in reality, nothing happens.
There are two options on how to proceed here, but in both cases, we need to adapt helm.
The first option is to adapt the code that adopts resources so that, in case a custom resource is spotted, the “current” release (which really doesn’t exist at that point yet) is to be changed in a way that the patch created from this state and the desired state not only succeeds and does not result in an empty patch, but the resource is properly adopted, which means that values from the actual state are preserved. For that, the actual state of the object needs to be considered.
The second option is to extend helm to use a three-way-merge even in case of custom resources as has been discussed in https://github.com/helm/helm/issues/9937. We’re inclined to do that.
Also, this issue seems to be related to https://github.com/rancher/fleet/issues/2805.
I have a somewhat related issue and i’m not sure how to proceed, do you have some advice? I’m in the process of migrating resources that were previously not managed by fleet into fleet, and as part of that, i’m importing CRDs that are already deployed on clusters into a new fleet bundle. simply deleting and re-creating everything is not an option in my scenario.
In my case, the issue manifests itself as this error instead (just noting it here for the record since it was quite difficult to figure out the connection):
Now i was wondering if there is any way i can get these existing CRDs imported, so i tried applying the manifests manually in a super hacky way like this:
but this of course doesn’t account for the fact that in my case, there isn’t a helm release yet, so fleet-agent still can’t operate properly.
So now i’m thinking: i guess the only way to import the CRDs is
would this work? am i understanding the underlying issue correctly? do you have another suggestion for my particular case?
(informal side-note: i think https://github.com/werf/nelm also fixes the issue now, but it’s probably not an option to use that in fleet i assume)
I’ve created https://github.com/helm/helm/pull/13411.