Allow referencing to TLS secret from other namespace

When TLS secret referred to when creating an ingress is of pattern
<namespace>/<secretName> ingress controller will check the namespace
specified rather than ingress' namespace.

Fixes #2170
This commit is contained in:
Amit Kumar 2018-03-07 11:20:47 +00:00
parent 01399dd625
commit cef2e6f5e2
No known key found for this signature in database
GPG key ID: 3DD124873C5CD108
2 changed files with 19 additions and 3 deletions

View file

@ -997,7 +997,13 @@ func (n *NGINXController) createServers(data []*extensions.Ingress,
continue
}
key := fmt.Sprintf("%v/%v", ing.Namespace, tlsSecretName)
key := ""
if strings.Contains(tlsSecretName, "/") {
key = tlsSecretName
} else {
key = fmt.Sprintf("%v/%v", ing.Namespace, tlsSecretName)
}
cert, err := n.store.GetLocalSecret(key)
if err != nil {
glog.Warningf("ssl certificate \"%v\" does not exist in local store", key)

View file

@ -188,7 +188,7 @@ func (s k8sStore) checkMissingSecrets() {
continue
}
key := fmt.Sprintf("%v/%v", ing.Namespace, tls.SecretName)
key := getSecretKey(ing.Namespace, tls.SecretName)
if _, ok := s.sslStore.Get(key); !ok {
s.syncSecret(key)
}
@ -212,7 +212,7 @@ func (s k8sStore) ReadSecrets(ing *extensions.Ingress) {
continue
}
key := fmt.Sprintf("%v/%v", ing.Namespace, tls.SecretName)
key := getSecretKey(ing.Namespace, tls.SecretName)
s.syncSecret(key)
}
@ -236,3 +236,13 @@ func (s *k8sStore) sendDummyEvent() {
},
}
}
// getSecretKey gets a key in format namespace/secretName
func getSecretKey(namespace, secretName string) (key string) {
if strings.Contains(secretName, "/") {
key = secretName
} else {
key = fmt.Sprintf("%v/%v", namespace, secretName)
}
return
}