k8c.io/api/v3@v3.0.0-20230904060738-b0a93889c0b6/pkg/apis/ee.kubermatic/v1/helper/provider.go (about) 1 /* 2 Copyright 2023 The Kubermatic Kubernetes Platform contributors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package helper 18 19 import ( 20 "fmt" 21 22 kubermaticeev1 "k8c.io/api/v3/pkg/apis/ee.kubermatic/v1" 23 kubermaticv1 "k8c.io/api/v3/pkg/apis/kubermatic/v1" 24 ) 25 26 // ClusterCloudProviderName returns the provider name for the given CloudSpec. 27 func ClusterCloudProviderName(spec kubermaticv1.CloudSpec) (kubermaticeev1.CloudProvider, error) { 28 var providers []kubermaticeev1.CloudProvider 29 if spec.AWS != nil { 30 providers = append(providers, kubermaticeev1.CloudProviderAWS) 31 } 32 if spec.Alibaba != nil { 33 providers = append(providers, kubermaticeev1.CloudProviderAlibaba) 34 } 35 if spec.Anexia != nil { 36 providers = append(providers, kubermaticeev1.CloudProviderAnexia) 37 } 38 if spec.Azure != nil { 39 providers = append(providers, kubermaticeev1.CloudProviderAzure) 40 } 41 if spec.BringYourOwn != nil { 42 providers = append(providers, kubermaticeev1.CloudProviderBringYourOwn) 43 } 44 if spec.Digitalocean != nil { 45 providers = append(providers, kubermaticeev1.CloudProviderDigitalocean) 46 } 47 if spec.Fake != nil { 48 providers = append(providers, kubermaticeev1.CloudProviderFake) 49 } 50 if spec.GCP != nil { 51 providers = append(providers, kubermaticeev1.CloudProviderGCP) 52 } 53 if spec.Hetzner != nil { 54 providers = append(providers, kubermaticeev1.CloudProviderHetzner) 55 } 56 if spec.KubeVirt != nil { 57 providers = append(providers, kubermaticeev1.CloudProviderKubeVirt) 58 } 59 if spec.OpenStack != nil { 60 providers = append(providers, kubermaticeev1.CloudProviderOpenStack) 61 } 62 if spec.Packet != nil { 63 providers = append(providers, kubermaticeev1.CloudProviderPacket) 64 } 65 if spec.VSphere != nil { 66 providers = append(providers, kubermaticeev1.CloudProviderVSphere) 67 } 68 if spec.Nutanix != nil { 69 providers = append(providers, kubermaticeev1.CloudProviderNutanix) 70 } 71 if spec.VMwareCloudDirector != nil { 72 providers = append(providers, kubermaticeev1.CloudProviderVMwareCloudDirector) 73 } 74 if len(providers) == 0 { 75 return "", nil 76 } 77 if len(providers) != 1 { 78 return "", fmt.Errorf("only one cloud provider can be set in CloudSpec, but found the following providers: %v", providers) 79 } 80 return providers[0], nil 81 }