Skip to content

Commit

Permalink
Add managementState annotation
Browse files Browse the repository at this point in the history
  • Loading branch information
VaishnaviHire committed Oct 18, 2024
1 parent 04e1ccd commit 4b40c43
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 16 deletions.
28 changes: 16 additions & 12 deletions controllers/components/dashboard/dashboard_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,28 +111,32 @@ func NewDashboardReconciler(ctx context.Context, mgr ctrl.Manager) error {
}

func GetDashboardInstance(dsc *dscv1.DataScienceCluster) *componentsv1.Dashboard {
dashboardInstance := &componentsv1.Dashboard{
dashboardAnnotations := make(map[string]string)

switch dsc.Spec.Components.Dashboard.ManagementState {
case operatorv1.Managed:
dashboardAnnotations[annotation.ManagementStateAnnotation] = string(operatorv1.Managed)
case operatorv1.Removed:
dashboardAnnotations[annotation.ManagementStateAnnotation] = string(operatorv1.Removed)
case operatorv1.Unmanaged:
dashboardAnnotations[annotation.ManagementStateAnnotation] = string(operatorv1.Unmanaged)
default:
dashboardAnnotations[annotation.ManagementStateAnnotation] = "Unknown"
}

return &componentsv1.Dashboard{
TypeMeta: metav1.TypeMeta{
Kind: "Dashboard",
APIVersion: "components.opendatahub.io/v1",
},
ObjectMeta: metav1.ObjectMeta{
Name: componentsv1.DashboardInstanceName,
Name: componentsv1.DashboardInstanceName,
Annotations: dashboardAnnotations,
},
Spec: componentsv1.DashboardSpec{
DSCDashboard: dsc.Spec.Components.Dashboard,
},
}

dashboardAnnotation := dashboardInstance.GetAnnotations()
if dsc.Spec.Components.Dashboard.ManagementState == operatorv1.Removed {
dashboardAnnotation[annotation.DeletionAnnotation] = "false"
} else {
dashboardAnnotation[annotation.DeletionAnnotation] = "true"
}

dashboardInstance.SetAnnotations(dashboardAnnotation)
return dashboardInstance
}

// +kubebuilder:rbac:groups=components.opendatahub.io,resources=dashboards,verbs=get;list;watch;create;update;patch;delete
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -372,8 +372,8 @@ func (r *DataScienceClusterReconciler) apply(ctx context.Context, dsc *dscv1.Dat
return err
}

objDeletionAnn, exists := obj.GetAnnotations()[annotations.DeletionAnnotation]
if exists && objDeletionAnn == "true" {
managementStateAnn, exists := obj.GetAnnotations()[annotations.ManagementStateAnnotation]
if exists && managementStateAnn == string(operatorv1.Removed) {
return r.Client.Delete(ctx, obj)
}
if err := r.Client.Apply(ctx, obj, client.FieldOwner(dsc.Name), client.ForceOwnership); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions pkg/metadata/annotations/annotations.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ const (
SecretOauthClientAnnotation = "secret-generator.opendatahub.io/oauth-client-route"
)

// DeletionAnnotation for component CRs.
const DeletionAnnotation = "component.opendatahub.io/deletion"
// ManagementStateAnnotation defines what ManagementState value if defined in DSC for the component.
const ManagementStateAnnotation = "component.opendatahub.io/management-state"

0 comments on commit 4b40c43

Please sign in to comment.