Skip to content

Commit 16b131d

Browse files
committed
Update use of controller-runtime for revendor
Rewrite codebase to support update to controller-runtime 0.18.3. Signed-off-by: Leah Leshchinsky <[email protected]>
1 parent fdc3089 commit 16b131d

File tree

74 files changed

+352
-376
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+352
-376
lines changed

Dockerfile

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
ARG CONTAINER_SUB_MANAGER_OFF=0
22

3-
FROM registry.ci.openshift.org/openshift/release:rhel-8-release-golang-1.21-openshift-4.16 as builder_rhel8
3+
FROM registry.ci.openshift.org/ocp/builder:rhel-8-golang-1.22-openshift-4.17 as builder_rhel8
44
RUN mkdir -p /go/src/github.com/openshift/hive
55
WORKDIR /go/src/github.com/openshift/hive
66
COPY . .
@@ -10,7 +10,7 @@ RUN if [ -e "/activation-key/org" ]; then unlink /etc/rhsm-host; subscription-ma
1010
RUN dnf -y install git python3-pip
1111
RUN make build-hiveutil
1212

13-
FROM registry.ci.openshift.org/openshift/release:rhel-9-release-golang-1.21-openshift-4.16 as builder_rhel9
13+
FROM registry.ci.openshift.org/ocp/builder:rhel-9-golang-1.22-openshift-4.17 as builder_rhel9
1414
ARG CONTAINER_SUB_MANAGER_OFF
1515
RUN mkdir -p /go/src/github.com/openshift/hive
1616
WORKDIR /go/src/github.com/openshift/hive

cmd/hiveadmission/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func main() {
3333
)
3434
}
3535

