Skip to content

Commit 1e738c1

Browse files
committed
re arrange depreciation check
1 parent a5ce7ed commit 1e738c1

File tree

7 files changed

+75
-68
lines changed

7 files changed

+75
-68
lines changed

pkg/apis/apm/v1/webhook.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,16 @@ func (as *ApmServer) WebhookPath() string {
8282
func (as *ApmServer) validate(old *ApmServer) (admission.Warnings, error) {
8383
var errors field.ErrorList
8484
var warnings admission.Warnings
85+
86+
// depreciation check
87+
depreciationWarnings, depreciationErrors := checkIfVersionDeprecated(as)
88+
if depreciationErrors != nil {
89+
errors = append(errors, depreciationErrors...)
90+
}
91+
if depreciationWarnings != "" {
92+
warnings = append(warnings, depreciationWarnings)
93+
}
94+
8595
if old != nil {
8696
for _, uc := range updateChecks {
8797
if err := uc(old, as); err != nil {
@@ -90,7 +100,7 @@ func (as *ApmServer) validate(old *ApmServer) (admission.Warnings, error) {
90100
}
91101

92102
if len(errors) > 0 {
93-
return nil, apierrors.NewInvalid(groupKind, as.Name, errors)
103+
return warnings, apierrors.NewInvalid(groupKind, as.Name, errors)
94104
}
95105
}
96106

@@ -100,15 +110,6 @@ func (as *ApmServer) validate(old *ApmServer) (admission.Warnings, error) {
100110
}
101111
}
102112

103-
// depreciation check
104-
depreciationWarnings, depreciationErrors := checkIfVersionDeprecated(as)
105-
if depreciationErrors != nil {
106-
errors = append(errors, depreciationErrors...)
107-
}
108-
if depreciationWarnings != "" {
109-
warnings = append(warnings, depreciationWarnings)
110-
}
111-
112113
if len(errors) > 0 {
113114
return warnings, apierrors.NewInvalid(groupKind, as.Name, errors)
114115
}

pkg/apis/apm/v1beta1/webhook.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,16 @@ func (as *ApmServer) WebhookPath() string {
7676
func (as *ApmServer) validate(old *ApmServer) (admission.Warnings, error) {
7777
var errors field.ErrorList
7878
var warnings admission.Warnings
79+
80+
// depreciation check
81+
depreciationWarnings, depreciationErrors := checkIfVersionDeprecated(as)
82+
if depreciationErrors != nil {
83+
errors = append(errors, depreciationErrors...)
84+
}
85+
if depreciationWarnings != "" {
86+
warnings = append(warnings, depreciationWarnings)
87+
}
88+
7989
if old != nil {
8090
for _, uc := range updateChecks {
8191
if err := uc(old, as); err != nil {
@@ -84,7 +94,7 @@ func (as *ApmServer) validate(old *ApmServer) (admission.Warnings, error) {
8494
}
8595

8696
if len(errors) > 0 {
87-
return nil, apierrors.NewInvalid(groupKind, as.Name, errors)
97+
return warnings, apierrors.NewInvalid(groupKind, as.Name, errors)
8898
}
8999
}
90100

@@ -94,15 +104,6 @@ func (as *ApmServer) validate(old *ApmServer) (admission.Warnings, error) {
94104
}
95105
}
96106

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

pkg/apis/beat/v1beta1/webhook.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,16 @@ func (b *Beat) WebhookPath() string {
6464
func (b *Beat) validate(old *Beat) (admission.Warnings, error) {
6565
var errors field.ErrorList
6666
var warnings admission.Warnings
67+
68+
// deprecation check
69+
deprecationWarning, deprecationError := checkIfVersionDeprecated(b)
70+
if deprecationError != nil {
71+
errors = append(errors, deprecationError...)
72+
}
73+
if deprecationWarning != "" {
74+
warnings = append(warnings, deprecationWarning)
75+
}
76+
6777
if old != nil {
6878
for _, uc := range updateChecks {
6979
if err := uc(old, b); err != nil {
@@ -72,7 +82,7 @@ func (b *Beat) validate(old *Beat) (admission.Warnings, error) {
7282
}
7383

7484
if len(errors) > 0 {
75-
return nil, apierrors.NewInvalid(groupKind, b.Name, errors)
85+
return warnings, apierrors.NewInvalid(groupKind, b.Name, errors)
7686
}
7787
}
7888

@@ -82,15 +92,6 @@ func (b *Beat) validate(old *Beat) (admission.Warnings, error) {
8292
}
8393
}
8494

85-
// deprecation check
86-
deprecationWarning, deprecationError := checkIfVersionDeprecated(b)
87-
if deprecationError != nil {
88-
errors = append(errors, deprecationError...)
89-
}
90-
if deprecationWarning != "" {
91-
warnings = append(warnings, deprecationWarning)
92-
}
93-
9495
if len(errors) > 0 {
9596
return warnings, apierrors.NewInvalid(groupKind, b.Name, errors)
9697
}

pkg/apis/enterprisesearch/v1/webhook.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,16 @@ func (ent *EnterpriseSearch) WebhookPath() string {
7777
func (ent *EnterpriseSearch) validate(old *EnterpriseSearch) (admission.Warnings, error) {
7878
var errors field.ErrorList
7979
var warnings admission.Warnings
80+
81+
// check if the version is deprecated
82+
deprecationWarnings, deprecationErrors := checkIfVersionDeprecated(ent)
83+
if deprecationErrors != nil {
84+
errors = append(errors, deprecationErrors...)
85+
}
86+
if deprecationWarnings != "" {
87+
warnings = append(warnings, deprecationWarnings)
88+
}
89+
8090
if old != nil {
8191
for _, uc := range updateChecks {
8292
if err := uc(old, ent); err != nil {
@@ -85,7 +95,7 @@ func (ent *EnterpriseSearch) validate(old *EnterpriseSearch) (admission.Warnings
8595
}
8696

8797
if len(errors) > 0 {
88-
return nil, apierrors.NewInvalid(groupKind, ent.Name, errors)
98+
return warnings, apierrors.NewInvalid(groupKind, ent.Name, errors)
8999
}
90100
}
91101

@@ -95,15 +105,6 @@ func (ent *EnterpriseSearch) validate(old *EnterpriseSearch) (admission.Warnings
95105
}
96106
}
97107

98-
// check if the version is deprecated
99-
deprecationWarnings, deprecationErrors := checkIfVersionDeprecated(ent)
100-
if deprecationErrors != nil {
101-
errors = append(errors, deprecationErrors...)
102-
}
103-
if deprecationWarnings != "" {
104-
warnings = append(warnings, deprecationWarnings)
105-
}
106-
107108
if len(errors) > 0 {
108109
return warnings, apierrors.NewInvalid(groupKind, ent.Name, errors)
109110
}

pkg/apis/enterprisesearch/v1beta1/webhook.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,16 @@ func (ent *EnterpriseSearch) WebhookPath() string {
7676
func (ent *EnterpriseSearch) validate(old *EnterpriseSearch) (admission.Warnings, error) {
7777
var errors field.ErrorList
7878
var warnings admission.Warnings
79+
80+
// check if the version is deprecated
81+
deprecationWarnings, deprecationErrors := checkIfVersionDeprecated(ent)
82+
if deprecationErrors != nil {
83+
errors = append(errors, deprecationErrors...)
84+
}
85+
if deprecationWarnings != "" {
86+
warnings = append(warnings, deprecationWarnings)
87+
}
88+
7989
if old != nil {
8090
for _, uc := range updateChecks {
8191
if err := uc(old, ent); err != nil {
@@ -84,7 +94,7 @@ func (ent *EnterpriseSearch) validate(old *EnterpriseSearch) (admission.Warnings
8494
}
8595

8696
if len(errors) > 0 {
87-
return nil, apierrors.NewInvalid(groupKind, ent.Name, errors)
97+
return warnings, apierrors.NewInvalid(groupKind, ent.Name, errors)
8898
}
8999
}
90100

@@ -94,15 +104,6 @@ func (ent *EnterpriseSearch) validate(old *EnterpriseSearch) (admission.Warnings
94104
}
95105
}
96106

97-
// check if the version is deprecated
98-
deprecationWarnings, deprecationErrors := checkIfVersionDeprecated(ent)
99-
if deprecationErrors != nil {
100-
errors = append(errors, deprecationErrors...)
101-
}
102-
if deprecationWarnings != "" {
103-
warnings = append(warnings, deprecationWarnings)
104-
}
105-
106107
if len(errors) > 0 {
107108
return warnings, apierrors.NewInvalid(groupKind, ent.Name, errors)
108109
}

pkg/apis/kibana/v1/webhook.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,15 @@ func (k *Kibana) WebhookPath() string {
8080
func (k *Kibana) validate(old *Kibana) (admission.Warnings, error) {
8181
var errors field.ErrorList
8282
var warnings admission.Warnings
83+
84+
deprecatedWarnings, deprecatedErrors := checkIfVersionDeprecated(k)
85+
if len(deprecatedErrors) > 0 {
86+
errors = append(errors, deprecatedErrors...)
87+
}
88+
if len(deprecatedWarnings) > 0 {
89+
warnings = append(warnings, deprecatedWarnings)
90+
}
91+
8392
if old != nil {
8493
for _, uc := range updateChecks {
8594
if err := uc(old, k); err != nil {
@@ -88,7 +97,7 @@ func (k *Kibana) validate(old *Kibana) (admission.Warnings, error) {
8897
}
8998

9099
if len(errors) > 0 {
91-
return nil, apierrors.NewInvalid(groupKind, k.Name, errors)
100+
return warnings, apierrors.NewInvalid(groupKind, k.Name, errors)
92101
}
93102
}
94103

@@ -98,14 +107,6 @@ func (k *Kibana) validate(old *Kibana) (admission.Warnings, error) {
98107
}
99108
}
100109

101-
deprecatedWarnings, deprecatedErrors := checkIfVersionDeprecated(k)
102-
if len(deprecatedErrors) > 0 {
103-
errors = append(errors, deprecatedErrors...)
104-
}
105-
if len(deprecatedWarnings) > 0 {
106-
warnings = append(warnings, deprecatedWarnings)
107-
}
108-
109110
if len(errors) > 0 {
110111
return warnings, apierrors.NewInvalid(groupKind, k.Name, errors)
111112
}

pkg/apis/kibana/v1beta1/webhook.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,15 @@ func (k *Kibana) WebhookPath() string {
7676
func (k *Kibana) validate(old *Kibana) (admission.Warnings, error) {
7777
var errors field.ErrorList
7878
var warnings admission.Warnings
79+
80+
deprecatedWarnings, deprecatedErrors := checkIfVersionDeprecated(k)
81+
if len(deprecatedErrors) > 0 {
82+
errors = append(errors, deprecatedErrors...)
83+
}
84+
if len(deprecatedWarnings) > 0 {
85+
warnings = append(warnings, deprecatedWarnings)
86+
}
87+
7988
if old != nil {
8089
for _, uc := range updateChecks {
8190
if err := uc(old, k); err != nil {
@@ -84,7 +93,7 @@ func (k *Kibana) validate(old *Kibana) (admission.Warnings, error) {
8493
}
8594

8695
if len(errors) > 0 {
87-
return nil, apierrors.NewInvalid(groupKind, k.Name, errors)
96+
return warnings, apierrors.NewInvalid(groupKind, k.Name, errors)
8897
}
8998
}
9099

@@ -94,14 +103,6 @@ func (k *Kibana) validate(old *Kibana) (admission.Warnings, error) {
94103
}
95104
}
96105

97-
deprecatedWarnings, deprecatedErrors := checkIfVersionDeprecated(k)
98-
if len(deprecatedErrors) > 0 {
99-
errors = append(errors, deprecatedErrors...)
100-
}
101-
if len(deprecatedWarnings) > 0 {
102-
warnings = append(warnings, deprecatedWarnings)
103-
}
104-
105106
if len(errors) > 0 {
106107
return warnings, apierrors.NewInvalid(groupKind, k.Name, errors)
107108
}

0 commit comments

Comments
 (0)