Skip to content

Commit

Permalink
Add missing requeue and Owns
Browse files Browse the repository at this point in the history
  • Loading branch information
Mauricio Harley committed Oct 31, 2023
1 parent b0449e3 commit ed1aa45
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 86 deletions.
3 changes: 0 additions & 3 deletions api/v1beta1/barbicankeystonelistener_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`

Expand Down
21 changes: 2 additions & 19 deletions controllers/barbican_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion controllers/barbicanapi_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down Expand Up @@ -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{}).
Expand Down
29 changes: 4 additions & 25 deletions controllers/barbicankeystonelistener_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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))

Expand Down Expand Up @@ -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)
}
6 changes: 4 additions & 2 deletions controllers/barbicanworker_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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))

Expand Down Expand Up @@ -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)
}
33 changes: 0 additions & 33 deletions pkg/barbicankeystonelistener/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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{
Expand Down Expand Up @@ -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",
Expand All @@ -143,8 +112,6 @@ func Deployment(
keystoneListenerVolumeMounts...,
),
Resources: instance.Spec.Resources,
//ReadinessProbe: readinessProbe,
//LivenessProbe: livenessProbe,
},
},
},
Expand Down
4 changes: 1 addition & 3 deletions templates/barbican/config/00-default.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ed1aa45

Please sign in to comment.