Repository: kubernetes/kops (go)

Issue:
Openstack CCM should have --cluster-name defined
/kind feature

**1. Describe IN DETAIL the feature/behavior/change you would like to see.**

Like discussed in https://github.com/kubernetes/kops/pull/15095#issuecomment-1414352848 we should have `--cluster-name` defined in our clusters if we want to run multiple Kubernetes clusters in same project.

**2. Feel free to provide a design supporting your feature request.**

Currently when its not enabled it uses default value `kubernetes` and we cannot modify the flag for existing clusters. I am not 100% sure but we could try populating the https://github.com/kubernetes/kops/blob/master/pkg/apis/kops/componentconfig.go#L676 value in https://github.com/kubernetes/kops/blob/master/upup/pkg/fi/cloudup/new_cluster.go#L326 and see will it be added to ccm configuration.


Pull request:
Add cluster name to OCCM opts
fixes #15108

We cannot add it to existing clusters (this value is used things like loadbalancer and routes), we can add it only to new clusters.

Patch:
diff --git a/upup/pkg/fi/cloudup/new_cluster.go b/upup/pkg/fi/cloudup/new_cluster.go
index 8eead5066a..267adc738d 100644
--- a/upup/pkg/fi/cloudup/new_cluster.go
+++ b/upup/pkg/fi/cloudup/new_cluster.go
@@ -1438,6 +1438,11 @@ func initializeOpenstack(opt *NewClusterOptions, cluster *api.Cluster) {
 			cluster.Spec.Networking.Topology.DNS = api.DNSTypeNone
 		}
 	}
+
+	if cluster.Spec.ExternalCloudControllerManager == nil {
+		cluster.Spec.ExternalCloudControllerManager = &api.CloudControllerManagerConfig{}
+	}
+	cluster.Spec.ExternalCloudControllerManager.ClusterName = opt.ClusterName
 }
 
 func createEtcdCluster(etcdCluster string, controlPlanes []*api.InstanceGroup, encryptEtcdStorage bool, etcdStorageType string) api.EtcdClusterSpec {


Test patch:
diff --git a/tests/integration/create_cluster/ha_openstack/expected-v1alpha2.yaml b/tests/integration/create_cluster/ha_openstack/expected-v1alpha2.yaml
index c64a7d3ab7..c9e0eac712 100644
--- a/tests/integration/create_cluster/ha_openstack/expected-v1alpha2.yaml
+++ b/tests/integration/create_cluster/ha_openstack/expected-v1alpha2.yaml
@@ -21,6 +21,8 @@ spec:
         timeout: 10s
       router:
         externalNetwork: ""
+  cloudControllerManager:
+    clusterName: minimal.k8s.local
   cloudProvider: openstack
   configBase: memfs://tests/minimal.k8s.local
   etcdClusters:
diff --git a/tests/integration/create_cluster/ha_openstack_nodns/expected-v1alpha2.yaml b/tests/integration/create_cluster/ha_openstack_nodns/expected-v1alpha2.yaml
index e27554adcc..c54eaaf1c4 100644
--- a/tests/integration/create_cluster/ha_openstack_nodns/expected-v1alpha2.yaml
+++ b/tests/integration/create_cluster/ha_openstack_nodns/expected-v1alpha2.yaml
@@ -29,6 +29,8 @@ spec:
         dnsServers: 1.1.1.1
         externalNetwork: vlan1
         externalSubnet: vlan1subnet
+  cloudControllerManager:
+    clusterName: ha.example.com
   cloudProvider: openstack
   configBase: memfs://tests/ha.example.com
   etcdClusters:
diff --git a/tests/integration/create_cluster/ha_openstack_octavia/expected-v1alpha2.yaml b/tests/integration/create_cluster/ha_openstack_octavia/expected-v1alpha2.yaml
index 4b40f59c16..b341bff70e 100644
--- a/tests/integration/create_cluster/ha_openstack_octavia/expected-v1alpha2.yaml
+++ b/tests/integration/create_cluster/ha_openstack_octavia/expected-v1alpha2.yaml
@@ -27,6 +27,8 @@ spec:
       router:
         dnsServers: 1.1.1.1
         externalNetwork: vlan1
+  cloudControllerManager:
+    clusterName: minimal.k8s.local
   cloudProvider: openstack
   configBase: memfs://tests/minimal.k8s.local
   etcdClusters: