Skip to content

Commit cdfdb06

Browse files
committed
fix(annotations): change path logic
* Add tests to check if the annotation takes presedence over the ingress resource `Path` options
1 parent 6cb4112 commit cdfdb06

2 files changed

Lines changed: 45 additions & 10 deletions

File tree

internal/controller/networking/ingress_controller.go

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -229,20 +229,16 @@ func (r *IngressReconciler) gatherApiCheckData(
229229
// Get the path(s)
230230
var paths []string
231231

232-
if rule.HTTP == nil { // HTTP may not exist
233-
paths = append(paths, "/")
234-
} else if rule.HTTP.Paths == nil { // Paths may not exist
232+
if value, exists := ingress.Annotations[annotationPath]; exists {
233+
paths = append(paths, value)
234+
} else if rule.HTTP == nil || rule.HTTP.Paths == nil {
235235
paths = append(paths, "/")
236236
} else {
237237
for _, rulePath := range rule.HTTP.Paths {
238-
if ingress.Annotations[annotationPath] == "" {
239-
if rulePath.Path == "" {
240-
paths = append(paths, "/")
241-
} else {
242-
paths = append(paths, rulePath.Path)
243-
}
238+
if rulePath.Path == "" {
239+
paths = append(paths, "/")
244240
} else {
245-
paths = append(paths, ingress.Annotations[annotationPath])
241+
paths = append(paths, rulePath.Path)
246242
}
247243
}
248244
}

internal/controller/networking/ingress_controller_test.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,45 @@ var _ = Describe("Ingress Controller", func() {
138138
return true
139139
}, timeout, interval).Should(BeTrue(), "Timed out waiting for success")
140140

141+
// Update path and use annotation
142+
By("Expecting path to update successfully")
143+
Eventually(func() error {
144+
// Get existing ingress object
145+
f := &networkingv1.Ingress{}
146+
err := k8sClient.Get(context.Background(), ingressKey, f)
147+
if err != nil {
148+
return err
149+
}
150+
151+
newPath := "new-path"
152+
// Update annotations with new path
153+
f.Annotations["testing.domain.tld/path"] = newPath
154+
err = k8sClient.Update(context.Background(), f)
155+
if err != nil {
156+
return err
157+
}
158+
u := &networkingv1.Ingress{}
159+
err = k8sClient.Get(context.Background(), ingressKey, u)
160+
if err != nil {
161+
return err
162+
}
163+
Expect(u.Annotations["testing.domain.tld/path"]).To(Equal("new-path"), "Path annotation should be updated")
164+
165+
apiCheckKeyNewPath := types.NamespacedName{
166+
Name: fmt.Sprintf("%s-%s-%s", "test-ingress", "foobar", newPath),
167+
Namespace: "default",
168+
}
169+
// Expect API Check to be updated
170+
f2 := &checklyv1alpha1.ApiCheck{}
171+
err = k8sClient.Get(context.Background(), apiCheckKeyNewPath, f2)
172+
if err != nil {
173+
return err
174+
}
175+
Expect(f2.Spec.Endpoint).To(Equal(fmt.Sprintf("https://%s/%s", testHost, newPath)), "Endpoint should be updated")
176+
177+
return nil
178+
}, timeout, interval).Should(Succeed(), "Timeout waiting for update")
179+
141180
// Set enabled false
142181
By("Expecting enabled false to remove ApiCheck")
143182
Eventually(func() error {

0 commit comments

Comments
 (0)