Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions internal/controller/components/dashboard/dashboard_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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()).
Expand All @@ -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).
Expand All @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)}

Expand Down Expand Up @@ -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
}

This file was deleted.

4 changes: 2 additions & 2 deletions internal/controller/datasciencecluster/kubebuilder_rbac.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading