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 12, 2024
1 parent 6273a56 commit 813158e
Showing 1 changed file with 11 additions and 18 deletions.
29 changes: 11 additions & 18 deletions controllers/placementapi_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"

"github.com/go-logr/logr"
keystonev1 "github.com/openstack-k8s-operators/keystone-operator/api/v1beta1"
Expand Down Expand Up @@ -179,7 +178,6 @@ func (r *PlacementAPIReconciler) GetSecretMapperFor(crs client.ObjectList, ctx c
}
return nil
})

if err != nil {
Log.Error(err, "Unable to iterate the list of CRs")
panic(err)
Expand Down Expand Up @@ -481,7 +479,7 @@ func (r *PlacementAPIReconciler) ensureServiceExposed(
h *helper.Helper,
instance *placementv1.PlacementAPI,
) (map[string]string, ctrl.Result, error) {
var placementEndpoints = map[service.Endpoint]endpoint.Data{
placementEndpoints := map[service.Endpoint]endpoint.Data{
service.EndpointPublic: {Port: placement.PlacementPublicPort},
service.EndpointInternal: {Port: placement.PlacementInternalPort},
}
Expand Down Expand Up @@ -625,7 +623,6 @@ func (r *PlacementAPIReconciler) ensureNetworkAttachments(
instance.Spec.NetworkAttachments, err)
}
return nadAnnotations, ctrl.Result{}, nil

}

func (r *PlacementAPIReconciler) ensureKeystoneServiceUser(
Expand Down Expand Up @@ -668,7 +665,6 @@ func (r *PlacementAPIReconciler) ensureKeystoneEndpoint(
instance *placementv1.PlacementAPI,
apiEndpoints map[string]string,
) (ctrl.Result, error) {

ksEndptSpec := keystonev1.KeystoneEndpointSpec{
ServiceName: placement.ServiceName,
Endpoints: apiEndpoints,
Expand Down Expand Up @@ -804,14 +800,12 @@ const (
tlsAPIPublicField = ".spec.tls.api.public.secretName"
)

var (
allWatchFields = []string{
passwordSecretField,
caBundleSecretNameField,
tlsAPIInternalField,
tlsAPIPublicField,
}
)
var allWatchFields = []string{
passwordSecretField,
caBundleSecretNameField,
tlsAPIInternalField,
tlsAPIPublicField,
}

// SetupWithManager sets up the controller with the Manager.
func (r *PlacementAPIReconciler) SetupWithManager(mgr ctrl.Manager) error {
Expand Down Expand Up @@ -878,14 +872,14 @@ func (r *PlacementAPIReconciler) SetupWithManager(mgr ctrl.Manager) error {
Owns(&rbacv1.Role{}).
Owns(&rbacv1.RoleBinding{}).
Watches(
&source.Kind{Type: &corev1.Secret{}},
&corev1.Secret{},
handler.EnqueueRequestsFromMapFunc(r.findObjectsForSrc),
builder.WithPredicates(predicate.ResourceVersionChangedPredicate{}),
).
Complete(r)
}

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

l := log.FromContext(context.Background()).WithName("Controllers").WithName("PlacementAPI")
Expand Down Expand Up @@ -1037,7 +1031,6 @@ func (r *PlacementAPIReconciler) ensureDB(
instance.Status.DatabaseHostname = db.GetDatabaseHostname()
instance.Status.Conditions.MarkTrue(condition.DBReadyCondition, condition.DBReadyMessage)
return ctrlResult, nil

}

func (r *PlacementAPIReconciler) ensureDbSync(
Expand Down Expand Up @@ -1092,15 +1085,15 @@ func (r *PlacementAPIReconciler) ensureDeployment(
h *helper.Helper,
instance *placementv1.PlacementAPI,
inputHash string,
serviceAnnotations map[string]string) (ctrl.Result, error) {
serviceAnnotations map[string]string,
) (ctrl.Result, error) {
Log := r.GetLogger(ctx)
Log.Info("Reconciling Service")

serviceLabels := getServiceLabels(instance)

// Define a new Deployment object
deplDef, err := placement.Deployment(ctx, h, instance, inputHash, serviceLabels, serviceAnnotations)

if err != nil {
instance.Status.Conditions.Set(condition.FalseCondition(
condition.DeploymentReadyCondition,
Expand Down

0 comments on commit 813158e

Please sign in to comment.