Skip to content

Commit ff8cd42

Browse files
authored
fix: exclude status-only API v2 resources from readiness gating (#2745)
1 parent 19e40c9 commit ff8cd42

2 files changed

Lines changed: 67 additions & 9 deletions

File tree

internal/manager/controllers.go

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -337,15 +337,7 @@ func registerAPIv2ForReadiness(
337337
readier readiness.ReadinessManager,
338338
) {
339339
var installed []schema.GroupVersionKind
340-
for _, resource := range []client.Object{
341-
&netv1.Ingress{},
342-
&apiv2.ApisixRoute{},
343-
&apiv2.ApisixGlobalRule{},
344-
&apiv2.ApisixPluginConfig{},
345-
&apiv2.ApisixTls{},
346-
&apiv2.ApisixConsumer{},
347-
&apiv2.ApisixUpstream{},
348-
} {
340+
for _, resource := range apiV2ReadinessResources() {
349341
gvk := types.GvkOf(resource)
350342
if utils.HasAPIResource(mgr, resource) {
351343
installed = append(installed, gvk)
@@ -368,6 +360,16 @@ func registerAPIv2ForReadiness(
368360
})
369361
}
370362

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

0 commit comments

Comments
 (0)