forked from opendatahub-io/odh-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathopenshift.go
More file actions
83 lines (70 loc) · 2.55 KB
/
openshift.go
File metadata and controls
83 lines (70 loc) · 2.55 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
package openshift
import (
"context"
"github.com/blang/semver/v4"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"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/util/version"
)
const (
kind = "openshift-platform"
checkType = "version-requirement"
)
//nolint:gochecknoglobals
var minVersion = semver.MustParse("4.19.9")
// Check validates OpenShift version requirements for RHOAI 3.x upgrades.
type Check struct {
check.BaseCheck
}
// NewCheck creates a new OpenShift version requirement check.
func NewCheck() *Check {
return &Check{
BaseCheck: check.BaseCheck{
CheckGroup: check.GroupDependency,
Kind: kind,
Type: checkType,
CheckID: "dependencies.openshift.version-requirement",
CheckName: "Dependencies :: OpenShift :: Version Requirement (3.x)",
CheckDescription: "Validates that OpenShift is at least version 4.19.9 when upgrading to RHOAI 3.x",
},
}
}
func (c *Check) CanApply(_ context.Context, target check.Target) (bool, error) {
return version.IsVersion3x(target.CurrentVersion) || version.IsVersion3x(target.TargetVersion), nil
}
func (c *Check) Validate(
ctx context.Context,
target check.Target,
) (*result.DiagnosticResult, error) {
dr := c.NewResult()
tv := version.MajorMinorLabel(target.TargetVersion)
ver, err := version.DetectOpenShiftVersion(ctx, target.Client)
switch {
case err != nil:
dr.SetCondition(check.NewCondition(
check.ConditionTypeCompatible,
metav1.ConditionFalse,
check.WithReason(check.ReasonInsufficientData),
check.WithMessage("Unable to detect OpenShift version: %s. RHOAI %s requires OpenShift %s or later", err.Error(), tv, minVersion.String()),
check.WithImpact(result.ImpactBlocking),
))
case ver.GTE(minVersion):
dr.SetCondition(check.NewCondition(
check.ConditionTypeCompatible,
metav1.ConditionTrue,
check.WithReason(check.ReasonVersionCompatible),
check.WithMessage("OpenShift %s meets RHOAI %s minimum version requirement (%s+)", ver.String(), tv, minVersion.String()),
))
default:
dr.SetCondition(check.NewCondition(
check.ConditionTypeCompatible,
metav1.ConditionFalse,
check.WithReason(check.ReasonVersionIncompatible),
check.WithMessage("OpenShift %s does not meet RHOAI %s minimum version requirement (%s+). Upgrade OpenShift to %s or later before upgrading RHOAI",
ver.String(), tv, minVersion.String(), minVersion.String()),
check.WithImpact(result.ImpactBlocking),
))
}
return dr, nil
}