Skip to content

Commit

Permalink
feat: disable creation of components when no nodes have supported arc…
Browse files Browse the repository at this point in the history
…hitecture
  • Loading branch information
carlkyrillos committed Feb 26, 2025
1 parent 32f05b8 commit 647384c
Show file tree
Hide file tree
Showing 21 changed files with 494 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,14 @@ spec:
- services
verbs:
- '*'
- apiGroups:
- '*'
resources:
- nodes
verbs:
- get
- list
- watch
- apiGroups:
- '*'
resources:
Expand Down
8 changes: 8 additions & 0 deletions config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ rules:
- services
verbs:
- '*'
- apiGroups:
- '*'
resources:
- nodes
verbs:
- get
- list
- watch
- apiGroups:
- '*'
resources:
Expand Down
4 changes: 3 additions & 1 deletion controllers/components/codeflare/codeflare_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
ctrl "sigs.k8s.io/controller-runtime"

componentApi "github.com/opendatahub-io/opendatahub-operator/v2/apis/components/v1alpha1"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/controller/actions/architecture"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/controller/actions/deploy"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/controller/actions/gc"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/controller/actions/render/kustomize"
Expand Down Expand Up @@ -66,9 +67,10 @@ func (s *componentHandler) NewComponentReconciler(ctx context.Context, mgr ctrl.
component.ForLabel(labels.ODH.Component(LegacyComponentName), labels.True)),
).
// Add CodeFlare-specific actions
WithAction(releases.NewAction()).
WithAction(architecture.VerifySupportedArchitectures).
WithAction(initialize).
WithAction(devFlags).
WithAction(releases.NewAction()).
WithAction(kustomize.NewAction(
kustomize.WithCache(),
kustomize.WithLabel(labels.ODH.Component(LegacyComponentName), labels.True),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
ctrl "sigs.k8s.io/controller-runtime"

componentApi "github.com/opendatahub-io/opendatahub-operator/v2/apis/components/v1alpha1"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/controller/actions/architecture"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/controller/actions/deploy"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/controller/actions/gc"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/controller/actions/render/kustomize"
Expand Down Expand Up @@ -63,9 +64,10 @@ func (s *componentHandler) NewComponentReconciler(ctx context.Context, mgr ctrl.
).
// Add datasciencepipelines-specific actions
WithAction(checkPreConditions).
WithAction(releases.NewAction()).
WithAction(architecture.VerifySupportedArchitectures).
WithAction(initialize).
WithAction(devFlags).
WithAction(releases.NewAction()).
WithAction(kustomize.NewAction(
kustomize.WithCache(),
kustomize.WithLabel(labels.ODH.Component(LegacyComponentName), labels.True),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
ctrl "sigs.k8s.io/controller-runtime"

componentApi "github.com/opendatahub-io/opendatahub-operator/v2/apis/components/v1alpha1"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/controller/actions/architecture"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/controller/actions/deploy"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/controller/actions/gc"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/controller/actions/render/kustomize"
Expand Down Expand Up @@ -41,9 +42,10 @@ func (s *componentHandler) NewComponentReconciler(ctx context.Context, mgr ctrl.
component.ForLabel(labels.ODH.Component(ComponentName), labels.True)),
).
// Add FeastOperator-specific actions
WithAction(releases.NewAction()).
WithAction(architecture.VerifySupportedArchitectures).
WithAction(initialize).
WithAction(devFlags).
WithAction(releases.NewAction()).
WithAction(kustomize.NewAction(
kustomize.WithCache(),
kustomize.WithLabel(labels.ODH.Component(ComponentName), labels.True),
Expand Down
4 changes: 3 additions & 1 deletion controllers/components/kserve/kserve_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
dsciv1 "github.com/opendatahub-io/opendatahub-operator/v2/apis/dscinitialization/v1"
featuresv1 "github.com/opendatahub-io/opendatahub-operator/v2/apis/features/v1"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/cluster/gvk"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/controller/actions/architecture"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/controller/actions/deploy"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/controller/actions/gc"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/controller/actions/render/kustomize"
Expand Down Expand Up @@ -150,9 +151,10 @@ func (s *componentHandler) NewComponentReconciler(ctx context.Context, mgr ctrl.

// actions
WithAction(checkPreConditions).
WithAction(releases.NewAction()).
WithAction(architecture.VerifySupportedArchitectures).
WithAction(initialize).
WithAction(devFlags).
WithAction(releases.NewAction()).
WithAction(removeLegacyFeatureTrackerOwnerRef).
WithAction(configureServerless).
WithAction(configureServiceMesh).
Expand Down
4 changes: 3 additions & 1 deletion controllers/components/kueue/kueue_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
componentApi "github.com/opendatahub-io/opendatahub-operator/v2/apis/components/v1alpha1"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/cluster"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/cluster/gvk"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/controller/actions/architecture"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/controller/actions/deploy"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/controller/actions/gc"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/controller/actions/render/kustomize"
Expand Down Expand Up @@ -76,9 +77,10 @@ func (s *componentHandler) NewComponentReconciler(ctx context.Context, mgr ctrl.
).
// Add Kueue-specific actions
WithAction(checkPreConditions). // check if CRD multikueueconfigs/multikueueclusters with v1alpha1 exist in cluster and not in termination
WithAction(releases.NewAction()).
WithAction(architecture.VerifySupportedArchitectures).
WithAction(initialize).
WithAction(devFlags).
WithAction(releases.NewAction()).
WithAction(kustomize.NewAction(
kustomize.WithCache(),
kustomize.WithLabel(labels.ODH.Component(LegacyComponentName), labels.True),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/predicate"

componentApi "github.com/opendatahub-io/opendatahub-operator/v2/apis/components/v1alpha1"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/controller/actions/architecture"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/controller/actions/deploy"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/controller/actions/gc"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/controller/actions/render/kustomize"
Expand Down Expand Up @@ -84,9 +85,10 @@ func (s *componentHandler) NewComponentReconciler(ctx context.Context, mgr ctrl.
)),
).
// Add ModelMeshServing specific actions
WithAction(releases.NewAction()).
WithAction(architecture.VerifySupportedArchitectures).
WithAction(initialize).
WithAction(devFlags).
WithAction(releases.NewAction()).
WithAction(kustomize.NewAction(
kustomize.WithCache(),
kustomize.WithLabel(labels.ODH.Component(LegacyComponentName), labels.True),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
componentApi "github.com/opendatahub-io/opendatahub-operator/v2/apis/components/v1alpha1"
dsciv1 "github.com/opendatahub-io/opendatahub-operator/v2/apis/dscinitialization/v1"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/cluster/gvk"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/controller/actions/architecture"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/controller/actions/deploy"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/controller/actions/gc"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/controller/actions/render/kustomize"
Expand Down Expand Up @@ -78,8 +79,9 @@ func (s *componentHandler) NewComponentReconciler(ctx context.Context, mgr ctrl.
WatchesGVK(gvk.ServiceMeshMember, reconciler.Dynamic()).
// actions
WithAction(checkPreConditions).
WithAction(initialize).
WithAction(releases.NewAction()).
WithAction(architecture.VerifySupportedArchitectures).
WithAction(initialize).
WithAction(configureDependencies).
WithAction(template.NewAction(
template.WithCache(),
Expand Down
4 changes: 3 additions & 1 deletion controllers/components/ray/ray_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
ctrl "sigs.k8s.io/controller-runtime"

componentApi "github.com/opendatahub-io/opendatahub-operator/v2/apis/components/v1alpha1"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/controller/actions/architecture"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/controller/actions/deploy"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/controller/actions/gc"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/controller/actions/render/kustomize"
Expand Down Expand Up @@ -59,9 +60,10 @@ func (s *componentHandler) NewComponentReconciler(ctx context.Context, mgr ctrl.
component.ForLabel(labels.ODH.Component(LegacyComponentName), labels.True)),
).
// Add Ray-specific actions
WithAction(releases.NewAction()).
WithAction(architecture.VerifySupportedArchitectures).
WithAction(initialize).
WithAction(devFlags).
WithAction(releases.NewAction()).
WithAction(kustomize.NewAction(
kustomize.WithCache(),
kustomize.WithLabel(labels.ODH.Component(LegacyComponentName), labels.True),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
ctrl "sigs.k8s.io/controller-runtime"

componentApi "github.com/opendatahub-io/opendatahub-operator/v2/apis/components/v1alpha1"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/controller/actions/architecture"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/controller/actions/deploy"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/controller/actions/gc"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/controller/actions/render/kustomize"
Expand Down Expand Up @@ -56,9 +57,10 @@ func (s *componentHandler) NewComponentReconciler(ctx context.Context, mgr ctrl.
component.ForLabel(labels.ODH.Component(LegacyComponentName), labels.True)),
).
// Add TrainingOperator-specific actions
WithAction(releases.NewAction()).
WithAction(architecture.VerifySupportedArchitectures).
WithAction(initialize).
WithAction(devFlags).
WithAction(releases.NewAction()).
WithAction(kustomize.NewAction(
kustomize.WithCache(),
kustomize.WithLabel(labels.ODH.Component(LegacyComponentName), labels.True),
Expand Down
4 changes: 3 additions & 1 deletion controllers/components/trustyai/trustyai_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/predicate"

componentApi "github.com/opendatahub-io/opendatahub-operator/v2/apis/components/v1alpha1"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/controller/actions/architecture"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/controller/actions/deploy"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/controller/actions/gc"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/controller/actions/render/kustomize"
Expand Down Expand Up @@ -67,9 +68,10 @@ func (s *componentHandler) NewComponentReconciler(ctx context.Context, mgr ctrl.
).
// Add TrustyAI-specific actions
WithAction(checkPreConditions). // check if CRD isvc is there
WithAction(releases.NewAction()).
WithAction(architecture.VerifySupportedArchitectures).
WithAction(initialize).
WithAction(devFlags).
WithAction(releases.NewAction()).
WithAction(kustomize.NewAction(
kustomize.WithCache(),
kustomize.WithLabel(labels.ODH.Component(LegacyComponentName), labels.True),
Expand Down
6 changes: 4 additions & 2 deletions controllers/components/workbenches/workbenches_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
ctrl "sigs.k8s.io/controller-runtime"

componentApi "github.com/opendatahub-io/opendatahub-operator/v2/apis/components/v1alpha1"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/controller/actions/architecture"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/controller/actions/deploy"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/controller/actions/gc"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/controller/actions/render/kustomize"
Expand Down Expand Up @@ -61,11 +62,12 @@ func (s *componentHandler) NewComponentReconciler(ctx context.Context, mgr ctrl.
reconciler.WithPredicates(
component.ForLabel(labels.ODH.Component(LegacyComponentName), labels.True)),
).
WithAction(initialize).
WithAction(devFlags).
WithAction(releases.NewAction(
releases.WithMetadataFilePath(
path.Join(odhdeploy.DefaultManifestPath, ComponentName, kfNotebookControllerPath, releases.ComponentMetadataFilename)))).
WithAction(architecture.VerifySupportedArchitectures).
WithAction(initialize).
WithAction(devFlags).
WithAction(configureDependencies).
WithAction(kustomize.NewAction(
kustomize.WithCache(),
Expand Down
2 changes: 2 additions & 0 deletions controllers/datasciencecluster/kubebuilder_rbac.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ package datasciencecluster
// +kubebuilder:rbac:groups="*",resources=deployments,verbs=*
// +kubebuilder:rbac:groups="extensions",resources=deployments,verbs=*

// +kubebuilder:rbac:groups="*",resources=nodes,verbs=get;list;watch

// +kubebuilder:rbac:groups="admissionregistration.k8s.io",resources=validatingwebhookconfigurations,verbs=get;list;watch;create;update;delete;patch
// +kubebuilder:rbac:groups="admissionregistration.k8s.io",resources=mutatingwebhookconfigurations,verbs=create;delete;list;update;watch;patch;get

Expand Down
6 changes: 6 additions & 0 deletions controllers/status/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,12 @@ const (
ISVCMissingCRDMessage = "InferenceServices CRD does not exist, please enable serving component first"
)

// For verifying supported architectures.
const (
UnsupportedArchitectureReason = "UnsupportedArchitecture"
UnsupportedArchitectureMessage = "Failed to deploy component - there are no nodes running on an architecture that this component supports"
)

// SetProgressingCondition sets the ProgressingCondition to True and other conditions to false or
// Unknown. Used when we are just starting to reconcile, and there are no existing conditions.
func SetProgressingCondition(conditions *[]conditionsv1.Condition, reason string, message string) {
Expand Down
30 changes: 30 additions & 0 deletions pkg/cluster/cluster_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (

"github.com/opendatahub-io/opendatahub-operator/v2/apis/common"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/cluster/gvk"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/metadata/labels"
)

type ClusterInfo struct {
Expand Down Expand Up @@ -287,3 +288,32 @@ func IsDefaultAuthMethod(ctx context.Context, cli client.Client) (bool, error) {
// we only create userGroups for "IntegratedOAuth" or "" and leave other or new supported type value in the future
return authenticationobj.Spec.Type == configv1.AuthenticationTypeIntegratedOAuth || authenticationobj.Spec.Type == "", nil
}

func GetNodeArchitectures(ctx context.Context, client client.Client) (map[string]struct{}, error) {
nodeList := &corev1.NodeList{}
if err := client.List(ctx, nodeList); err != nil {
return nil, fmt.Errorf("failed to list nodes: %w", err)
}

// Create a map to track unique architectures
nodeArchitectures := make(map[string]struct{})

for _, node := range nodeList.Items {
if arch, exists := node.Labels[labels.NodeArch]; exists {
if node.Status.Conditions != nil {
// Only count nodes that are Ready
for _, condition := range node.Status.Conditions {
if condition.Type == corev1.NodeReady && condition.Status == corev1.ConditionTrue {
nodeArchitectures[arch] = struct{}{}
}
}
}
}
}

if len(nodeArchitectures) < 1 {
return nil, errors.New("no valid architectures found")
}

return nodeArchitectures, nil
}
Loading

0 comments on commit 647384c

Please sign in to comment.