Skip to content

Commit ccd1a97

Browse files
authored
fix: incorrect kuadrant status if limitador/authorino is not found (#1000)
* fix: incorrect kuadrant status if limitador/authorino is not found Signed-off-by: KevFan <[email protected]> * test: kuadrant status on bare k8s Signed-off-by: KevFan <[email protected]> * refactor: include ErrMissingAuthorino in kuadrant status Signed-off-by: KevFan <[email protected]> --------- Signed-off-by: KevFan <[email protected]>
1 parent 365b170 commit ccd1a97

File tree

2 files changed

+43
-45
lines changed

2 files changed

+43
-45
lines changed

controllers/kuadrant_status_updater.go

+26-34
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,11 @@ package controllers
22

33
import (
44
"context"
5-
"errors"
65
"fmt"
76
"slices"
87
"sync"
98

109
"github.com/go-logr/logr"
11-
authorinov1beta1 "github.com/kuadrant/authorino-operator/api/v1beta1"
12-
limitadorv1alpha1 "github.com/kuadrant/limitador-operator/api/v1alpha1"
1310
"github.com/kuadrant/policy-machinery/controller"
1411
"github.com/kuadrant/policy-machinery/machinery"
1512
corev1 "k8s.io/api/core/v1"
@@ -128,43 +125,33 @@ func (r *KuadrantStatusUpdater) readyCondition(topology *machinery.Topology, log
128125
return cond
129126
}
130127

131-
limitadorObj, err := GetLimitadorFromTopology(topology)
132-
if err != nil && !errors.Is(err, ErrMissingLimitador) {
133-
logger.V(1).Error(err, "failed getting Limitador resource from topology", "status", "error")
134-
}
135-
136-
if limitadorObj != nil {
137-
reason := checkLimitadorReady(limitadorObj)
138-
if reason != nil {
139-
cond.Status = metav1.ConditionFalse
140-
cond.Reason = "limitadornotready"
141-
cond.Message = *reason
142-
return cond
143-
}
128+
if reason := checkLimitadorReady(topology, logger); reason != nil {
129+
cond.Status = metav1.ConditionFalse
130+
cond.Reason = "LimitadorNotReady"
131+
cond.Message = *reason
132+
return cond
144133
}
145134

146-
authorinoObj, err := GetAuthorinoFromTopology(topology)
147-
if err != nil && !errors.Is(err, ErrMissingAuthorino) {
148-
logger.V(1).Error(err, "failed getting Authorino resource from topology", "status", "error")
135+
if reason := checkAuthorinoAvailable(topology, logger); reason != nil {
136+
cond.Status = metav1.ConditionFalse
137+
cond.Reason = "AuthorinoNotReady"
138+
cond.Message = *reason
139+
return cond
149140
}
150141

151-
if authorinoObj != nil {
152-
reason := checkAuthorinoAvailable(authorinoObj)
153-
if reason != nil {
154-
cond.Status = metav1.ConditionFalse
155-
cond.Reason = "AuthorinoNotReady"
156-
cond.Message = *reason
157-
return cond
158-
}
159-
}
160142
return cond
161143
}
162144

163-
func checkLimitadorReady(limitadorObj *limitadorv1alpha1.Limitador) *string {
145+
func checkLimitadorReady(topology *machinery.Topology, logger logr.Logger) *string {
146+
limitadorObj, err := GetLimitadorFromTopology(topology)
147+
if err != nil {
148+
logger.V(1).Error(err, "failed getting Limitador resource from topology", "status", "error")
149+
return ptr.To(err.Error())
150+
}
151+
164152
statusConditionReady := meta.FindStatusCondition(limitadorObj.Status.Conditions, "Ready")
165153
if statusConditionReady == nil {
166-
reason := "Ready condition not found"
167-
return &reason
154+
return ptr.To("Ready condition not found")
168155
}
169156
if statusConditionReady.Status != metav1.ConditionTrue {
170157
return &statusConditionReady.Message
@@ -173,11 +160,16 @@ func checkLimitadorReady(limitadorObj *limitadorv1alpha1.Limitador) *string {
173160
return nil
174161
}
175162

176-
func checkAuthorinoAvailable(authorinoObj *authorinov1beta1.Authorino) *string {
163+
func checkAuthorinoAvailable(topology *machinery.Topology, logger logr.Logger) *string {
164+
authorinoObj, err := GetAuthorinoFromTopology(topology)
165+
if err != nil {
166+
logger.V(1).Error(err, "failed getting Authorino resource from topology", "status", "error")
167+
return ptr.To(err.Error())
168+
}
169+
177170
readyCondition := authorino.FindAuthorinoStatusCondition(authorinoObj.Status.Conditions, "Ready")
178171
if readyCondition == nil {
179-
tmp := "Ready condition not found"
180-
return &tmp
172+
return ptr.To("Ready condition not found")
181173
}
182174

183175
if readyCondition.Status != corev1.ConditionTrue {

tests/bare_k8s/kuadrant_controller_test.go

+17-11
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,20 @@ import (
77

88
. "github.com/onsi/ginkgo/v2"
99
. "github.com/onsi/gomega"
10+
"k8s.io/apimachinery/pkg/api/meta"
1011
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1112
"sigs.k8s.io/controller-runtime/pkg/client"
1213

1314
kuadrantv1beta1 "github.com/kuadrant/kuadrant-operator/api/v1beta1"
15+
"github.com/kuadrant/kuadrant-operator/controllers"
1416
"github.com/kuadrant/kuadrant-operator/tests"
1517
)
1618

17-
var _ = Describe("Kuadrant controller is disabled", func() {
19+
var _ = Describe("Controller", func() {
1820
var (
1921
testNamespace string
20-
kuadrantName string = "local"
21-
afterEachTimeOut = NodeTimeout(3 * time.Minute)
22+
testTimeOut = SpecTimeout(15 * time.Second)
23+
afterEachTimeOut = NodeTimeout(3 * time.Minute)
2224
)
2325

2426
BeforeEach(func(ctx SpecContext) {
@@ -30,24 +32,28 @@ var _ = Describe("Kuadrant controller is disabled", func() {
3032
}, afterEachTimeOut)
3133

3234
Context("when default kuadrant CR is created", func() {
33-
It("Status is not populated", func(ctx SpecContext) {
35+
It("Status is populated with missing GatewayProvide", func(ctx SpecContext) {
3436
kuadrantCR := &kuadrantv1beta1.Kuadrant{
3537
TypeMeta: metav1.TypeMeta{
3638
Kind: "Kuadrant",
3739
APIVersion: kuadrantv1beta1.GroupVersion.String(),
3840
},
3941
ObjectMeta: metav1.ObjectMeta{
40-
Name: kuadrantName,
42+
Name: "local",
4143
Namespace: testNamespace,
4244
},
4345
}
4446
Expect(testClient().Create(ctx, kuadrantCR)).ToNot(HaveOccurred())
4547

46-
kObj := &kuadrantv1beta1.Kuadrant{}
47-
err := testClient().Get(ctx, client.ObjectKeyFromObject(kuadrantCR), kObj)
48-
Expect(err).ToNot(HaveOccurred())
49-
// expected empty. The controller should not have updated it
50-
Expect(kObj.Status).To(Equal(kuadrantv1beta1.KuadrantStatus{}))
51-
})
48+
Eventually(func(g Gomega) {
49+
g.Expect(testClient().Get(ctx, client.ObjectKeyFromObject(kuadrantCR), kuadrantCR)).To(Succeed())
50+
51+
cond := meta.FindStatusCondition(kuadrantCR.Status.Conditions, controllers.ReadyConditionType)
52+
g.Expect(cond).ToNot(BeNil())
53+
g.Expect(cond.Status).To(Equal(metav1.ConditionFalse))
54+
g.Expect(cond.Reason).To(Equal("GatewayAPIProviderNotFound"))
55+
g.Expect(cond.Message).To(Equal("GatewayAPI provider not found"))
56+
}).WithContext(ctx).Should(Succeed())
57+
}, testTimeOut)
5258
})
5359
})

0 commit comments

Comments
 (0)