Skip to content

Commit 57e182a

Browse files
committed
feat/ccm-nlb-sg: support featuregate on cfg syncer
1 parent c61b48d commit 57e182a

File tree

8 files changed

+66
-10
lines changed

8 files changed

+66
-10
lines changed

cmd/config-sync-controllers/main.go

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030

3131
"k8s.io/apimachinery/pkg/runtime"
3232
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
33+
"k8s.io/client-go/kubernetes"
3334
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
3435
"k8s.io/component-base/config"
3536
"k8s.io/component-base/config/options"
@@ -41,9 +42,13 @@ import (
4142

4243
configv1 "github.com/openshift/api/config/v1"
4344

45+
configv1client "github.com/openshift/client-go/config/clientset/versioned"
46+
configinformers "github.com/openshift/client-go/config/informers/externalversions"
4447
"github.com/openshift/cluster-cloud-controller-manager-operator/pkg/controllers"
4548
"github.com/openshift/cluster-cloud-controller-manager-operator/pkg/restmapper"
4649
"github.com/openshift/cluster-cloud-controller-manager-operator/pkg/util"
50+
"github.com/openshift/library-go/pkg/operator/configobserver/featuregates"
51+
"github.com/openshift/library-go/pkg/operator/events"
4752
// +kubebuilder:scaffold:imports
4853
)
4954

@@ -132,15 +137,49 @@ func main() {
132137
}
133138

134139
sharedClock := clock.RealClock{}
140+
// Feature gate accessor
141+
missingVersion := "0.0.1-snapshot"
142+
desiredVersion := controllers.GetReleaseVersion()
143+
ctx := ctrl.SetupSignalHandler()
144+
configClient, err := configv1client.NewForConfig(mgr.GetConfig())
145+
if err != nil {
146+
setupLog.Error(err, "unable to create config client")
147+
os.Exit(1)
148+
}
149+
configInformers := configinformers.NewSharedInformerFactory(configClient, 10*time.Minute)
150+
kubeClient, err := kubernetes.NewForConfig(mgr.GetConfig())
151+
if err != nil {
152+
setupLog.Error(err, "unable to create kube client")
153+
os.Exit(1)
154+
}
155+
controllerRef, err := events.GetControllerReferenceForCurrentPod(ctx, kubeClient, *managedNamespace, nil)
156+
if err != nil {
157+
klog.Warningf("unable to get owner reference (falling back to namespace): %v", err)
158+
}
159+
recorderName := "cloud-controller-manager-operator-cloud-config-sync-controller"
160+
recorder := events.NewKubeRecorder(kubeClient.CoreV1().Events(*managedNamespace), recorderName, controllerRef, sharedClock)
161+
featureGateAccessor := featuregates.NewFeatureGateAccess(
162+
desiredVersion, missingVersion,
163+
configInformers.Config().V1().ClusterVersions(), configInformers.Config().V1().FeatureGates(),
164+
recorder,
165+
)
166+
featureGateAccessor.SetChangeHandler(func(featureChange featuregates.FeatureChange) {
167+
// Do nothing here. The controller watches feature gate changes and will react to them.
168+
klog.InfoS("FeatureGates changed", "enabled", featureChange.New.Enabled, "disabled", featureChange.New.Disabled)
169+
})
170+
go featureGateAccessor.Run(ctx)
171+
go configInformers.Start(ctx.Done())
172+
135173
if err = (&controllers.CloudConfigReconciler{
136174
ClusterOperatorStatusClient: controllers.ClusterOperatorStatusClient{
137175
Client: mgr.GetClient(),
138-
Recorder: mgr.GetEventRecorderFor("cloud-controller-manager-operator-cloud-config-sync-controller"),
176+
Recorder: mgr.GetEventRecorderFor(recorderName),
139177
Clock: sharedClock,
140178
ReleaseVersion: controllers.GetReleaseVersion(),
141179
ManagedNamespace: *managedNamespace,
142180
},
143-
Scheme: mgr.GetScheme(),
181+
Scheme: mgr.GetScheme(),
182+
FeatureGateAccess: featureGateAccessor,
144183
}).SetupWithManager(mgr); err != nil {
145184
setupLog.Error(err, "unable to create cloud-config sync controller", "controller", "ClusterOperator")
146185
os.Exit(1)

pkg/cloud/azure/azure.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020

2121
"github.com/openshift/cluster-cloud-controller-manager-operator/pkg/cloud/common"
2222
"github.com/openshift/cluster-cloud-controller-manager-operator/pkg/config"
23+
"github.com/openshift/library-go/pkg/operator/configobserver/featuregates"
2324
)
2425

2526
const providerName = "azure"
@@ -136,7 +137,7 @@ func IsAzure(infra *configv1.Infrastructure) bool {
136137
return false
137138
}
138139

