-
Notifications
You must be signed in to change notification settings - Fork 104
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
Apply metadata the same way as Kustomize did #1308
Conversation
I was working on this issue also, as we talked in yesterday sync
|
Yeah, that would work as well for StatefulSets and Deployments. The recursively apply is more in Line with what Kustomize did, although your approach is less invasive. I really don't know which one is better. |
|
Yeah, but the code I see in |
ok, I understand what you mean here. But I don't see why we would need to take special care of that when unmarshalling the map back to the object would ignore those fields |
Ok, I understand it now, at the end we convert it back from unstructured to the actual object type, which gets rid of any extra attributes. Leaves the point of any other embedded resources. I don't know if there are any apart from StatefulSets and Deployments, to be honest. |
…mple in a pod Signed-off-by: Andreas Neumann <aneumann@mesosphere.com>
yes, correct. To see exactly what kustomize was doing--> you can see they were adding far more labels then annotations, one example is |
Signed-off-by: Andreas Neumann <aneumann@mesosphere.com>
Yeah... I'm testing your approach now, seems recursively adding the labels/annotations fails the e2e test, something complains that only certain changes are allowed... |
Looks like it's overwriting the existing labels which were |
Restructured enhancer to merge existing label and annotations maps Signed-off-by: Andreas Neumann <aneumann@mesosphere.com>
@ANeumann82 we would be missing annotations for and labels from more places like |
Signed-off-by: Andreas Neumann <aneumann@mesosphere.com>
Added code to handle unstructured object paths that contain slices Signed-off-by: Andreas Neumann <aneumann@mesosphere.com>
Signed-off-by: Andreas Neumann <aneumann@mesosphere.com>
@zmalik I've added the missing paths and added code to handle the slice parts of paths for volumeClaimTemplates. Added some more unit tests as well. |
# Conflicts: # pkg/engine/renderer/enhancer.go
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this adds needed functionality and I have lots of comments / questions but nothing to stop the merge.
I would appreciate:
- some restructuring / reordering
- naming that better communicates intent
Future work should include "discovery" of labels as opposed to static paths
func addLabels(obj map[string]interface{}, metadata Metadata) error { | ||
// List of paths for labels from here: | ||
// https://github.com/kubernetes-sigs/kustomize/blob/master/api/konfig/builtinpluginconsts/commonlabels.go | ||
labelPaths := [][]string{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wouldn't it be better to "discover" the label locations? this static approach works with existing kube objects... We could "discover" the labels (granted it is by naming convention).
k explain job --recursive | grep -A 10 labels
labels <map[string]string>
managedFields <[]Object>
apiVersion <string>
fieldsType <string>
fieldsV1 <map[string]>
manager <string>
operation <string>
time <string>
name <string>
namespace <string>
ownerReferences <[]Object>
--
labels <map[string]string>
managedFields <[]Object>
apiVersion <string>
fieldsType <string>
fieldsV1 <map[string]>
manager <string>
operation <string>
time <string>
name <string>
namespace <string>
ownerReferences <[]Object>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My first approach was just to walk the yaml tree recursively, looking for metadata and applying the labels/annotations there. The problem with that is, that there's a lot of metadata that can't be changed once the resource is created. I think that's why Kustomize has a list of static places as well.
func addAnnotations(obj map[string]interface{}, metadata Metadata) error { | ||
// List of pathsfor annotations from here: | ||
// https://github.com/kubernetes-sigs/kustomize/blob/master/api/konfig/builtinpluginconsts/commonannotations.go | ||
annotationPaths := [][]string{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same comment as above for labels... we should "discover" annotations
k explain job --recursive | grep -A 10 annotat
annotations <map[string]string>
clusterName <string>
creationTimestamp <string>
deletionGracePeriodSeconds <integer>
deletionTimestamp <string>
finalizers <[]string>
generateName <string>
generation <integer>
labels <map[string]string>
managedFields <[]Object>
apiVersion <string>
--
annotations <map[string]string>
clusterName <string>
creationTimestamp <string>
deletionGracePeriodSeconds <integer>
deletionTimestamp <string>
finalizers <[]string>
generateName <string>
generation <integer>
labels <map[string]string>
managedFields <[]Object>
apiVersion <string>
Signed-off-by: Andreas Neumann <aneumann@mesosphere.com>
Signed-off-by: Ken Sipe <kensipe@gmail.com>
Co-authored-by: Ken Sipe <kensipe@gmail.com> Signed-off-by: Andreas Neumann <aneumann@mesosphere.com>
Co-authored-by: Ken Sipe <kensipe@gmail.com> Signed-off-by: Andreas Neumann <aneumann@mesosphere.com> Signed-off-by: Thomas Runyon <runyontr@gmail.com>
This fix applies metadata in the enhancer recursivly.
An Alternative would be to put Kustomize back in, or handling any embedded resources manually, i.e. code for StatefulSets, Deployments, etc.
Fixes #1302 #1303
Signed-off-by: Andreas Neumann aneumann@mesosphere.com