Skip to content
Open
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 @@ -68,6 +68,8 @@ spec:
value: {{ .globalCredsSecretName }}
- name: ENABLE_ALPHA_DUAL_STACK
value: "true"
- name: ADDITIONAL_NODE_LABELS
value: {{ .additionalLabels }}
resources:
requests:
cpu: 200m
Expand Down Expand Up @@ -100,7 +102,8 @@ spec:
--leader-elect-resource-namespace=openshift-cloud-controller-manager \
--feature-gates={{ .featureGates }} \
--use-service-account-credentials=true \
--secure-port=0
--secure-port=0 {{if ne .additionalLabels ""}}\
--node-labels="$(ADDITIONAL_NODE_LABELS)"{{end}}
terminationMessagePolicy: FallbackToLogsOnError
volumeMounts:
- name: host-etc-kube
Expand Down
11 changes: 11 additions & 0 deletions pkg/cloud/vsphere/vsphere.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"

"github.com/asaskevich/govalidator"
"github.com/openshift/api/features"
appsv1 "k8s.io/api/apps/v1"
rbacv1 "k8s.io/api/rbac/v1"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand All @@ -18,6 +19,8 @@ const (

// see manifests/0000_26_cloud-controller-manager-operator_16_credentialsrequest-vsphere.yaml
globalCredsSecretName = "vsphere-cloud-credentials"

vSpherePlatformTypeLabel = "node.openshift.io/platform-type=vsphere"
)

var (
Expand Down Expand Up @@ -45,6 +48,7 @@ var templateValuesValidationMap = map[string]interface{}{
"globalCredsSecretName": "required,type(string)",
"cloudproviderName": "required,type(string)",
"featureGates": "type(string)",
"additionalLabels": "type(string)",
}

type vsphereAssets struct {
Expand All @@ -57,13 +61,20 @@ func (assets *vsphereAssets) GetRenderedResources() []client.Object {
}

func getTemplateValues(images *imagesReference, operatorConfig config.OperatorConfig) (common.TemplateValues, error) {
additionalLabels := ""

// We are only going to set the new platform-type node labels if the featuregate is enabled.
if operatorConfig.OCPFeatureGates != nil && operatorConfig.OCPFeatureGates.Enabled(features.FeatureGateVSphereMixedNodeEnv) {
additionalLabels = vSpherePlatformTypeLabel
}
values := common.TemplateValues{
"images": images,
"infrastructureName": operatorConfig.InfrastructureName,
"globalCredsSecretNamespace": operatorConfig.ManagedNamespace,
"globalCredsSecretName": globalCredsSecretName,
"cloudproviderName": operatorConfig.GetPlatformNameString(),
"featureGates": operatorConfig.FeatureGates,
"additionalLabels": additionalLabels,
}
_, err := govalidator.ValidateMap(values, templateValuesValidationMap)
if err != nil {
Expand Down
15 changes: 15 additions & 0 deletions pkg/cloud/vsphere/vsphere_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@ import (
"testing"

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

"github.com/stretchr/testify/assert"

"github.com/openshift/cluster-cloud-controller-manager-operator/pkg/config"
)

func TestResourcesRenderingSmoke(t *testing.T) {
customFeatureGates := featuregates.NewFeatureGate([]configv1.FeatureGateName{"SomeOtherFeatureGate", features.FeatureGateVSphereMixedNodeEnv}, nil)

tc := []struct {
name string
Expand Down Expand Up @@ -41,6 +44,18 @@ func TestResourcesRenderingSmoke(t *testing.T) {
PlatformStatus: &configv1.PlatformStatus{Type: configv1.VSpherePlatformType},
InfrastructureName: "infra",
},
}, {
name: "FeatureGate FeatureGateVSphereMixedNodeEnv=true results in node-labels generated without error",
config: config.OperatorConfig{
ManagedNamespace: "my-cool-namespace",
ImagesReference: config.ImagesReference{
CloudControllerManagerVSphere: "CloudControllerManagerVsphere",
},
PlatformStatus: &configv1.PlatformStatus{Type: configv1.VSpherePlatformType},
InfrastructureName: "infra",
FeatureGates: "FeatureGateVSphereMixedNodeEnv=true",
OCPFeatureGates: customFeatureGates,
},
},
}

Expand Down
7 changes: 6 additions & 1 deletion pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ type OperatorConfig struct {
PlatformStatus *configv1.PlatformStatus
ClusterProxy *configv1.Proxy
FeatureGates string
OCPFeatureGates featuregates.FeatureGate
}

func (cfg *OperatorConfig) GetPlatformNameString() string {
Expand Down Expand Up @@ -97,11 +98,14 @@ func ComposeConfig(infrastructure *configv1.Infrastructure, clusterProxy *config
klog.Errorf("Unable to get upstream feature gates: %s", err)
return OperatorConfig{}, fmt.Errorf("unable to get upstream feature gates: %w", err)
}

var features featuregates.FeatureGate
if featureGateAccessor != nil {
features, _ := featureGateAccessor.CurrentFeatureGates()
features, _ = featureGateAccessor.CurrentFeatureGates()
enabled, _ := util.GetEnabledDisabledFeatures(features, upstreamGates)
featureGatesString = util.BuildFeatureGateString(enabled, nil)
}
fmt.Printf("Generated feature gates string: %s\n", featureGatesString)

config := OperatorConfig{
PlatformStatus: infrastructure.Status.PlatformStatus.DeepCopy(),
Expand All @@ -111,6 +115,7 @@ func ComposeConfig(infrastructure *configv1.Infrastructure, clusterProxy *config
InfrastructureName: infrastructure.Status.InfrastructureName,
IsSingleReplica: infrastructure.Status.ControlPlaneTopology == configv1.SingleReplicaTopologyMode,
FeatureGates: featureGatesString,
OCPFeatureGates: features,
}

return config, nil
Expand Down
4 changes: 4 additions & 0 deletions pkg/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,10 @@ func TestComposeConfig(t *testing.T) {
// longer appears in the features package linked above. You'll need to
// choose something present in the vendored k8s version.
FeatureGates: "CloudControllerManagerWebhook=true",
OCPFeatureGates: featuregates.NewFeatureGate(
[]configv1.FeatureGateName{"CloudControllerManagerWebhook", "ChocobombVanilla", "ChocobombStrawberry"},
[]configv1.FeatureGateName{"ChocobombBlueberry", "ChocobombBanana"},
),
},
}, {
name: "Empty infrastructure should return error",
Expand Down
Loading