This commit is contained in:
Amit Kumar 2018-03-07 16:12:35 +00:00 committed by GitHub
commit 56b1813d7b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 40 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
}

View file

@ -18,6 +18,7 @@ package store
import (
"encoding/base64"
"testing"
apiv1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@ -127,6 +128,26 @@ func buildCrtKeyAndCA() ([]byte, []byte, []byte, error) {
return dCrt, dKey, dCa, nil
}
func TestGetSecretKey(t *testing.T) {
secretName := "secretNamespace/superSecret"
ingressNamespace := "ingressNamespace"
// Test when secret is in not in the same namespace as ingress.
secretKey := getSecretKey(ingressNamespace, secretName)
if secretKey != "secretNamespace/superSecret" {
t.Errorf("expected 0 items in the store but %v returned", secretKey)
}
// Test when secret resides in the same namespace as ingress.
secretName = "superSecret"
secretKey = getSecretKey(ingressNamespace, secretName)
if secretKey != "ingressNamespace/superSecret" {
t.Errorf("expected 0 items in the store but %v returned", secretKey)
}
}
/*
func TestSyncSecret(t *testing.T) {
// prepare for test