Skip to content

Commit

Permalink
fix: Honor kluctl.io/diff-name again
Browse files Browse the repository at this point in the history
  • Loading branch information
codablock committed Jun 9, 2023
1 parent 87f9e7c commit 949f8c3
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 21 deletions.
47 changes: 37 additions & 10 deletions pkg/deployment/commands/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (

func collectObjects(c *deployment.DeploymentCollection, ru *utils.RemoteObjectUtils, au *utils.ApplyDeploymentsUtil, du *utils.DiffUtil, orphans []k8s.ObjectRef, deleted []k8s.ObjectRef) []result.ResultObject {
m := map[k8s.ObjectRef]*result.ResultObject{}
remoteDiffNames := map[k8s.ObjectRef]k8s.ObjectRef{}
appliedDiffNames := map[k8s.ObjectRef]k8s.ObjectRef{}

getOrCreate := func(ref k8s.ObjectRef) *result.ResultObject {
x, ok := m[ref]
Expand All @@ -23,42 +25,67 @@ func collectObjects(c *deployment.DeploymentCollection, ru *utils.RemoteObjectUt

if c != nil {
for _, x := range c.LocalObjects() {
o := getOrCreate(x.GetK8sRef())
dn := du.GetDiffRef(x)
o := getOrCreate(dn)
o.Rendered = x
}
}
if ru != nil {
for _, x := range ru.GetFilteredRemoteObjects(nil) {
o := getOrCreate(x.GetK8sRef())
dn := du.GetDiffRef(x)
remoteDiffNames[x.GetK8sRef()] = dn

o := getOrCreate(dn)
o.Remote = x
}
}

if au != nil {
for _, x := range au.GetAppliedObjects() {
o := getOrCreate(x.GetK8sRef())
dn := du.GetDiffRef(x)
appliedDiffNames[x.GetK8sRef()] = dn
o := getOrCreate(dn)
o.Applied = x
}

for _, x := range au.GetAppliedHookObjects() {
o := getOrCreate(x.GetK8sRef())
dn := du.GetDiffRef(x)
appliedDiffNames[x.GetK8sRef()] = dn
o := getOrCreate(dn)
o.Hook = true
}
for _, x := range au.GetNewObjectRefs() {
o := getOrCreate(x)
o.New = true
}
for _, x := range au.GetDeletedObjects() {
o := getOrCreate(x)
dn, ok := remoteDiffNames[x]
if !ok {
dn = x
}
o := getOrCreate(dn)
o.Deleted = true
}
}
if du != nil {
for _, x := range du.ChangedObjects {
o := getOrCreate(x.Ref)
dn, ok := appliedDiffNames[x.Ref]
if !ok {
dn = x.Ref
}
o := getOrCreate(dn)
o.Changes = x.Changes
}
}
if au != nil {
for _, x := range au.GetNewObjectRefs() {
dn, ok := appliedDiffNames[x]
if !ok {
dn = x
}
o := getOrCreate(dn)
if len(o.Changes) != 0 {
continue
}
o.New = true
}
}
for _, x := range orphans {
o := getOrCreate(x)
o.Orphan = true
Expand Down
21 changes: 10 additions & 11 deletions pkg/deployment/utils/diff_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,7 @@ func (u *DiffUtil) diffObject(lo *uo.UnstructuredObject, diffRef k8s2.ObjectRef,
func (u *DiffUtil) calcRemoteObjectsForDiff() {
u.remoteDiffObjects = make(map[k8s2.ObjectRef]*uo.UnstructuredObject)
for _, o := range u.ru.remoteObjects {
diffName := o.GetK8sAnnotation("kluctl.io/diff-name")
if diffName == nil {
x := o.GetK8sName()
diffName = &x
}
diffRef := o.GetK8sRef()
diffRef.Name = *diffName
diffRef := u.GetDiffRef(o)
oldCreationTime := time.Time{}
if old, ok := u.remoteDiffObjects[diffRef]; ok {
oldCreationTime = old.GetK8sCreationTime()
Expand All @@ -145,11 +139,16 @@ func (u *DiffUtil) calcRemoteObjectsForDiff() {
}

func (u *DiffUtil) getRemoteObjectForDiff(localObject *uo.UnstructuredObject) (k8s2.ObjectRef, *uo.UnstructuredObject) {
ref := localObject.GetK8sRef()
diffName := localObject.GetK8sAnnotation("kluctl.io/diff-name")
ref := u.GetDiffRef(localObject)
o, _ := u.remoteDiffObjects[ref]
return ref, o
}

func (u *DiffUtil) GetDiffRef(o *uo.UnstructuredObject) k8s2.ObjectRef {
ref := o.GetK8sRef()
diffName := o.GetK8sAnnotation("kluctl.io/diff-name")
if diffName != nil {
ref.Name = *diffName
}
o, _ := u.remoteDiffObjects[ref]
return ref, o
return ref
}

0 comments on commit 949f8c3

Please sign in to comment.