forked from opendatahub-io/odh-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkueue_operator_installed.go
More file actions
130 lines (114 loc) · 5 KB
/
kueue_operator_installed.go
File metadata and controls
130 lines (114 loc) · 5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
package kueue
import (
"context"
"fmt"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"github.com/opendatahub-io/odh-cli/pkg/constants"
"github.com/opendatahub-io/odh-cli/pkg/lint/check"
"github.com/opendatahub-io/odh-cli/pkg/lint/check/result"
"github.com/opendatahub-io/odh-cli/pkg/lint/check/validate"
"github.com/opendatahub-io/odh-cli/pkg/util/client"
"github.com/opendatahub-io/odh-cli/pkg/util/components"
"github.com/opendatahub-io/odh-cli/pkg/util/kube/olm"
)
const (
checkTypeOperatorInstalled = "operator-installed"
subscriptionName = "kueue-operator"
annotationInstalledVersion = "operator.opendatahub.io/installed-version"
msgManagedNotSupported = "Kueue managementState is Managed — migration to the Red Hat build of Kueue operator is required before upgrading"
operatorInstalledManagedRemediation = "Migrate to the Red Hat build of Kueue operator following https://docs.redhat.com/en/documentation/red_hat_openshift_ai_self-managed/2.25/html/managing_openshift_ai/managing-workloads-with-kueue#migrating-to-the-rhbok-operator_kueue before upgrading"
)
// OperatorInstalledCheck is currently deregistered — re-enable when a future 3.3.x release
// supports Unmanaged + Red Hat build of Kueue Operator (see command.go registration).
//
// It validates the Red Hat build of Kueue operator installation status against the Kueue
// component management state:
// - Managed: prohibited — no supported upgrade path from embedded Kueue, must migrate to RHBoK first
// - Unmanaged + operator absent: blocking — Unmanaged requires the Red Hat build of Kueue operator
// - Unmanaged + operator present: pass
type OperatorInstalledCheck struct {
check.BaseCheck
}
func NewOperatorInstalledCheck() *OperatorInstalledCheck {
return &OperatorInstalledCheck{
BaseCheck: check.BaseCheck{
CheckGroup: check.GroupComponent,
Kind: kind,
Type: checkTypeOperatorInstalled,
CheckID: "components.kueue.operator-installed",
CheckName: "Components :: Kueue :: Operator Installed",
CheckDescription: "Validates Red Hat build of Kueue operator installation is consistent with Kueue management state",
},
}
}
func (c *OperatorInstalledCheck) CanApply(ctx context.Context, target check.Target) (bool, error) {
dsc, err := client.GetDataScienceCluster(ctx, target.Client)
if err != nil {
return false, fmt.Errorf("getting DataScienceCluster: %w", err)
}
return components.HasManagementState(
dsc, "kueue",
constants.ManagementStateManaged, constants.ManagementStateUnmanaged,
), nil
}
func (c *OperatorInstalledCheck) Validate(ctx context.Context, target check.Target) (*result.DiagnosticResult, error) {
return validate.Component(c, target).
Run(ctx, func(ctx context.Context, req *validate.ComponentRequest) error {
// Managed state is unconditionally prohibited — no supported upgrade path
// from embedded Kueue. Emit the condition without querying OLM since the
// operator presence is irrelevant for this state.
if req.ManagementState == constants.ManagementStateManaged {
c.validateManaged(req)
return nil
}
info, err := olm.FindOperator(ctx, req.Client, func(sub *olm.SubscriptionInfo) bool {
return sub.Name == subscriptionName
})
if err != nil {
return fmt.Errorf("checking Red Hat build of Kueue operator presence: %w", err)
}
if info.GetVersion() != "" {
req.Result.Annotations[annotationInstalledVersion] = info.GetVersion()
}
c.validateUnmanaged(req, info)
return nil
})
}
// validateManaged flags Kueue Managed state as a prohibited condition.
// There is no supported upgrade path from embedded Kueue — migration to the
// Red Hat build of Kueue operator is required before upgrading.
func (c *OperatorInstalledCheck) validateManaged(
req *validate.ComponentRequest,
) {
req.Result.SetCondition(check.NewCondition(
check.ConditionTypeCompatible,
metav1.ConditionFalse,
check.WithReason(check.ReasonVersionIncompatible),
check.WithMessage(msgManagedNotSupported),
check.WithImpact(result.ImpactProhibited),
check.WithRemediation(operatorInstalledManagedRemediation),
))
}
// validateUnmanaged checks that the Red Hat build of Kueue operator IS installed when Kueue is Unmanaged.
func (c *OperatorInstalledCheck) validateUnmanaged(
req *validate.ComponentRequest,
info *olm.SubscriptionInfo,
) {
switch {
case !info.Found():
req.Result.SetCondition(check.NewCondition(
check.ConditionTypeCompatible,
metav1.ConditionFalse,
check.WithReason(check.ReasonVersionIncompatible),
check.WithMessage("Red Hat build of Kueue operator is not installed but Kueue managementState is Unmanaged — Red Hat build of Kueue operator is required"),
check.WithImpact(result.ImpactBlocking),
))
default:
req.Result.SetCondition(check.NewCondition(
check.ConditionTypeCompatible,
metav1.ConditionTrue,
check.WithReason(check.ReasonVersionCompatible),
check.WithMessage("Red Hat build of Kueue operator installed: %s", info.GetVersion()),
))
}
}