36-
func createDecoder() *admission.Decoder {
36+
func createDecoder() admission.Decoder {
3737
scheme := scheme.GetScheme()
3838
decoder := admission.NewDecoder(scheme)
3939
return decoder

hack/app-sre/saas-template.yaml

+16-4
Original file line numberDiff line numberDiff line change
@@ -2489,9 +2489,15 @@ objects:
24892489
description: The key to select.
24902490
type: string
24912491
name:
2492-
description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
2492+
default: ''
2493+
description: 'Name of the referent. This field is
2494+
effectively required, but due to backwards compatibility
2495+
is allowed to be empty. Instances of this type with
2496+
an empty value here are almost certainly wrong.
24932497
TODO: Add other useful fields. apiVersion, kind,
2494-
uid?'
2498+
uid? More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
2499+
TODO: Drop `kubebuilder:default` when controller-gen
2500+
doesn''t need it https://github.com/kubernetes-sigs/kubebuilder/issues/3896.'
24952501
type: string
24962502
optional:
24972503
description: Specify whether the ConfigMap or its
@@ -2552,9 +2558,15 @@ objects:
25522558
be a valid secret key.
25532559
type: string
25542560
name:
2555-
description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
2561+
default: ''
2562+
description: 'Name of the referent. This field is
2563+
effectively required, but due to backwards compatibility
2564+
is allowed to be empty. Instances of this type with
2565+
an empty value here are almost certainly wrong.
25562566
TODO: Add other useful fields. apiVersion, kind,
2557-
uid?'
2567+
uid? More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
2568+
TODO: Drop `kubebuilder:default` when controller-gen
2569+
doesn''t need it https://github.com/kubernetes-sigs/kubebuilder/issues/3896.'
25582570
type: string
25592571
optional:
25602572
description: Specify whether the Secret or its key

pkg/controller/argocdregister/argocdregister_controller.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,7 @@ func AddToManager(mgr manager.Manager, r reconcile.Reconciler, concurrentReconci
102102
}
103103

104104
// Watch for changes to ClusterDeployment
105-
err = c.Watch(source.Kind(mgr.GetCache(), &hivev1.ClusterDeployment{}),
106-
controllerutils.NewRateLimitedUpdateEventHandler(&handler.EnqueueRequestForObject{}, controllerutils.IsClusterDeploymentErrorUpdateEvent))
105+
err = c.Watch(source.Kind(mgr.GetCache(), &hivev1.ClusterDeployment{}, controllerutils.NewTypedRateLimitedUpdateEventHandler(&handler.TypedEnqueueRequestForObject[*hivev1.ClusterDeployment]{}, controllerutils.IsClusterDeploymentErrorUpdateEvent)))
107106
if err != nil {
108107
return err
109108
}

pkg/controller/awsprivatelink/awsprivatelink_controller.go

+4-7
Original file line numberDiff line numberDiff line change
@@ -106,23 +106,20 @@ func AddToManager(mgr manager.Manager, r *ReconcileAWSPrivateLink, concurrentRec
106106
}
107107

108108
// Watch for changes to ClusterDeployment
109-
err = c.Watch(source.Kind(mgr.GetCache(), &hivev1.ClusterDeployment{}),
110-
controllerutils.NewRateLimitedUpdateEventHandler(&handler.EnqueueRequestForObject{}, controllerutils.IsClusterDeploymentErrorUpdateEvent))
109+
err = c.Watch(source.Kind(mgr.GetCache(), &hivev1.ClusterDeployment{}, controllerutils.NewTypedRateLimitedUpdateEventHandler(&handler.TypedEnqueueRequestForObject[*hivev1.ClusterDeployment]{}, controllerutils.IsClusterDeploymentErrorUpdateEvent)))
111110
if err != nil {
112111
log.WithField("controller", ControllerName).WithError(err).Error("Error watching cluster deployment")
113112
return err
114113
}
115114

116115
// Watch for changes to ClusterProvision
117-
if err := c.Watch(source.Kind(mgr.GetCache(), &hivev1.ClusterProvision{}),
118-
handler.EnqueueRequestForOwner(mgr.GetScheme(), mgr.GetRESTMapper(), &hivev1.ClusterDeployment{}, handler.OnlyControllerOwner())); err != nil {
119-
log.WithField("controller", ControllerName).WithError(err).Error("Error watching cluster provision")
116+
if err := c.Watch(source.Kind(mgr.GetCache(), &hivev1.ClusterProvision{}, handler.TypedEnqueueRequestForOwner[*hivev1.ClusterProvision](mgr.GetScheme(), mgr.GetRESTMapper(), &hivev1.ClusterDeployment{}, handler.OnlyControllerOwner()))); err != nil {
117+
log.WithField("controller", ControllerName).WithError(err).Error("Error watching cluster deprovision")
120118
return err
121119
}
122120

123121
// Watch for changes to ClusterDeprovision
124-
if err := c.Watch(source.Kind(mgr.GetCache(), &hivev1.ClusterDeprovision{}),
125-
handler.EnqueueRequestForOwner(mgr.GetScheme(), mgr.GetRESTMapper(), &hivev1.ClusterDeployment{}, handler.OnlyControllerOwner())); err != nil {
122+
if err := c.Watch(source.Kind(mgr.GetCache(), &hivev1.ClusterDeprovision{}, handler.TypedEnqueueRequestForOwner[*hivev1.ClusterDeprovision](mgr.GetScheme(), mgr.GetRESTMapper(), &hivev1.ClusterDeployment{}, handler.OnlyControllerOwner()))); err != nil {
126123
log.WithField("controller", ControllerName).WithError(err).Error("Error watching cluster deprovision")
127124
return err
128125
}

pkg/controller/clusterclaim/clusterclaim_controller.go

+28-16
Original file line numberDiff line numberDiff line change
@@ -74,30 +74,27 @@ func AddToManager(mgr manager.Manager, r *ReconcileClusterClaim, concurrentRecon
7474
}
7575

7676
// Watch for changes to ClusterClaim
77-
if err := c.Watch(source.Kind(mgr.GetCache(), &hivev1.ClusterClaim{}), &handler.EnqueueRequestForObject{}); err != nil {
77+
if err := c.Watch(source.Kind(mgr.GetCache(), &hivev1.ClusterClaim{}, &handler.TypedEnqueueRequestForObject[*hivev1.ClusterClaim]{})); err != nil {
7878
return err
7979
}
8080

8181
// Watch for changes to ClusterDeployment
8282
if err := c.Watch(
83-
source.Kind(mgr.GetCache(), &hivev1.ClusterDeployment{}),
84-
controllerutils.NewRateLimitedUpdateEventHandler(
85-
handler.EnqueueRequestsFromMapFunc(requestsForClusterDeployment),
86-
controllerutils.IsClusterDeploymentErrorUpdateEvent)); err != nil {
83+
source.Kind(mgr.GetCache(), &hivev1.ClusterDeployment{}, controllerutils.NewTypedRateLimitedUpdateEventHandler(
84+
handler.TypedEnqueueRequestsFromMapFunc(requestsForClusterDeployment),
85+
controllerutils.IsClusterDeploymentErrorUpdateEvent))); err != nil {
8786
return err
8887
}
8988

9089
// Watch for changes to the hive-claim-owner Role
9190
if err := c.Watch(
92-
source.Kind(mgr.GetCache(), &rbacv1.Role{}),
93-
handler.EnqueueRequestsFromMapFunc(requestsForRBACResources(r.Client, hiveClaimOwnerRoleName, r.logger))); err != nil {
91+
source.Kind(mgr.GetCache(), &rbacv1.Role{}, handler.TypedEnqueueRequestsFromMapFunc(requestsForRBACResourcesRole(r.Client, hiveClaimOwnerRoleName, r.logger)))); err != nil {
9492
return err
9593
}
9694

9795
// Watch for changes to the hive-claim-owner RoleBinding
9896
if err := c.Watch(
99-
source.Kind(mgr.GetCache(), &rbacv1.RoleBinding{}),
100-
handler.EnqueueRequestsFromMapFunc(requestsForRBACResources(r.Client, hiveClaimOwnerRoleBindingName, r.logger))); err != nil {
97+
source.Kind(mgr.GetCache(), &rbacv1.RoleBinding{}, handler.TypedEnqueueRequestsFromMapFunc(requestsForRBACResourcesRoleBinding(r.Client, hiveClaimOwnerRoleBindingName, r.logger)))); err != nil {
10198
return err
10299
}
103100

@@ -117,20 +114,35 @@ func claimForClusterDeployment(cd *hivev1.ClusterDeployment) *types.NamespacedNa
117114
}
118115
}
119116

120-
func requestsForClusterDeployment(ctx context.Context, o client.Object) []reconcile.Request {
121-
cd, ok := o.(*hivev1.ClusterDeployment)
122-
if !ok {
123-
return nil
124-
}
117+
func requestsForClusterDeployment(ctx context.Context, cd *hivev1.ClusterDeployment) []reconcile.Request {
125118
claim := claimForClusterDeployment(cd)
126119
if claim == nil {
127120
return nil
128121
}
129122
return []reconcile.Request{{NamespacedName: *claim}}
130123
}
131124

132-
func requestsForRBACResources(c client.Client, resourceName string, logger log.FieldLogger) handler.MapFunc {
133-
return func(ctx context.Context, o client.Object) []reconcile.Request {
125+
func requestsForRBACResourcesRole(c client.Client, resourceName string, logger log.FieldLogger) handler.TypedMapFunc[*rbacv1.Role] {
126+
return func(ctx context.Context, o *rbacv1.Role) []reconcile.Request {
127+
if o.GetName() != resourceName {
128+
return nil
129+
}
130+
clusterName := o.GetNamespace()
131+
cd := &hivev1.ClusterDeployment{}
132+
if err := c.Get(context.Background(), client.ObjectKey{Namespace: clusterName, Name: clusterName}, cd); err != nil {
133+
logger.WithError(err).Log(controllerutils.LogLevel(err), "failed to get ClusterDeployment for RBAC resource")
134+
return nil
135+
}
136+
claim := claimForClusterDeployment(cd)
137+
if claim == nil {
138+
return nil
139+
}
140+
return []reconcile.Request{{NamespacedName: *claim}}
141+
}
142+
}
143+
144+
func requestsForRBACResourcesRoleBinding(c client.Client, resourceName string, logger log.FieldLogger) handler.TypedMapFunc[*rbacv1.RoleBinding] {
145+
return func(ctx context.Context, o *rbacv1.RoleBinding) []reconcile.Request {
134146
if o.GetName() != resourceName {
135147
return nil
136148
}

pkg/controller/clusterdeployment/clusterdeployment_controller.go

+8-15
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,7 @@ func AddToManager(mgr manager.Manager, r reconcile.Reconciler, concurrentReconci
195195
}
196196

197197
// Watch for changes to ClusterDeployment
198-
err = c.Watch(source.Kind(mgr.GetCache(), &hivev1.ClusterDeployment{}),
199-
controllerutils.NewRateLimitedUpdateEventHandler(&handler.EnqueueRequestForObject{}, controllerutils.IsClusterDeploymentErrorUpdateEvent))
198+
err = c.Watch(source.Kind(mgr.GetCache(), &hivev1.ClusterDeployment{}, controllerutils.NewTypedRateLimitedUpdateEventHandler(&handler.TypedEnqueueRequestForObject[*hivev1.ClusterDeployment]{}, controllerutils.IsClusterDeploymentErrorUpdateEvent)))
200199
if err != nil {
201200
logger.WithError(err).Error("Error watching cluster deployment")
202201
return err
@@ -208,37 +207,37 @@ func AddToManager(mgr manager.Manager, r reconcile.Reconciler, concurrentReconci
208207
}
209208

210209
// Watch for jobs created by a ClusterDeployment:
211-
err = c.Watch(source.Kind(mgr.GetCache(), &batchv1.Job{}), handler.EnqueueRequestForOwner(mgr.GetScheme(), mgr.GetRESTMapper(), &hivev1.ClusterDeployment{}, handler.OnlyControllerOwner()))
210+
err = c.Watch(source.Kind(mgr.GetCache(), &batchv1.Job{}, handler.TypedEnqueueRequestForOwner[*batchv1.Job](mgr.GetScheme(), mgr.GetRESTMapper(), &hivev1.ClusterDeployment{}, handler.OnlyControllerOwner())))
212211
if err != nil {
213212
logger.WithError(err).Error("Error watching cluster deployment job")
214213
return err
215214
}
216215

217216
// Watch for pods created by an install job
218-
err = c.Watch(source.Kind(mgr.GetCache(), &corev1.Pod{}), handler.EnqueueRequestsFromMapFunc(selectorPodWatchHandler))
217+
err = c.Watch(source.Kind(mgr.GetCache(), &corev1.Pod{}, handler.TypedEnqueueRequestsFromMapFunc(selectorPodWatchHandler)))
219218
if err != nil {
220219
logger.WithError(err).Error("Error watching cluster deployment pods")
221220
return err
222221
}
223222

224223
// Watch for deprovision requests created by a ClusterDeployment
225-
err = c.Watch(source.Kind(mgr.GetCache(), &hivev1.ClusterDeprovision{}), handler.EnqueueRequestForOwner(mgr.GetScheme(), mgr.GetRESTMapper(), &hivev1.ClusterDeployment{}, handler.OnlyControllerOwner()))
224+
err = c.Watch(source.Kind(mgr.GetCache(), &hivev1.ClusterDeprovision{}, handler.TypedEnqueueRequestForOwner[*hivev1.ClusterDeprovision](mgr.GetScheme(), mgr.GetRESTMapper(), &hivev1.ClusterDeployment{}, handler.OnlyControllerOwner())))
226225
if err != nil {
227226
logger.WithError(err).Error("Error watching deprovision request created by cluster deployment")
228227
return err
229228
}
230229

231230
// Watch for dnszones created by a ClusterDeployment
232-
err = c.Watch(source.Kind(mgr.GetCache(), &hivev1.DNSZone{}), handler.EnqueueRequestForOwner(mgr.GetScheme(), mgr.GetRESTMapper(), &hivev1.ClusterDeployment{}, handler.OnlyControllerOwner()))
231+
err = c.Watch(source.Kind(mgr.GetCache(), &hivev1.DNSZone{}, handler.TypedEnqueueRequestForOwner[*hivev1.DNSZone](mgr.GetScheme(), mgr.GetRESTMapper(), &hivev1.ClusterDeployment{}, handler.OnlyControllerOwner())))
233232
if err != nil {
234233
logger.WithError(err).Error("Error watching cluster deployment dnszones")
235234
return err
236235
}
237236

238237
// Watch for changes to ClusterSyncs
239238
if err := c.Watch(
240-
source.Kind(mgr.GetCache(), &hiveintv1alpha1.ClusterSync{}),
241-
handler.EnqueueRequestForOwner(mgr.GetScheme(), mgr.GetRESTMapper(), &hivev1.ClusterDeployment{}),
239+
source.Kind(mgr.GetCache(), &hiveintv1alpha1.ClusterSync{},
240+
handler.TypedEnqueueRequestForOwner[*hiveintv1alpha1.ClusterSync](mgr.GetScheme(), mgr.GetRESTMapper(), &hivev1.ClusterDeployment{})),
242241
); err != nil {
243242
return errors.Wrap(err, "cannot start watch on ClusterSyncs")
244243
}
@@ -1828,15 +1827,9 @@ func (r *ReconcileClusterDeployment) createManagedDNSZone(cd *hivev1.ClusterDepl
18281827
return nil
18291828
}
18301829

1831-
func selectorPodWatchHandler(ctx context.Context, a client.Object) []reconcile.Request {
1830+
func selectorPodWatchHandler(ctx context.Context, pod *corev1.Pod) []reconcile.Request {
18321831
retval := []reconcile.Request{}
18331832

1834-
pod := a.(*corev1.Pod)
1835-
if pod == nil {
1836-
// Wasn't a Pod, bail out. This should not happen.
1837-
log.Errorf("Error converting MapObject.Object to Pod. Value: %+v", a)
1838-
return retval
1839-
}
18401833
if pod.Labels == nil {
18411834
return retval
18421835
}

pkg/controller/clusterdeployment/clusterinstalls.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ func (r *ReconcileClusterDeployment) watchClusterInstall(gvk schema.GroupVersion
324324

325325
obj := &unstructured.Unstructured{}
326326
obj.SetGroupVersionKind(gvk)
327-
err := r.watcher.Watch(source.Kind(r.Manager.GetCache(), obj), handler.EnqueueRequestsFromMapFunc(func(ctx context.Context, o client.Object) []reconcile.Request {
327+
err := r.watcher.Watch(source.Kind(r.Manager.GetCache(), obj, handler.TypedEnqueueRequestsFromMapFunc(func(ctx context.Context, o *unstructured.Unstructured) []reconcile.Request {
328328
retval := []reconcile.Request{}
329329

330330
cdList := &hivev1.ClusterDeploymentList{}
@@ -344,7 +344,7 @@ func (r *ReconcileClusterDeployment) watchClusterInstall(gvk schema.GroupVersion
344344
logger.WithField("retval", retval).Debug("trigger reconcile for clusterdeployments for cluster install objects")
345345

346346
return retval
347-
}))
347+
})))
348348
if err != nil {
349349
return err
350350
}

pkg/controller/clusterdeployment/clusterprovisions.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -775,24 +775,24 @@ func (r *ReconcileClusterDeployment) setupAWSCredentialForAssumeRole(cd *hivev1.
775775

776776
func (r *ReconcileClusterDeployment) watchClusterProvisions(mgr manager.Manager, c controller.Controller) error {
777777
handler := &clusterProvisionEventHandler{
778-
EventHandler: handler.EnqueueRequestForOwner(mgr.GetScheme(), mgr.GetRESTMapper(), &hivev1.ClusterDeployment{}, handler.OnlyControllerOwner()),
779-
reconciler: r,
778+
TypedEventHandler: handler.TypedEnqueueRequestForOwner[*hivev1.ClusterProvision](mgr.GetScheme(), mgr.GetRESTMapper(), &hivev1.ClusterDeployment{}, handler.OnlyControllerOwner()),
779+
reconciler: r,
780780
}
781-
return c.Watch(source.Kind(mgr.GetCache(), &hivev1.ClusterProvision{}), handler)
781+
return c.Watch(source.Kind(mgr.GetCache(), &hivev1.ClusterProvision{}, handler))
782782
}
783783

784-
var _ handler.EventHandler = &clusterProvisionEventHandler{}
784+
var _ handler.TypedEventHandler[*hivev1.ClusterProvision] = &clusterProvisionEventHandler{}
785785

786786
type clusterProvisionEventHandler struct {
787-
handler.EventHandler
787+
handler.TypedEventHandler[*hivev1.ClusterProvision]
788788
reconciler *ReconcileClusterDeployment
789789
}
790790

791791
// Create implements handler.EventHandler
792-
func (h *clusterProvisionEventHandler) Create(ctx context.Context, e event.CreateEvent, q workqueue.RateLimitingInterface) {
792+
func (h *clusterProvisionEventHandler) Create(ctx context.Context, e event.TypedCreateEvent[*hivev1.ClusterProvision], q workqueue.RateLimitingInterface) {
793793
h.reconciler.logger.Info("ClusterProvision created")
794794
h.reconciler.trackClusterProvisionAdd(e.Object)
795-
h.EventHandler.Create(ctx, e, q)
795+
h.TypedEventHandler.Create(ctx, e, q)
796796
}
797797

798798
// resolveControllerRef returns the controller referenced by a ControllerRef,

pkg/controller/clusterdeprovision/clusterdeprovision_controller.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -116,15 +116,14 @@ func add(mgr manager.Manager, r reconcile.Reconciler, concurrentReconciles int,
116116
}
117117

118118
// Watch for changes to ClusterDeprovision
119-
err = c.Watch(source.Kind(mgr.GetCache(), &hivev1.ClusterDeprovision{}), &handler.EnqueueRequestForObject{})
119+
err = c.Watch(source.Kind(mgr.GetCache(), &hivev1.ClusterDeprovision{}, &handler.TypedEnqueueRequestForObject[*hivev1.ClusterDeprovision]{}))
120120
if err != nil {
121121
log.WithField("controller", ControllerName).WithError(err).Error("Error watching changes to clusterdeprovision")
122122
return err
123123
}
124124

125125
// Watch for uninstall jobs created for ClusterDeprovisions
126-
err = c.Watch(source.Kind(mgr.GetCache(), &batchv1.Job{}),
127-
handler.EnqueueRequestForOwner(mgr.GetScheme(), mgr.GetRESTMapper(), &hivev1.ClusterDeprovision{}, handler.OnlyControllerOwner()))
126+
err = c.Watch(source.Kind(mgr.GetCache(), &batchv1.Job{}, handler.TypedEnqueueRequestForOwner[*batchv1.Job](mgr.GetScheme(), mgr.GetRESTMapper(), &hivev1.ClusterDeprovision{}, handler.OnlyControllerOwner())))
128127
if err != nil {
129128
log.WithField("controller", ControllerName).WithError(err).Error("Error watching uninstall jobs created for clusterdeprovisionreques")
130129
return err

0 commit comments

Comments
 (0)