forked from opendatahub-io/odh-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrenaming.go
More file actions
74 lines (62 loc) · 2.9 KB
/
renaming.go
File metadata and controls
74 lines (62 loc) · 2.9 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
package datasciencepipelines
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/version"
)
const (
kind = "datasciencepipelines"
checkTypeRenaming = "renaming"
)
type RenamingCheck struct {
check.BaseCheck
}
func NewRenamingCheck() *RenamingCheck {
return &RenamingCheck{
BaseCheck: check.BaseCheck{
CheckGroup: check.GroupComponent,
Kind: kind,
Type: checkTypeRenaming,
CheckID: "components.datasciencepipelines.renaming",
CheckName: "Components :: DataSciencePipelines :: Component Renaming (3.x)",
CheckDescription: "Informs about DataSciencePipelines component renaming to AIPipelines in DSC v2 (RHOAI 3.x)",
CheckRemediation: "No action required - the component will be automatically renamed. Update any automation referencing '.spec.components.datasciencepipelines' to use '.spec.components.aipipelines' after upgrade",
},
}
}
// CanApply returns whether this check should run for the given target.
// This check only applies when upgrading FROM 2.x TO 3.x and DataSciencePipelines is Managed.
func (c *RenamingCheck) 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, kind, constants.ManagementStateManaged), nil
}
func (c *RenamingCheck) Validate(ctx context.Context, target check.Target) (*result.DiagnosticResult, error) {
return validate.Component(c, target).
Complete(ctx, newRenamingCondition)
}
func newRenamingCondition(_ context.Context, req *validate.ComponentRequest) ([]result.Condition, error) {
tv := version.MajorMinorLabel(req.TargetVersion)
return []result.Condition{
check.NewCondition(
check.ConditionTypeCompatible,
metav1.ConditionFalse,
check.WithReason(check.ReasonComponentRenamed),
check.WithMessage("DataSciencePipelines component (state: %s) will be renamed to AIPipelines in DSC v2 (RHOAI %s). The field path changes from '.spec.components.datasciencepipelines' to '.spec.components.aipipelines'", req.ManagementState, tv),
check.WithImpact(result.ImpactAdvisory),
check.WithRemediation("No action required - the component will be automatically renamed. Update any automation referencing '.spec.components.datasciencepipelines' to use '.spec.components.aipipelines' after upgrade"),
),
}, nil
}