Skip to content

Commit 0c43bbd

Browse files
authored
Trigger Deployment rollout on object updates (#1017)
Originating issue: [IBMPrivateCloud/roadmap#64855](https://github.ibm.com/IBMPrivateCloud/roadmap/issues/64855) * When ConfigMaps and Secrets mounted by Deployments are updated, trigger a rollout to ensure any bootstrap activities are reexecuted with the new values. * Refactor ConfigMap and Secret reconcilers to use common logic for comparing contents of `.data`. Signed-off-by: Rob Hundley <[email protected]>
1 parent 345bc44 commit 0c43bbd

19 files changed

+2554
-1482
lines changed

controllers/common/resources.go

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ import (
2020
"regexp"
2121

2222
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
23-
"k8s.io/apimachinery/pkg/runtime/schema"
23+
"k8s.io/apimachinery/pkg/runtime"
2424
"sigs.k8s.io/controller-runtime/pkg/client"
25+
"sigs.k8s.io/controller-runtime/pkg/client/apiutil"
2526
)
2627

2728
var CsConfigAnnotationSuffix = "common-service/config"
@@ -67,13 +68,16 @@ func isControllerOf(controller client.Object, ownerRef v1.OwnerReference) (isCon
6768
return
6869
}
6970

70-
// IsOwnerOf determines whether one object is listed in another object's OwnerReferences. Requires GVK due to
71-
// https://github.com/kubernetes/kubernetes/issues/80609.
72-
func IsOwnerOf(gvk schema.GroupVersionKind, owner, owned client.Object) (isOwner bool) {
71+
// IsOwnerOf determines whether one object is listed in another object's OwnerReferences.
72+
func IsOwnerOf(scheme *runtime.Scheme, owner, owned client.Object) (isOwner bool) {
7373
ownerRefs := owned.GetOwnerReferences()
7474
if len(ownerRefs) == 0 {
7575
return
7676
}
77+
gvk, err := apiutil.GVKForObject(owner, scheme)
78+
if err != nil {
79+
return
80+
}
7781
owner.GetObjectKind().SetGroupVersionKind(gvk)
7882
for _, ownerRef := range ownerRefs {
7983
if isOwnerOf(owner, ownerRef) {
@@ -84,12 +88,16 @@ func IsOwnerOf(gvk schema.GroupVersionKind, owner, owned client.Object) (isOwner
8488
}
8589

8690
// IsControllerOf determines whether one object is listed as the controller of another object within its
87-
// OwnerReferences. Requires GVK due to https://github.com/kubernetes/kubernetes/issues/80609.
88-
func IsControllerOf(gvk schema.GroupVersionKind, controller, controlled client.Object) (isController bool) {
91+
// OwnerReferences.
92+
func IsControllerOf(scheme *runtime.Scheme, controller, controlled client.Object) (isController bool) {
8993
ownerRefs := controlled.GetOwnerReferences()
9094
if len(ownerRefs) == 0 {
9195
return
9296
}
97+
gvk, err := apiutil.GVKForObject(controller, scheme)
98+
if err != nil {
99+
return
100+
}
93101
controller.GetObjectKind().SetGroupVersionKind(gvk)
94102
for _, ownerRef := range ownerRefs {
95103
if isControllerOf(controller, ownerRef) {

0 commit comments

Comments
 (0)