Skip to content

Commit 7034a99

Browse files
author
Brendan Shephard
committed
Add Watches function for Registries MachineConfig
This change adds a Watches function to retreive and queue reconcile requests based on changes to the Registries Machine Config object. Signed-off-by: Brendan Shephard <bshephar@redhat.com>
1 parent 6bd7d3c commit 7034a99

2 files changed

Lines changed: 44 additions & 4 deletions

File tree

config/rbac/role.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -502,10 +502,11 @@ rules:
502502
- apiGroups:
503503
- machineconfiguration.openshift.io
504504
resources:
505-
- machineconfig
505+
- machineconfigs
506506
verbs:
507507
- get
508508
- list
509+
- watch
509510
- apiGroups:
510511
- manila.openstack.org
511512
resources:
@@ -657,7 +658,7 @@ rules:
657658
- apiGroups:
658659
- operator.openshift.io
659660
resources:
660-
- imagecontentsourcepolicy
661+
- imagecontentsourcepolicies
661662
verbs:
662663
- get
663664
- list

controllers/dataplane/openstackdataplanenodeset_controller.go

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ import (
5454
dataplanev1 "github.com/openstack-k8s-operators/openstack-operator/apis/dataplane/v1beta1"
5555
deployment "github.com/openstack-k8s-operators/openstack-operator/pkg/dataplane"
5656
dataplaneutil "github.com/openstack-k8s-operators/openstack-operator/pkg/dataplane/util"
57+
58+
machineconfig "github.com/openshift/api/machineconfiguration/v1"
5759
)
5860

5961
const (
@@ -121,8 +123,8 @@ func (r *OpenStackDataPlaneNodeSetReconciler) GetLogger(ctx context.Context) log
121123
// +kubebuilder:rbac:groups="image.openshift.io",resources=imagestreamtags,verbs=get;list;watch
122124

123125
// RBAC for ImageContentSourcePolicy and MachineConfig
124-
// +kubebuilder:rbac:groups="operator.openshift.io",resources=imagecontentsourcepolicy,verbs=get;list
125-
// +kubebuilder:rbac:groups="machineconfiguration.openshift.io",resources=machineconfig,verbs=get;list
126+
// +kubebuilder:rbac:groups="operator.openshift.io",resources=imagecontentsourcepolicies,verbs=get;list
127+
// +kubebuilder:rbac:groups="machineconfiguration.openshift.io",resources=machineconfigs,verbs=get;list;watch
126128

127129
// Reconcile is part of the main kubernetes reconciliation loop which aims to
128130
// move the current state of the cluster closer to the desired state.
@@ -644,9 +646,46 @@ func (r *OpenStackDataPlaneNodeSetReconciler) SetupWithManager(
644646
builder.WithPredicates(predicate.ResourceVersionChangedPredicate{})).
645647
Watches(&openstackv1.OpenStackVersion{},
646648
handler.EnqueueRequestsFromMapFunc(r.genericWatcherFn)).
649+
Watches(&machineconfig.MachineConfig{},
650+
handler.EnqueueRequestsFromMapFunc(r.machineConfigWatcherFn),
651+
builder.WithPredicates(predicate.ResourceVersionChangedPredicate{})).
647652
Complete(r)
648653
}
649654

655+
// machineConfigWatcherFn - watches for changes to the registries MachineConfig resource and queues
656+
// a reconcile of each NodeSet if the MachineConfig is changed.
657+
func (r *OpenStackDataPlaneNodeSetReconciler) machineConfigWatcherFn(
658+
ctx context.Context, obj client.Object,
659+
) []reconcile.Request {
660+
Log := r.GetLogger(ctx)
661+
nodeSets := &dataplanev1.OpenStackDataPlaneNodeSetList{}
662+
kind := strings.ToLower(obj.GetObjectKind().GroupVersionKind().Kind)
663+
const registryMachineConfigName string = "99-master-generated-registries"
664+
665+
mcNamespacedName := types.NamespacedName{
666+
Name: registryMachineConfigName,
667+
Namespace: "",
668+
}
669+
670+
if err := r.Get(ctx, mcNamespacedName, obj); err != nil {
671+
Log.Error(err, fmt.Sprintf("Unable to retrieve MachingConfig %s", registryMachineConfigName))
672+
return nil
673+
}
674+
675+
requests := make([]reconcile.Request, 0, len(nodeSets.Items))
676+
for _, nodeSet := range nodeSets.Items {
677+
requests = append(requests, reconcile.Request{
678+
NamespacedName: types.NamespacedName{
679+
Namespace: obj.GetNamespace(),
680+
Name: nodeSet.Name,
681+
},
682+
})
683+
Log.Info(fmt.Sprintf("reconcile loop for openstackdataplanenodeset %s triggered by %s %s",
684+
nodeSet.Name, kind, obj.GetName()))
685+
}
686+
return requests
687+
}
688+
650689
func (r *OpenStackDataPlaneNodeSetReconciler) secretWatcherFn(
651690
ctx context.Context, obj client.Object,
652691
) []reconcile.Request {

0 commit comments

Comments
 (0)