Skip to content

Commit

Permalink
Merge pull request #164 from mauricioharley/continuation_PR145
Browse files Browse the repository at this point in the history
Continuation pr145
  • Loading branch information
openshift-merge-bot[bot] authored Sep 27, 2024
2 parents 11e87a8 + eecd44d commit 1c976d0
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 28 deletions.
29 changes: 15 additions & 14 deletions controllers/barbicankeystonelistener_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,31 +178,32 @@ func (r *BarbicanKeystoneListenerReconciler) getSecret(
h *helper.Helper,
instance *barbicanv1beta1.BarbicanKeystoneListener,
secretName string,
expectedFields []string,
envVars *map[string]env.Setter,
) (ctrl.Result, error) {
secret, hash, err := secret.GetSecret(ctx, h, secretName, instance.Namespace)
Log := r.GetLogger(ctx)
hash, result, err := secret.VerifySecret(ctx, types.NamespacedName{Name: secretName, Namespace: instance.Namespace}, expectedFields, h.GetClient(), time.Second*10)
if err != nil {
if k8s_errors.IsNotFound(err) {
h.GetLogger().Info(fmt.Sprintf("secret %s not found", secretName))
instance.Status.Conditions.Set(condition.FalseCondition(
condition.InputReadyCondition,
condition.RequestedReason,
condition.SeverityInfo,
condition.InputReadyWaitingMessage))
return ctrl.Result{RequeueAfter: time.Duration(10) * time.Second}, nil
}
instance.Status.Conditions.Set(condition.FalseCondition(
condition.InputReadyCondition,
condition.ErrorReason,
condition.SeverityWarning,
condition.InputReadyErrorMessage,
err.Error()))
return ctrl.Result{}, err
} else if (result != ctrl.Result{}) {
Log.Info(fmt.Sprintf("OpenStack secret %s not found", secretName))
instance.Status.Conditions.Set(condition.FalseCondition(
condition.InputReadyCondition,
condition.RequestedReason,
condition.SeverityInfo,
condition.InputReadyWaitingMessage))
return result, nil
}

// Add a prefix to the var name to avoid accidental collision with other non-secret
// vars. The secret names themselves will be unique.
(*envVars)["secret-"+secret.Name] = env.SetValue(hash)
(*envVars)["secret-"+secretName] = env.SetValue(hash)
// env[secret-osp-secret] = hash?

return ctrl.Result{}, nil
Expand Down Expand Up @@ -369,8 +370,8 @@ func (r *BarbicanKeystoneListenerReconciler) reconcileNormal(ctx context.Context
//
// check for required OpenStack secret holding passwords for service/admin user and add hash to the vars map
//
Log.Info(fmt.Sprintf("[KeystoneListener] Get secret 1 '%s'", instance.Name))
ctrlResult, err := r.getSecret(ctx, helper, instance, instance.Spec.Secret, &configVars)
Log.Info(fmt.Sprintf("[KeystoneListener] Get secret 1 '%s'", instance.Spec.Secret))
ctrlResult, err := r.getSecret(ctx, helper, instance, instance.Spec.Secret, []string{instance.Spec.PasswordSelectors.Service}, &configVars)
if err != nil {
return ctrlResult, err
}
Expand All @@ -379,7 +380,7 @@ func (r *BarbicanKeystoneListenerReconciler) reconcileNormal(ctx context.Context
// check for required TransportURL secret holding transport URL string
//
Log.Info(fmt.Sprintf("[KeystoneListener] Get secret 2 '%s'", instance.Spec.TransportURLSecret))
ctrlResult, err = r.getSecret(ctx, helper, instance, instance.Spec.TransportURLSecret, &configVars)
ctrlResult, err = r.getSecret(ctx, helper, instance, instance.Spec.TransportURLSecret, []string{TransportURL}, &configVars)
if err != nil {
return ctrlResult, err
}
Expand Down
29 changes: 15 additions & 14 deletions controllers/barbicanworker_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,31 +167,32 @@ func (r *BarbicanWorkerReconciler) getSecret(
h *helper.Helper,
instance *barbicanv1beta1.BarbicanWorker,
secretName string,
expectedFields []string,
envVars *map[string]env.Setter,
) (ctrl.Result, error) {
secret, hash, err := secret.GetSecret(ctx, h, secretName, instance.Namespace)
Log := r.GetLogger(ctx)
hash, result, err := secret.VerifySecret(ctx, types.NamespacedName{Name: secretName, Namespace: instance.Namespace}, expectedFields, h.GetClient(), time.Second*10)
if err != nil {
if k8s_errors.IsNotFound(err) {
h.GetLogger().Info(fmt.Sprintf("secret %s not found", secretName))
instance.Status.Conditions.Set(condition.FalseCondition(
condition.InputReadyCondition,
condition.RequestedReason,
condition.SeverityInfo,
condition.InputReadyWaitingMessage))
return ctrl.Result{RequeueAfter: time.Duration(10) * time.Second}, nil
}
instance.Status.Conditions.Set(condition.FalseCondition(
condition.InputReadyCondition,
condition.ErrorReason,
condition.SeverityWarning,
condition.InputReadyErrorMessage,
err.Error()))
return ctrl.Result{}, err
} else if (result != ctrl.Result{}) {
Log.Info(fmt.Sprintf("OpenStack secret %s not found", secretName))
instance.Status.Conditions.Set(condition.FalseCondition(
condition.InputReadyCondition,
condition.RequestedReason,
condition.SeverityInfo,
condition.InputReadyWaitingMessage))
return result, nil
}

// Add a prefix to the var name to avoid accidental collision with other non-secret
// vars. The secret names themselves will be unique.
(*envVars)["secret-"+secret.Name] = env.SetValue(hash)
(*envVars)["secret-"+secretName] = env.SetValue(hash)
// env[secret-osp-secret] = hash?

return ctrl.Result{}, nil
Expand Down Expand Up @@ -331,8 +332,8 @@ func (r *BarbicanWorkerReconciler) reconcileNormal(ctx context.Context, instance
//
// check for required OpenStack secret holding passwords for service/admin user and add hash to the vars map
//
Log.Info(fmt.Sprintf("[Worker] Get secret 1 '%s'", instance.Name))
ctrlResult, err := r.getSecret(ctx, helper, instance, instance.Spec.Secret, &configVars)
Log.Info(fmt.Sprintf("[API] Get secret 1 '%s'", instance.Spec.Secret))
ctrlResult, err := r.getSecret(ctx, helper, instance, instance.Spec.Secret, []string{instance.Spec.PasswordSelectors.Service}, &configVars)
if err != nil {
return ctrlResult, err
}
Expand All @@ -341,7 +342,7 @@ func (r *BarbicanWorkerReconciler) reconcileNormal(ctx context.Context, instance
// check for required TransportURL secret holding transport URL string
//
Log.Info(fmt.Sprintf("[Worker] Get secret 2 '%s'", instance.Spec.TransportURLSecret))
ctrlResult, err = r.getSecret(ctx, helper, instance, instance.Spec.TransportURLSecret, &configVars)
ctrlResult, err = r.getSecret(ctx, helper, instance, instance.Spec.TransportURLSecret, []string{TransportURL}, &configVars)
if err != nil {
return ctrlResult, err
}
Expand Down

0 comments on commit 1c976d0

Please sign in to comment.