Skip to content

Commit a5ce7ed

Browse files
committed
address review comments
1 parent 5f6b35e commit a5ce7ed

File tree

24 files changed

+43
-46
lines changed

24 files changed

+43
-46
lines changed

pkg/apis/agent/v1alpha1/validations.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func checkSupportedVersion(a *Agent) field.ErrorList {
6262
}
6363

6464
func checkIfVersionDeprecated(a *Agent) (string, field.ErrorList) {
65-
return commonv1.CheckDeprecatedStackVersion(a.Spec.Version, version.DeprecatedVersions)
65+
return commonv1.CheckDeprecatedStackVersion(a.Spec.Version)
6666
}
6767

6868
func checkAtMostOneDeploymentOption(a *Agent) field.ErrorList {

pkg/apis/agent/v1alpha1/validations_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ func Test_checkIfVersionDeprecated(t *testing.T) {
177177
{
178178
name: "deprecated",
179179
version: "7.4.0",
180-
want: "Version 7.4.0 is EOL and will be removed in a future release of the ECK operator",
180+
want: "Version 7.4.0 is EOL and support for it will be removed in a future release of the ECK operator",
181181
},
182182
}
183183

pkg/apis/agent/v1alpha1/webhook.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,16 @@ func (a *Agent) WebhookPath() string {
7777
func (a *Agent) validate(old *Agent) (admission.Warnings, error) {
7878
warnings := a.warnings()
7979
var errors field.ErrorList
80+
81+
// depreciation check
82+
depreciationWarnings, depreciationErrors := checkIfVersionDeprecated(a)
83+
if depreciationErrors != nil {
84+
errors = append(errors, depreciationErrors...)
85+
}
86+
if depreciationWarnings != "" {
87+
warnings = append(warnings, depreciationWarnings)
88+
}
89+
8090
if old != nil {
8191
for _, uc := range updateChecks {
8292
if err := uc(old, a); err != nil {
@@ -95,15 +105,6 @@ func (a *Agent) validate(old *Agent) (admission.Warnings, error) {
95105
}
96106
}
97107

98-
// depreciation check
99-
depreciationWarnings, depreciationErrors := checkIfVersionDeprecated(a)
100-
if depreciationErrors != nil {
101-
errors = append(errors, depreciationErrors...)
102-
}
103-
if depreciationWarnings != "" {
104-
warnings = append(warnings, depreciationWarnings)
105-
}
106-
107108
if len(errors) > 0 {
108109
return warnings, apierrors.NewInvalid(groupKind, a.Name, errors)
109110
}

pkg/apis/apm/v1/webhook.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ func checkSupportedVersion(as *ApmServer) field.ErrorList {
128128
}
129129

130130
func checkIfVersionDeprecated(as *ApmServer) (string, field.ErrorList) {
131-
return commonv1.CheckDeprecatedStackVersion(as.Spec.Version, version.DeprecatedVersions)
131+
return commonv1.CheckDeprecatedStackVersion(as.Spec.Version)
132132
}
133133

134134
func checkNoDowngrade(prev, curr *ApmServer) field.ErrorList {

pkg/apis/apm/v1/webhook_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,8 @@ func TestWebhook(t *testing.T) {
122122
apm.Spec.Version = "7.4.0"
123123
return serialize(t, apm)
124124
},
125-
Check: test.ValidationWebhookSuceededWithWarnings(
126-
`Version 7.4.0 is EOL and will be removed in a future release of the ECK operator`,
125+
Check: test.ValidationWebhookSucceededWithWarnings(
126+
`Version 7.4.0 is EOL and support for it will be removed in a future release of the ECK operator`,
127127
),
128128
},
129129
{

pkg/apis/apm/v1beta1/webhook.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ func checkSupportedVersion(as *ApmServer) field.ErrorList {
122122
}
123123

124124
func checkIfVersionDeprecated(as *ApmServer) (string, field.ErrorList) {
125-
return commonv1.CheckDeprecatedStackVersion(as.Spec.Version, version.DeprecatedVersions)
125+
return commonv1.CheckDeprecatedStackVersion(as.Spec.Version)
126126
}
127127

128128
func checkNoDowngrade(prev, curr *ApmServer) field.ErrorList {

pkg/apis/apm/v1beta1/webhook_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,8 @@ func TestWebhook(t *testing.T) {
144144
apm.Spec.Version = "7.4.0"
145145
return serialize(t, apm)
146146
},
147-
Check: test.ValidationWebhookSuceededWithWarnings(
148-
`Version 7.4.0 is EOL and will be removed in a future release of the ECK operator`,
147+
Check: test.ValidationWebhookSucceededWithWarnings(
148+
`Version 7.4.0 is EOL and support for it will be removed in a future release of the ECK operator`,
149149
),
150150
},
151151
{

pkg/apis/beat/v1beta1/validations.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func checkSupportedVersion(b *Beat) field.ErrorList {
4848
}
4949

5050
func checkIfVersionDeprecated(b *Beat) (string, field.ErrorList) {
51-
return commonv1.CheckDeprecatedStackVersion(b.Spec.Version, version.DeprecatedVersions)
51+
return commonv1.CheckDeprecatedStackVersion(b.Spec.Version)
5252
}
5353

5454
func checkAtMostOneDeploymentOption(b *Beat) field.ErrorList {

pkg/apis/beat/v1beta1/validations_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ func Test_checkIfVersionDeprecated(t *testing.T) {
375375
Version: "7.10.0",
376376
},
377377
},
378-
want: "Version 7.10.0 is EOL and will be removed in a future release of the ECK operator",
378+
want: "Version 7.10.0 is EOL and support for it will be removed in a future release of the ECK operator",
379379
},
380380
}
381381
for _, tt := range tests {

pkg/apis/common/v1/validations.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,14 @@ func CheckSupportedStackVersion(ver string, supported version.MinMaxVersion) fie
7777
}
7878

7979
// CheckDeprecatedStackVersion checks that the given version is not deprecated.
80-
func CheckDeprecatedStackVersion(ver string, deprecatedVersion version.MinMaxVersion) (string, field.ErrorList) {
80+
func CheckDeprecatedStackVersion(ver string) (string, field.ErrorList) {
8181
v, err := ParseVersion(ver)
8282
if err != nil {
8383
return "", err
8484
}
8585

86-
if v.Major >= deprecatedVersion.Min.Major && v.Major <= deprecatedVersion.Max.Major && v.Minor >= deprecatedVersion.Min.Minor && v.Minor <= deprecatedVersion.Max.Minor {
87-
return fmt.Sprintf("Version %s is EOL and will be removed in a future release of the ECK operator", ver), nil
86+
if v.GTE(version.DeprecatedVersions.Min) && v.LT(version.DeprecatedVersions.Max) {
87+
return fmt.Sprintf("Version %s is EOL and support for it will be removed in a future release of the ECK operator", ver), nil
8888
}
8989

9090
return "", nil

0 commit comments

Comments
 (0)