Skip to content

Commit

Permalink
[watches] Fix watches declarations for CR update
Browse files Browse the repository at this point in the history
This change fixes the Watches declarations to comply with the new
controller-runtime standards.

Signed-off-by: Brendan Shephard <[email protected]>
  • Loading branch information
bshephar committed Feb 14, 2024
1 parent 76df8f6 commit 7c66b75
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
7 changes: 3 additions & 4 deletions controllers/swiftproxy_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import (
"sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/predicate"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
"sigs.k8s.io/controller-runtime/pkg/source"

appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -218,7 +217,7 @@ func (r *SwiftProxyReconciler) Reconcile(ctx context.Context, req ctrl.Request)
instance.Status.Conditions.MarkTrue(condition.TLSInputReadyCondition, condition.InputReadyMessage)

// Create a Service and endpoints for the proxy
var swiftPorts = map[service.Endpoint]endpoint.Data{
swiftPorts := map[service.Endpoint]endpoint.Data{
service.EndpointPublic: {
Port: swift.ProxyHttpdPort,
Path: "/v1/AUTH_%(tenant_id)s",
Expand Down Expand Up @@ -605,14 +604,14 @@ func (r *SwiftProxyReconciler) SetupWithManager(mgr ctrl.Manager) error {
Owns(&corev1.Service{}).
Owns(&corev1.ConfigMap{}).
Watches(
&source.Kind{Type: &corev1.Secret{}},
&corev1.Secret{},
handler.EnqueueRequestsFromMapFunc(r.findObjectsForSrc),
builder.WithPredicates(predicate.ResourceVersionChangedPredicate{}),
).
Complete(r)
}

func (r *SwiftProxyReconciler) findObjectsForSrc(src client.Object) []reconcile.Request {
func (r *SwiftProxyReconciler) findObjectsForSrc(ctx context.Context, src client.Object) []reconcile.Request {
requests := []reconcile.Request{}

l := log.FromContext(context.Background()).WithName("Controllers").WithName("SwiftProxy")
Expand Down
6 changes: 2 additions & 4 deletions controllers/swiftring_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/handler"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
"sigs.k8s.io/controller-runtime/pkg/source"

"github.com/openstack-k8s-operators/lib-common/modules/common/condition"
"github.com/openstack-k8s-operators/lib-common/modules/common/configmap"
Expand Down Expand Up @@ -196,8 +195,7 @@ func (r *SwiftRingReconciler) Reconcile(ctx context.Context, req ctrl.Request) (

// SetupWithManager sets up the controller with the Manager.
func (r *SwiftRingReconciler) SetupWithManager(mgr ctrl.Manager) error {

deviceConfigMapFilter := func(o client.Object) []reconcile.Request {
deviceConfigMapFilter := func(ctx context.Context, o client.Object) []reconcile.Request {
result := []reconcile.Request{}
if o.GetName() == swiftv1beta1.DeviceConfigMapName {
// There should be only one SwiftRing instance within
Expand Down Expand Up @@ -225,6 +223,6 @@ func (r *SwiftRingReconciler) SetupWithManager(mgr ctrl.Manager) error {
Owns(&corev1.ConfigMap{}).
Owns(&rbacv1.ClusterRole{}).
Owns(&rbacv1.ClusterRoleBinding{}).
Watches(&source.Kind{Type: &corev1.ConfigMap{}}, handler.EnqueueRequestsFromMapFunc(deviceConfigMapFilter)).
Watches(&corev1.ConfigMap{}, handler.EnqueueRequestsFromMapFunc(deviceConfigMapFilter)).
Complete(r)
}

0 comments on commit 7c66b75

Please sign in to comment.