Skip to content

Commit 3bf9e3f

Browse files
AlinsRanCopilot
andcommitted
fix: remove duplicate failurePolicy in webhook markers; fix ApisixConsumer skip logic
- Remove redundant failurePolicy=fail from all 4 webhook marker lines, keeping only failurePolicy=Ignore (kubebuilder uses the last occurrence, having both was ambiguous and wrong) - Fix ApisixConsumer ValidateCreate/ValidateUpdate: remove the unnecessary len(warnings) > 0 guard that skipped ADC validation when secrets were missing. Unlike ApisixTls, missing secretRef in ApisixConsumer merely skips that credential in translation; the consumer can still be validated by ADC. Only skip when initErr is non-nil (ADC client init failed). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent c3e4ec4 commit 3bf9e3f

4 files changed

Lines changed: 8 additions & 6 deletions

File tree

internal/webhook/v1/apisixconsumer_webhook.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func SetupApisixConsumerWebhookWithManager(mgr ctrl.Manager) error {
4242
Complete()
4343
}
4444

45-
// +kubebuilder:webhook:path=/validate-apisix-apache-org-v2-apisixconsumer,mutating=false,failurePolicy=fail,sideEffects=None,groups=apisix.apache.org,resources=apisixconsumers,verbs=create;update,versions=v2,name=vapisixconsumer-v2.kb.io,admissionReviewVersions=v1,failurePolicy=Ignore
45+
// +kubebuilder:webhook:path=/validate-apisix-apache-org-v2-apisixconsumer,mutating=false,failurePolicy=Ignore,sideEffects=None,groups=apisix.apache.org,resources=apisixconsumers,verbs=create;update,versions=v2,name=vapisixconsumer-v2.kb.io,admissionReviewVersions=v1
4646

4747
type ApisixConsumerCustomValidator struct {
4848
Client client.Client
@@ -75,7 +75,8 @@ func (v *ApisixConsumerCustomValidator) ValidateCreate(ctx context.Context, obj
7575
}
7676

7777
warnings := v.collectWarnings(ctx, consumer)
78-
if v.initErr != nil || len(warnings) > 0 {
78+
if v.initErr != nil {
79+
apisixConsumerLog.Error(v.initErr, "ADC validator init failed, skipping ADC validation")
7980
return warnings, nil
8081
}
8182
return warnings, v.adcValidator.Validate(ctx, consumer)
@@ -92,7 +93,8 @@ func (v *ApisixConsumerCustomValidator) ValidateUpdate(ctx context.Context, oldO
9293
}
9394

9495
warnings := v.collectWarnings(ctx, consumer)
95-
if v.initErr != nil || len(warnings) > 0 {
96+
if v.initErr != nil {
97+
apisixConsumerLog.Error(v.initErr, "ADC validator init failed, skipping ADC validation")
9698
return warnings, nil
9799
}
98100
return warnings, v.adcValidator.Validate(ctx, consumer)

internal/webhook/v1/apisixroute_webhook.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func SetupApisixRouteWebhookWithManager(mgr ctrl.Manager) error {
4141
Complete()
4242
}
4343

44-
// +kubebuilder:webhook:path=/validate-apisix-apache-org-v2-apisixroute,mutating=false,failurePolicy=fail,sideEffects=None,groups=apisix.apache.org,resources=apisixroutes,verbs=create;update,versions=v2,name=vapisixroute-v2.kb.io,admissionReviewVersions=v1,failurePolicy=Ignore
44+
// +kubebuilder:webhook:path=/validate-apisix-apache-org-v2-apisixroute,mutating=false,failurePolicy=Ignore,sideEffects=None,groups=apisix.apache.org,resources=apisixroutes,verbs=create;update,versions=v2,name=vapisixroute-v2.kb.io,admissionReviewVersions=v1
4545

4646
type ApisixRouteCustomValidator struct {
4747
Client client.Client

internal/webhook/v1/apisixtls_webhook.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func SetupApisixTlsWebhookWithManager(mgr ctrl.Manager) error {
4242
Complete()
4343
}
4444

45-
// +kubebuilder:webhook:path=/validate-apisix-apache-org-v2-apisixtls,mutating=false,failurePolicy=fail,sideEffects=None,groups=apisix.apache.org,resources=apisixtlses,verbs=create;update,versions=v2,name=vapisixtls-v2.kb.io,admissionReviewVersions=v1,failurePolicy=Ignore
45+
// +kubebuilder:webhook:path=/validate-apisix-apache-org-v2-apisixtls,mutating=false,failurePolicy=Ignore,sideEffects=None,groups=apisix.apache.org,resources=apisixtlses,verbs=create;update,versions=v2,name=vapisixtls-v2.kb.io,admissionReviewVersions=v1
4646

4747
type ApisixTlsCustomValidator struct {
4848
Client client.Client

internal/webhook/v1/consumer_webhook.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func SetupConsumerWebhookWithManager(mgr ctrl.Manager) error {
4545
Complete()
4646
}
4747

48-
// +kubebuilder:webhook:path=/validate-apisix-apache-org-v1alpha1-consumer,mutating=false,failurePolicy=fail,sideEffects=None,groups=apisix.apache.org,resources=consumers,verbs=create;update,versions=v1alpha1,name=vconsumer-v1alpha1.kb.io,admissionReviewVersions=v1,failurePolicy=Ignore
48+
// +kubebuilder:webhook:path=/validate-apisix-apache-org-v1alpha1-consumer,mutating=false,failurePolicy=Ignore,sideEffects=None,groups=apisix.apache.org,resources=consumers,verbs=create;update,versions=v1alpha1,name=vconsumer-v1alpha1.kb.io,admissionReviewVersions=v1
4949

5050
type ConsumerCustomValidator struct {
5151
Client client.Client

0 commit comments

Comments
 (0)