Skip to content

Commit

Permalink
add secret reading
Browse files Browse the repository at this point in the history
  • Loading branch information
jcmoraisjr committed Jan 29, 2019
1 parent 403025f commit 9a543c8
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 17 deletions.
28 changes: 16 additions & 12 deletions pkg/common/ingress/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -1540,19 +1540,21 @@ func (ic *GenericController) Start() {

createDefaultSSLCertificate()

time.Sleep(5 * time.Second)
// initial sync of secrets to avoid unnecessary reloads
glog.Info("running initial sync of secrets")
for _, obj := range ic.listers.Ingress.List() {
ing := obj.(*extensions.Ingress)
if ic.cfg.V07 {
time.Sleep(5 * time.Second)
// initial sync of secrets to avoid unnecessary reloads
glog.Info("running initial sync of secrets")
for _, obj := range ic.listers.Ingress.List() {
ing := obj.(*extensions.Ingress)

if !class.IsValid(ing, ic.cfg.IngressClass, ic.cfg.DefaultIngressClass) {
a, _ := parser.GetStringAnnotation(class.IngressKey, ing)
glog.V(2).Infof("ignoring add for ingress %v based on annotation %v with value %v", ing.Name, class.IngressKey, a)
continue
}

if !class.IsValid(ing, ic.cfg.IngressClass, ic.cfg.DefaultIngressClass) {
a, _ := parser.GetStringAnnotation(class.IngressKey, ing)
glog.V(2).Infof("ignoring add for ingress %v based on annotation %v with value %v", ing.Name, class.IngressKey, a)
continue
ic.readSecrets(ing)
}

ic.readSecrets(ing)
}

go ic.syncQueue.Run(time.Second, ic.stopCh)
Expand All @@ -1561,7 +1563,9 @@ func (ic *GenericController) Start() {
go ic.syncStatus.Run(ic.stopCh)
}

go wait.Until(ic.checkMissingSecrets, 30*time.Second, ic.stopCh)
if ic.cfg.V07 {
go wait.Until(ic.checkMissingSecrets, 30*time.Second, ic.stopCh)
}

// force initial sync
ic.syncQueue.Enqueue(&extensions.Ingress{})
Expand Down
39 changes: 35 additions & 4 deletions pkg/controller/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,19 @@ import (
api "k8s.io/api/core/v1"

"github.com/jcmoraisjr/haproxy-ingress/pkg/common/ingress"
"github.com/jcmoraisjr/haproxy-ingress/pkg/common/ingress/controller"
)

type cache struct {
listers *ingress.StoreLister
listers *ingress.StoreLister
controller *controller.GenericController
}

func newCache(listers *ingress.StoreLister, controller *controller.GenericController) *cache {
return &cache{
listers: listers,
controller: controller,
}
}

func (c *cache) GetService(serviceName string) (*api.Service, error) {
Expand All @@ -47,13 +56,35 @@ func (c *cache) GetPod(podName string) (*api.Pod, error) {
}

func (c *cache) GetTLSSecretPath(secretName string) (string, error) {
return "", fmt.Errorf("implement")
sslCert, err := c.controller.GetCertificate(secretName)
if err != nil {
return "", err
}
if sslCert.PemFileName == "" {
return "", fmt.Errorf("secret '%s' does not have tls/key pair", secretName)
}
return sslCert.PemFileName, nil
}

func (c *cache) GetCASecretPath(secretName string) (string, error) {
return "", fmt.Errorf("implement")
sslCert, err := c.controller.GetCertificate(secretName)
if err != nil {
return "", err
}
if sslCert.CAFileName == "" {
return "", fmt.Errorf("secret '%s' does not have ca.crt key", secretName)
}
return sslCert.CAFileName, nil
}

func (c *cache) GetSecretContent(secretName, keyName string) ([]byte, error) {
return []byte{}, fmt.Errorf("implement")
secret, err := c.listers.Secret.GetByName(secretName)
if err != nil {
return nil, err
}
data, found := secret.Data[keyName]
if !found {
return nil, fmt.Errorf("secret '%s' does not have key '%s'", secretName, keyName)
}
return data, nil
}
2 changes: 1 addition & 1 deletion pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func (hc *HAProxyController) configController() {
logger := &logger{depth: 1}
hc.converterOptions = &ingtypes.ConverterOptions{
Logger: logger,
Cache: &cache{listers: hc.storeLister},
Cache: newCache(hc.storeLister, hc.controller),
AnnotationPrefix: "ingress.kubernetes.io",
DefaultBackend: hc.cfg.DefaultService,
DefaultSSLSecret: hc.cfg.DefaultSSLCertificate,
Expand Down

0 comments on commit 9a543c8

Please sign in to comment.