Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/openshift/library-go/pkg/operator/configobserver"
"github.com/openshift/library-go/pkg/operator/configobserver/cloudprovider"
"github.com/openshift/library-go/pkg/operator/configobserver/featuregates"
"github.com/openshift/library-go/pkg/operator/configobserver/proxy"
"github.com/openshift/library-go/pkg/operator/events"
"github.com/openshift/library-go/pkg/operator/resourcesynccontroller"
"github.com/openshift/library-go/pkg/operator/v1helpers"
Expand Down Expand Up @@ -47,6 +48,7 @@ func NewConfigObserver(
FeatureGateLister_: configinformers.Config().V1().FeatureGates().Lister(),
InfrastructureLister_: configinformers.Config().V1().Infrastructures().Lister(),
NetworkLister: configinformers.Config().V1().Networks().Lister(),
ProxyLister_: configinformers.Config().V1().Proxies().Lister(),

ResourceSync: resourceSyncer,
ConfigMapLister: kubeInformersForNamespaces.InformersFor(operatorclient.TargetNamespace).Core().V1().ConfigMaps().Lister(),
Expand All @@ -59,6 +61,7 @@ func NewConfigObserver(
configinformers.Config().V1().FeatureGates().Informer().HasSynced,
configinformers.Config().V1().Infrastructures().Informer().HasSynced,
configinformers.Config().V1().Networks().Informer().HasSynced,
configinformers.Config().V1().Proxies().Informer().HasSynced,
),
},
cloudprovider.NewCloudProviderObserver(
Expand All @@ -68,6 +71,7 @@ func NewConfigObserver(
featuregates.NewObserveFeatureFlagsFunc(nil, []string{"extendedArguments", "feature-gates"}),
network.ObserveClusterCIDRs,
network.ObserveServiceClusterIPRanges,
proxy.NewProxyObserveFunc([]string{"targetconfigcontroller", "proxy"}),
serviceca.ObserveServiceCA,
clustername.ObserveInfraID,
),
Expand All @@ -82,6 +86,7 @@ func NewConfigObserver(
configinformers.Config().V1().FeatureGates().Informer().AddEventHandler(c.EventHandler())
configinformers.Config().V1().Infrastructures().Informer().AddEventHandler(c.EventHandler())
configinformers.Config().V1().Networks().Informer().AddEventHandler(c.EventHandler())
configinformers.Config().V1().Proxies().Informer().AddEventHandler(c.EventHandler())

return c
}
5 changes: 5 additions & 0 deletions pkg/operator/configobservation/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type Listers struct {
FeatureGateLister_ configlistersv1.FeatureGateLister
InfrastructureLister_ configlistersv1.InfrastructureLister
NetworkLister configlistersv1.NetworkLister
ProxyLister_ configlistersv1.ProxyLister
ConfigMapLister corev1listers.ConfigMapLister

ResourceSync resourcesynccontroller.ResourceSyncer
Expand All @@ -29,6 +30,10 @@ func (l Listers) FeatureGateLister() configlistersv1.FeatureGateLister {
return l.FeatureGateLister_
}

func (l Listers) ProxyLister() configlistersv1.ProxyLister {
return l.ProxyLister_
}

func (l Listers) ResourceSyncer() resourcesynccontroller.ResourceSyncer {
return l.ResourceSync
}
Expand Down
31 changes: 31 additions & 0 deletions pkg/operator/targetconfigcontroller/targetconfigcontroller.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ import (
"encoding/json"
"fmt"
"reflect"
"sort"
"strings"
"time"

yaml "gopkg.in/yaml.v2"
Copy link
Contributor

Choose a reason for hiding this comment

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

@stlaz this was the culprit of yaml issues. I've fixed that and changed configmap merging to MergePrunedConfigMap in #285.

corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -291,6 +293,20 @@ func managePod(configMapsGetter corev1client.ConfigMapsGetter, secretsGetter cor
required.Spec.Containers[0].Args = append(required.Spec.Containers[0].Args, "--tls-private-key-file=/etc/kubernetes/static-pod-resources/secrets/serving-cert/tls.key")
Copy link
Contributor

Choose a reason for hiding this comment

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

manageKubeControllerManagerConfig() needs to use MergePrunedConfigMap() instead, this function removes fields that are not part of the config object from observedConfig

}

var observedConfig map[string]interface{}
if err := yaml.Unmarshal(operatorSpec.ObservedConfig.Raw, &observedConfig); err != nil {
return nil, false, fmt.Errorf("failed to unmarshal the observedConfig: %v", err)
}
proxyConfig, _, err := unstructured.NestedStringMap(observedConfig, "targetconfigcontroller", "proxy")
if err != nil {
return nil, false, fmt.Errorf("couldn't get the proxy config from observedConfig: %v", err)
}

proxyEnvVars := proxyMapToEnvVars(proxyConfig)
for i, container := range required.Spec.Containers {
required.Spec.Containers[i].Env = append(container.Env, proxyEnvVars...)
}

configMap := resourceread.ReadConfigMapV1OrDie(v411_00_assets.MustAsset("v4.1.0/kube-controller-manager/pod-cm.yaml"))
configMap.Data["pod.yaml"] = resourceread.WritePodV1OrDie(required)
configMap.Data["forceRedeploymentReason"] = operatorSpec.ForceRedeploymentReason
Expand Down Expand Up @@ -536,3 +552,18 @@ func (c *TargetConfigController) namespaceEventHandler() cache.ResourceEventHand
},
}
}

func proxyMapToEnvVars(proxyConfig map[string]string) []corev1.EnvVar {
if proxyConfig == nil {
return nil
}

envVars := []corev1.EnvVar{}
for k, v := range proxyConfig {
envVars = append(envVars, corev1.EnvVar{Name: k, Value: v})
}

// need to sort the slice so that kube-apiserver-pod configmap does not change all the time
sort.Slice(envVars, func(i, j int) bool { return envVars[i].Name < envVars[j].Name })
return envVars
}