Added status updates to config to prevent wasted cycles.

This commit is contained in:
Jason 2019-11-27 11:10:12 +11:00
Родитель c0a5ccfd71
Коммит 85e7b9bedc
4 изменённых файлов: 15 добавлений и 14 удалений

Просмотреть файл

@ -38,7 +38,7 @@ type SecretScopeStatus struct {
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
// Important: Run "make" to regenerate code after modifying this file
SecretScope *dbmodels.SecretScope `json:"secretscope,omitempty"`
SecretScopeCreated bool `json:"secretscopecreated,omitempty"`
WorkspaceVerified bool `json:"workspaceverified,omitempty"`
SecretInClusterAvailable bool `json:"secretinclusteravailable,omitempty"`
}
@ -58,9 +58,9 @@ func (ss *SecretScope) IsSecretAvailable() bool {
return ss.Status.SecretInClusterAvailable
}
// IsCreated returns SecretScopeCreated's value
func (ss *SecretScope) IsCreated() bool {
return ss.Status.SecretScopeCreated
// IsVerified returns true if the workspace has been verified as deployable ready
func (ss *SecretScope) IsVerified() bool {
return ss.Status.WorkspaceVerified
}
// IsSubmitted returns true if the item has been submitted to DataBricks

Просмотреть файл

@ -84,7 +84,7 @@ spec:
name:
type: string
type: object
secretscopecreated:
workspaceverified:
type: boolean
type: object
type: object

Просмотреть файл

@ -81,21 +81,24 @@ func (r *SecretScopeReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error)
return ctrl.Result{}, nil
}
if !instance.IsSubmitted() {
if !instance.IsVerified() {
if err = r.verifyWorkspace(instance); err != nil {
r.Recorder.Event(instance, corev1.EventTypeWarning, "Failed", err.Error())
return ctrl.Result{}, nil
}
}
if !instance.IsSecretAvailable() {
if err = r.checkSecrets(instance); err != nil {
r.Recorder.Event(instance, corev1.EventTypeWarning, "Failed", err.Error())
return ctrl.Result{Requeue: true, RequeueAfter: 30 * time.Second}, fmt.Errorf("error when submitting secret scope to the API: %v", err)
}
}
if !instance.IsSubmitted() {
if err = r.submit(instance); err != nil {
r.Recorder.Event(instance, corev1.EventTypeWarning, "Failed", err.Error())
return ctrl.Result{}, nil
return ctrl.Result{}, fmt.Errorf("error when submitting secret scope to the API: %v", err)
}
}

Просмотреть файл

@ -184,27 +184,25 @@ func (r *SecretScopeReconciler) verifyWorkspace(instance *databricksv1alpha1.Sec
}
}
return nil
instance.Status.WorkspaceVerified = true
return r.Update(context.Background(), instance)
}
// checkSecrets checks if referenced secret is present in k8s or not.
func (r *SecretScopeReconciler) checkSecrets(instance *databricksv1alpha1.SecretScope) error {
scope := instance.ObjectMeta.Name
namespace := instance.Namespace
// if secret in cluster is reference, see if secret exists.
for _, secret := range instance.Spec.SecretScopeSecrets {
if secret.ValueFrom != nil {
if _, err := r.getSecretValueFrom(namespace, secret); err != nil {
// delete scope here because next time the config is applied, it will fail
// because the secret scope already exists from the previous run.
_ = r.APIClient.Secrets().DeleteSecretScope(scope)
return err
}
}
}
return nil
instance.Status.SecretInClusterAvailable = true
return r.Update(context.Background(), instance)
}
func (r *SecretScopeReconciler) submit(instance *databricksv1alpha1.SecretScope) error {