forked from openshift/hypershift
-
Notifications
You must be signed in to change notification settings - Fork 0
/
infrastructure.go
79 lines (69 loc) · 2.68 KB
/
infrastructure.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
package globalconfig
import (
"fmt"
"strings"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
configv1 "github.com/openshift/api/config/v1"
hyperv1 "github.com/openshift/hypershift/api/v1alpha1"
)
func InfrastructureConfig() *configv1.Infrastructure {
infra := &configv1.Infrastructure{
ObjectMeta: metav1.ObjectMeta{
Name: "cluster",
},
}
return infra
}
func ReconcileInfrastructure(infra *configv1.Infrastructure, hcp *hyperv1.HostedControlPlane) {
platformType := hcp.Spec.Platform.Type
apiServerAddress := hcp.Status.ControlPlaneEndpoint.Host
apiServerPort := hcp.Status.ControlPlaneEndpoint.Port
infra.Spec.PlatformSpec.Type = configv1.PlatformType(platformType)
infra.Status.APIServerInternalURL = fmt.Sprintf("https://%s:%d", apiServerAddress, apiServerPort)
infra.Status.APIServerURL = fmt.Sprintf("https://%s:%d", apiServerAddress, apiServerPort)
infra.Status.EtcdDiscoveryDomain = BaseDomain(hcp)
infra.Status.InfrastructureName = hcp.Spec.InfraID
infra.Status.ControlPlaneTopology = configv1.ExternalTopologyMode
infra.Status.Platform = configv1.PlatformType(platformType)
infra.Status.PlatformStatus = &configv1.PlatformStatus{
Type: configv1.PlatformType(platformType),
}
switch hcp.Spec.InfrastructureAvailabilityPolicy {
case hyperv1.HighlyAvailable:
infra.Status.InfrastructureTopology = configv1.HighlyAvailableTopologyMode
default:
infra.Status.InfrastructureTopology = configv1.SingleReplicaTopologyMode
}
switch platformType {
case hyperv1.AWSPlatform:
infra.Spec.PlatformSpec.AWS = &configv1.AWSPlatformSpec{}
infra.Status.PlatformStatus.AWS = &configv1.AWSPlatformStatus{
Region: hcp.Spec.Platform.AWS.Region,
}
tags := []configv1.AWSResourceTag{}
for _, tag := range hcp.Spec.Platform.AWS.ResourceTags {
// This breaks the AWS CSI driver as it ends up being used there as an extra tag
// which makes it fail to start with "Invalid extra tags: Tag key prefix 'kubernetes.io' is reserved".
if strings.HasPrefix(tag.Key, "kubernetes.io") {
continue
}
tags = append(tags, configv1.AWSResourceTag{
Key: tag.Key,
Value: tag.Value,
})
}
infra.Status.PlatformStatus.AWS.ResourceTags = tags
case hyperv1.AzurePlatform:
infra.Spec.CloudConfig.Name = "cloud.conf"
infra.Status.PlatformStatus.Azure = &configv1.AzurePlatformStatus{
CloudName: configv1.AzurePublicCloud,
ResourceGroupName: hcp.Spec.Platform.Azure.ResourceGroupName,
}
case hyperv1.PowerVSPlatform:
infra.Status.PlatformStatus.PowerVS = &configv1.PowerVSPlatformStatus{
Region: hcp.Spec.Platform.PowerVS.Region,
Zone: hcp.Spec.Platform.PowerVS.Zone,
CISInstanceCRN: hcp.Spec.Platform.PowerVS.CISInstanceCRN,
}
}
}