Skip to content

Commit bcd4679

Browse files
AlinsRanCopilot
andcommitted
fix: exclude status-only API v2 resources from readiness gating
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent e5a51c9 commit bcd4679

2 files changed

Lines changed: 75 additions & 10 deletions

File tree

internal/manager/controllers.go

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -308,16 +308,13 @@ func registerV2ForReadinessGVK(mgr manager.Manager, readier readiness.ReadinessM
308308
icgv = netv1beta1.SchemeGroupVersion
309309
}
310310

311-
gvks := []schema.GroupVersionKind{
312-
types.GvkOf(&apiv2.ApisixRoute{}),
313-
types.GvkOf(&apiv2.ApisixGlobalRule{}),
314-
types.GvkOf(&apiv2.ApisixPluginConfig{}),
315-
types.GvkOf(&apiv2.ApisixTls{}),
316-
types.GvkOf(&apiv2.ApisixConsumer{}),
317-
types.GvkOf(&apiv2.ApisixUpstream{}),
318-
}
319-
if utils.HasAPIResource(mgr, &netv1.Ingress{}) {
320-
gvks = append(gvks, types.GvkOf(&netv1.Ingress{}))
311+
resources := v2ReadinessResources()
312+
gvks := make([]schema.GroupVersionKind, 0, len(resources))
313+
for _, resource := range resources {
314+
if _, ok := resource.(*netv1.Ingress); ok && !utils.HasAPIResource(mgr, resource) {
315+
continue
316+
}
317+
gvks = append(gvks, types.GvkOf(resource))
321318
}
322319

323320
c := mgr.GetClient()
@@ -332,6 +329,16 @@ func registerV2ForReadinessGVK(mgr manager.Manager, readier readiness.ReadinessM
332329
log.Info("Registered v2 GVKs for readiness checks", "gvks", gvks)
333330
}
334331

332+
func v2ReadinessResources() []client.Object {
333+
return []client.Object{
334+
&netv1.Ingress{},
335+
&apiv2.ApisixRoute{},
336+
&apiv2.ApisixGlobalRule{},
337+
&apiv2.ApisixTls{},
338+
&apiv2.ApisixConsumer{},
339+
}
340+
}
341+
335342
func registerGatewayAPIForReadinessGVK(mgr manager.Manager, readier readiness.ReadinessManager, log logr.Logger) {
336343
gvks := []schema.GroupVersionKind{}
337344
if utils.HasAPIResource(mgr, &gatewayv1.HTTPRoute{}) {
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
package manager
19+
20+
import (
21+
"testing"
22+
23+
netv1 "k8s.io/api/networking/v1"
24+
25+
apiv2 "github.com/apache/apisix-ingress-controller/api/v2"
26+
types "github.com/apache/apisix-ingress-controller/internal/types"
27+
)
28+
29+
func TestV2ReadinessResources(t *testing.T) {
30+
resources := v2ReadinessResources()
31+
seen := make(map[string]bool, len(resources))
32+
for _, resource := range resources {
33+
seen[types.GvkOf(resource).String()] = true
34+
}
35+
36+
want := []string{
37+
types.GvkOf(&netv1.Ingress{}).String(),
38+
types.GvkOf(&apiv2.ApisixRoute{}).String(),
39+
types.GvkOf(&apiv2.ApisixGlobalRule{}).String(),
40+
types.GvkOf(&apiv2.ApisixTls{}).String(),
41+
types.GvkOf(&apiv2.ApisixConsumer{}).String(),
42+
}
43+
for _, gvk := range want {
44+
if !seen[gvk] {
45+
t.Fatalf("expected readiness resources to include %s", gvk)
46+
}
47+
}
48+
49+
notExpected := []string{
50+
types.GvkOf(&apiv2.ApisixPluginConfig{}).String(),
51+
types.GvkOf(&apiv2.ApisixUpstream{}).String(),
52+
}
53+
for _, gvk := range notExpected {
54+
if seen[gvk] {
55+
t.Fatalf("expected readiness resources to exclude %s", gvk)
56+
}
57+
}
58+
}

0 commit comments

Comments
 (0)