Skip to content
This repository has been archived by the owner on Jan 28, 2022. It is now read-only.

Commit

Permalink
Added status updates to config to prevent wasted cycles.
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonTheDeveloper committed Nov 27, 2019
1 parent c0a5ccf commit a4c4b6e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
8 changes: 4 additions & 4 deletions api/v1alpha1/secretscope_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}

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

Expand Down
10 changes: 4 additions & 6 deletions controllers/secretscope_controller_databricks.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit a4c4b6e

Please sign in to comment.