From 219d761f434c4d0a91d7e1dc4a87b699d48d589a Mon Sep 17 00:00:00 2001 From: Wen Zhou Date: Thu, 16 Oct 2025 14:30:14 +0200 Subject: [PATCH] update: cleanup reference to old dashboard AProfile and HWProfile - we should keep the webhook part remain for a while - the upgrade part will be remain for a while too Signed-off-by: Wen Zhou --- .../dashboard/dashboard_controller.go | 11 -- .../dashboard/dashboard_controller_actions.go | 149 ------------------ .../dashboard_controller_actions_test.go | 149 ------------------ .../datasciencecluster/kubebuilder_rbac.go | 4 +- .../dscinitialization_controller.go | 33 ---- 5 files changed, 2 insertions(+), 344 deletions(-) delete mode 100644 internal/controller/components/dashboard/dashboard_controller_actions_test.go diff --git a/internal/controller/components/dashboard/dashboard_controller.go b/internal/controller/components/dashboard/dashboard_controller.go index f856b821bda2..0bd667b7e3b1 100644 --- a/internal/controller/components/dashboard/dashboard_controller.go +++ b/internal/controller/components/dashboard/dashboard_controller.go @@ -27,9 +27,6 @@ import ( rbacv1 "k8s.io/api/rbac/v1" extv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" ctrl "sigs.k8s.io/controller-runtime" - "sigs.k8s.io/controller-runtime/pkg/client" - "sigs.k8s.io/controller-runtime/pkg/event" - "sigs.k8s.io/controller-runtime/pkg/predicate" componentApi "github.com/opendatahub-io/opendatahub-operator/v2/api/components/v1alpha1" "github.com/opendatahub-io/opendatahub-operator/v2/pkg/cluster/gvk" @@ -67,7 +64,6 @@ func (s *componentHandler) NewComponentReconciler(ctx context.Context, mgr ctrl. Owns(&consolev1.ConsoleLink{}). // Those APIs are provided by the component itself hence they should // be watched dynamically - OwnsGVK(gvk.DashboardAcceleratorProfile, reconciler.Dynamic(reconciler.CrdExists(gvk.DashboardAcceleratorProfile))). OwnsGVK(gvk.OdhApplication, reconciler.Dynamic()). OwnsGVK(gvk.OdhDocument, reconciler.Dynamic()). OwnsGVK(gvk.OdhQuickStart, reconciler.Dynamic()). @@ -89,12 +85,6 @@ func (s *componentHandler) NewComponentReconciler(ctx context.Context, mgr ctrl. reconciler.Dynamic(), reconciler.WithPredicates(resources.Deleted()), ). - WatchesGVK(gvk.DashboardHardwareProfile, reconciler.WithEventHandler( - handlers.ToNamed(componentApi.DashboardInstanceName), - ), reconciler.WithPredicates(predicate.Funcs{ - GenericFunc: func(tge event.TypedGenericEvent[client.Object]) bool { return false }, - DeleteFunc: func(tde event.TypedDeleteEvent[client.Object]) bool { return false }, - }), reconciler.Dynamic(reconciler.CrdExists(gvk.DashboardHardwareProfile))). WithAction(initialize). WithAction(setKustomizedParams). WithAction(configureDependencies). @@ -112,7 +102,6 @@ func (s *componentHandler) NewComponentReconciler(ctx context.Context, mgr ctrl. )). WithAction(deploy.NewAction()). WithAction(deployments.NewAction()). - WithAction(reconcileHardwareProfiles). WithAction(updateStatus). // must be the final action WithAction(gc.NewAction( diff --git a/internal/controller/components/dashboard/dashboard_controller_actions.go b/internal/controller/components/dashboard/dashboard_controller_actions.go index 97e6aea50168..3934db67cbd6 100644 --- a/internal/controller/components/dashboard/dashboard_controller_actions.go +++ b/internal/controller/components/dashboard/dashboard_controller_actions.go @@ -5,54 +5,21 @@ import ( "context" "errors" "fmt" - "maps" - "strconv" "strings" - "github.com/go-logr/logr" routev1 "github.com/openshift/api/route/v1" corev1 "k8s.io/api/core/v1" - k8serr "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" - "k8s.io/apimachinery/pkg/runtime" "sigs.k8s.io/controller-runtime/pkg/client" - "sigs.k8s.io/controller-runtime/pkg/log" componentApi "github.com/opendatahub-io/opendatahub-operator/v2/api/components/v1alpha1" - infrav1 "github.com/opendatahub-io/opendatahub-operator/v2/api/infrastructure/v1" "github.com/opendatahub-io/opendatahub-operator/v2/pkg/cluster" - "github.com/opendatahub-io/opendatahub-operator/v2/pkg/cluster/gvk" - odherrors "github.com/opendatahub-io/opendatahub-operator/v2/pkg/controller/actions/errors" odhtypes "github.com/opendatahub-io/opendatahub-operator/v2/pkg/controller/types" odhdeploy "github.com/opendatahub-io/opendatahub-operator/v2/pkg/deploy" "github.com/opendatahub-io/opendatahub-operator/v2/pkg/metadata/labels" "github.com/opendatahub-io/opendatahub-operator/v2/pkg/resources" ) -type DashboardHardwareProfile struct { - metav1.TypeMeta `json:",inline"` - metav1.ObjectMeta `json:"metadata,omitempty"` - - Spec DashboardHardwareProfileSpec `json:"spec"` -} - -type DashboardHardwareProfileSpec struct { - DisplayName string `json:"displayName"` - Enabled bool `json:"enabled"` - Description string `json:"description,omitempty"` - Tolerations []corev1.Toleration `json:"tolerations,omitempty"` - Identifiers []infrav1.HardwareIdentifier `json:"identifiers,omitempty"` - NodeSelector map[string]string `json:"nodeSelector,omitempty"` -} - -type DashboardHardwareProfileList struct { - metav1.TypeMeta `json:",inline"` - metav1.ListMeta `json:"metadata,omitempty"` - - Items []DashboardHardwareProfile `json:"items"` -} - func initialize(ctx context.Context, rr *odhtypes.ReconciliationRequest) error { rr.Manifests = []odhtypes.ManifestInfo{defaultManifestInfo(rr.Release.Name)} @@ -135,119 +102,3 @@ func updateStatus(ctx context.Context, rr *odhtypes.ReconciliationRequest) error return nil } - -func reconcileHardwareProfiles(ctx context.Context, rr *odhtypes.ReconciliationRequest) error { - // If the dashboard HWP CRD doesn't exist, skip any migration logic - dashHwpCRDExists, err := cluster.HasCRD(ctx, rr.Client, gvk.DashboardHardwareProfile) - if err != nil { - return odherrors.NewStopError("failed to check if %s CRD exists: %w", gvk.DashboardHardwareProfile, err) - } - if !dashHwpCRDExists { - return nil - } - - dashboardHardwareProfiles := &unstructured.UnstructuredList{} - dashboardHardwareProfiles.SetGroupVersionKind(gvk.DashboardHardwareProfile) - - err = rr.Client.List(ctx, dashboardHardwareProfiles) - if err != nil { - return fmt.Errorf("failed to list dashboard hardware profiles: %w", err) - } - - logger := log.FromContext(ctx) - for _, hwprofile := range dashboardHardwareProfiles.Items { - var dashboardHardwareProfile DashboardHardwareProfile - - if err := runtime.DefaultUnstructuredConverter.FromUnstructured(hwprofile.Object, &dashboardHardwareProfile); err != nil { - return fmt.Errorf("failed to convert dashboard hardware profile: %w", err) - } - - infraHWP := &infrav1.HardwareProfile{} - err := rr.Client.Get(ctx, client.ObjectKey{ - Name: dashboardHardwareProfile.Name, - Namespace: dashboardHardwareProfile.Namespace, - }, infraHWP) - - if k8serr.IsNotFound(err) { - if err = createInfraHWP(ctx, rr, logger, &dashboardHardwareProfile); err != nil { - return fmt.Errorf("failed to create infrastructure hardware profile: %w", err) - } - continue - } - - if err != nil { - return fmt.Errorf("failed to get infrastructure hardware profile: %w", err) - } - - err = updateInfraHWP(ctx, rr, logger, &dashboardHardwareProfile, infraHWP) - if err != nil { - return fmt.Errorf("failed to update existing infrastructure hardware profile: %w", err) - } - } - return nil -} - -func createInfraHWP(ctx context.Context, rr *odhtypes.ReconciliationRequest, logger logr.Logger, dashboardhwp *DashboardHardwareProfile) error { - annotations := make(map[string]string) - maps.Copy(annotations, dashboardhwp.Annotations) - - annotations["opendatahub.io/migrated-from"] = fmt.Sprintf("hardwareprofiles.dashboard.opendatahub.io/%s", dashboardhwp.Name) - annotations["opendatahub.io/display-name"] = dashboardhwp.Spec.DisplayName - annotations["opendatahub.io/description"] = dashboardhwp.Spec.Description - annotations["opendatahub.io/disabled"] = strconv.FormatBool(!dashboardhwp.Spec.Enabled) - - infraHardwareProfile := &infrav1.HardwareProfile{ - ObjectMeta: metav1.ObjectMeta{ - Name: dashboardhwp.Name, - Namespace: dashboardhwp.Namespace, - Annotations: annotations, - }, - Spec: infrav1.HardwareProfileSpec{ - SchedulingSpec: &infrav1.SchedulingSpec{ - SchedulingType: infrav1.NodeScheduling, - Node: &infrav1.NodeSchedulingSpec{ - NodeSelector: dashboardhwp.Spec.NodeSelector, - Tolerations: dashboardhwp.Spec.Tolerations, - }, - }, - Identifiers: dashboardhwp.Spec.Identifiers, - }, - } - - if err := rr.Client.Create(ctx, infraHardwareProfile); err != nil { - return err - } - - logger.Info("successfully created infrastructure hardware profile", "name", infraHardwareProfile.GetName()) - return nil -} - -func updateInfraHWP( - ctx context.Context, rr *odhtypes.ReconciliationRequest, logger logr.Logger, dashboardhwp *DashboardHardwareProfile, infrahwp *infrav1.HardwareProfile) error { - if infrahwp.Annotations == nil { - infrahwp.Annotations = make(map[string]string) - } - - maps.Copy(infrahwp.Annotations, dashboardhwp.Annotations) - - infrahwp.Annotations["opendatahub.io/migrated-from"] = fmt.Sprintf("hardwareprofiles.dashboard.opendatahub.io/%s", dashboardhwp.Name) - infrahwp.Annotations["opendatahub.io/display-name"] = dashboardhwp.Spec.DisplayName - infrahwp.Annotations["opendatahub.io/description"] = dashboardhwp.Spec.Description - infrahwp.Annotations["opendatahub.io/disabled"] = strconv.FormatBool(!dashboardhwp.Spec.Enabled) - - infrahwp.Spec.SchedulingSpec = &infrav1.SchedulingSpec{ - SchedulingType: infrav1.NodeScheduling, - Node: &infrav1.NodeSchedulingSpec{ - NodeSelector: dashboardhwp.Spec.NodeSelector, - Tolerations: dashboardhwp.Spec.Tolerations, - }, - } - infrahwp.Spec.Identifiers = dashboardhwp.Spec.Identifiers - - if err := rr.Client.Update(ctx, infrahwp); err != nil { - return fmt.Errorf("failed to update infrastructure hardware profile: %w", err) - } - - logger.Info("successfully updated infrastructure hardware profile", "name", infrahwp.GetName()) - return nil -} diff --git a/internal/controller/components/dashboard/dashboard_controller_actions_test.go b/internal/controller/components/dashboard/dashboard_controller_actions_test.go deleted file mode 100644 index cf115fea0b3b..000000000000 --- a/internal/controller/components/dashboard/dashboard_controller_actions_test.go +++ /dev/null @@ -1,149 +0,0 @@ -//nolint:testpackage -package dashboard - -import ( - "testing" - - apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" - "k8s.io/apimachinery/pkg/runtime/schema" - "sigs.k8s.io/controller-runtime/pkg/client" - "sigs.k8s.io/controller-runtime/pkg/log" - - infrav1 "github.com/opendatahub-io/opendatahub-operator/v2/api/infrastructure/v1" - "github.com/opendatahub-io/opendatahub-operator/v2/pkg/cluster/gvk" - "github.com/opendatahub-io/opendatahub-operator/v2/pkg/controller/types" - "github.com/opendatahub-io/opendatahub-operator/v2/pkg/utils/test/fakeclient" - "github.com/opendatahub-io/opendatahub-operator/v2/pkg/utils/test/scheme" - - . "github.com/onsi/gomega" -) - -func TestMigrateHardwareProfiles(t *testing.T) { - ctx := t.Context() - g := NewWithT(t) - - fakeSchema, err := scheme.New() - g.Expect(err).ShouldNot(HaveOccurred()) - - dashboardHardwareProfileListGVK := schema.GroupVersionKind{ - Group: "dashboard.opendatahub.io", - Version: "v1alpha1", - Kind: "HardwareProfileList", - } - - fakeSchema.AddKnownTypeWithName(gvk.DashboardHardwareProfile, &unstructured.Unstructured{}) - fakeSchema.AddKnownTypeWithName(dashboardHardwareProfileListGVK, &unstructured.UnstructuredList{}) - fakeSchema.AddKnownTypeWithName(gvk.HardwareProfile, &infrav1.HardwareProfile{}) - fakeSchema.AddKnownTypeWithName(gvk.HardwareProfile.GroupVersion().WithKind("HardwareProfileList"), &infrav1.HardwareProfileList{}) - - // Create a CRD for Dashboard HardwareProfile to make HasCRD check pass - dashboardHWPCRD := &apiextensionsv1.CustomResourceDefinition{ - ObjectMeta: v1.ObjectMeta{ - Name: "hardwareprofiles.dashboard.opendatahub.io", - }, - Status: apiextensionsv1.CustomResourceDefinitionStatus{ - StoredVersions: []string{gvk.DashboardHardwareProfile.Version}, - }, - } - - mockDashboardHardwareProfile := &unstructured.Unstructured{ - Object: map[string]any{ - "apiVersion": "dashboard.opendatahub.io/v1alpha1", - "kind": "HardwareProfile", - "metadata": map[string]any{ - "name": "test-name", - "namespace": "test-namespace", - }, - "spec": map[string]any{ - "displayName": "Test Display Name", - "enabled": true, - "description": "Test Description", - "tolerations": []any{}, - "nodeSelector": map[string]any{}, - "identifiers": []any{}, - }, - }, - } - - cli, err := fakeclient.New( - fakeclient.WithObjects(mockDashboardHardwareProfile, dashboardHWPCRD), - fakeclient.WithScheme(fakeSchema), - ) - g.Expect(err).ShouldNot(HaveOccurred()) - rr := &types.ReconciliationRequest{ - Client: cli, - } - - err = reconcileHardwareProfiles(ctx, rr) - g.Expect(err).ShouldNot(HaveOccurred()) - - var createdInfraHWProfile infrav1.HardwareProfile - err = cli.Get(ctx, client.ObjectKey{ - Name: "test-name", - Namespace: "test-namespace", - }, &createdInfraHWProfile) - - g.Expect(err).ShouldNot(HaveOccurred()) - g.Expect(createdInfraHWProfile.Name).Should(Equal("test-name")) - g.Expect(createdInfraHWProfile.Namespace).Should(Equal("test-namespace")) - g.Expect(createdInfraHWProfile.Spec.SchedulingSpec.SchedulingType).Should(Equal(infrav1.NodeScheduling)) - g.Expect(createdInfraHWProfile.GetAnnotations()["opendatahub.io/display-name"]).Should(Equal("Test Display Name")) - g.Expect(createdInfraHWProfile.GetAnnotations()["opendatahub.io/description"]).Should(Equal("Test Description")) - g.Expect(createdInfraHWProfile.GetAnnotations()["opendatahub.io/disabled"]).Should(Equal("false")) -} - -func TestCreateInfraHardwareProfile(t *testing.T) { - ctx := t.Context() - g := NewWithT(t) - - fakeSchema, err := scheme.New() - g.Expect(err).ShouldNot(HaveOccurred()) - - fakeSchema.AddKnownTypeWithName(gvk.HardwareProfile, &infrav1.HardwareProfile{}) - fakeSchema.AddKnownTypeWithName(gvk.HardwareProfile.GroupVersion().WithKind("HardwareProfileList"), &infrav1.HardwareProfileList{}) - cli, err := fakeclient.New( - fakeclient.WithObjects(), - fakeclient.WithScheme(fakeSchema), - ) - g.Expect(err).ShouldNot(HaveOccurred()) - - rr := &types.ReconciliationRequest{ - Client: cli, - } - - logger := log.FromContext(ctx) - - mockDashboardHardwareProfile := &DashboardHardwareProfile{ - ObjectMeta: v1.ObjectMeta{ - Name: "test-name", - Namespace: "test-namespace", - }, - Spec: DashboardHardwareProfileSpec{ - DisplayName: "Test Display Name", - Enabled: true, - Description: "Test Description", - Tolerations: nil, - NodeSelector: nil, - Identifiers: nil, - }, - } - - var receivedHardwareProfile infrav1.HardwareProfile - - err = createInfraHWP(ctx, rr, logger, mockDashboardHardwareProfile) - g.Expect(err).ShouldNot(HaveOccurred()) - - err = cli.Get(ctx, client.ObjectKey{ - Name: "test-name", - Namespace: "test-namespace", - }, &receivedHardwareProfile) - g.Expect(err).ShouldNot(HaveOccurred()) - - g.Expect(receivedHardwareProfile.Name).Should(Equal("test-name")) - g.Expect(receivedHardwareProfile.Namespace).Should(Equal("test-namespace")) - g.Expect(receivedHardwareProfile.GetAnnotations()["opendatahub.io/display-name"]).Should(Equal("Test Display Name")) - g.Expect(receivedHardwareProfile.GetAnnotations()["opendatahub.io/description"]).Should(Equal("Test Description")) - g.Expect(receivedHardwareProfile.GetAnnotations()["opendatahub.io/disabled"]).Should(Equal("false")) -} diff --git a/internal/controller/datasciencecluster/kubebuilder_rbac.go b/internal/controller/datasciencecluster/kubebuilder_rbac.go index 2d47c27726d8..fd7abc10bfa4 100644 --- a/internal/controller/datasciencecluster/kubebuilder_rbac.go +++ b/internal/controller/datasciencecluster/kubebuilder_rbac.go @@ -168,8 +168,8 @@ package datasciencecluster // +kubebuilder:rbac:groups="console.openshift.io",resources=odhquickstarts,verbs=create;get;patch;list;delete;watch;update // +kubebuilder:rbac:groups="dashboard.opendatahub.io",resources=odhdocuments,verbs=create;get;patch;list;delete;watch;update // +kubebuilder:rbac:groups="dashboard.opendatahub.io",resources=odhapplications,verbs=create;get;patch;list;delete;watch;update -// +kubebuilder:rbac:groups="dashboard.opendatahub.io",resources=acceleratorprofiles,verbs=create;get;patch;list;delete;watch;update -// +kubebuilder:rbac:groups="dashboard.opendatahub.io",resources=hardwareprofiles,verbs=get;list;watch;update +// +kubebuilder:rbac:groups="dashboard.opendatahub.io",resources=acceleratorprofiles,verbs=get;list;watch +// +kubebuilder:rbac:groups="dashboard.opendatahub.io",resources=hardwareprofiles,verbs=get;list;watch // ModelRegistry // +kubebuilder:rbac:groups=components.platform.opendatahub.io,resources=modelregistries,verbs=get;list;watch;create;update;patch;delete diff --git a/internal/controller/dscinitialization/dscinitialization_controller.go b/internal/controller/dscinitialization/dscinitialization_controller.go index 7195b52a45ce..0d435a15c94b 100644 --- a/internal/controller/dscinitialization/dscinitialization_controller.go +++ b/internal/controller/dscinitialization/dscinitialization_controller.go @@ -29,7 +29,6 @@ import ( corev1 "k8s.io/api/core/v1" networkingv1 "k8s.io/api/networking/v1" rbacv1 "k8s.io/api/rbac/v1" - apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" k8serr "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" @@ -393,14 +392,6 @@ func (r *DSCInitializationReconciler) SetupWithManager(ctx context.Context, mgr &serviceApi.Auth{}, handler.EnqueueRequestsFromMapFunc(r.watchAuthResource), ). - Watches( // TODO: this might not be needed after v3.3. - &apiextensionsv1.CustomResourceDefinition{}, - handler.EnqueueRequestsFromMapFunc(r.watchHWProfileCRDResource), - builder.WithPredicates(predicate.Or( - rp.CreatedOrUpdatedName("acceleratorprofiles.dashboard.opendatahub.io"), - rp.CreatedOrUpdatedName("hardwareprofiles.dashboard.opendatahub.io"), - )), - ). Complete(r) } @@ -540,27 +531,3 @@ func (r *DSCInitializationReconciler) newMonitoringCR(ctx context.Context, dsci } return nil } - -// watchHWProfileCRDResource triggers DSCI reconciliation when Dashboard AcceleratorProfile/HWProfile CRDs are created. -// This ensures VAP/VAPB resources can be created when Dashboard CRDs become available. -// TODO: this is a temporary solution to ensure VAP/VAPB resources are created when Dashboard CRDs become available, it should be removed in v3.3. -func (r *DSCInitializationReconciler) watchHWProfileCRDResource(ctx context.Context, a client.Object) []reconcile.Request { - log := logf.FromContext(ctx) - - log.V(1).Info("Dashboard CRD change detected, triggering DSCI reconciliation for VAP/VAPB resources", "CRD", a.GetName()) - - instanceList := &dsciv2.DSCInitializationList{} - if err := r.Client.List(ctx, instanceList); err != nil { - log.Error(err, "Failed to get DSCInitializationList") - return []reconcile.Request{{NamespacedName: types.NamespacedName{Name: "default-dsci"}}} - } - - if len(instanceList.Items) == 0 { - // No DSCI found, but trigger anyway for default name in case of race conditions - // If no DSCI actually exists, the reconcile request will be ignored - log.V(1).Info("No DSCI instances found, triggering default-dsci reconciliation as fallback to create VAP/VAPB") - return []reconcile.Request{{NamespacedName: types.NamespacedName{Name: "default-dsci"}}} - } - - return []reconcile.Request{{NamespacedName: types.NamespacedName{Name: instanceList.Items[0].Name}}} -}