From ed1aa4502c73a255214e9655f653d1264e0d52d5 Mon Sep 17 00:00:00 2001 From: Mauricio Harley Date: Wed, 25 Oct 2023 07:12:30 -0400 Subject: [PATCH] Add missing requeue and Owns --- api/v1beta1/barbicankeystonelistener_types.go | 3 -- controllers/barbican_controller.go | 21 ++---------- controllers/barbicanapi_controller.go | 3 +- .../barbicankeystonelistener_controller.go | 29 +++------------- controllers/barbicanworker_controller.go | 6 ++-- pkg/barbicankeystonelistener/deployment.go | 33 ------------------- templates/barbican/config/00-default.conf | 4 +-- 7 files changed, 13 insertions(+), 86 deletions(-) diff --git a/api/v1beta1/barbicankeystonelistener_types.go b/api/v1beta1/barbicankeystonelistener_types.go index b7732aa..28e69df 100644 --- a/api/v1beta1/barbicankeystonelistener_types.go +++ b/api/v1beta1/barbicankeystonelistener_types.go @@ -49,9 +49,6 @@ type BarbicanKeystoneListenerStatus struct { // Map of hashes to track e.g. job status Hash map[string]string `json:"hash,omitempty"` - // API endpoint - //APIEndpoints map[string]string `json:"apiEndpoint,omitempty"` - // Conditions Conditions condition.Conditions `json:"conditions,omitempty" optional:"true"` diff --git a/controllers/barbican_controller.go b/controllers/barbican_controller.go index a59574d..f4f0c7c 100644 --- a/controllers/barbican_controller.go +++ b/controllers/barbican_controller.go @@ -353,23 +353,6 @@ func (r *BarbicanReconciler) reconcileNormal(ctx context.Context, instance *barb func (r *BarbicanReconciler) reconcileDelete(ctx context.Context, instance *barbicanv1beta1.Barbican, helper *helper.Helper) (ctrl.Result, error) { r.Log.Info(fmt.Sprintf("Reconciling Service '%s' delete", instance.Name)) - // TODO(afaranha): Rename Keystone with Barbican - // 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 - // case of the Memcached dependency, if Memcached is deleted before all Keystone - // cleanup has finished, then the Keystone logic will likely hit a 500 error and - // thus its deletion will hang indefinitely. - for _, finalizer := range instance.Finalizers { - // If this finalizer is not our KeystoneAPI finalizer, then it is either - // a KeystoneService or KeystoneEndpointer finalizer, which indicates that - // there is more Keystone processing that needs to finish before we can - // allow our DB and Memcached dependencies to be potentially deleted - // themselves - if finalizer != helper.GetFinalizer() { - return ctrl.Result{}, nil - } - } - // remove db finalizer first db, err := mariadbv1.GetDatabaseByName(ctx, helper, instance.Name) if err != nil && !k8s_errors.IsNotFound(err) { @@ -615,7 +598,7 @@ func (r *BarbicanReconciler) workerDeploymentCreateOrUpdate(ctx context.Context, return err } - // Add a finalizer to prevent user from manually removing child BarbicanAPI + // Add a finalizer to prevent user from manually removing child BarbicanWorker controllerutil.AddFinalizer(deployment, helper.GetFinalizer()) return nil @@ -651,7 +634,7 @@ func (r *BarbicanReconciler) keystoneListenerDeploymentCreateOrUpdate(ctx contex return err } - // Add a finalizer to prevent user from manually removing child BarbicanAPI + // Add a finalizer to prevent user from manually removing child BarbicanKeystoneListener controllerutil.AddFinalizer(deployment, helper.GetFinalizer()) return nil diff --git a/controllers/barbicanapi_controller.go b/controllers/barbicanapi_controller.go index 4452cd8..8da1eb0 100644 --- a/controllers/barbicanapi_controller.go +++ b/controllers/barbicanapi_controller.go @@ -92,6 +92,8 @@ func (r *BarbicanAPIReconciler) Reconcile(ctx context.Context, req ctrl.Request) // Object not found return ctrl.Result{}, err } + // Error reading the object - requeue the request. + return ctrl.Result{}, err } r.Log.Info(fmt.Sprintf("Reconciling BarbicanAPI %s", instance.Name)) @@ -621,7 +623,6 @@ func (r *BarbicanAPIReconciler) reconcileNormal(ctx context.Context, instance *b func (r *BarbicanAPIReconciler) SetupWithManager(mgr ctrl.Manager) error { return ctrl.NewControllerManagedBy(mgr). For(&barbicanv1beta1.BarbicanAPI{}). - //Owns(&keystonev1.KeystoneEndpoint{}). Owns(&corev1.Service{}). Owns(&corev1.Secret{}). Owns(&appsv1.Deployment{}). diff --git a/controllers/barbicankeystonelistener_controller.go b/controllers/barbicankeystonelistener_controller.go index aeb0710..450a9ec 100644 --- a/controllers/barbicankeystonelistener_controller.go +++ b/controllers/barbicankeystonelistener_controller.go @@ -44,33 +44,11 @@ import ( "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" "sigs.k8s.io/controller-runtime/pkg/log" - //appsv1 "k8s.io/api/apps/v1" + appsv1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" k8s_errors "k8s.io/apimachinery/pkg/api/errors" ) -/* -// GetClient - -func (r *BarbicanAPIReconciler) GetClient() client.Client { - return r.Client -} - -// GetKClient - -func (r *BarbicanAPIReconciler) GetKClient() kubernetes.Interface { - return r.Kclient -} - -// GetLogger - -func (r *BarbicanAPIReconciler) GetLogger() logr.Logger { - return r.Log -} - -// GetScheme - -func (r *BarbicanAPIReconciler) GetScheme() *runtime.Scheme { - return r.Scheme -} -*/ - // BarbicanKeystoneListenerReconciler reconciles a BarbicanKeystoneListener object type BarbicanKeystoneListenerReconciler struct { client.Client @@ -94,6 +72,8 @@ func (r *BarbicanKeystoneListenerReconciler) Reconcile(ctx context.Context, req // Object not found return ctrl.Result{}, err } + // Error reading the object - requeue the request. + return ctrl.Result{}, err } r.Log.Info(fmt.Sprintf("Reconciling BarbicanKeystoneListener %s", instance.Name)) @@ -637,10 +617,9 @@ func (r *BarbicanKeystoneListenerReconciler) reconcileNormal(ctx context.Context func (r *BarbicanKeystoneListenerReconciler) SetupWithManager(mgr ctrl.Manager) error { return ctrl.NewControllerManagedBy(mgr). For(&barbicanv1beta1.BarbicanKeystoneListener{}). - //Owns(&keystonev1.KeystoneEndpoint{}). //Owns(&corev1.Service{}). //Owns(&corev1.Secret{}). - //Owns(&appsv1.Deployment{}). + Owns(&appsv1.Deployment{}). //Owns(&routev1.Route{}). Complete(r) } diff --git a/controllers/barbicanworker_controller.go b/controllers/barbicanworker_controller.go index 73c214f..90408db 100644 --- a/controllers/barbicanworker_controller.go +++ b/controllers/barbicanworker_controller.go @@ -43,11 +43,11 @@ import ( "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" "sigs.k8s.io/controller-runtime/pkg/log" + appsv1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" k8s_errors "k8s.io/apimachinery/pkg/api/errors" ) - // BarbicanWorkerReconciler reconciles a BarbicanWorker object type BarbicanWorkerReconciler struct { client.Client @@ -70,6 +70,8 @@ func (r *BarbicanWorkerReconciler) Reconcile(ctx context.Context, req ctrl.Reque if k8s_errors.IsNotFound(err) { return ctrl.Result{}, err } + // Error reading the object - requeue the request. + return ctrl.Result{}, err } r.Log.Info(fmt.Sprintf("Reconciling BarbicanWorker %s", instance.Name)) @@ -477,7 +479,7 @@ func (r *BarbicanWorkerReconciler) SetupWithManager(mgr ctrl.Manager) error { For(&barbicanv1beta1.BarbicanWorker{}). //Owns(&corev1.Service{}). //Owns(&corev1.Secret{}). - //Owns(&appsv1.Deployment{}). + Owns(&appsv1.Deployment{}). //Owns(&routev1.Route{}). Complete(r) } diff --git a/pkg/barbicankeystonelistener/deployment.go b/pkg/barbicankeystonelistener/deployment.go index 7f485c8..5c771d1 100644 --- a/pkg/barbicankeystonelistener/deployment.go +++ b/pkg/barbicankeystonelistener/deployment.go @@ -8,7 +8,6 @@ import ( appsv1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - //"k8s.io/apimachinery/pkg/util/intstr" barbicanv1beta1 "github.com/openstack-k8s-operators/barbican-operator/api/v1beta1" barbican "github.com/openstack-k8s-operators/barbican-operator/pkg/barbican" @@ -31,39 +30,11 @@ func Deployment( envVars := map[string]env.Setter{} envVars["KOLLA_CONFIG_STRATEGY"] = env.SetValue("COPY_ALWAYS") envVars["CONFIG_HASH"] = env.SetValue(configHash) - /* - livenessProbe := &corev1.Probe{ - // TODO might need tuning - TimeoutSeconds: 5, - PeriodSeconds: 3, - InitialDelaySeconds: 5, - } - readinessProbe := &corev1.Probe{ - // TODO might need tuning - TimeoutSeconds: 5, - PeriodSeconds: 5, - InitialDelaySeconds: 5, - } - */ args := []string{"-c"} if instance.Spec.Debug.Service { args = append(args, common.DebugCommand) - //livenessProbe.Exec = &corev1.ExecAction{ - // Command: []string{ - // "/bin/true", - // }, - //} - //readinessProbe.Exec = livenessProbe.Exec } else { args = append(args, ServiceCommand) - // - // https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/ - // - //livenessProbe.HTTPGet = &corev1.HTTPGetAction{ - // Path: "/healthcheck", - // Port: intstr.IntOrString{Type: intstr.Int, IntVal: int32(barbican.BarbicanPublicPort)}, - //} - //readinessProbe.HTTPGet = livenessProbe.HTTPGet } keystoneListenerVolumes := []corev1.Volume{ @@ -123,8 +94,6 @@ func Deployment( Env: env.MergeEnvs([]corev1.EnvVar{}, envVars), VolumeMounts: barbican.GetLogVolumeMount(), Resources: instance.Spec.Resources, - //ReadinessProbe: readinessProbe, - //LivenessProbe: livenessProbe, }, { Name: barbican.ServiceName + "-keystone-listener", @@ -143,8 +112,6 @@ func Deployment( keystoneListenerVolumeMounts..., ), Resources: instance.Spec.Resources, - //ReadinessProbe: readinessProbe, - //LivenessProbe: livenessProbe, }, }, }, diff --git a/templates/barbican/config/00-default.conf b/templates/barbican/config/00-default.conf index 42198a8..ec21131 100644 --- a/templates/barbican/config/00-default.conf +++ b/templates/barbican/config/00-default.conf @@ -22,12 +22,10 @@ interface = internal [keystone_notifications] enable = true -topic = notifications +topic = barbican_notifications [oslo_messaging_notifications] -# TODO: update later once rabbit is working driver=messagingv2 -#driver=noop [oslo_policy] enforce_scope = true