Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ingress V1: Parse Ingress V1 entries from Store. #832

Merged
merged 9 commits into from
Sep 14, 2020
14 changes: 12 additions & 2 deletions internal/ingress/controller/parser/ingressrules.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import (
"github.com/kong/kubernetes-ingress-controller/internal/ingress/controller/parser/kongstate"
"github.com/kong/kubernetes-ingress-controller/internal/ingress/store"
"github.com/sirupsen/logrus"
networking "k8s.io/api/networking/v1beta1"
networkingv1 "k8s.io/api/networking/v1"
networkingv1beta1 "k8s.io/api/networking/v1beta1"
)

type ingressRules struct {
Expand Down Expand Up @@ -79,7 +80,16 @@ func newSecretNameToSNIs() SecretNameToSNIs {
return SecretNameToSNIs(map[string][]string{})
}

func (m SecretNameToSNIs) addFromIngressTLS(tlsSections []networking.IngressTLS, namespace string) {
func (m SecretNameToSNIs) addFromIngressV1beta1TLS(tlsSections []networkingv1beta1.IngressTLS, namespace string) {
// Assume that v1beta1 and v1 tlsSections have identical semantics and field-wise content.
var v1 []networkingv1.IngressTLS
for _, item := range tlsSections {
v1 = append(v1, networkingv1.IngressTLS{Hosts: item.Hosts, SecretName: item.SecretName})
}
mflendrich marked this conversation as resolved.
Show resolved Hide resolved
m.addFromIngressV1TLS(v1, namespace)
}

func (m SecretNameToSNIs) addFromIngressV1TLS(tlsSections []networkingv1.IngressTLS, namespace string) {
for _, tls := range tlsSections {
if len(tls.Hosts) == 0 {
continue
Expand Down
4 changes: 2 additions & 2 deletions internal/ingress/controller/parser/ingressrules_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func TestMergeIngressRules(t *testing.T) {
}
}

func Test_addFromIngressTLS(t *testing.T) {
func Test_addFromIngressV1beta1TLS(t *testing.T) {
type args struct {
tlsSections []networking.IngressTLS
namespace string
Expand Down Expand Up @@ -165,7 +165,7 @@ func Test_addFromIngressTLS(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
m := newSecretNameToSNIs()
m.addFromIngressTLS(tt.args.tlsSections, tt.args.namespace)
m.addFromIngressV1beta1TLS(tt.args.tlsSections, tt.args.namespace)
assert.Equal(t, m, tt.want)
})
}
Expand Down
8 changes: 4 additions & 4 deletions internal/ingress/controller/parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ import (
)

func parseAll(log logrus.FieldLogger, s store.Storer) ingressRules {
ings := s.ListIngressesV1beta1()
parsedIngress := fromIngressV1beta1(log, ings)
parsedIngressV1beta1 := fromIngressV1beta1(log, s.ListIngressesV1beta1())
parsedIngressV1 := fromIngressV1(log, s.ListIngressesV1())

tcpIngresses, err := s.ListTCPIngresses()
if err != nil {
Expand All @@ -38,9 +38,9 @@ func parseAll(log logrus.FieldLogger, s store.Storer) ingressRules {
if err != nil {
log.Errorf("failed to list Knative Ingresses: %v", err)
}
parsedKnative := fromKnativeIngress(knativeIngresses)
parsedKnative := fromKnativeIngress(log, knativeIngresses)

return mergeIngressRules(parsedIngress, parsedTCPIngress, parsedKnative)
return mergeIngressRules(parsedIngressV1beta1, parsedIngressV1, parsedTCPIngress, parsedKnative)
}

// Build creates a Kong configuration from Ingress and Custom resources
Expand Down
Loading