Skip to content

Commit 963d662

Browse files
Merge pull request #1745 from stephenfin/csi-cm-annotation-hooks
csi: Add Deployment, DaemonSet hooks for config map hash annotations
2 parents e20ca28 + 7ff20ea commit 963d662

File tree

2 files changed

+39
-0
lines changed
  • pkg/operator/csi

2 files changed

+39
-0
lines changed

pkg/operator/csi/csidrivercontrollerservicecontroller/helpers.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,25 @@ func WithCABundleDeploymentHook(
102102
}
103103
}
104104

105+
// WithConfigMapHashAnnotationHook creates a deployment hook that annotates a Deployment with a config map's hash.
106+
func WithConfigMapHashAnnotationHook(
107+
namespace string,
108+
configMapName string,
109+
configMapInformer corev1.ConfigMapInformer,
110+
) dc.DeploymentHookFunc {
111+
return func(opSpec *opv1.OperatorSpec, deployment *appsv1.Deployment) error {
112+
inputHashes, err := resourcehash.MultipleObjectHashStringMapForObjectReferenceFromLister(
113+
configMapInformer.Lister(),
114+
nil,
115+
resourcehash.NewObjectRef().ForConfigMap().InNamespace(namespace).Named(configMapName),
116+
)
117+
if err != nil {
118+
return fmt.Errorf("invalid dependency reference: %w", err)
119+
}
120+
return addObjectHash(deployment, inputHashes)
121+
}
122+
}
123+
105124
// WithSecretHashAnnotationHook creates a deployment hook that annotates a Deployment with a secret's hash.
106125
func WithSecretHashAnnotationHook(
107126
namespace string,

pkg/operator/csi/csidrivernodeservicecontroller/helpers.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,26 @@ func WithCABundleDaemonSetHook(
7474
}
7575
}
7676

77+
// WithConfigMapHashAnnotationHook creates a DaemonSet hook that annotates a DaemonSet with a config map's hash.
78+
func WithConfigMapHashAnnotationHook(
79+
namespace string,
80+
configMapName string,
81+
configMapInformer corev1.ConfigMapInformer,
82+
) DaemonSetHookFunc {
83+
return func(_ *opv1.OperatorSpec, ds *appsv1.DaemonSet) error {
84+
inputHashes, err := resourcehash.MultipleObjectHashStringMapForObjectReferenceFromLister(
85+
configMapInformer.Lister(),
86+
nil,
87+
resourcehash.NewObjectRef().ForConfigMap().InNamespace(namespace).Named(configMapName),
88+
)
89+
if err != nil {
90+
return fmt.Errorf("invalid dependency reference: %w", err)
91+
}
92+
93+
return addObjectHash(ds, inputHashes)
94+
}
95+
}
96+
7797
// WithSecretHashAnnotationHook creates a DaemonSet hook that annotates a DaemonSet with a secret's hash.
7898
func WithSecretHashAnnotationHook(
7999
namespace string,

0 commit comments

Comments
 (0)