forked from opendatahub-io/odh-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserverless.go
More file actions
92 lines (80 loc) · 3.56 KB
/
serverless.go
File metadata and controls
92 lines (80 loc) · 3.56 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
package kserve
import (
"context"
"errors"
"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/jq"
"github.com/opendatahub-io/odh-cli/pkg/util/version"
)
const checkType = "serverless-removal"
// ServerlessRemovalCheck validates that KServe serverless is disabled before upgrading to 3.x.
type ServerlessRemovalCheck struct {
check.BaseCheck
}
func NewServerlessRemovalCheck() *ServerlessRemovalCheck {
return &ServerlessRemovalCheck{
BaseCheck: check.BaseCheck{
CheckGroup: check.GroupComponent,
Kind: constants.ComponentKServe,
Type: checkType,
CheckID: "components.kserve.serverless-removal",
CheckName: "Components :: KServe :: Serverless Removal (3.x)",
CheckDescription: "Validates that KServe serverless mode is disabled before upgrading from RHOAI 2.x to 3.x (serverless support will be removed)",
CheckRemediation: "Disable KServe serverless mode by setting serving.managementState to 'Removed' in DataScienceCluster before upgrading",
},
}
}
// CanApply returns whether this check should run for the given target.
// This check only applies when upgrading FROM 2.x TO 3.x and KServe is Managed.
func (c *ServerlessRemovalCheck) CanApply(ctx context.Context, target check.Target) (bool, error) {
if !version.IsUpgradeFrom2xTo3x(target.CurrentVersion, target.TargetVersion) {
return false, nil
}
dsc, err := client.GetDataScienceCluster(ctx, target.Client)
if err != nil {
return false, fmt.Errorf("getting DataScienceCluster: %w", err)
}
return components.HasManagementState(dsc, constants.ComponentKServe, constants.ManagementStateManaged), nil
}
func (c *ServerlessRemovalCheck) Validate(ctx context.Context, target check.Target) (*result.DiagnosticResult, error) {
return validate.Component(c, target).
Run(ctx, func(_ context.Context, req *validate.ComponentRequest) error {
tv := version.MajorMinorLabel(req.TargetVersion)
state, err := jq.Query[string](req.DSC, ".spec.components.kserve.serving.managementState")
switch {
case errors.Is(err, jq.ErrNotFound):
req.Result.SetCondition(check.NewCondition(
check.ConditionTypeCompatible,
metav1.ConditionTrue,
check.WithReason(check.ReasonVersionCompatible),
check.WithMessage("KServe serverless mode is not configured - ready for RHOAI %s upgrade", tv),
))
case err != nil:
return fmt.Errorf("querying kserve serving managementState: %w", err)
case state == constants.ManagementStateManaged || state == constants.ManagementStateUnmanaged:
req.Result.SetCondition(check.NewCondition(
check.ConditionTypeCompatible,
metav1.ConditionFalse,
check.WithReason(check.ReasonVersionIncompatible),
check.WithMessage("KServe serverless mode is enabled (state: %s) but will be removed in RHOAI %s", state, tv),
check.WithImpact(result.ImpactBlocking),
check.WithRemediation(c.CheckRemediation),
))
default:
req.Result.SetCondition(check.NewCondition(
check.ConditionTypeCompatible,
metav1.ConditionTrue,
check.WithReason(check.ReasonVersionCompatible),
check.WithMessage("KServe serverless mode is disabled (state: %s) - ready for RHOAI %s upgrade", state, tv),
))
}
return nil
})
}