Skip to content
Merged
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
48 changes: 45 additions & 3 deletions cmd/config-sync-controllers/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (

// Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.)
// to ensure that exec-entrypoint and run can make use of them.
"k8s.io/client-go/kubernetes"
_ "k8s.io/client-go/plugin/pkg/client/auth"

"k8s.io/apimachinery/pkg/runtime"
Expand All @@ -40,6 +41,11 @@ import (
metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server"

configv1 "github.com/openshift/api/config/v1"
"github.com/openshift/library-go/pkg/operator/configobserver/featuregates"
"github.com/openshift/library-go/pkg/operator/events"

configv1client "github.com/openshift/client-go/config/clientset/versioned"
configinformers "github.com/openshift/client-go/config/informers/externalversions"

"github.com/openshift/cluster-cloud-controller-manager-operator/pkg/controllers"
"github.com/openshift/cluster-cloud-controller-manager-operator/pkg/restmapper"
Expand Down Expand Up @@ -79,6 +85,12 @@ func main() {
"The namespace for managed objects, target cloud-conf in particular.",
)

recorderName := "cloud-controller-manager-operator-cloud-config-sync-controller"
missingVersion := "0.0.1-snapshot"
desiredVersion := controllers.GetReleaseVersion()
sharedClock := clock.RealClock{}
ctx := ctrl.SetupSignalHandler()

// Once all the flags are regitered, switch to pflag
// to allow leader lection flags to be bound
pflag.CommandLine.AddGoFlagSet(flag.CommandLine)
Expand Down Expand Up @@ -131,7 +143,36 @@ func main() {
os.Exit(1)
}

sharedClock := clock.RealClock{}
// Feature gate accessor
configClient, err := configv1client.NewForConfig(mgr.GetConfig())
if err != nil {
setupLog.Error(err, "unable to create config client")
os.Exit(1)
}
kubeClient, err := kubernetes.NewForConfig(mgr.GetConfig())
if err != nil {
setupLog.Error(err, "unable to create kube client")
os.Exit(1)
}

configInformers := configinformers.NewSharedInformerFactory(configClient, 10*time.Minute)
controllerRef, err := events.GetControllerReferenceForCurrentPod(ctx, kubeClient, *managedNamespace, nil)
if err != nil {
klog.Warningf("unable to get owner reference (falling back to namespace): %v", err)
}

featureGateAccessor := featuregates.NewFeatureGateAccess(
desiredVersion, missingVersion,
configInformers.Config().V1().ClusterVersions(), configInformers.Config().V1().FeatureGates(),
events.NewKubeRecorder(kubeClient.CoreV1().Events(*managedNamespace), recorderName, controllerRef, sharedClock),
)
featureGateAccessor.SetChangeHandler(func(featureChange featuregates.FeatureChange) {
// Do nothing here. The controller watches feature gate changes and will react to them.
klog.InfoS("FeatureGates changed", "enabled", featureChange.New.Enabled, "disabled", featureChange.New.Disabled)
})
go featureGateAccessor.Run(ctx)
go configInformers.Start(ctx.Done())

if err = (&controllers.CloudConfigReconciler{
ClusterOperatorStatusClient: controllers.ClusterOperatorStatusClient{
Client: mgr.GetClient(),
Expand All @@ -140,7 +181,8 @@ func main() {
ReleaseVersion: controllers.GetReleaseVersion(),
ManagedNamespace: *managedNamespace,
},
Scheme: mgr.GetScheme(),
Scheme: mgr.GetScheme(),
FeatureGateAccess: featureGateAccessor,
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create cloud-config sync controller", "controller", "ClusterOperator")
os.Exit(1)
Expand Down Expand Up @@ -171,7 +213,7 @@ func main() {
}

setupLog.Info("starting manager")
if err := mgr.Start(ctrl.SetupSignalHandler()); err != nil {
if err := mgr.Start(ctx); err != nil {
setupLog.Error(err, "problem running manager")
os.Exit(1)
}
Expand Down
4 changes: 3 additions & 1 deletion pkg/cloud/aws/aws_config_transformer.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (
"gopkg.in/ini.v1"

awsconfig "k8s.io/cloud-provider-aws/pkg/providers/v1/config"

"github.com/openshift/library-go/pkg/operator/configobserver/featuregates"
)

// defaultConfig is a string holding the absolute bare minimum INI string that the AWS CCM needs to start.
Expand All @@ -20,7 +22,7 @@ const defaultConfig = `[Global]

// CloudConfigTransformer is used to inject OpenShift configuration defaults into the Cloud Provider config
// for the AWS Cloud Provider. If an empty source string is provided, a minimal default configuration will be created.
func CloudConfigTransformer(source string, infra *configv1.Infrastructure, network *configv1.Network) (string, error) {
func CloudConfigTransformer(source string, infra *configv1.Infrastructure, network *configv1.Network, features featuregates.FeatureGate) (string, error) {
cfg, err := readAWSConfig(source)
if err != nil {
return "", fmt.Errorf("failed to read the cloud.conf: %w", err)
Expand Down
4 changes: 3 additions & 1 deletion pkg/cloud/aws/aws_config_transformer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"testing"

. "github.com/onsi/gomega"

"github.com/openshift/library-go/pkg/operator/configobserver/featuregates"
)

func TestCloudConfigTransformer(t *testing.T) {
Expand Down Expand Up @@ -87,7 +89,7 @@ SigningRegion = signing_region
t.Run(tc.name, func(t *testing.T) {
g := NewWithT(t)

gotConfig, err := CloudConfigTransformer(tc.source, nil, nil) // No Infra or Network are required for the current functionality.
gotConfig, err := CloudConfigTransformer(tc.source, nil, nil, featuregates.NewFeatureGate(nil, nil)) // No Infra or Network are required for the current functionality.
g.Expect(err).ToNot(HaveOccurred())

g.Expect(gotConfig).To(Equal(tc.expected))
Expand Down
3 changes: 2 additions & 1 deletion pkg/cloud/azure/azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (

"github.com/openshift/cluster-cloud-controller-manager-operator/pkg/cloud/common"
"github.com/openshift/cluster-cloud-controller-manager-operator/pkg/config"
"github.com/openshift/library-go/pkg/operator/configobserver/featuregates"
)

const providerName = "azure"
Expand Down Expand Up @@ -136,7 +137,7 @@ func IsAzure(infra *configv1.Infrastructure) bool {
return false
}

func CloudConfigTransformer(source string, infra *configv1.Infrastructure, network *configv1.Network) (string, error) {
func CloudConfigTransformer(source string, infra *configv1.Infrastructure, network *configv1.Network, features featuregates.FeatureGate) (string, error) {
if !IsAzure(infra) {
return "", fmt.Errorf("invalid platform, expected CloudName to be %s", configv1.AzurePublicCloud)
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/cloud/azure/azure_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/onsi/gomega/format"
configv1 "github.com/openshift/api/config/v1"
"github.com/openshift/cluster-cloud-controller-manager-operator/pkg/config"
"github.com/openshift/library-go/pkg/operator/configobserver/featuregates"
"github.com/stretchr/testify/assert"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -259,7 +260,7 @@ func TestCloudConfigTransformer(t *testing.T) {
src, err := json.Marshal(tc.source)
g.Expect(err).NotTo(HaveOccurred(), "Marshal of source data should succeed")

actual, err := CloudConfigTransformer(string(src), tc.infra, nil)
actual, err := CloudConfigTransformer(string(src), tc.infra, nil, featuregates.NewFeatureGate(nil, nil))
if tc.errMsg != "" {
g.Expect(err).Should(MatchError(tc.errMsg))
g.Expect(actual).Should(Equal(""))
Expand Down
3 changes: 2 additions & 1 deletion pkg/cloud/azurestack/azurestack.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (

"github.com/openshift/cluster-cloud-controller-manager-operator/pkg/cloud/common"
"github.com/openshift/cluster-cloud-controller-manager-operator/pkg/config"
"github.com/openshift/library-go/pkg/operator/configobserver/featuregates"
)

const providerName = "azurestack"
Expand Down Expand Up @@ -104,7 +105,7 @@ func IsAzureStackHub(platformStatus *configv1.PlatformStatus) bool {
// modifies it to be compatible with the external cloud provider. It returns
// an error if the platform is not OpenStackPlatformType or if any errors are
// encountered while attempting to rework the configuration.
func CloudConfigTransformer(source string, infra *configv1.Infrastructure, network *configv1.Network) (string, error) {
func CloudConfigTransformer(source string, infra *configv1.Infrastructure, network *configv1.Network, features featuregates.FeatureGate) (string, error) {
if !IsAzureStackHub(infra.Status.PlatformStatus) {
return "", fmt.Errorf("invalid platform, expected CloudName to be %s", configv1.AzureStackCloud)
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/cloud/azurestack/azurestack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/stretchr/testify/assert"

"github.com/openshift/cluster-cloud-controller-manager-operator/pkg/config"
"github.com/openshift/library-go/pkg/operator/configobserver/featuregates"
)

const (
Expand Down Expand Up @@ -144,7 +145,7 @@ func TestCloudConfigTransformer(t *testing.T) {
src, err := json.Marshal(tc.source)
g.Expect(err).NotTo(HaveOccurred(), "Marshal of source data should succeed")

actual, err := CloudConfigTransformer(string(src), tc.infra, nil)
actual, err := CloudConfigTransformer(string(src), tc.infra, nil, featuregates.NewFeatureGate(nil, nil))
if tc.errMsg != "" {
g.Expect(err).Should(MatchError(tc.errMsg))
g.Expect(actual).Should(Equal(""))
Expand Down
3 changes: 2 additions & 1 deletion pkg/cloud/cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/openshift/cluster-cloud-controller-manager-operator/pkg/cloud/common"
"github.com/openshift/cluster-cloud-controller-manager-operator/pkg/config"
"github.com/openshift/library-go/pkg/operator/configobserver/featuregates"

"github.com/openshift/cluster-cloud-controller-manager-operator/pkg/cloud/aws"
"github.com/openshift/cluster-cloud-controller-manager-operator/pkg/cloud/azure"
Expand All @@ -23,7 +24,7 @@ import (
// cloudConfigTransformer function transforms the source config map using the input infrastructure.config.openshift.io
// and network.config.openshift.io objects. Only the data and binaryData field of the output ConfigMap will be respected by
// consumer of the transformer.
type cloudConfigTransformer func(source string, infra *configv1.Infrastructure, network *configv1.Network) (string, error)
type cloudConfigTransformer func(source string, infra *configv1.Infrastructure, network *configv1.Network, features featuregates.FeatureGate) (string, error)

// GetCloudConfigTransformer returns the function that should be used to transform
// the cloud configuration config map, and a boolean to indicate if the config should
Expand Down
4 changes: 3 additions & 1 deletion pkg/cloud/common/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ package common

import (
configv1 "github.com/openshift/api/config/v1"

"github.com/openshift/library-go/pkg/operator/configobserver/featuregates"
)

// NoOpTransformer implements the cloudConfigTransformer. It makes no changes
// to the source configuration and simply returns it as-is.
func NoOpTransformer(source string, infra *configv1.Infrastructure, network *configv1.Network) (string, error) {
func NoOpTransformer(source string, infra *configv1.Infrastructure, network *configv1.Network, features featuregates.FeatureGate) (string, error) {
return source, nil
}
3 changes: 2 additions & 1 deletion pkg/cloud/openstack/openstack.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (

"github.com/openshift/cluster-cloud-controller-manager-operator/pkg/cloud/common"
"github.com/openshift/cluster-cloud-controller-manager-operator/pkg/config"
"github.com/openshift/library-go/pkg/operator/configobserver/featuregates"
)

const providerName = "openstack"
Expand Down Expand Up @@ -142,7 +143,7 @@ func NewProviderAssets(config config.OperatorConfig) (common.CloudProviderAssets
// modifies it to be compatible with the external cloud provider. It returns
// an error if the platform is not OpenStackPlatformType or if any errors are
// encountered while attempting to rework the configuration.
func CloudConfigTransformer(source string, infra *configv1.Infrastructure, network *configv1.Network) (string, error) {
func CloudConfigTransformer(source string, infra *configv1.Infrastructure, network *configv1.Network, features featuregates.FeatureGate) (string, error) {
if infra.Status.PlatformStatus == nil ||
infra.Status.PlatformStatus.Type != configv1.OpenStackPlatformType {
return "", fmt.Errorf("invalid platform, expected to be %s", configv1.OpenStackPlatformType)
Expand Down
3 changes: 2 additions & 1 deletion pkg/cloud/openstack/openstack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/openshift/cluster-cloud-controller-manager-operator/pkg/config"
"github.com/openshift/library-go/pkg/operator/configobserver/featuregates"
)

const (
Expand Down Expand Up @@ -172,7 +173,7 @@ use-octavia = false
for _, tc := range tc {
t.Run(tc.name, func(t *testing.T) {
g := NewWithT(t)
actual, err := CloudConfigTransformer(tc.source, tc.infra, tc.network)
actual, err := CloudConfigTransformer(tc.source, tc.infra, tc.network, featuregates.NewFeatureGate(nil, nil))
if tc.errMsg != "" {
g.Expect(err).Should(MatchError(tc.errMsg))
return
Expand Down
3 changes: 2 additions & 1 deletion pkg/cloud/vsphere/vsphere_config_transformer.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"k8s.io/utils/net"

ccmConfig "github.com/openshift/cluster-cloud-controller-manager-operator/pkg/cloud/vsphere/vsphere_cloud_config"
"github.com/openshift/library-go/pkg/operator/configobserver/featuregates"
)

// Well-known OCP-specific vSphere tags. These values are going to the "labels" sections in CCM cloud-config.
Expand All @@ -27,7 +28,7 @@ const (
// Currently, CloudConfigTransformer is responsible to populate vcenters, labels, and node networking parameters from
// the Infrastructure resource.
// Also, this function converts legacy deprecated INI configuration format to a YAML-based one.
func CloudConfigTransformer(source string, infra *configv1.Infrastructure, network *configv1.Network) (string, error) {
func CloudConfigTransformer(source string, infra *configv1.Infrastructure, network *configv1.Network, features featuregates.FeatureGate) (string, error) {
if infra.Status.PlatformStatus == nil ||
infra.Status.PlatformStatus.Type != configv1.VSpherePlatformType {
return "", fmt.Errorf("invalid platform, expected to be %s", configv1.VSpherePlatformType)
Expand Down
Loading