-
Notifications
You must be signed in to change notification settings - Fork 154
/
cloudcontroller.go
133 lines (116 loc) · 4.85 KB
/
cloudcontroller.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/*
Copyright 2022 The Kubermatic Kubernetes Platform contributors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package resources
import (
"net/url"
kubermaticv1 "k8c.io/kubermatic/v2/pkg/apis/kubermatic/v1"
"k8c.io/kubermatic/v2/pkg/semver"
"k8c.io/kubermatic/v2/pkg/version"
)
// ExternalCloudControllerFeatureSupported checks if the cloud provider supports
// external CCM. The clusterVersion has to be specified, depending on whether you
// want to verify against the spec'ed (desired) version or the current version
// in the ClusterStatus.
func ExternalCloudControllerFeatureSupported(dc *kubermaticv1.Datacenter, cloudSpec *kubermaticv1.CloudSpec, clusterVersion semver.Semver, incompatibilities ...*version.ProviderIncompatibility) bool {
switch t := kubermaticv1.ProviderType(cloudSpec.ProviderName); t {
case kubermaticv1.OpenstackCloudProvider:
// When using OpenStack external CCM with Open Telekom Cloud the creation
// of LBs fail as documented in the issue below:
// https://github.com/kubernetes/cloud-provider-openstack/issues/960
// Falling back to the in-tree CloudProvider mitigates the problem, even if
// not all features are expected to work properly (e.g.
// `manage-security-groups` should be set to false in cloud config).
//
// TODO This is a dirty hack to temporarily support OTC using
// Openstack provider, remove this when dedicated OTC support is
// introduced in Kubermatic.
return !isOTC(dc.Spec.Openstack)
case kubermaticv1.HetznerCloudProvider:
if cloudSpec.Hetzner.Network == "" && dc.Spec.Hetzner.Network == "" {
return false
}
fallthrough
case kubermaticv1.AWSCloudProvider,
kubermaticv1.AnexiaCloudProvider,
kubermaticv1.AzureCloudProvider,
kubermaticv1.GCPCloudProvider,
kubermaticv1.DigitaloceanCloudProvider,
kubermaticv1.KubevirtCloudProvider,
kubermaticv1.VSphereCloudProvider:
supported, err := version.IsSupported(clusterVersion.Semver(), t, incompatibilities, kubermaticv1.ExternalCloudProviderCondition)
if err != nil {
return false
}
return supported
default:
return false
}
}
// MigrationToExternalCloudControllerSupported checks if the cloud provider supports the migration to the
// external CCM.
func MigrationToExternalCloudControllerSupported(dc *kubermaticv1.Datacenter, cluster *kubermaticv1.Cluster, incompatibilities ...*version.ProviderIncompatibility) bool {
// External CCM must only be enabled when the cluster has reached a given
// version, so this check must depend on the status if possible.
v := cluster.Status.Versions.ControlPlane
if v == "" {
v = cluster.Spec.Version
}
switch t := kubermaticv1.ProviderType(cluster.Spec.Cloud.ProviderName); t {
case kubermaticv1.OpenstackCloudProvider:
// When using OpenStack external CCM with Open Telekom Cloud the creation
// of LBs fail as documented in the issue below:
// https://github.com/kubernetes/cloud-provider-openstack/issues/960
// Falling back to the in-tree CloudProvider mitigates the problem, even if
// not all features are expected to work properly (e.g.
// `manage-security-groups` should be set to false in cloud config).
//
// TODO This is a dirty hack to temporarily support OTC using
// Openstack provider, remove this when dedicated OTC support is
// introduced in Kubermatic.
return !isOTC(dc.Spec.Openstack)
case kubermaticv1.AWSCloudProvider,
kubermaticv1.VSphereCloudProvider,
kubermaticv1.AzureCloudProvider,
kubermaticv1.GCPCloudProvider:
supported, err := version.IsSupported(v.Semver(), t, incompatibilities, kubermaticv1.ExternalCloudProviderCondition)
if err != nil {
return false
}
return supported
default:
return false
}
}
// ExternalCloudControllerClusterName checks if the ClusterFeatureCCMClusterName is supported
// for the cloud provider.
func ExternalCloudControllerClusterName(cloudSpec *kubermaticv1.CloudSpec) bool {
switch kubermaticv1.ProviderType(cloudSpec.ProviderName) {
case kubermaticv1.OpenstackCloudProvider,
kubermaticv1.AzureCloudProvider,
kubermaticv1.AWSCloudProvider,
kubermaticv1.GCPCloudProvider,
kubermaticv1.KubevirtCloudProvider:
return true
default:
return false
}
}
// isOTC returns `true` if the OpenStack Datacenter uses OTC (i.e.
// Open Telekom Cloud), `false` otherwise.
func isOTC(dc *kubermaticv1.DatacenterSpecOpenstack) bool {
u, err := url.Parse(dc.AuthURL)
if err != nil {
return false
}
return u.Host == "iam.eu-de.otc.t-systems.com"
}