Skip to content
This repository was archived by the owner on Mar 26, 2025. It is now read-only.

Commit 8c76627

Browse files
Rename webhooks errors exported funcs (#925)
* pkg webhooks: update new error functions names to IsAdmission prefix; NOT API breaking * pkg webhooks: update IsInvalidReplicationFactor exported func name with IsAdmission prefix; API breaking change
1 parent 2ee4a81 commit 8c76627

File tree

3 files changed

+20
-20
lines changed

3 files changed

+20
-20
lines changed

pkg/resources/cruisecontrol/topicManager.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ func generateCCTopic(cluster *v1beta1.KafkaCluster, client client.Client, log lo
9999
return errorfactory.New(errorfactory.ResourceNotReady{}, err, "topic admission failed to connect to kafka cluster")
100100
}
101101
// If less than the required brokers are available - return not ready
102-
if webhooks.IsInvalidReplicationFactor(err) {
102+
if webhooks.IsAdmissionInvalidReplicationFactor(err) {
103103
return errorfactory.New(errorfactory.ResourceNotReady{}, err, fmt.Sprintf("not enough brokers available (at least %d needed) for CC topic", topic.Spec.ReplicationFactor))
104104
}
105105
return errorfactory.New(errorfactory.APIFailure{}, err, "could not create cruise control topic")

pkg/webhooks/errors.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,26 +36,26 @@ func IsAdmissionCantConnect(err error) bool {
3636
return apierrors.IsInternalError(err) && strings.Contains(err.Error(), cantConnectErrorMsg)
3737
}
3838

39-
func IsCantConnectAPIServer(err error) bool {
39+
func IsAdmissionCantConnectAPIServer(err error) bool {
4040
return apierrors.IsInternalError(err) && strings.Contains(err.Error(), cantConnectAPIServerMsg)
4141
}
4242

43-
func IsInvalidReplicationFactor(err error) bool {
43+
func IsAdmissionInvalidReplicationFactor(err error) bool {
4444
return apierrors.IsInvalid(err) && strings.Contains(err.Error(), invalidReplicationFactorErrMsg)
4545
}
4646

47-
func IsOutOfRangeReplicationFactor(err error) bool {
47+
func IsAdmissionOutOfRangeReplicationFactor(err error) bool {
4848
return apierrors.IsInvalid(err) && strings.Contains(err.Error(), outOfRangeReplicationFactorErrMsg)
4949
}
5050

51-
func IsOutOfRangePartitions(err error) bool {
51+
func IsAdmissionOutOfRangePartitions(err error) bool {
5252
return apierrors.IsInvalid(err) && strings.Contains(err.Error(), outOfRangePartitionsErrMsg)
5353
}
5454

55-
func IsInvalidRemovingStorage(err error) bool {
55+
func IsAdmissionInvalidRemovingStorage(err error) bool {
5656
return apierrors.IsInvalid(err) && strings.Contains(err.Error(), unsupportedRemovingStorageMsg)
5757
}
5858

59-
func IsErrorDuringValidation(err error) bool {
59+
func IsAdmissionErrorDuringValidation(err error) bool {
6060
return apierrors.IsInternalError(err) && strings.Contains(err.Error(), errorDuringValidationMsg)
6161
}

pkg/webhooks/errors_test.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -55,22 +55,22 @@ func TestIsInvalidReplicationFactor(t *testing.T) {
5555
kafkaTopic.GetObjectKind().GroupVersionKind().GroupKind(),
5656
kafkaTopic.Name, fieldErrs)
5757

58-
if !IsInvalidReplicationFactor(err) {
58+
if !IsAdmissionInvalidReplicationFactor(err) {
5959
t.Error("Expected is invalid replication error to be true, got false")
6060
}
6161

6262
err = apierrors.NewServiceUnavailable("some other reason")
63-
if IsInvalidReplicationFactor(err) {
63+
if IsAdmissionInvalidReplicationFactor(err) {
6464
t.Error("Expected is invalid replication error to be false, got true")
6565
}
6666

6767
err = apierrors.NewServiceUnavailable(invalidReplicationFactorErrMsg)
68-
if IsInvalidReplicationFactor(err) {
68+
if IsAdmissionInvalidReplicationFactor(err) {
6969
t.Error("Expected is invalid replication error to be false, got true")
7070
}
7171
}
7272

73-
func TestIsCantConnectAPIServer(t *testing.T) {
73+
func TestIsAdmissionCantConnectAPIServer(t *testing.T) {
7474
testCases := []struct {
7575
testName string
7676
err error
@@ -90,40 +90,40 @@ func TestIsCantConnectAPIServer(t *testing.T) {
9090

9191
for _, tc := range testCases {
9292
t.Run(tc.testName, func(t *testing.T) {
93-
if got := IsCantConnectAPIServer(tc.err); got != tc.want {
93+
if got := IsAdmissionCantConnectAPIServer(tc.err); got != tc.want {
9494
t.Errorf("Check connection to API Server error message. Expected: %t ; Got: %t", tc.want, got)
9595
}
9696
})
9797
}
9898
}
9999

100-
func TestIsOutOfRangeReplicationFactor(t *testing.T) {
100+
func TestIsAdmissionOutOfRangeReplicationFactor(t *testing.T) {
101101
kafkaTopic := banzaicloudv1alpha1.KafkaTopic{ObjectMeta: metav1.ObjectMeta{Name: "test-KafkaTopic"}}
102102
var fieldErrs field.ErrorList
103103
fieldErrs = append(fieldErrs, field.Invalid(field.NewPath("spec").Child("replicationFactor"), "-2", outOfRangeReplicationFactorErrMsg))
104104
err := apierrors.NewInvalid(
105105
kafkaTopic.GetObjectKind().GroupVersionKind().GroupKind(),
106106
kafkaTopic.Name, fieldErrs)
107107

108-
if ok := IsOutOfRangeReplicationFactor(err); !ok {
108+
if ok := IsAdmissionOutOfRangeReplicationFactor(err); !ok {
109109
t.Errorf("Check Out of Range ReplicationFactor error message. Expected: %t ; Got: %t", true, ok)
110110
}
111111
}
112112

113-
func TestIsOutOfRangePartitions(t *testing.T) {
113+
func TestIsAdmissionOutOfRangePartitions(t *testing.T) {
114114
kafkaTopic := banzaicloudv1alpha1.KafkaTopic{ObjectMeta: metav1.ObjectMeta{Name: "test-KafkaTopic"}}
115115
var fieldErrs field.ErrorList
116116
fieldErrs = append(fieldErrs, field.Invalid(field.NewPath("spec").Child("partitions"), "-2", outOfRangePartitionsErrMsg))
117117
err := apierrors.NewInvalid(
118118
kafkaTopic.GetObjectKind().GroupVersionKind().GroupKind(),
119119
kafkaTopic.Name, fieldErrs)
120120

121-
if ok := IsOutOfRangePartitions(err); !ok {
121+
if ok := IsAdmissionOutOfRangePartitions(err); !ok {
122122
t.Errorf("Check Out of Range Partitions error message. Expected: %t ; Got: %t", true, ok)
123123
}
124124
}
125125

126-
func TestIsInvalidRemovingStorage(t *testing.T) {
126+
func TestIsAdmissionInvalidRemovingStorage(t *testing.T) {
127127
testCases := []struct {
128128
testName string
129129
fieldErrs field.ErrorList
@@ -159,14 +159,14 @@ func TestIsInvalidRemovingStorage(t *testing.T) {
159159
kafkaCluster.GetObjectKind().GroupVersionKind().GroupKind(),
160160
kafkaCluster.Name, tc.fieldErrs)
161161

162-
if got := IsInvalidRemovingStorage(err); got != tc.want {
162+
if got := IsAdmissionInvalidRemovingStorage(err); got != tc.want {
163163
t.Errorf("Check Storage Removal Error message. Expected: %t ; Got: %t", tc.want, got)
164164
}
165165
})
166166
}
167167
}
168168

169-
func TestIsErrorDuringValidation(t *testing.T) {
169+
func TestIsAdmissionErrorDuringValidation(t *testing.T) {
170170
testCases := []struct {
171171
testName string
172172
err error
@@ -186,7 +186,7 @@ func TestIsErrorDuringValidation(t *testing.T) {
186186

187187
for _, tc := range testCases {
188188
t.Run(tc.testName, func(t *testing.T) {
189-
if got := IsErrorDuringValidation(tc.err); got != tc.want {
189+
if got := IsAdmissionErrorDuringValidation(tc.err); got != tc.want {
190190
t.Errorf("Check overall Error During Validation error message. Expected: %t ; Got: %t", tc.want, got)
191191
}
192192
})

0 commit comments

Comments
 (0)