Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configure routing subdomain #51

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 50 additions & 4 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,8 +32,9 @@ import (
)

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

type observeConfigFunc func(Listers, map[string]interface{}) (map[string]interface{}, error)
Expand All @@ -46,6 +49,7 @@ type ConfigObserver struct {

operatorConfigSynced cache.InformerSynced
endpointSynced cache.InformerSynced
clusterConfigSynced cache.InformerSynced
configImageSynced cache.InformerSynced

rateLimiter flowcontrol.RateLimiter
Expand All @@ -55,6 +59,7 @@ type ConfigObserver struct {
func NewConfigObserver(
operatorConfigInformer operatorconfiginformerv1alpha1.OpenShiftAPIServerOperatorConfigInformer,
kubeInformersForEtcdNamespace kubeinformers.SharedInformerFactory,
kubeInformersForClusterConfigNamespace kubeinformers.SharedInformerFactory,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: ForKubeSystem if you would

imageConfigInformer imageconfiginformers.SharedInformerFactory,
operatorConfigClient operatorconfigclientv1alpha1.OpenshiftapiserverV1alpha1Interface,
) *ConfigObserver {
Expand All @@ -67,19 +72,23 @@ func NewConfigObserver(
observers: []observeConfigFunc{
observeEtcdEndpoints,
observeInternalRegistryHostname,
observeRoutingSubdomain,
},
listers: Listers{
imageConfigLister: imageConfigInformer.Config().V1().Images().Lister(),
endpointLister: kubeInformersForEtcdNamespace.Core().V1().Endpoints().Lister(),
imageConfigLister: imageConfigInformer.Config().V1().Images().Lister(),
endpointLister: kubeInformersForClusterConfigNamespace.Core().V1().Endpoints().Lister(),
clusterConfigLister: kubeInformersForClusterConfigNamespace.Core().V1().ConfigMaps().Lister(),
},
}

c.operatorConfigSynced = operatorConfigInformer.Informer().HasSynced
c.endpointSynced = kubeInformersForEtcdNamespace.Core().V1().Endpoints().Informer().HasSynced
c.clusterConfigSynced = kubeInformersForClusterConfigNamespace.Core().V1().Endpoints().Informer().HasSynced
c.configImageSynced = imageConfigInformer.Config().V1().Images().Informer().HasSynced

operatorConfigInformer.Informer().AddEventHandler(c.eventHandler())
kubeInformersForEtcdNamespace.Core().V1().ConfigMaps().Informer().AddEventHandler(c.eventHandler())
kubeInformersForClusterConfigNamespace.Core().V1().ConfigMaps().Informer().AddEventHandler(c.eventHandler())
imageConfigInformer.Config().V1().Images().Informer().AddEventHandler(c.eventHandler())

return c
Expand Down Expand Up @@ -157,6 +166,42 @@ func observeInternalRegistryHostname(listers Listers, observedConfig map[string]
return observedConfig, nil
}

func observeRoutingSubdomain(listers Listers, observedConfig map[string]interface{}) (map[string]interface{}, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sanchezl figure out what state this config observation is in to finish this review

// TODO: Get the value for routingConfig.subdomain from global config or
// from a ClusterIngress resource instead of from the install config.
clusterConfig, err := listers.clusterConfigLister.ConfigMaps(clusterConfigNamespaceName).Get(clusterConfigName)
if errors.IsNotFound(err) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

glog a warning

return observedConfig, nil
}
if err != nil {
return nil, err
}

if clusterConfig != nil {
if installConfig, ok := clusterConfig.Data["install-config"]; ok {
type InstallConfigMetadata struct {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, don't defined a schema here. use the unstructured helpers like the rest

Name string `json:"name"`
}

type InstallConfig struct {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no. Use the usntructured helpers

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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

apps is hardcoded? that surprises me.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really? 😁

We have outstanding work to pull this out to cluster config one way or another.


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 All @@ -167,6 +212,7 @@ func (c *ConfigObserver) Run(workers int, stopCh <-chan struct{}) {
cache.WaitForCacheSync(stopCh,
c.operatorConfigSynced,
c.endpointSynced,
c.clusterConfigSynced,
c.configImageSynced,
)

Expand Down
4 changes: 4 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 (
clusterConfigNamespaceName = "kube-system"
clusterConfigName = "cluster-config-v1"
etcdNamespaceName = "kube-system"
kubeAPIServerNamespaceName = "openshift-kube-apiserver"
targetNamespaceName = "openshift-apiserver"
Expand All @@ -52,6 +54,7 @@ func NewKubeApiserverOperator(
operatorConfigInformer operatorconfiginformerv1alpha1.OpenShiftAPIServerOperatorConfigInformer,
kubeInformersForOpenShiftAPIServerNamespace kubeinformers.SharedInformerFactory,
kubeInformersForEtcdNamespace kubeinformers.SharedInformerFactory,
kubeInformersForClusterConfigNamespace kubeinformers.SharedInformerFactory,
kubeInformersForKubeAPIServerNamespace kubeinformers.SharedInformerFactory,
apiregistrationInformers apiregistrationinformers.SharedInformerFactory,
operatorConfigClient operatorconfigclientv1alpha1.OpenshiftapiserverV1alpha1Interface,
Expand All @@ -71,6 +74,7 @@ func NewKubeApiserverOperator(
operatorConfigInformer.Informer().AddEventHandler(c.eventHandler())
kubeInformersForEtcdNamespace.Core().V1().ConfigMaps().Informer().AddEventHandler(c.eventHandler())
kubeInformersForEtcdNamespace.Core().V1().Secrets().Informer().AddEventHandler(c.eventHandler())
kubeInformersForClusterConfigNamespace.Core().V1().ConfigMaps().Informer().AddEventHandler(c.eventHandler())
kubeInformersForKubeAPIServerNamespace.Core().V1().ConfigMaps().Informer().AddEventHandler(c.eventHandler())
kubeInformersForOpenShiftAPIServerNamespace.Core().V1().ConfigMaps().Informer().AddEventHandler(c.eventHandler())
kubeInformersForOpenShiftAPIServerNamespace.Core().V1().ServiceAccounts().Informer().AddEventHandler(c.eventHandler())
Expand Down
4 changes: 4 additions & 0 deletions pkg/operator/starter.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,15 @@ func RunOperator(clientConfig *rest.Config, stopCh <-chan struct{}) error {
kubeInformersForOpenShiftAPIServerNamespace := kubeinformers.NewSharedInformerFactoryWithOptions(kubeClient, 10*time.Minute, kubeinformers.WithNamespace(targetNamespaceName))
kubeInformersForKubeAPIServerNamespace := kubeinformers.NewSharedInformerFactoryWithOptions(kubeClient, 10*time.Minute, kubeinformers.WithNamespace(kubeAPIServerNamespaceName))
kubeInformersForEtcdNamespace := kubeinformers.NewSharedInformerFactoryWithOptions(kubeClient, 10*time.Minute, kubeinformers.WithNamespace(etcdNamespaceName))
kubeInformersForClusterConfigNamespace := kubeinformers.NewSharedInformerFactoryWithOptions(kubeClient, 10*time.Minute, kubeinformers.WithNamespace(clusterConfigNamespaceName))
apiregistrationInformers := apiregistrationinformers.NewSharedInformerFactory(apiregistrationv1Client, 10*time.Minute)
imageConfigInformers := imageconfiginformers.NewSharedInformerFactory(configClient, 10*time.Minute)

operator := NewKubeApiserverOperator(
operatorConfigInformers.Openshiftapiserver().V1alpha1().OpenShiftAPIServerOperatorConfigs(),
kubeInformersForOpenShiftAPIServerNamespace,
kubeInformersForEtcdNamespace,
kubeInformersForClusterConfigNamespace,
kubeInformersForKubeAPIServerNamespace,
apiregistrationInformers,
operatorConfigClient.OpenshiftapiserverV1alpha1(),
Expand All @@ -74,6 +76,7 @@ func RunOperator(clientConfig *rest.Config, stopCh <-chan struct{}) error {
configObserver := NewConfigObserver(
operatorConfigInformers.Openshiftapiserver().V1alpha1().OpenShiftAPIServerOperatorConfigs(),
kubeInformersForEtcdNamespace,
kubeInformersForClusterConfigNamespace,
imageConfigInformers,
operatorConfigClient.OpenshiftapiserverV1alpha1(),
)
Expand All @@ -89,6 +92,7 @@ func RunOperator(clientConfig *rest.Config, stopCh <-chan struct{}) error {
kubeInformersForOpenShiftAPIServerNamespace.Start(stopCh)
kubeInformersForKubeAPIServerNamespace.Start(stopCh)
kubeInformersForEtcdNamespace.Start(stopCh)
kubeInformersForClusterConfigNamespace.Start(stopCh)
apiregistrationInformers.Start(stopCh)
imageConfigInformers.Start(stopCh)

Expand Down