Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OCPBUGS-36357: Replace watches for CO, Proxy and Machine with actual Watches #452

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
43 changes: 39 additions & 4 deletions controllers/provisioning_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,12 @@ import (
"k8s.io/klog/v2"
utilnet "k8s.io/utils/net"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/builder"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
"sigs.k8s.io/controller-runtime/pkg/handler"
"sigs.k8s.io/controller-runtime/pkg/predicate"
"sigs.k8s.io/controller-runtime/pkg/reconcile"

baremetalv1alpha1 "github.com/metal3-io/baremetal-operator/apis/metal3.io/v1alpha1"
osconfigv1 "github.com/openshift/api/config/v1"
Expand Down Expand Up @@ -650,14 +654,45 @@ func (r *ProvisioningReconciler) SetupWithManager(mgr ctrl.Manager) error {

klog.InfoS("Network stack calculation", "NetworkStack", r.NetworkStack)

provisioningFilter := predicate.NewPredicateFuncs(func(object client.Object) bool {
if object.GetName() == metal3iov1alpha1.ProvisioningSingletonName {
return true
}
klog.Info("ignoring provisioning config with unexpected name", "name", object.GetName(), "expected-name", metal3iov1alpha1.ProvisioningSingletonName)
return false
})

// Watch Secret openshift-config/pull-secret. If this secret changes, we must requeue the provisioning Singleton,
// if it exists.
watchOCPConfigPullSecret := func(ctx context.Context, object client.Object) []reconcile.Request {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: this variable is confusingly named: it's not used just for the pull secret

prov, err := r.readProvisioningCR(ctx)
// readProvisioningCR can return nil, nil upon IsNotFound, account for this as well.
if err != nil || prov == nil {
return []reconcile.Request{}
}
return []reconcile.Request{
{
NamespacedName: types.NamespacedName{
Namespace: prov.Namespace,
Name: prov.Name,
},
},
}
}
secretFilter := predicate.NewPredicateFuncs(func(object client.Object) bool {
return object.GetNamespace() == provisioning.OpenshiftConfigNamespace &&
object.GetName() == provisioning.PullSecretName
})

return ctrl.NewControllerManagedBy(mgr).
For(&metal3iov1alpha1.Provisioning{}).
For(&metal3iov1alpha1.Provisioning{}, builder.WithPredicates(provisioningFilter)).
Owns(&corev1.Secret{}).
Owns(&appsv1.Deployment{}).
Owns(&corev1.Service{}).
Owns(&appsv1.DaemonSet{}).
Owns(&osconfigv1.ClusterOperator{}).
Owns(&osconfigv1.Proxy{}).
Owns(&machinev1beta1.Machine{}).
Watches(&osconfigv1.ClusterOperator{}, handler.EnqueueRequestsFromMapFunc(watchOCPConfigPullSecret)).
Watches(&osconfigv1.Proxy{}, handler.EnqueueRequestsFromMapFunc(watchOCPConfigPullSecret)).
Watches(&machinev1beta1.Machine{}, handler.EnqueueRequestsFromMapFunc(watchOCPConfigPullSecret)).
Watches(&corev1.Secret{}, handler.EnqueueRequestsFromMapFunc(watchOCPConfigPullSecret), builder.WithPredicates(secretFilter)).
Complete(r)
}