@@ -32,7 +32,7 @@ type KongValidator interface {
3232 ValidateConsumerGroup (ctx context.Context , consumerGroup kongv1beta1.KongConsumerGroup ) (bool , string , error )
3333 ValidatePlugin (ctx context.Context , plugin kongv1.KongPlugin ) (bool , string , error )
3434 ValidateClusterPlugin (ctx context.Context , plugin kongv1.KongClusterPlugin ) (bool , string , error )
35- ValidateCredential (ctx context.Context , secret corev1.Secret ) (bool , string , error )
35+ ValidateCredential (ctx context.Context , secret corev1.Secret ) (bool , string )
3636 ValidateGateway (ctx context.Context , gateway gatewayapi.Gateway ) (bool , string , error )
3737 ValidateHTTPRoute (ctx context.Context , httproute gatewayapi.HTTPRoute ) (bool , string , error )
3838 ValidateIngress (ctx context.Context , ingress netv1.Ingress ) (bool , string , error )
@@ -125,7 +125,7 @@ func (validator KongHTTPValidator) ValidateConsumer(
125125 // credentials so that the consumers credentials references can be validated.
126126 managedConsumers , err := validator .listManagedConsumers (ctx )
127127 if err != nil {
128- return false , ErrTextConsumerUnretrievable , err
128+ return false , fmt . Sprintf ( "failed to fetch managed KongConsumers from cache: %s" , err ), nil
129129 }
130130
131131 // retrieve the consumer's credentials secrets to validate them with the index
@@ -136,14 +136,14 @@ func (validator KongHTTPValidator) ValidateConsumer(
136136 secret , err := validator .SecretGetter .GetSecret (consumer .Namespace , secretName )
137137 if err != nil {
138138 if apierrors .IsNotFound (err ) {
139- return false , ErrTextConsumerCredentialSecretNotFound , err
139+ return false , fmt . Sprintf ( "%s: %s" , ErrTextConsumerCredentialSecretNotFound , err ), nil
140140 }
141141 return false , ErrTextFailedToRetrieveSecret , err
142142 }
143143
144144 // do the basic credentials validation
145145 if err := credsvalidation .ValidateCredentials (secret ); err != nil {
146- return false , ErrTextConsumerCredentialValidationFailed , err
146+ return false , fmt . Sprintf ( "%s: %s" , ErrTextConsumerCredentialValidationFailed , err ), nil
147147 }
148148
149149 // if valid, store it so we can index it for upcoming constraints validation
@@ -164,15 +164,15 @@ func (validator KongHTTPValidator) ValidateConsumer(
164164 // testing them against themselves.
165165 credentialsIndex , err := globalValidationIndexForCredentials (ctx , validator .ManagerClient , managedConsumers , ignoredSecrets )
166166 if err != nil {
167- return false , ErrTextConsumerCredentialValidationFailed , err
167+ return false , fmt . Sprintf ( "%s: %s" , ErrTextConsumerCredentialValidationFailed , err ), nil
168168 }
169169
170170 // validate the consumer's credentials against the index of all managed
171171 // credentials to ensure they're not in violation of any unique constraints.
172172 for _ , secret := range credentials {
173173 // do the unique constraints validation of the credentials using the credentials index
174174 if err := credentialsIndex .ValidateCredentialsForUniqueKeyConstraints (secret ); err != nil {
175- return false , ErrTextConsumerCredentialValidationFailed , err
175+ return false , fmt . Sprintf ( "%s: %s" , ErrTextConsumerCredentialValidationFailed , err ), nil
176176 }
177177 }
178178
@@ -232,34 +232,31 @@ func (validator KongHTTPValidator) ValidateConsumerGroup(
232232// are present in it or not. If valid, it returns true with an empty string,
233233// else it returns false with the error message. If an error happens during
234234// validation, error is returned.
235- func (validator KongHTTPValidator ) ValidateCredential (
236- ctx context.Context ,
237- secret corev1.Secret ,
238- ) (bool , string , error ) {
235+ func (validator KongHTTPValidator ) ValidateCredential (ctx context.Context , secret corev1.Secret ) (bool , string ) {
239236 // If the secret doesn't specify a credential type (either by label or the secret's key) it's not a credentials secret.
240237 if _ , s := util .ExtractKongCredentialType (& secret ); s == util .CredentialTypeAbsent {
241- return true , "" , nil
238+ return true , ""
242239 }
243240
244241 // If we know it's a credentials secret, we can ensure its base-level validity.
245242 if err := credsvalidation .ValidateCredentials (& secret ); err != nil {
246- return false , fmt .Sprintf ("%s: %s" , ErrTextConsumerCredentialValidationFailed , err ), nil
243+ return false , fmt .Sprintf ("%s: %s" , ErrTextConsumerCredentialValidationFailed , err )
247244 }
248245
249246 // Credentials are validated further for unique key constraints only if they are referenced by a managed consumer
250247 // in the namespace, as such we pull a list of all consumers from the cached client to determine
251248 // if the credentials are referenced.
252249 managedConsumers , err := validator .listManagedConsumers (ctx )
253250 if err != nil {
254- return false , ErrTextConsumerUnretrievable , err
251+ return false , fmt . Sprintf ( "failed to fetch managed KongConsumers from cache: %s" , err )
255252 }
256253
257254 // Verify whether this secret is referenced by any managed consumer.
258255 managedConsumersWithReferences := listManagedConsumersReferencingCredentialsSecret (secret , managedConsumers )
259256 if len (managedConsumersWithReferences ) == 0 {
260257 // If no managed consumers reference this secret, its considered unmanaged, and we don't validate it
261258 // unless it becomes referenced by a managed consumer at a later time.
262- return true , "" , nil
259+ return true , ""
263260 }
264261
265262 // If base-level validation passed and the credential is referenced by a consumer,
@@ -268,16 +265,16 @@ func (validator KongHTTPValidator) ValidateCredential(
268265 ignoreSecrets := map [string ]map [string ]struct {}{secret .Namespace : {secret .Name : {}}}
269266 credentialsIndex , err := globalValidationIndexForCredentials (ctx , validator .ManagerClient , managedConsumers , ignoreSecrets )
270267 if err != nil {
271- return false , ErrTextConsumerCredentialValidationFailed , err
268+ return false , fmt . Sprintf ( "%s: %s" , ErrTextConsumerCredentialValidationFailed , err )
272269 }
273270
274271 // The index is built, now validate that the newly updated secret
275272 // is not in violation of any constraints.
276273 if err := credentialsIndex .ValidateCredentialsForUniqueKeyConstraints (& secret ); err != nil {
277- return false , fmt .Sprintf ("%s: %s" , ErrTextConsumerCredentialValidationFailed , err ), nil
274+ return false , fmt .Sprintf ("%s: %s" , ErrTextConsumerCredentialValidationFailed , err )
278275 }
279276
280- return true , "" , nil
277+ return true , ""
281278}
282279
283280// ValidatePlugin checks if k8sPlugin is valid. It does so by performing
@@ -404,13 +401,19 @@ func (validator KongHTTPValidator) ValidateHTTPRoute(
404401 Namespace : namespace ,
405402 Name : string (parentRef .Name ),
406403 }, & gateway ); err != nil {
407- return false , fmt .Sprintf ("Couldn't retrieve referenced gateway %s/%s" , namespace , parentRef .Name ), err
404+ if apierrors .IsNotFound (err ) {
405+ return false , fmt .Sprintf ("referenced gateway %s/%s not found" , namespace , parentRef .Name ), nil
406+ }
407+ return false , "" , err
408408 }
409409
410410 // pull the referenced GatewayClass object from the Gateway
411411 gatewayClass := gatewayapi.GatewayClass {}
412412 if err := validator .ManagerClient .Get (ctx , client.ObjectKey {Name : string (gateway .Spec .GatewayClassName )}, & gatewayClass ); err != nil {
413- return false , fmt .Sprintf ("Couldn't retrieve referenced gatewayclass %s" , gateway .Spec .GatewayClassName ), err
413+ if apierrors .IsNotFound (err ) {
414+ return false , fmt .Sprintf ("referenced gatewayclass %s not found" , gateway .Spec .GatewayClassName ), nil
415+ }
416+ return false , "" , err
414417 }
415418
416419 // determine ultimately whether the Gateway is managed by this controller implementation
0 commit comments