Skip to content
This repository has been archived by the owner on Aug 26, 2021. It is now read-only.

Commit

Permalink
Merge pull request #101 from gianrubio/specify-ingress
Browse files Browse the repository at this point in the history
Add ability to customize ingress class
  • Loading branch information
simonswine committed Mar 13, 2017
2 parents 9c8b7d8 + 51371bf commit de058f9
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 27 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ Please note:
| `LEGO_SECRET_NAME` | n | `kube-lego-account` | Name of the secret in the same namespace that contains ACME account secret |
| `LEGO_SERVICE_NAME_NGINX` | n | `kube-lego-nginx` | Service name for NGINX ingress |
| `LEGO_SERVICE_NAME_GCE` | n | `kube-lego-gce` | Service name for GCE ingress |
| `LEGO_SUPPORTED_INGRESS_CLASS` | n | `nginx,gce` | Specify the supported ingress class |
| `LEGO_INGRESS_NAME_NGINX` | n | `kube-lego-nginx` | Ingress name which contains the routing for HTTP verification for nginx ingress |
| `LEGO_PORT` | n | `8080` | Port where this daemon is listening for verifcation calls (HTTP method)|
| `LEGO_CHECK_INTERVAL` | n | `8h` | Interval for periodically certificate checks (to find expired certs)|
Expand Down
8 changes: 4 additions & 4 deletions pkg/ingress/ingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ import (
k8sExtensions "k8s.io/client-go/pkg/apis/extensions/v1beta1"
)

