mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-13 10:00:56 +00:00
Keep var refernce in resources
This commit is contained in:
@@ -31,8 +31,9 @@ import (
|
||||
// paired with a GenerationBehavior.
|
||||
type Resource struct {
|
||||
ifc.Kunstructured
|
||||
options *types.GenArgs
|
||||
refBy []resid.ResId
|
||||
options *types.GenArgs
|
||||
refBy []resid.ResId
|
||||
refVarNames []string
|
||||
}
|
||||
|
||||
func (r *Resource) KunstructEqual(o *Resource) bool {
|
||||
@@ -59,6 +60,11 @@ func (r *Resource) DeepCopy() *Resource {
|
||||
copy(refby, r.refBy)
|
||||
rc.refBy = refby
|
||||
}
|
||||
if len(r.refVarNames) > 0 {
|
||||
refVarNames := make([]string, len(r.refVarNames))
|
||||
copy(refVarNames, r.refVarNames)
|
||||
rc.refVarNames = refVarNames
|
||||
}
|
||||
return rc
|
||||
}
|
||||
|
||||
@@ -98,6 +104,16 @@ func (r *Resource) AppendRefBy(id resid.ResId) {
|
||||
r.refBy = append(r.refBy, id)
|
||||
}
|
||||
|
||||
// GetRefVarNames returns vars that refer to current resource
|
||||
func (r *Resource) GetRefVarNames() []string {
|
||||
return r.refVarNames
|
||||
}
|
||||
|
||||
// AppendRefVarName appends a name of a var into the refVar list
|
||||
func (r *Resource) AppendRefVarName(variable types.Var) {
|
||||
r.refVarNames = append(r.refVarNames, variable.Name)
|
||||
}
|
||||
|
||||
// Merge performs merge with other resource.
|
||||
func (r *Resource) Merge(other *Resource) {
|
||||
r.Replace(other)
|
||||
|
||||
@@ -24,6 +24,7 @@ import (
|
||||
"sigs.k8s.io/kustomize/pkg/gvk"
|
||||
"sigs.k8s.io/kustomize/pkg/resid"
|
||||
. "sigs.k8s.io/kustomize/pkg/resource"
|
||||
"sigs.k8s.io/kustomize/pkg/types"
|
||||
)
|
||||
|
||||
var factory = NewFactory(
|
||||
@@ -122,6 +123,14 @@ func TestDeepCopy(t *testing.T) {
|
||||
})
|
||||
r.AppendRefBy(resid.NewResId(gvk.Gvk{Group: "somegroup", Kind: "MyKind"}, "random"))
|
||||
|
||||
var1 := types.Var{
|
||||
Name: "SERVICE_ONE",
|
||||
ObjRef: types.Target{
|
||||
Gvk: gvk.Gvk{Version: "v1", Kind: "Service"},
|
||||
Name: "backendOne"},
|
||||
}
|
||||
r.AppendRefVarName(var1)
|
||||
|
||||
cr := r.DeepCopy()
|
||||
if !reflect.DeepEqual(r, cr) {
|
||||
t.Errorf("expected %v\nbut got%v", r, cr)
|
||||
|
||||
Reference in New Issue
Block a user