-
Notifications
You must be signed in to change notification settings - Fork 4
/
defaultInfo_sync.go
101 lines (91 loc) · 3.07 KB
/
defaultInfo_sync.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
package clusterinfo
import (
"fmt"
clusterv1beta1 "github.com/stolostron/cluster-lifecycle-api/clusterinfo/v1beta1"
"golang.org/x/net/context"
"k8s.io/apimachinery/pkg/labels"
clusterv1alpha1lister "open-cluster-management.io/api/client/cluster/listers/cluster/v1alpha1"
"github.com/stolostron/multicluster-controlplane/pkg/agent/addons/controllers/clusterclaim"
)
type defaultInfoSyncer struct {
claimLister clusterv1alpha1lister.ClusterClaimLister
}
func (s *defaultInfoSyncer) sync(ctx context.Context, clusterInfo *clusterv1beta1.ManagedClusterInfo) error {
claims, err := s.claimLister.List(labels.Everything())
if err != nil {
return fmt.Errorf("failed to list clusterClaims error:%v ", err)
}
for _, claim := range claims {
value := claim.Spec.Value
switch claim.Name {
case clusterclaim.ClaimOCMConsoleURL:
clusterInfo.Status.ConsoleURL = value
case clusterclaim.ClaimOCMKubeVersion:
clusterInfo.Status.Version = value
case clusterclaim.ClaimOpenshiftID:
clusterInfo.Status.ClusterID = value
case clusterclaim.ClaimOCMProduct:
clusterInfo.Status.KubeVendor = getKubeVendor(value)
case clusterclaim.ClaimOCMPlatform:
clusterInfo.Status.CloudVendor = getCloudVendor(value)
}
}
return nil
}
func getCloudVendor(platform string) (cloudVendor clusterv1beta1.CloudVendorType) {
switch platform {
case clusterclaim.PlatformAzure:
cloudVendor = clusterv1beta1.CloudVendorAzure
case clusterclaim.PlatformAWS:
cloudVendor = clusterv1beta1.CloudVendorAWS
case clusterclaim.PlatformIBM:
cloudVendor = clusterv1beta1.CloudVendorIBM
case clusterclaim.PlatformIBMZ:
cloudVendor = clusterv1beta1.CloudVendorIBMZ
case clusterclaim.PlatformIBMP:
cloudVendor = clusterv1beta1.CloudVendorIBMP
case clusterclaim.PlatformGCP:
cloudVendor = clusterv1beta1.CloudVendorGoogle
case clusterclaim.PlatformVSphere:
cloudVendor = clusterv1beta1.CloudVendorVSphere
case clusterclaim.PlatformOpenStack:
cloudVendor = clusterv1beta1.CloudVendorOpenStack
case clusterclaim.PlatformRHV:
cloudVendor = clusterv1beta1.CloudVendorRHV
case clusterclaim.PlatformAlibabaCloud:
cloudVendor = clusterv1beta1.CloudVendorAlibabaCloud
case clusterclaim.PlatformBareMetal:
cloudVendor = clusterv1beta1.CloudVendorBareMetal
default:
cloudVendor = clusterv1beta1.CloudVendorOther
}
return
}
func getKubeVendor(product string) (kubeVendor clusterv1beta1.KubeVendorType) {
switch product {
case clusterclaim.ProductAKS:
return clusterv1beta1.KubeVendorAKS
case clusterclaim.ProductGKE:
return clusterv1beta1.KubeVendorGKE
case clusterclaim.ProductEKS:
return clusterv1beta1.KubeVendorEKS
case clusterclaim.ProductIKS:
return clusterv1beta1.KubeVendorIKS
case clusterclaim.ProductICP:
return clusterv1beta1.KubeVendorICP
case clusterclaim.ProductOSD:
return clusterv1beta1.KubeVendorOSD
}
if isProductOCP(product) {
return clusterv1beta1.KubeVendorOpenShift
}
return clusterv1beta1.KubeVendorOther
}
func isProductOCP(product string) bool {
for _, productOCP := range clusterclaim.ProductOCPList {
if productOCP == product {
return true
}
}
return false
}