func IsSupportedIngressClass(in string) (out string, err error) {
func IsSupportedIngressClass(supportedClass []string, in string) (out string, err error) {
out = strings.ToLower(in)
for _, ingClass := range kubelego.SupportedIngressClasses {
for _, ingClass := range supportedClass {
if ingClass == out {
return out, nil
}
}
return "", fmt.Errorf("unsupported ingress class '%s'", in)
return "", fmt.Errorf("unsupported ingress class '%s'. Did you you forget to specify LEGO_DEFAULT_INGRESS_CLASS ?", in)
}

func IgnoreIngress(ing *k8sExtensions.Ingress) error {
Expand Down Expand Up @@ -170,7 +170,7 @@ func (i *Ingress) Ignore() bool {
return true
}

_, err = IsSupportedIngressClass(i.IngressClass())
_, err = IsSupportedIngressClass(i.kubelego.LegoSupportedIngressClass(), i.IngressClass())
if err != nil {
i.Log().Info("ignoring as ", err)
return true
Expand Down
8 changes: 5 additions & 3 deletions pkg/ingress/ingress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,18 @@ import (
)

func TestIsSupportedIngressClass(t *testing.T) {
out, err := IsSupportedIngressClass("Nginx")
supportedClass := []string{"nginx","gce","custom"}
out, err := IsSupportedIngressClass(supportedClass,"Nginx")
assert.Equal(t, "nginx", out)
assert.Nil(t, err)

out, err = IsSupportedIngressClass("customlb")
out, err = IsSupportedIngressClass(supportedClass,"customlb")
assert.NotNil(t, err)

out, err = IsSupportedIngressClass("gce")
out, err = IsSupportedIngressClass(supportedClass,"gce")
assert.Equal(t, "gce", out)
assert.Nil(t, err)

}

func TestIngress_Tls(t *testing.T) {
Expand Down
10 changes: 9 additions & 1 deletion pkg/kubelego/kubelego.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,9 @@ func (kl *KubeLego) LegoDefaultIngressClass() string {
func (kl *KubeLego) LegoIngressNameNginx() string {
return kl.legoIngressNameNginx
}
func (kl *KubeLego) LegoSupportedIngressClass() []string {
return kl.legoSupportedIngressClass
}

func (kl *KubeLego) LegoServiceNameNginx() string {
return kl.legoServiceNameNginx
Expand Down Expand Up @@ -247,12 +250,17 @@ func (kl *KubeLego) paramsLego() error {
kl.legoServiceNameGce = "kube-lego-gce"
}

kl.legoSupportedIngressClass = strings.Split(os.Getenv("LEGO_SUPPORTED_INGRESS_CLASS"),",")
if len(kl.legoSupportedIngressClass) == 1 {
kl.legoSupportedIngressClass = kubelego.SupportedIngressClasses
}

legoDefaultIngressClass := os.Getenv("LEGO_DEFAULT_INGRESS_CLASS")
if len(legoDefaultIngressClass) == 0 {
kl.legoDefaultIngressClass = "nginx"
} else {
var err error = nil
kl.legoDefaultIngressClass, err = ingress.IsSupportedIngressClass(legoDefaultIngressClass)
kl.legoDefaultIngressClass, err = ingress.IsSupportedIngressClass(kl.legoSupportedIngressClass, legoDefaultIngressClass)
if err != nil {
return fmt.Errorf("Unsupported default ingress class: '%s'", legoDefaultIngressClass)
}
Expand Down
37 changes: 19 additions & 18 deletions pkg/kubelego/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,25 @@ import (
)

type KubeLego struct {
legoURL string
legoEmail string
legoSecretName string
legoIngressNameNginx string
legoNamespace string
legoPodIP net.IP
legoServiceNameNginx string
legoServiceNameGce string
legoHTTPPort intstr.IntOrString
legoCheckInterval time.Duration
legoMinimumValidity time.Duration
legoDefaultIngressClass string
legoKubeApiURL string
kubeClient *kubernetes.Clientset
legoIngressSlice []*ingress.Ingress
legoIngressProvider map[string]kubelego.IngressProvider
version string
acmeClient kubelego.Acme
legoURL string
legoEmail string
legoSecretName string
legoIngressNameNginx string
legoNamespace string
legoPodIP net.IP
legoServiceNameNginx string
legoServiceNameGce string
legoSupportedIngressClass []string
legoHTTPPort intstr.IntOrString
legoCheckInterval time.Duration
legoMinimumValidity time.Duration
legoDefaultIngressClass string
legoKubeApiURL string
kubeClient *kubernetes.Clientset
legoIngressSlice []*ingress.Ingress
legoIngressProvider map[string]kubelego.IngressProvider
version string
acmeClient kubelego.Acme

// stop channel for services
stopCh chan struct{}
Expand Down
1 change: 1 addition & 0 deletions pkg/kubelego_const/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type KubeLego interface {
LegoServiceNameNginx() string
LegoServiceNameGce() string
LegoDefaultIngressClass() string
LegoSupportedIngressClass() []string
LegoCheckInterval() time.Duration
LegoMinimumValidity() time.Duration
LegoPodIP() net.IP
Expand Down
6 changes: 6 additions & 0 deletions pkg/mocks/mocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,12 @@ func (_m *MockKubeLego) LegoDefaultIngressClass() string {
return ret0
}

func (_m *MockKubeLego) LegoSupportedIngressClass() []string {
ret := _m.ctrl.Call(_m, "LegoSupportedIngressClass")
ret0, _ := ret[0].([]string)
return ret0
}

func (_mr *_MockKubeLegoRecorder) LegoDefaultIngressClass() *gomock.Call {
return _mr.mock.ctrl.RecordCall(_mr.mock, "LegoDefaultIngressClass")
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/provider/nginx/nginx.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func (p *Nginx) updateIngress() error {
ing.Annotations = map[string]string{
kubelego.AnnotationIngressChallengeEndpoints: "true",
kubelego.AnnotationSslRedirect: "false",
kubelego.AnnotationIngressClass: "nginx",
kubelego.AnnotationIngressClass: p.kubelego.LegoDefaultIngressClass(),
}

ing.Spec = k8sExtensions.IngressSpec{
Expand Down

0 comments on commit de058f9

Please sign in to comment.