rancher / fleet

Deploy workloads from Git to large fleets of Kubernetes clusters
https://fleet.rancher.io/
Apache License 2.0
1.5k stars 219 forks source link

Feature Request: Enable namespaceAnnotations (and namespaceLabels) as targetCustomizations #2441

Open EdKingscote opened 3 months ago

EdKingscote commented 3 months ago

Is your feature request related to a problem?

1627 introduced the ability to have namespaceLabels and namespaceAnnotations as part of the bundle deployment options.

This doesn't quite go far enough, as a single set of values can only be applied to all clusters, which means annotations and labels have to be identical across all environments.

I am specifically after namespaceAnnotations in the targetCustomizations, however I think it makes sense to look at both of these elements together to also resolve #2262 in the same feature given the similarities.

I believe this could also provide a quick path for enabling #304 via static configuration as an interim step too (which is my immediate use-case for this right now)

Solution you'd like

Adding the necessary elements to the fleet.yaml doesn't appear to incur complaint, and from deeper analysis in the codebase, I believe the only missing piece of the jigsaw to enable this is in the merge function? as well as the necessary testing and documentation.

This is only the second time ever that I've attempted to write anything in Go, but this feels close to what the missing code should be?

if result.NamespaceAnnotations == nil {
    result.NamespaceAnnotations = custom.NamespaceAnnotations
} else if custom.NamespaceAnnotations != nil {
    result.NamespaceAnnotations.Data = data.MergeMaps(result.NamespaceAnnotations.Data, custom.NamespaceAnnotations.Data)
}

if result.NamespaceLabels == nil {
    result.NamespaceLabels = custom.NamespaceLabels
} else if custom.NamespaceLabels != nil {
    result.NamespaceLabels.Data = data.MergeMaps(result.NamespaceLabels.Data, custom.NamespaceLabels.Data)
}

Alternatives you've considered

I've tried to have my helm chart create the namespace with the appropriate annotations to place in a Rancher project via helm values and takeOwnership: true, however whilst the namespace lands correctly, Rancher doesn't assign appropriate permissions for non-administrative users to see everything else in the namespace, which puts me in a tricky spot!

I also considered using kustomize, but this suggests it won't work when using helm charts for the applications to be deployed.

For now, I think I'm going to end up with the plethora of fleet.yaml files in multiple directories to force split things across my different clusters and work with the top level bundle deployment options.

Anything else?

@raulcabello as you did the original work on namespaceLabels/namespaceAnnotations support - I'd value your thoughts and input!

manno commented 1 month ago

Possible duplicate of https://github.com/rancher/fleet/issues/2262

EdKingscote commented 1 month ago

@manno I'm interested in namespaceAnnotations as a targetCustomization, but it is very similar to the namespaceLabels one!

manno commented 1 month ago

Assigning @weyfonk because of ongoing work on https://github.com/rancher/fleet/pull/2664

weyfonk commented 1 week ago

Additional QA

Problem

namespaceLabels and namespaceAnnotations, specified as bundle deployment options in fleet.yaml, could only be specified once for all clusters, but could not be overridden on a per-cluster basis.

Solution

Both namespaceLabels and namespaceAnnotations are now supported in fleet.yaml's targetCustomizations.

Testing

Engineering Testing

Manual Testing

N/A

Automated Testing

End-to-end tests have been added to cover merging of namespace labels and annotations specified at the root of fleet.yaml (ie for all clusters) with those set (with different keys) within targetCustomizations. They do not cover:

QA Testing Considerations

N/A

Regressions Considerations

N/A