139-
func CloudConfigTransformer(source string, infra *configv1.Infrastructure, network *configv1.Network) (string, error) {
140+
func CloudConfigTransformer(source string, infra *configv1.Infrastructure, network *configv1.Network, features featuregates.FeatureGate) (string, error) {
140141
if !IsAzure(infra) {
141142
return "", fmt.Errorf("invalid platform, expected CloudName to be %s", configv1.AzurePublicCloud)
142143
}

pkg/cloud/azurestack/azurestack.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515

1616
"github.com/openshift/cluster-cloud-controller-manager-operator/pkg/cloud/common"
1717
"github.com/openshift/cluster-cloud-controller-manager-operator/pkg/config"
18+
"github.com/openshift/library-go/pkg/operator/configobserver/featuregates"
1819
)
1920

2021
const providerName = "azurestack"
@@ -104,7 +105,7 @@ func IsAzureStackHub(platformStatus *configv1.PlatformStatus) bool {
104105
// modifies it to be compatible with the external cloud provider. It returns
105106
// an error if the platform is not OpenStackPlatformType or if any errors are
106107
// encountered while attempting to rework the configuration.
107-
func CloudConfigTransformer(source string, infra *configv1.Infrastructure, network *configv1.Network) (string, error) {
108+
func CloudConfigTransformer(source string, infra *configv1.Infrastructure, network *configv1.Network, features featuregates.FeatureGate) (string, error) {
108109
if !IsAzureStackHub(infra.Status.PlatformStatus) {
109110
return "", fmt.Errorf("invalid platform, expected CloudName to be %s", configv1.AzureStackCloud)
110111
}

pkg/cloud/cloud.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88

99
"github.com/openshift/cluster-cloud-controller-manager-operator/pkg/cloud/common"
1010
"github.com/openshift/cluster-cloud-controller-manager-operator/pkg/config"
11+
"github.com/openshift/library-go/pkg/operator/configobserver/featuregates"
1112

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

2829
// GetCloudConfigTransformer returns the function that should be used to transform
2930
// the cloud configuration config map, and a boolean to indicate if the config should

pkg/cloud/common/config.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ package common
22

33
import (
44
configv1 "github.com/openshift/api/config/v1"
5+
"github.com/openshift/library-go/pkg/operator/configobserver/featuregates"
56
)
67

78
// NoOpTransformer implements the cloudConfigTransformer. It makes no changes
89
// to the source configuration and simply returns it as-is.
9-
func NoOpTransformer(source string, infra *configv1.Infrastructure, network *configv1.Network) (string, error) {
10+
func NoOpTransformer(source string, infra *configv1.Infrastructure, network *configv1.Network, features featuregates.FeatureGate) (string, error) {
1011
return source, nil
1112
}

pkg/cloud/openstack/openstack.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414

1515
"github.com/openshift/cluster-cloud-controller-manager-operator/pkg/cloud/common"
1616
"github.com/openshift/cluster-cloud-controller-manager-operator/pkg/config"
17+
"github.com/openshift/library-go/pkg/operator/configobserver/featuregates"
1718
)
1819

1920
const providerName = "openstack"
@@ -142,7 +143,7 @@ func NewProviderAssets(config config.OperatorConfig) (common.CloudProviderAssets
142143
// modifies it to be compatible with the external cloud provider. It returns
143144
// an error if the platform is not OpenStackPlatformType or if any errors are
144145
// encountered while attempting to rework the configuration.
145-
func CloudConfigTransformer(source string, infra *configv1.Infrastructure, network *configv1.Network) (string, error) {
146+
func CloudConfigTransformer(source string, infra *configv1.Infrastructure, network *configv1.Network, features featuregates.FeatureGate) (string, error) {
146147
if infra.Status.PlatformStatus == nil ||
147148
infra.Status.PlatformStatus.Type != configv1.OpenStackPlatformType {
148149
return "", fmt.Errorf("invalid platform, expected to be %s", configv1.OpenStackPlatformType)

pkg/cloud/vsphere/vsphere_config_transformer.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"k8s.io/utils/net"
99

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

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

pkg/controllers/cloud_config_sync_controller.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
configv1 "github.com/openshift/api/config/v1"
1919

2020
"github.com/openshift/cluster-cloud-controller-manager-operator/pkg/cloud"
21+
"github.com/openshift/library-go/pkg/operator/configobserver/featuregates"
2122
)
2223

2324
const (
@@ -32,7 +33,8 @@ const (
3233

3334
type CloudConfigReconciler struct {
3435
ClusterOperatorStatusClient
35-
Scheme *runtime.Scheme
36+
Scheme *runtime.Scheme
37+
FeatureGateAccess featuregates.FeatureGateAccess
3638
}
3739

3840
func (r *CloudConfigReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
@@ -55,6 +57,15 @@ func (r *CloudConfigReconciler) Reconcile(ctx context.Context, req ctrl.Request)
5557
return ctrl.Result{}, err
5658
}
5759

60+
// TODO: evaluate if we can check gate starting here
61+
features, err := r.FeatureGateAccess.CurrentFeatureGates()
62+
if err != nil {
63+
klog.Errorf("unable to get feature gates: %v", err)
64+
if err := r.setDegradedCondition(ctx); err != nil {
65+
return ctrl.Result{}, fmt.Errorf("failed to set conditions for cloud config controller: %v", err)
66+
}
67+
}
68+
5869
syncNeeded, err := r.isCloudConfigSyncNeeded(infra.Status.PlatformStatus, infra.Spec.CloudConfig)
5970
if err != nil {
6071
if err := r.setDegradedCondition(ctx); err != nil {
@@ -134,7 +145,7 @@ func (r *CloudConfigReconciler) Reconcile(ctx context.Context, req ctrl.Request)
134145
// We ignore stuff in sourceCM.BinaryData. This isn't allowed to
135146
// contain any key that overlaps with those found in sourceCM.Data and
136147
// we're not expecting users to put their data in the former.
137-
output, err := cloudConfigTransformerFn(sourceCM.Data[defaultConfigKey], infra, network)
148+
output, err := cloudConfigTransformerFn(sourceCM.Data[defaultConfigKey], infra, network, features)
138149
if err != nil {
139150
if err := r.setDegradedCondition(ctx); err != nil {
140151
return ctrl.Result{}, fmt.Errorf("failed to set conditions for cloud config controller: %v", err)

0 commit comments

Comments
 (0)