Skip to content

Commit

Permalink
Configure routing subdomain
Browse files Browse the repository at this point in the history
* pkg/operator/observe_config.go (Listers): Add new lister installConfigLister.
(NewConfigObserver): Add installConfigLister to listers, and add
observeRoutingSubdomain to observers.
(observeRoutingSubdomain): Add new observer to set routingConfig.Subdomain
from the install config.
* pkg/operator/operator.go: Add constants clusterConfigNamespace and
clusterConfigName.

This commit resolves NE-100.

https://jira.coreos.com/browse/NE-100
  • Loading branch information
Miciah committed Nov 16, 2018
1 parent 236a1ac commit f314cdc
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 6 deletions.
51 changes: 45 additions & 6 deletions pkg/operator/observe_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"reflect"
"time"

"github.com/ghodss/yaml"

"github.com/golang/glog"

corev1 "k8s.io/api/core/v1"
Expand All @@ -30,9 +32,10 @@ import (
)

type Listers struct {
imageConfigLister configlistersv1.ImageLister
endpointLister corelistersv1.EndpointsLister
configmapLister corelistersv1.ConfigMapLister
imageConfigLister configlistersv1.ImageLister
endpointLister corelistersv1.EndpointsLister
configmapLister corelistersv1.ConfigMapLister
installConfigLister corelistersv1.ConfigMapLister
}

type observeConfigFunc func(Listers, map[string]interface{}) (map[string]interface{}, error)
Expand Down Expand Up @@ -71,11 +74,13 @@ func NewConfigObserver(
observeKubeAPIServerPublicInfo,
observeEtcdEndpoints,
observeInternalRegistryHostname,
observeRoutingSubdomain,
},
listers: Listers{
imageConfigLister: imageConfigInformer.Config().V1().Images().Lister(),
endpointLister: kubeInformersForKubeSystemNamespace.Core().V1().Endpoints().Lister(),
configmapLister: kubeInformersForKubeApiserverNamespace.Core().V1().ConfigMaps().Lister(),
imageConfigLister: imageConfigInformer.Config().V1().Images().Lister(),
endpointLister: kubeInformersForKubeSystemNamespace.Core().V1().Endpoints().Lister(),
installConfigLister: kubeInformersForKubeSystemNamespace.Core().V1().ConfigMaps().Lister(),
configmapLister: kubeInformersForKubeApiserverNamespace.Core().V1().ConfigMaps().Lister(),
},
}

Expand Down Expand Up @@ -179,6 +184,40 @@ func observeInternalRegistryHostname(listers Listers, observedConfig map[string]
return observedConfig, nil
}

func observeRoutingSubdomain(listers Listers, observedConfig map[string]interface{}) (map[string]interface{}, error) {
clusterConfig, err := listers.installConfigLister.ConfigMaps(clusterConfigNamespace).Get(clusterConfigName)
if errors.IsNotFound(err) {
return observedConfig, nil
}
if err != nil {
return nil, err
}

if clusterConfig != nil {
if installConfig, ok := clusterConfig.Data["install-config"]; ok {
type InstallConfigMetadata struct {
Name string `json:"name"`
}

type InstallConfig struct {
Metadata InstallConfigMetadata `json:"metadata"`
BaseDomain string `json:"baseDomain"`
}

var config InstallConfig
if err := yaml.Unmarshal([]byte(installConfig), &config); err != nil {
return nil, fmt.Errorf("invalid InstallConfig: %v\njson:\n%s", err, installConfig)
}

subdomain := fmt.Sprintf("%s.%s", config.Metadata.Name, config.BaseDomain)

unstructured.SetNestedField(observedConfig, subdomain, "routingConfig", "subdomain")
}
}

return observedConfig, nil
}

func (c *ConfigObserver) Run(workers int, stopCh <-chan struct{}) {
defer utilruntime.HandleCrash()
defer c.queue.ShutDown()
Expand Down
2 changes: 2 additions & 0 deletions pkg/operator/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ import (
)

const (
clusterConfigNamespace = "kube-system"
clusterConfigName = "cluster-config-v1"
etcdNamespaceName = "kube-system"
kubeAPIServerNamespaceName = "openshift-kube-apiserver"
targetNamespaceName = "openshift-apiserver"
Expand Down

0 comments on commit f314cdc

Please sign in to comment.