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

Commit

Permalink
fix: add logic to load ingress-config ConfigMap on startup
Browse files Browse the repository at this point in the history
  • Loading branch information
jstrachan committed Sep 10, 2018
1 parent 0e2f827 commit 5da3ff0
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 4 deletions.
12 changes: 12 additions & 0 deletions controller/config.go
Expand Up @@ -70,6 +70,18 @@ var (
DefaultConfig = Config{}
)

// MapToConfig converts the ConfigMap data to a Config object
func MapToConfig(data map[string]string) (*Config, error) {
answer := &Config{}

b, err := yaml.Marshal(data)
if err != nil {
return nil, err
}
err = yaml.Unmarshal(b, answer)
return answer, err
}

func (c *Config) UnmarshalYAML(unmarshal func(interface{}) error) error {
*c = DefaultConfig
// We want to set c to the defaults and then overwrite it with the input.
Expand Down
29 changes: 29 additions & 0 deletions controller/config_test.go
@@ -0,0 +1,29 @@
package controller

import (
"fmt"
"github.com/stretchr/testify/assert"
"testing"
)

func TestMapToConfig(t *testing.T) {
expectedExposer := "Ingress"
expectedDomain := "35.233.48.48.nip.io"

data := map[string]string{
"domain": expectedDomain,
"exposer": expectedExposer,
"tls": "false",
}
config, err := MapToConfig(data)
if err != nil {
t.Errorf("Failed to create Config %s\n", err)
} else if config == nil {
t.Error("No Config created!\n", err)
} else {
assert.Equal(t, expectedExposer, config.Exposer, "Exposer")
assert.Equal(t, expectedDomain, config.Domain, "Domain")

fmt.Printf("Config is %#v\n", config)
}
}
19 changes: 15 additions & 4 deletions exposecontroller.go
Expand Up @@ -83,9 +83,6 @@ func main() {
ns := currentNamespace
// TODO allow this name to be passed in?
cm, err := kubeClient.ConfigMaps(ns).Get("exposecontroller")
if err != nil {
cm, err = kubeClient.ConfigMaps(ns).Get("ingress-config")
}
if err == nil {
glog.Infof("Using ConfigMap exposecontroller to load configuration...")
// TODO we could allow the config to be passed in via key/value pairs?
Expand All @@ -98,7 +95,21 @@ func main() {
glog.Infof("Loaded ConfigMap exposecontroller to load configuration!")
}
} else {
glog.Warningf("Could not find ConfigMap exposecontroller in namespace %s", ns)
glog.Warningf("Could not find ConfigMap exposecontroller ConfigMap in namespace %s", ns)

cm, err = kubeClient.ConfigMaps(ns).Get("ingress-config")
if err != nil {
glog.Warningf("Could not find ConfigMap ingress-config ConfigMap in namespace %s", ns)
} else {
glog.Infof("Loaded ConfigMap ingress-config to load configuration!")
data := cm.Data
if data != nil {
controllerConfig, err = controller.MapToConfig(data)
if err != nil {
glog.Warningf("Failed to convert Map data %#v from configMap ingress-config in namespace %s due to: %s\n", controllerConfig, ns, err)
}
}
}
}
} else {
glog.Infof("Loaded config file %s", *configFile)
Expand Down
2 changes: 2 additions & 0 deletions glide.yaml
Expand Up @@ -33,3 +33,5 @@ import:
version: 559433598c7be9d30d6cfc5cad5b5dfdb686725c
repo: git://github.com/openshift/docker-distribution.git
vcs: git
testImport:
- package: github.com/stretchr/testify

0 comments on commit 5da3ff0

Please sign in to comment.