mappings cannot target metadata
lukebond opened this issue · comments
consider the following ResourceSync
, taken from our current system:
apiVersion: sinker.influxdata.io/v1alpha1
kind: ResourceSync
metadata:
name: cluster-0001-kustomization-status
namespace: customer-0001
spec:
mappings:
- fromFieldPath: status
toFieldPath: spec
- fromFieldPath: metadata.labels
toFieldPath: metadata.labels
source:
cluster:
kubeConfig:
secretRef:
key: value
name: cluster-0001-kubeconfig
namespace: iox
resourceRef:
apiVersion: kustomize.toolkit.fluxcd.io/v1beta2
kind: Kustomization
name: iox-manifests
target:
resourceRef:
apiVersion: tubernetes.influxdata.io/v1beta2
kind: FluxcdKustomizationStatus
name: iox-manifests
note that it has a mapping to copy the labels from source to target.
this doesn't work because on this line it is root.data
that is passed into the set_field_path
function: https://github.com/influxdata/sinker/blob/main/src/controller.rs#L168
root.data
contains { spec: {...}, status: {...} }
, the metadata is kept outside of the data
object.
the result is that there results in two .metadata
objects! somewhere one gets dropped.
i have a failing test for this, will work on a fix.
Nice find. Something that comes to mind as I read this issue is that it is important that sinker only take ownership of the labels it sets, not all labels, assuming it uses SSA. Do you think that is achievable? Written as a general feature, "sinker should take ownership of only leaf nodes of the jsonpath graph."
assuming it uses SSA
it does
Do you think that is achievable?
i don't know :/ i'll make the change and see what it does to managed fields and report back. solvitur ambulando!
okay so i fixed the bug and checked what it did to managedFields:
managedFields:
- apiVersion: tubernetes.influxdata.io/v1beta2
fieldsType: FieldsV1
fieldsV1:
f:metadata:
f:labels: {}
f:spec:
f:conditions: {}
f:inventory:
f:entries: {}
f:lastAppliedRevision: {}
f:lastAttemptedRevision: {}
f:observedGeneration: {}
manager: sinker.influxdata.io
operation: Apply
time: "2023-04-12T13:00:53Z"
not very helpful, because this ResourceSync
is modifying the spec and the labels. i would have to test it on a mapping that modifies only labels to be sure, but it looks like it will own the whole labels object.
here is another where it is copying to spec and to labels, but labels actually existed:
managedFields:
- apiVersion: tubernetes.influxdata.io/v1
fieldsType: FieldsV1
fieldsV1:
f:metadata:
f:labels:
f:app: {}
f:idpe.influxdata.io/component: {}
f:influxdata.io/owner: {}
f:kustomize.toolkit.fluxcd.io/name: {}
f:kustomize.toolkit.fluxcd.io/namespace: {}
f:spec:
f:loadBalancer:
f:ingress: {}
looks like it will own only the labels it sets?
Nice, that's promising. Thanks for checking.