Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ require (
gopkg.in/evanphx/json-patch.v4 v4.13.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
k8s.io/apiextensions-apiserver v0.36.1 // indirect
k8s.io/kube-openapi v0.0.0-20260512234627-ef417d054102 // indirect
k8s.io/kube-openapi v0.0.0-20260519202549-bbf5c5577288 // indirect
k8s.io/utils v0.0.0-20260507154919-ff6756f316d2 // indirect
sigs.k8s.io/controller-runtime v0.24.1 // indirect
sigs.k8s.io/gateway-api v1.5.1 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,8 @@ k8s.io/client-go v0.36.1 h1:FN/K8QIT2CEDt+2WB2HnWrUANZ50AP5GII43/SP2JR0=
k8s.io/client-go v0.36.1/go.mod h1:s6rAnCtTGYDQnpNjEhSaISV+2O8jwruZ6m3QOYBFbtU=
k8s.io/klog/v2 v2.140.0 h1:Tf+J3AH7xnUzZyVVXhTgGhEKnFqye14aadWv7bzXdzc=
k8s.io/klog/v2 v2.140.0/go.mod h1:o+/RWfJ6PwpnFn7OyAG3QnO47BFsymfEfrz6XyYSSp0=
k8s.io/kube-openapi v0.0.0-20260512234627-ef417d054102 h1:xs2ux1MvyrOdfKwS3vuFWrGuLgDOHk6id975Twx2Jss=
k8s.io/kube-openapi v0.0.0-20260512234627-ef417d054102/go.mod h1:V/QaCUYDa+0QpcHhVVc5l99Uz56wEMEXBSj9oCDkNDY=
k8s.io/kube-openapi v0.0.0-20260519202549-bbf5c5577288 h1:A7Lby6ekC6nv+6oO38huCMFBRP0Os+tIeq1GkwxOQes=
k8s.io/kube-openapi v0.0.0-20260519202549-bbf5c5577288/go.mod h1:V/QaCUYDa+0QpcHhVVc5l99Uz56wEMEXBSj9oCDkNDY=
k8s.io/utils v0.0.0-20260507154919-ff6756f316d2 h1:wU4tMEhLGgIbLvXQb1cfN+EcM0wf7zC6CPF+C79jroc=
k8s.io/utils v0.0.0-20260507154919-ff6756f316d2/go.mod h1:xDxuJ0whA3d0I4mf/C4ppKHxXynQ+fxnkmQH0vTHnuk=
sigs.k8s.io/controller-runtime v0.24.1 h1:miPEwrmirImAvgME1L9qebGHrOnGJoVmVdtOU9fRfo4=
Expand Down
12 changes: 9 additions & 3 deletions internal/controller/informers.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package controller

import (
"reflect"
"time"

"github.com/sap/cap-operator/pkg/apis/sme.sap.com/v1alpha1"
"k8s.io/apimachinery/pkg/api/meta"
Expand Down Expand Up @@ -106,7 +107,7 @@ func (c *Controller) getEventHandlerFuncsForResource(res int) cache.ResourceEven
c.enqueueModifiedResource(res, new, old)
},
DeleteFunc: func(old any) {
c.enqueueModifiedResource(res, old, nil)
c.enqueueModifiedResource(res, nil, old)
},
}
}
Expand Down Expand Up @@ -183,6 +184,7 @@ func (c *Controller) registerGardenerDNSEntrytListeners() {

func (c *Controller) enqueueModifiedResource(sourceKey int, new, old any) {
newObj, ok := getMetaObject(new)
// Skip deletes in general!
if !ok {
return
}
Expand All @@ -208,12 +210,16 @@ func (c *Controller) enqueueModifiedResource(sourceKey int, new, old any) {
}
klog.InfoS(queuing, "namespace", newObj.GetNamespace(), "name", newObj.GetName(), "kind", dependentKind)
q.Add(QueueItem{Key: dependentKey, ResourceKey: NamespacedResourceKey{Name: newObj.GetName(), Namespace: newObj.GetNamespace()}})
}
// Only queue parent items on updates
if old == nil {
continue
} else if owner, ok := getOwnerByKind(newObj.GetOwnerReferences(), dependentKind); ok {
klog.InfoS(queuing, "namespace", newObj.GetNamespace(), "name", owner.Name, "kind", dependentKind)
q.Add(QueueItem{Key: dependentKey, ResourceKey: NamespacedResourceKey{Name: owner.Name, Namespace: newObj.GetNamespace()}})
q.AddAfter(QueueItem{Key: dependentKey, ResourceKey: NamespacedResourceKey{Name: owner.Name, Namespace: newObj.GetNamespace()}}, time.Second)
} else if owner, ok := getOwnerFromObjectMetadata(newObj, dependentKind); ok {
klog.InfoS(queuing, "namespace", owner.Namespace, "name", owner.Name, "kind", dependentKind)
q.Add(QueueItem{Key: dependentKey, ResourceKey: NamespacedResourceKey{Name: owner.Name, Namespace: owner.Namespace}})
q.AddAfter(QueueItem{Key: dependentKey, ResourceKey: NamespacedResourceKey{Name: owner.Name, Namespace: owner.Namespace}}, time.Second)
}
}
}
Expand Down
20 changes: 14 additions & 6 deletions internal/controller/informers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ func TestController_initializeInformers(t *testing.T) {
tests := []struct {
name string
expectedResult bool
ownerOnlyCheck bool
invalidOwnerRef bool
res int
itemName string
Expand All @@ -55,13 +56,15 @@ func TestController_initializeInformers(t *testing.T) {
{
name: "Test enqueueModifiedResource (ResourceCertificate) valid owner",
res: ResourceCertificate,
ownerOnlyCheck: true,
expectedResult: true,
itemName: "test-cert",
itemNamespace: corev1.NamespaceDefault,
},
{
name: "Test enqueueModifiedResource (ResourceCertificate) invalid owner",
res: ResourceCertificate,
ownerOnlyCheck: true,
expectedResult: false,
invalidOwnerRef: true,
itemName: "test-cert",
Expand Down Expand Up @@ -114,7 +117,7 @@ func TestController_initializeInformers(t *testing.T) {
}

testC.initializeInformers()
var res any
var res, oldRes any
switch tt.res {
case ResourceCAPApplication:
res = createCaCRO(tt.itemName, false)
Expand All @@ -135,17 +138,22 @@ func TestController_initializeInformers(t *testing.T) {
cert.Annotations[AnnotationOwnerIdentifier] = tt.itemNamespace + "." + tt.itemName
cert.Labels[LabelOwnerIdentifierHash] = sha1Sum(tt.itemNamespace, tt.itemName)
}
res = cert
oldRes = cert
newCert := cert.DeepCopy()
newCert.SetResourceVersion("2")
res = newCert
case 999:
res = &corev1.Pod{ObjectMeta: metav1.ObjectMeta{Name: tt.itemName}}
}
// Add/delete
testC.enqueueModifiedResource(tt.res, res, nil)
if expectedResult != tt.expectedResult {
t.Error("Unexpected result", expectedResult)
if !tt.ownerOnlyCheck {
testC.enqueueModifiedResource(tt.res, res, nil)
if expectedResult != tt.expectedResult {
t.Error("Unexpected result", expectedResult)
}
}
// Update
testC.enqueueModifiedResource(tt.res, res, res)
testC.enqueueModifiedResource(tt.res, res, oldRes)
if expectedResult != tt.expectedResult {
t.Error("Unexpected result", expectedResult)
}
Expand Down
Loading