Skip to content

Commit

Permalink
suggested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
natasha41575 committed Jul 22, 2021
1 parent a7f1ad0 commit aedc5c4
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 7 deletions.
2 changes: 0 additions & 2 deletions api/krusty/configmaps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,6 @@ configMapGenerator:
behavior: merge
literals:
- ANOTHER_ENV_VARIABLE="bar"
options:
disableNameSuffixHash: true
`)
th.WriteF("cm.yaml", `
apiVersion: v1
Expand Down
30 changes: 25 additions & 5 deletions api/resource/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ func (r *Resource) CopyMergeMetaDataFieldsFrom(other *Resource) error {

func (r *Resource) copyKustomizeSpecificFields(other *Resource) {
r.refVarNames = copyStringSlice(other.refVarNames)
r.setRefBy(other.GetRefBy())
r.SetOptions(other.getOptions())
}

func (r *Resource) MergeDataMapFrom(o *Resource) {
Expand Down Expand Up @@ -302,17 +304,23 @@ func (r *Resource) getOptions() *types.GenArgs {
yaml.Unmarshal([]byte(genOptsAnno), &genOpts)
return types.NewGenArgs(&genOpts)
}
return &types.GenArgs{}
return nil
}

// SetOptions updates the generator options for the resource.
func (r *Resource) SetOptions(o *types.GenArgs) {
annotations := r.GetAnnotations()
if o.IsNilOrEmpty() {
return
if len(annotations) == 0 {
return
}
if o == nil {
delete(annotations, utils.BuildAnnotationsGenOptions)
}
} else {
b, _ := yaml.Marshal(o.GetArgs())
annotations[utils.BuildAnnotationsGenOptions] = string(b)
}
annotations := r.GetAnnotations()
b, _ := yaml.Marshal(o.GetArgs())
annotations[utils.BuildAnnotationsGenOptions] = string(b)
r.SetAnnotations(annotations)
}

Expand Down Expand Up @@ -367,6 +375,18 @@ func (r *Resource) CurId() resid.ResId {
r.GetGvk(), r.GetName(), r.GetNamespace())
}

// setRefBy sets the resource's RefBy annotation
func (r *Resource) setRefBy(ids []resid.ResId) {
annotations := r.GetAnnotations()
if len(annotations) > 0 {
delete(annotations, utils.BuildAnnotationsRefBy)
r.SetAnnotations(annotations)
}
for _, id := range ids {
r.AppendRefBy(id)
}
}

// GetRefBy returns the ResIds that referred to current resource
func (r *Resource) GetRefBy() []resid.ResId {
var resIds []resid.ResId
Expand Down
3 changes: 3 additions & 0 deletions api/types/genargs.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,8 @@ func (g *GenArgs) IsNilOrEmpty() bool {

// GetArgs returns a copy of the underlying GeneratorArgs
func (g *GenArgs) GetArgs() GeneratorArgs {
if g == nil || g.args == nil {
return GeneratorArgs{}
}
return *g.args
}

0 comments on commit aedc5c4

Please sign in to comment.