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

Independently configure rules and TLS #702

Merged
merged 1 commit into from
Dec 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 19 additions & 20 deletions pkg/converters/ingress/ingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -440,31 +440,30 @@ func (c *converter) syncIngress(ing *networking.Ingress) {
}
}
}
for _, tls := range ing.Spec.TLS {
for _, tlshost := range tls.Hosts {
if tlshost == hostname {
tlsPath := c.addTLS(source, tlshost, tls.SecretName)
if host.TLS.TLSHash == "" {
host.TLS.TLSFilename = tlsPath.Filename
host.TLS.TLSHash = tlsPath.SHA1Hash
host.TLS.TLSCommonName = tlsPath.CommonName
host.TLS.TLSNotAfter = tlsPath.NotAfter
} else if host.TLS.TLSHash != tlsPath.SHA1Hash {
msg := fmt.Sprintf("TLS of host '%s' was already assigned", host.Hostname)
if tls.SecretName != "" {
c.logger.Warn("skipping TLS secret '%s' of ingress '%s': %s", tls.SecretName, fullIngName, msg)
} else {
c.logger.Warn("skipping default TLS secret of ingress '%s': %s", fullIngName, msg)
}
}
}
for _, tls := range ing.Spec.TLS {
// tls secret
for _, hostname := range tls.Hosts {
host := c.addHost(hostname, source, annHost)
tlsPath := c.addTLS(source, hostname, tls.SecretName)
if host.TLS.TLSHash == "" {
host.TLS.TLSFilename = tlsPath.Filename
host.TLS.TLSHash = tlsPath.SHA1Hash
host.TLS.TLSCommonName = tlsPath.CommonName
host.TLS.TLSNotAfter = tlsPath.NotAfter
} else if host.TLS.TLSHash != tlsPath.SHA1Hash {
msg := fmt.Sprintf("TLS of host '%s' was already assigned", host.Hostname)
if tls.SecretName != "" {
c.logger.Warn("skipping TLS secret '%s' of ingress '%s': %s", tls.SecretName, fullIngName, msg)
} else {
c.logger.Warn("skipping default TLS secret of ingress '%s': %s", fullIngName, msg)
}
}
}
}
for _, tls := range ing.Spec.TLS {
// distinct prefix, read from the Annotations map
// acme tracking
var tlsAcme bool
if c.options.AcmeTrackTLSAnn {
// distinct prefix, read from the Annotations map
tlsAcmeStr, _ := ing.Annotations[ingtypes.ExtraTLSAcme]
tlsAcme, _ = strconv.ParseBool(tlsAcmeStr)
}
Expand Down
35 changes: 35 additions & 0 deletions pkg/converters/ingress/ingress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,21 @@ func TestSyncInvalidTLS(t *testing.T) {
WARN using default certificate due to an error reading secret 'tls-invalid' on ingress 'default/echo': secret not found: 'default/tls-invalid'`)
}

func TestSyncTLSSecretWithoutHost(t *testing.T) {
c := setup(t)
defer c.teardown()

c.createSvc1Auto()
c.createSecretTLS1("default/tls-echo")
c.Sync(c.createIngTLS2("default/echo", "tls-echo:echo.example.com"))

c.compareConfigFront(`
- hostname: echo.example.com
paths: []
tls:
tlsfilename: /tls/default/tls-echo.pem`)
}

func TestSyncIngressClass(t *testing.T) {
apiGroup1 := "some.io"
testCases := []struct {
Expand Down Expand Up @@ -1985,6 +2000,26 @@ func (c *testConfig) createIngTLS1(name, hostname, path, service, secretHostName
return ing
}

func (c *testConfig) createIngTLS2(name, secretHostName string) *networking.Ingress {
tls := []networking.IngressTLS{}
for _, secret := range strings.Split(secretHostName, ";") {
ssecret := strings.Split(secret, ":")
hosts := []string{}
if len(ssecret) > 1 {
for _, host := range strings.Split(ssecret[1], ",") {
hosts = append(hosts, host)
}
}
tls = append(tls, networking.IngressTLS{
Hosts: hosts,
SecretName: ssecret[0],
})
}
ing := c.createIng3(name)
ing.Spec.TLS = tls
return ing
}

func (c *testConfig) createObject(cfg string) runtime.Object {
obj, _, err := c.decode([]byte(cfg), nil, nil)
if err != nil {
Expand Down