From 8bf05c0015a9f9bf4d35cfeab73cfc6b0749c7f6 Mon Sep 17 00:00:00 2001 From: r Date: Wed, 1 May 2024 00:53:29 +0300 Subject: [PATCH] rebase fix KeystoneServiceReconciler unused ctx param fix KeystoneServiceReconciler unused ctx param2 fix KeystoneAPIReconciler unused ctx param --- controllers/keystoneapi_controller.go | 65 ++++++++++----------- controllers/keystoneendpoint_controller.go | 53 +++++++++-------- controllers/keystoneservice_controller.go | 67 ++++++++++++---------- main.go | 3 +- tests/functional/suite_test.go | 2 +- 5 files changed, 103 insertions(+), 87 deletions(-) diff --git a/controllers/keystoneapi_controller.go b/controllers/keystoneapi_controller.go index 3f8e35f3..49b8e58b 100644 --- a/controllers/keystoneapi_controller.go +++ b/controllers/keystoneapi_controller.go @@ -81,8 +81,8 @@ func (r *KeystoneAPIReconciler) GetScheme() *runtime.Scheme { return r.Scheme } -// GetLog returns a logger object with a prefix of "conroller.name" and aditional controller context fields -func GetLog(ctx context.Context) logr.Logger { +// GetLog returns a logger object with a logging prefix of "controller.name" and additional controller context fields +func (r *KeystoneAPIReconciler) GetLogger(ctx context.Context) logr.Logger { return log.FromContext(ctx).WithName("Controllers").WithName("KeystoneAPI") } @@ -121,6 +121,7 @@ type KeystoneAPIReconciler struct { // Reconcile reconcile keystone API requests func (r *KeystoneAPIReconciler) Reconcile(ctx context.Context, req ctrl.Request) (result ctrl.Result, _err error) { + Log := r.GetLogger(ctx) // Fetch the KeystoneAPI instance instance := &keystonev1.KeystoneAPI{} err := r.Client.Get(ctx, req.NamespacedName, instance) @@ -140,7 +141,7 @@ func (r *KeystoneAPIReconciler) Reconcile(ctx context.Context, req ctrl.Request) r.Client, r.Kclient, r.Scheme, - GetLog(ctx), + Log, ) if err != nil { return ctrl.Result{}, err @@ -245,8 +246,8 @@ var allWatchFields = []string{ } // SetupWithManager - -func (r *KeystoneAPIReconciler) SetupWithManager(mgr ctrl.Manager) error { - logger := mgr.GetLogger() +func (r *KeystoneAPIReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager) error { + Log := r.GetLogger(ctx) // index passwordSecretField if err := mgr.GetFieldIndexer().IndexField(context.Background(), &keystonev1.KeystoneAPI{}, passwordSecretField, func(rawObj client.Object) []string { @@ -304,8 +305,8 @@ func (r *KeystoneAPIReconciler) SetupWithManager(mgr ctrl.Manager) error { listOpts := []client.ListOption{ client.InNamespace(o.GetNamespace()), } - if err := r.Client.List(context.Background(), keystoneAPIs, listOpts...); err != nil { - logger.Error(err, "Unable to retrieve KeystoneAPI CRs %w") + if err := r.Client.List(ctx, keystoneAPIs, listOpts...); err != nil { + Log.Error(err, "Unable to retrieve KeystoneAPI CRs %w") return nil } @@ -315,7 +316,7 @@ func (r *KeystoneAPIReconciler) SetupWithManager(mgr ctrl.Manager) error { Namespace: o.GetNamespace(), Name: cr.Name, } - logger.Info(fmt.Sprintf("Memcached %s is used by KeystoneAPI CR %s", o.GetName(), cr.Name)) + Log.Info(fmt.Sprintf("Memcached %s is used by KeystoneAPI CR %s", o.GetName(), cr.Name)) result = append(result, reconcile.Request{NamespacedName: name}) } } @@ -351,7 +352,7 @@ func (r *KeystoneAPIReconciler) SetupWithManager(mgr ctrl.Manager) error { func (r *KeystoneAPIReconciler) findObjectsForSrc(ctx context.Context, src client.Object) []reconcile.Request { requests := []reconcile.Request{} - l := log.FromContext(ctx).WithName("Controllers").WithName("KeystoneAPI") + Log := r.GetLogger(context.Background()) for _, field := range allWatchFields { crList := &keystonev1.KeystoneAPIList{} @@ -365,7 +366,7 @@ func (r *KeystoneAPIReconciler) findObjectsForSrc(ctx context.Context, src clien } for _, item := range crList.Items { - l.Info(fmt.Sprintf("input source %s changed, reconcile: %s - %s", src.GetName(), item.GetName(), item.GetNamespace())) + Log.Info(fmt.Sprintf("input source %s changed, reconcile: %s - %s", src.GetName(), item.GetName(), item.GetNamespace())) requests = append(requests, reconcile.Request{ @@ -382,8 +383,8 @@ func (r *KeystoneAPIReconciler) findObjectsForSrc(ctx context.Context, src clien } func (r *KeystoneAPIReconciler) reconcileDelete(ctx context.Context, instance *keystonev1.KeystoneAPI, helper *helper.Helper) (ctrl.Result, error) { - l := GetLog(ctx) - l.Info("Reconciling Service delete") + Log := r.GetLogger(ctx) + Log.Info("Reconciling Service delete") // We need to allow all KeystoneEndpoint and KeystoneService processing to finish // in the case of a delete before we remove the finalizers. For instance, in the @@ -430,7 +431,7 @@ func (r *KeystoneAPIReconciler) reconcileDelete(ctx context.Context, instance *k // Service is deleted so remove the finalizer. controllerutil.RemoveFinalizer(instance, helper.GetFinalizer()) - l.Info("Reconciled Service delete successfully") + Log.Info("Reconciled Service delete successfully") return ctrl.Result{}, nil } @@ -442,9 +443,8 @@ func (r *KeystoneAPIReconciler) reconcileInit( serviceLabels map[string]string, serviceAnnotations map[string]string, ) (ctrl.Result, error) { - l := GetLog(ctx) - l.Info("Reconciling Service init") - + Log := r.GetLogger(ctx) + Log.Info("Reconciling Service init") // // Service account, role, binding // @@ -503,7 +503,7 @@ func (r *KeystoneAPIReconciler) reconcileInit( } if dbSyncjob.HasChanged() { instance.Status.Hash[keystonev1.DbSyncHash] = dbSyncjob.GetHash() - l.Info(fmt.Sprintf("Job %s hash added - %s", jobDef.Name, instance.Status.Hash[keystonev1.DbSyncHash])) + Log.Info(fmt.Sprintf("Job %s hash added - %s", jobDef.Name, instance.Status.Hash[keystonev1.DbSyncHash])) } instance.Status.Conditions.MarkTrue(condition.DBSyncReadyCondition, condition.DBSyncReadyMessage) @@ -661,35 +661,35 @@ func (r *KeystoneAPIReconciler) reconcileInit( } if bootstrapjob.HasChanged() { instance.Status.Hash[keystonev1.BootstrapHash] = bootstrapjob.GetHash() - l.Info(fmt.Sprintf("Job %s hash added - %s", jobDef.Name, instance.Status.Hash[keystonev1.BootstrapHash])) + Log.Info(fmt.Sprintf("Job %s hash added - %s", jobDef.Name, instance.Status.Hash[keystonev1.BootstrapHash])) } instance.Status.Conditions.MarkTrue(condition.BootstrapReadyCondition, condition.BootstrapReadyMessage) // run keystone bootstrap - end - l.Info("Reconciled Service init successfully") + Log.Info("Reconciled Service init successfully") return ctrl.Result{}, nil } func (r *KeystoneAPIReconciler) reconcileUpdate(ctx context.Context) (ctrl.Result, error) { - l := GetLog(ctx) - l.Info("Reconciling Service update") + Log := r.GetLogger(ctx) + Log.Info("Reconciling Service update") // TODO: should have minor update tasks if required // - delete dbsync hash from status to rerun it? - l.Info("Reconciled Service update successfully") + Log.Info("Reconciled Service update successfully") return ctrl.Result{}, nil } func (r *KeystoneAPIReconciler) reconcileUpgrade(ctx context.Context) (ctrl.Result, error) { - l := GetLog(ctx) - l.Info("Reconciling Service upgrade") + Log := r.GetLogger(ctx) + Log.Info("Reconciling Service upgrade") // TODO: should have major version upgrade tasks // -delete dbsync hash from status to rerun it? - l.Info("Reconciled Service upgrade successfully") + Log.Info("Reconciled Service upgrade successfully") return ctrl.Result{}, nil } @@ -698,8 +698,8 @@ func (r *KeystoneAPIReconciler) reconcileNormal( instance *keystonev1.KeystoneAPI, helper *helper.Helper, ) (ctrl.Result, error) { - l := GetLog(ctx) - l.Info("Reconciling Service") + Log := r.GetLogger(ctx) + Log.Info("Reconciling Service") serviceLabels := map[string]string{ common.AppSelector: keystone.ServiceName, @@ -761,13 +761,13 @@ func (r *KeystoneAPIReconciler) reconcileNormal( return ctrl.Result{}, err } if op != controllerutil.OperationResultNone { - l.Info(fmt.Sprintf("TransportURL %s successfully reconciled - operation: %s", transportURL.Name, string(op))) + Log.Info(fmt.Sprintf("TransportURL %s successfully reconciled - operation: %s", transportURL.Name, string(op))) } instance.Status.TransportURLSecret = transportURL.Status.SecretName if instance.Status.TransportURLSecret == "" { - l.Info(fmt.Sprintf("Waiting for TransportURL %s secret to be created", transportURL.Name)) + Log.Info(fmt.Sprintf("Waiting for TransportURL %s secret to be created", transportURL.Name)) instance.Status.Conditions.Set(condition.FalseCondition( condition.RabbitMqTransportURLReadyCondition, condition.RequestedReason, @@ -775,7 +775,7 @@ func (r *KeystoneAPIReconciler) reconcileNormal( condition.RabbitMqTransportURLReadyRunningMessage)) return ctrl.Result{RequeueAfter: time.Duration(10) * time.Second}, nil } - l.Info(fmt.Sprintf("TransportURL secret name %s", transportURL.Status.SecretName)) + Log.Info(fmt.Sprintf("TransportURL secret name %s", transportURL.Status.SecretName)) instance.Status.Conditions.MarkTrue(condition.RabbitMqTransportURLReadyCondition, condition.RabbitMqTransportURLReadyMessage) // run check rabbitmq - end @@ -1091,7 +1091,7 @@ func (r *KeystoneAPIReconciler) reconcileNormal( return ctrl.Result{}, err } - l.Info("Reconciled Service successfully") + Log.Info("Reconciled Service successfully") return ctrl.Result{}, nil } @@ -1355,6 +1355,7 @@ func (r *KeystoneAPIReconciler) createHashOfInputHashes( instance *keystonev1.KeystoneAPI, envVars map[string]env.Setter, ) (string, bool, error) { + Log := r.GetLogger(ctx) var hashMap map[string]string changed := false mergedMapVars := env.MergeEnvs([]corev1.EnvVar{}, envVars) @@ -1364,7 +1365,7 @@ func (r *KeystoneAPIReconciler) createHashOfInputHashes( } if hashMap, changed = util.SetHash(instance.Status.Hash, common.InputHashName, hash); changed { instance.Status.Hash = hashMap - GetLog(ctx).Info(fmt.Sprintf("Input maps hash %s - %s", common.InputHashName, hash)) + Log.Info(fmt.Sprintf("Input maps hash %s - %s", common.InputHashName, hash)) } return hash, changed, nil } diff --git a/controllers/keystoneendpoint_controller.go b/controllers/keystoneendpoint_controller.go index c6e3a221..39a699a4 100644 --- a/controllers/keystoneendpoint_controller.go +++ b/controllers/keystoneendpoint_controller.go @@ -26,7 +26,9 @@ import ( ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" + "sigs.k8s.io/controller-runtime/pkg/log" + "github.com/go-logr/logr" keystonev1 "github.com/openstack-k8s-operators/keystone-operator/api/v1beta1" condition "github.com/openstack-k8s-operators/lib-common/modules/common/condition" helper "github.com/openstack-k8s-operators/lib-common/modules/common/helper" @@ -42,6 +44,11 @@ type KeystoneEndpointReconciler struct { Scheme *runtime.Scheme } +// GetLog returns a logger object with a logging prefix of "controller.name" and additional controller context fields +func (r *KeystoneEndpointReconciler) GetLogger(ctx context.Context) logr.Logger { + return log.FromContext(ctx).WithName("Controllers").WithName("KeystoneEndpoint") +} + //+kubebuilder:rbac:groups=keystone.openstack.org,resources=keystoneendpoints,verbs=get;list;watch;create;update;patch;delete //+kubebuilder:rbac:groups=keystone.openstack.org,resources=keystoneendpoints/status,verbs=get;update;patch //+kubebuilder:rbac:groups=keystone.openstack.org,resources=keystoneendpoints/finalizers,verbs=update @@ -52,7 +59,7 @@ type KeystoneEndpointReconciler struct { // Reconcile keystone endpoint requests func (r *KeystoneEndpointReconciler) Reconcile(ctx context.Context, req ctrl.Request) (result ctrl.Result, _err error) { - l := GetLog(ctx) + Log := r.GetLogger(ctx) // Fetch the KeystoneEndpoint instance instance := &keystonev1.KeystoneEndpoint{} @@ -74,7 +81,7 @@ func (r *KeystoneEndpointReconciler) Reconcile(ctx context.Context, req ctrl.Req r.Kclient, r.Scheme, //TODO remove later, log used here as to not break the helper struct signiture. - l, + Log, ) if err != nil { return ctrl.Result{}, err @@ -144,7 +151,7 @@ func (r *KeystoneEndpointReconciler) Reconcile(ctx context.Context, req ctrl.Req condition.SeverityWarning, keystonev1.KeystoneAPIReadyNotFoundMessage, )) - l.Info("KeystoneAPI not found!") + Log.Info("KeystoneAPI not found!") return ctrl.Result{RequeueAfter: time.Second * 5}, nil } @@ -181,7 +188,7 @@ func (r *KeystoneEndpointReconciler) Reconcile(ctx context.Context, req ctrl.Req condition.RequestedReason, condition.SeverityInfo, keystonev1.KeystoneAPIReadyWaitingMessage)) - l.Info("KeystoneAPI not yet ready!") + Log.Info("KeystoneAPI not yet ready!") return ctrl.Result{RequeueAfter: time.Second * 5}, nil } @@ -237,9 +244,9 @@ func (r *KeystoneEndpointReconciler) reconcileDelete( os *openstack.OpenStack, keystoneAPI *keystonev1.KeystoneAPI, ) (ctrl.Result, error) { - l := GetLog(ctx) + Log := r.GetLogger(ctx) - l.Info("Reconciling Endpoint delete") + Log.Info("Reconciling Endpoint delete") // We might not have an OpenStack backend to use in certain situations if os != nil { @@ -253,7 +260,7 @@ func (r *KeystoneEndpointReconciler) reconcileDelete( } err = os.DeleteEndpoint( - l, + Log, openstack.Endpoint{ Name: instance.Spec.ServiceName, ServiceID: instance.Status.ServiceID, @@ -297,7 +304,7 @@ func (r *KeystoneEndpointReconciler) reconcileDelete( // Endpoints are deleted so remove the finalizer. controllerutil.RemoveFinalizer(instance, helper.GetFinalizer()) - l.Info("Reconciled Endpoint delete successfully") + Log.Info("Reconciled Endpoint delete successfully") return ctrl.Result{}, nil } @@ -308,8 +315,8 @@ func (r *KeystoneEndpointReconciler) reconcileDeleteFinalizersOnly( helper *helper.Helper, keystoneAPI *keystonev1.KeystoneAPI, ) (ctrl.Result, error) { - l := GetLog(ctx) - l.Info("Reconciling Endpoint delete while KeystoneAPI is being deleted") + Log := r.GetLogger(ctx) + Log.Info("Reconciling Endpoint delete while KeystoneAPI is being deleted") ksSvc, err := keystonev1.GetKeystoneServiceWithName(ctx, helper, instance.Spec.ServiceName, instance.Namespace) if err == nil { @@ -334,7 +341,7 @@ func (r *KeystoneEndpointReconciler) reconcileDeleteFinalizersOnly( } controllerutil.RemoveFinalizer(instance, helper.GetFinalizer()) - l.Info("Reconciled Endpoint delete successfully") + Log.Info("Reconciled Endpoint delete successfully") return ctrl.Result{}, nil } @@ -346,8 +353,8 @@ func (r *KeystoneEndpointReconciler) reconcileNormal( os *openstack.OpenStack, keystoneAPI *keystonev1.KeystoneAPI, ) (ctrl.Result, error) { - l := GetLog(ctx) - l.Info("Reconciling Endpoint normal") + Log := r.GetLogger(ctx) + Log.Info("Reconciling Endpoint normal") // // Wait for KeystoneService is Ready and get the ServiceID from the object @@ -355,7 +362,7 @@ func (r *KeystoneEndpointReconciler) reconcileNormal( ksSvc, err := keystonev1.GetKeystoneServiceWithName(ctx, helper, instance.Spec.ServiceName, instance.Namespace) if err != nil { if k8s_errors.IsNotFound(err) { - l.Info("KeystoneService not found", "KeystoneService", instance.Spec.ServiceName) + Log.Info("KeystoneService not found", "KeystoneService", instance.Spec.ServiceName) return ctrl.Result{RequeueAfter: time.Second * 5}, nil } @@ -369,7 +376,7 @@ func (r *KeystoneEndpointReconciler) reconcileNormal( } if !ksSvc.IsReady() { - l.Info("KeystoneService not ready, waiting to create endpoints", "KeystoneService", instance.Spec.ServiceName) + Log.Info("KeystoneService not ready, waiting to create endpoints", "KeystoneService", instance.Spec.ServiceName) return ctrl.Result{RequeueAfter: 10 * time.Second}, nil } @@ -424,7 +431,7 @@ func (r *KeystoneEndpointReconciler) reconcileNormal( instance.Spec.Endpoints, ) - l.Info("Reconciled Endpoint normal successfully") + Log.Info("Reconciled Endpoint normal successfully") return ctrl.Result{}, nil } @@ -434,8 +441,8 @@ func (r *KeystoneEndpointReconciler) reconcileEndpoints( instance *keystonev1.KeystoneEndpoint, os *openstack.OpenStack, ) error { - l := GetLog(ctx) - l.Info("Reconciling Endpoints") + Log := r.GetLogger(ctx) + Log.Info("Reconciling Endpoints") // delete endpoint if it does no longer exist in Spec.Endpoints // but has a reference in Status.EndpointIDs @@ -449,7 +456,7 @@ func (r *KeystoneEndpointReconciler) reconcileEndpoints( } err = os.DeleteEndpoint( - l, + Log, openstack.Endpoint{ Name: instance.Spec.ServiceName, ServiceID: instance.Status.ServiceID, @@ -477,7 +484,7 @@ func (r *KeystoneEndpointReconciler) reconcileEndpoints( // get registered endpoints for the service and endpointType allEndpoints, err := os.GetEndpoints( - l, + Log, instance.Status.ServiceID, endpointType) if err != nil { @@ -488,7 +495,7 @@ func (r *KeystoneEndpointReconciler) reconcileEndpoints( if len(allEndpoints) == 0 { // Create the endpoint endpointID, err = os.CreateEndpoint( - l, + Log, openstack.Endpoint{ Name: instance.Spec.ServiceName, ServiceID: instance.Status.ServiceID, @@ -504,7 +511,7 @@ func (r *KeystoneEndpointReconciler) reconcileEndpoints( endpoint := allEndpoints[0] if endpointURL != endpoint.URL { endpointID, err = os.UpdateEndpoint( - l, + Log, openstack.Endpoint{ Name: endpoint.Name, ServiceID: endpoint.ServiceID, @@ -534,7 +541,7 @@ func (r *KeystoneEndpointReconciler) reconcileEndpoints( } } - l.Info("Reconciled Endpoints successfully") + Log.Info("Reconciled Endpoints successfully") return nil } diff --git a/controllers/keystoneservice_controller.go b/controllers/keystoneservice_controller.go index 508341c8..0a5fdb54 100644 --- a/controllers/keystoneservice_controller.go +++ b/controllers/keystoneservice_controller.go @@ -22,6 +22,7 @@ import ( "strings" "time" + "github.com/go-logr/logr" keystonev1 "github.com/openstack-k8s-operators/keystone-operator/api/v1beta1" condition "github.com/openstack-k8s-operators/lib-common/modules/common/condition" helper "github.com/openstack-k8s-operators/lib-common/modules/common/helper" @@ -34,6 +35,7 @@ import ( ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" + "sigs.k8s.io/controller-runtime/pkg/log" "sigs.k8s.io/controller-runtime/pkg/reconcile" ) @@ -59,6 +61,11 @@ type KeystoneServiceReconciler struct { Scheme *runtime.Scheme } +// GetLogger returns a logger object with a logging prefix of "controller.name" and additional controller context fields +func (r *KeystoneServiceReconciler) GetLogger(ctx context.Context) logr.Logger { + return log.FromContext(ctx).WithName("Controllers").WithName("KeystoneService") +} + // +kubebuilder:rbac:groups=keystone.openstack.org,resources=keystoneservices,verbs=get;list;watch;create;update;patch;delete // +kubebuilder:rbac:groups=keystone.openstack.org,resources=keystoneservices/status,verbs=get;update;patch // +kubebuilder:rbac:groups=keystone.openstack.org,resources=keystoneservices/finalizers,verbs=update @@ -68,7 +75,7 @@ type KeystoneServiceReconciler struct { // Reconcile keystone service requests func (r *KeystoneServiceReconciler) Reconcile(ctx context.Context, req ctrl.Request) (result ctrl.Result, _err error) { - l := GetLog(ctx) + log := r.GetLogger(ctx) // Fetch the KeystoneService instance instance := &keystonev1.KeystoneService{} @@ -90,7 +97,7 @@ func (r *KeystoneServiceReconciler) Reconcile(ctx context.Context, req ctrl.Requ r.Kclient, r.Scheme, //TODO remove later, log used here as to not break the helper struct signiture. - l, + log, ) if err != nil { return ctrl.Result{}, err @@ -158,7 +165,7 @@ func (r *KeystoneServiceReconciler) Reconcile(ctx context.Context, req ctrl.Requ condition.SeverityWarning, keystonev1.KeystoneAPIReadyNotFoundMessage, )) - l.Info("KeystoneAPI not found!") + log.Info("KeystoneAPI not found!") return ctrl.Result{RequeueAfter: time.Second * 5}, nil } instance.Status.Conditions.Set(condition.FalseCondition( @@ -194,7 +201,7 @@ func (r *KeystoneServiceReconciler) Reconcile(ctx context.Context, req ctrl.Requ condition.RequestedReason, condition.SeverityInfo, keystonev1.KeystoneAPIReadyWaitingMessage)) - l.Info("KeystoneAPI not yet ready") + log.Info("KeystoneAPI not yet ready") return ctrl.Result{RequeueAfter: time.Second * 5}, nil } instance.Status.Conditions.MarkTrue(keystonev1.KeystoneAPIReadyCondition, keystonev1.KeystoneAPIReadyMessage) @@ -250,15 +257,15 @@ func (r *KeystoneServiceReconciler) reconcileDelete( os *openstack.OpenStack, keystoneAPI *keystonev1.KeystoneAPI, ) (ctrl.Result, error) { - l := GetLog(ctx) - l.Info("Reconciling Service delete") + log := r.GetLogger(ctx) + log.Info("Reconciling Service delete") // only cleanup the service if there is the ServiceID reference in the // object status and if we have an OpenStack backend to use if instance.Status.ServiceID != "" && os != nil { // Delete User err := os.DeleteUser( - l, + log, instance.Spec.ServiceUser, "default") if err != nil { @@ -267,10 +274,10 @@ func (r *KeystoneServiceReconciler) reconcileDelete( // Delete Service err = os.DeleteService( - l, + log, instance.Status.ServiceID) if err != nil { - l.Info(err.Error()) + log.Info(err.Error()) return ctrl.Result{}, err } @@ -280,7 +287,7 @@ func (r *KeystoneServiceReconciler) reconcileDelete( // etcd) instance.Status.ServiceID = "" } else { - l.Info("Not deleting service as there is no stores service ID", "KeystoneService", instance.Spec.ServiceName) + log.Info("Not deleting service as there is no stores service ID", "KeystoneService", instance.Spec.ServiceName) } // There are certain deletion scenarios where we might not have the keystoneAPI @@ -297,7 +304,7 @@ func (r *KeystoneServiceReconciler) reconcileDelete( // Service is deleted so remove the finalizer. controllerutil.RemoveFinalizer(instance, helper.GetFinalizer()) - l.Info("Reconciled Service delete successfully") + log.Info("Reconciled Service delete successfully") return ctrl.Result{}, nil } @@ -308,8 +315,8 @@ func (r *KeystoneServiceReconciler) reconcileDeleteFinalizersOnly( helper *helper.Helper, keystoneAPI *keystonev1.KeystoneAPI, ) (ctrl.Result, error) { - l := GetLog(ctx) - l.Info("Reconciling Service delete while KeystoneAPI is being deleted") + Log := r.GetLogger(ctx) + Log.Info("Reconciling Service delete while KeystoneAPI is being deleted") if controllerutil.RemoveFinalizer(keystoneAPI, fmt.Sprintf("%s-%s", helper.GetFinalizer(), instance.Name)) { err := r.Update(ctx, keystoneAPI) @@ -320,7 +327,7 @@ func (r *KeystoneServiceReconciler) reconcileDeleteFinalizersOnly( } controllerutil.RemoveFinalizer(instance, helper.GetFinalizer()) - l.Info("Reconciled Service delete successfully") + Log.Info("Reconciled Service delete successfully") return ctrl.Result{}, nil } @@ -332,8 +339,8 @@ func (r *KeystoneServiceReconciler) reconcileNormal( os *openstack.OpenStack, keystoneAPI *keystonev1.KeystoneAPI, ) (ctrl.Result, error) { - l := GetLog(ctx) - l.Info("Reconciling Service") + log := r.GetLogger(ctx) + log.Info("Reconciling Service") // // Add a finalizer to the KeystoneAPI for this service instance, as we do not want the @@ -399,7 +406,7 @@ func (r *KeystoneServiceReconciler) reconcileNormal( instance.Spec.ServiceUser, ) - l.Info("Reconciled Service successfully") + log.Info("Reconciled Service successfully") return ctrl.Result{}, nil } @@ -408,12 +415,12 @@ func (r *KeystoneServiceReconciler) reconcileService( instance *keystonev1.KeystoneService, os *openstack.OpenStack, ) error { - l := GetLog(ctx) - l.Info("Reconciling Service ", "KeystoneService", instance.Spec.ServiceName) + log := r.GetLogger(ctx) + log.Info("Reconciling Service ", "KeystoneService", instance.Spec.ServiceName) // verify if there is already a service in keystone for the type and name service, err := os.GetService( - l, + log, instance.Spec.ServiceType, instance.Spec.ServiceName, ) @@ -426,7 +433,7 @@ func (r *KeystoneServiceReconciler) reconcileService( if service == nil { // create the service instance.Status.ServiceID, err = os.CreateService( - l, + log, openstack.Service{ Name: instance.Spec.ServiceName, Type: instance.Spec.ServiceType, @@ -446,7 +453,7 @@ func (r *KeystoneServiceReconciler) reconcileService( service.Extra["description"] != instance.Spec.ServiceDescription { // update the service ONLY if Enabled or Description changed. err := os.UpdateService( - l, + log, openstack.Service{ Name: instance.Spec.ServiceName, Type: instance.Spec.ServiceType, @@ -460,7 +467,7 @@ func (r *KeystoneServiceReconciler) reconcileService( } } - l.Info("Reconciled Service successfully") + log.Info("Reconciled Service successfully") return nil } @@ -470,8 +477,8 @@ func (r *KeystoneServiceReconciler) reconcileUser( instance *keystonev1.KeystoneService, os *openstack.OpenStack, ) (reconcile.Result, error) { - l := GetLog(ctx) - l.Info("Reconciling User", "User", instance.Spec.ServiceUser) + log := r.GetLogger(ctx) + log.Info("Reconciling User", "User", instance.Spec.ServiceUser) roleNames := []string{"admin", "service"} // get the password of the service user from the secret @@ -492,7 +499,7 @@ func (r *KeystoneServiceReconciler) reconcileUser( // create service project if it does not exist // serviceProjectID, err := os.CreateProject( - l, + log, openstack.Project{ Name: "service", Description: "service", @@ -506,7 +513,7 @@ func (r *KeystoneServiceReconciler) reconcileUser( // create user if it does not exist // userID, err := os.CreateUser( - l, + log, openstack.User{ Name: instance.Spec.ServiceUser, Password: password, @@ -522,7 +529,7 @@ func (r *KeystoneServiceReconciler) reconcileUser( // create role if it does not exist // _, err = os.CreateRole( - l, + log, roleName) if err != nil { return ctrl.Result{}, err @@ -532,7 +539,7 @@ func (r *KeystoneServiceReconciler) reconcileUser( // add the role to the user // err = os.AssignUserRole( - l, + log, roleName, userID, serviceProjectID) @@ -541,6 +548,6 @@ func (r *KeystoneServiceReconciler) reconcileUser( } } - l.Info("Reconciled User successfully") + log.Info("Reconciled User successfully") return ctrl.Result{}, nil } diff --git a/main.go b/main.go index f5f43d98..904e262f 100644 --- a/main.go +++ b/main.go @@ -17,6 +17,7 @@ limitations under the License. package main import ( + "context" "crypto/tls" "flag" "os" @@ -123,7 +124,7 @@ func main() { Client: mgr.GetClient(), Scheme: mgr.GetScheme(), Kclient: kclient, - }).SetupWithManager(mgr); err != nil { + }).SetupWithManager(context.Background(), mgr); err != nil { setupLog.Error(err, "unable to create controller", "controller", "KeystoneAPI") os.Exit(1) } diff --git a/tests/functional/suite_test.go b/tests/functional/suite_test.go index f82b8de8..1b15a639 100644 --- a/tests/functional/suite_test.go +++ b/tests/functional/suite_test.go @@ -173,7 +173,7 @@ var _ = BeforeSuite(func() { Client: k8sManager.GetClient(), Scheme: k8sManager.GetScheme(), Kclient: kclient, - }).SetupWithManager(k8sManager) + }).SetupWithManager(context.Background(), k8sManager) Expect(err).ToNot(HaveOccurred()) go func() {