Skip to content

Commit

Permalink
feature(helmController) enable/disablement of a plugin #556
Browse files Browse the repository at this point in the history
  • Loading branch information
ibakshay committed Sep 10, 2024
1 parent 4247246 commit a909e97
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
3 changes: 3 additions & 0 deletions pkg/apis/greenhouse/v1alpha1/plugin_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ const (
// NoHelmChartTestFailuresCondition reflects the status of the HelmChart tests.
NoHelmChartTestFailuresCondition ConditionType = "NoHelmChartTestFailures"

// PluginDisabled reflects the status of the Plugin being disabled.
PluginDisabledCondition ConditionType = "PluginDisabled"

// PluginDefinitionNotFoundReason is set when the pluginDefinition is not found.
PluginDefinitionNotFoundReason ConditionReason = "PluginDefinitionNotFound"

Expand Down
25 changes: 23 additions & 2 deletions pkg/controllers/plugin/helm_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ var exposedConditions = []greenhousev1alpha1.ConditionType{
greenhousev1alpha1.StatusUpToDateCondition,
greenhousev1alpha1.NoHelmChartTestFailuresCondition,
greenhousev1alpha1.WorkloadReadyCondition,
greenhousev1alpha1.PluginDisabledCondition,
}

// HelmReconciler reconciles a Plugin object.
Expand Down Expand Up @@ -154,10 +155,30 @@ func (r *HelmReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.
return ctrl.Result{}, fmt.Errorf("pluginDefinition not found: %s", helmReconcileFailedCondition.Message)
}

pluginDisabledCondition := *pluginStatus.GetConditionByType(greenhousev1alpha1.PluginDisabledCondition)
if plugin.Spec.Disabled {
// Uninstall the Helm release if it exists.
releaseNotFound, err := helm.UninstallHelmRelease(ctx, restClientGetter, plugin)
if err != nil {
c := greenhousev1alpha1.TrueCondition(greenhousev1alpha1.HelmReconcileFailedCondition, greenhousev1alpha1.HelmUninstallFailedReason, err.Error())
pluginStatus.StatusConditions.SetConditions(c)
return ctrl.Result{}, err
}
if !releaseNotFound {
fmt.Printf("Uninstalled Helm release for disabled plugin %s\n", plugin.Name)

pluginDisabledCondition.Status = metav1.ConditionTrue
pluginDisabledCondition.Message = "Plugin is disabled successfully"
pluginStatus.StatusConditions.SetConditions(pluginDisabledCondition)
}
return ctrl.Result{}, nil
}

driftDetectedCondition, reconcileFailedCondition := r.reconcileHelmRelease(ctx, restClientGetter, plugin, pluginDefinition, pluginStatus)
pluginStatus.StatusConditions.SetConditions(driftDetectedCondition, reconcileFailedCondition)
pluginDisabledCondition.Status = metav1.ConditionFalse
pluginDisabledCondition.Message = ""
statusReconcileCompleteCondition := r.reconcileStatus(ctx, restClientGetter, plugin, pluginDefinition, &pluginStatus)
pluginStatus.StatusConditions.SetConditions(statusReconcileCompleteCondition)
pluginStatus.StatusConditions.SetConditions(driftDetectedCondition, reconcileFailedCondition, pluginDisabledCondition, statusReconcileCompleteCondition)

if reconcileFailedCondition.IsTrue() {
return ctrl.Result{}, fmt.Errorf("helm reconcile failed: %s", reconcileFailedCondition.Message)
Expand Down

0 comments on commit a909e97

Please sign in to comment.