Skip to content

Commit

Permalink
allow path related ingress fields to co-exist
Browse files Browse the repository at this point in the history
  • Loading branch information
cfitzw committed Dec 16, 2024
1 parent 8d2f4f5 commit 3876fe1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
5 changes: 3 additions & 2 deletions pkg/trait/ingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,10 @@ func (t *ingressTrait) getPaths(service *corev1.Service) []networkingv1.HTTPIngr
paths := []networkingv1.HTTPIngressPath{}
if t.Path == "" && len(t.Paths) == 0 {
paths = append(paths, createIngressPath(defaultPath))
} else if t.Path != "" {
paths = append(paths, createIngressPath(t.Path))
} else {
if t.Path != "" {
paths = append(paths, createIngressPath(t.Path))
}
for _, p := range t.Paths {
paths = append(paths, createIngressPath(p))
}
Expand Down
15 changes: 15 additions & 0 deletions pkg/trait/ingress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,21 @@ func TestApplyIngressTraitWithPathsDoesSucceed(t *testing.T) {
assert.Equal(t, "service-name(hostname) -> service-name(http)", conditions[0].Message)
}

func TestApplyIngressTraitWithPathAndPathsDoesSucceed(t *testing.T) {
ingressTrait, environment := createNominalIngressTest()
ingressTrait.Path = string("/path")
ingressTrait.Paths = []string{"/path-a", "/path-b"}

err := ingressTrait.Apply(environment)

require.NoError(t, err)
environment.Resources.Visit(func(resource runtime.Object) {
if ingress, ok := resource.(*networkingv1.Ingress); ok {
assert.Len(t, ingress.Spec.Rules[0].HTTP.Paths, 3)
}
})
}

func TestApplyIngressTraitWithIngressClassNameDoesSucceed(t *testing.T) {
ingressTrait, environment := createNominalIngressTestWithIngressClassName("someIngressClass")

Expand Down

0 comments on commit 3876fe1

Please sign in to comment.