add origin annotation for resources generated by generators (#4341)

* add origin annotation for resources generated by builtin and custom generators

* decouple origin data from generator data and account for inline generators
This commit is contained in:
Natasha Sarkar
2021-12-23 10:40:29 -08:00
committed by GitHub
parent 233f1a3c2a
commit 964bb38ba2
8 changed files with 717 additions and 21 deletions

View File

@@ -67,6 +67,29 @@ func (r *Resource) SetGvk(gvk resid.Gvk) {
r.SetApiVersion(gvk.ApiVersion())
}
func (r *Resource) GetOrigin() (*Origin, error) {
annotations := r.GetAnnotations()
originAnnotations, ok := annotations[utils.OriginAnnotation]
if !ok {
return nil, nil
}
var origin Origin
if err := yaml.Unmarshal([]byte(originAnnotations), &origin); err != nil {
return nil, err
}
return &origin, nil
}
func (r *Resource) SetOrigin(origin *Origin) error {
annotations := r.GetAnnotations()
originStr, err := origin.String()
if err != nil {
return err
}
annotations[utils.OriginAnnotation] = originStr
return r.SetAnnotations(annotations)
}
// ResCtx is an interface describing the contextual added
// kept kustomize in the context of each Resource object.
// Currently mainly the name prefix and name suffix are added.