From 687e94781858ba87d69bb97b2fda0bde4481fec9 Mon Sep 17 00:00:00 2001 From: Miciah Masters Date: Thu, 15 Nov 2018 18:08:00 -0500 Subject: [PATCH] Configure routing subdomain * 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 --- pkg/operator/observe_config.go | 53 ++++++++++++++++++++++++++++++---- pkg/operator/operator.go | 2 ++ 2 files changed, 49 insertions(+), 6 deletions(-) diff --git a/pkg/operator/observe_config.go b/pkg/operator/observe_config.go index 8659a3a2f..fde040e19 100644 --- a/pkg/operator/observe_config.go +++ b/pkg/operator/observe_config.go @@ -7,6 +7,8 @@ import ( "reflect" "time" + "github.com/ghodss/yaml" + "github.com/golang/glog" corev1 "k8s.io/api/core/v1" @@ -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) @@ -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(), }, } @@ -179,6 +184,42 @@ func observeInternalRegistryHostname(listers Listers, observedConfig map[string] return observedConfig, nil } +func observeRoutingSubdomain(listers Listers, observedConfig map[string]interface{}) (map[string]interface{}, error) { + // TODO: Get the value for routingConfig.subdomain from global config or + // from a ClusterIngress resource instead of from the install config. + 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("apps.%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() diff --git a/pkg/operator/operator.go b/pkg/operator/operator.go index a90530e43..e130d9001 100644 --- a/pkg/operator/operator.go +++ b/pkg/operator/operator.go @@ -30,6 +30,8 @@ import ( ) const ( + clusterConfigNamespace = "kube-system" + clusterConfigName = "cluster-config-v1" etcdNamespaceName = "kube-system" kubeAPIServerNamespaceName = "openshift-kube-apiserver" targetNamespaceName = "openshift-apiserver"