-
Notifications
You must be signed in to change notification settings - Fork 72
/
Copy pathcreate.go
126 lines (110 loc) · 3.29 KB
/
create.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
package main
import (
"encoding/json"
"flag"
"fmt"
"os"
"github.com/Azure/ARO-HCP/internal/api"
"github.com/Azure/ARO-HCP/internal/api/arm"
)
const (
flagName = "type"
cluster = "cluster"
nodePool = "node_pool"
)
func main() {
example := "go run frontend/utils/create.go -type cluster"
usage := fmt.Sprintf("type of object you want to create: %v or %v.\nExample: %v\n", cluster, nodePool, example)
objectType := flag.String(flagName, cluster, usage)
flag.Parse()
if *objectType == cluster {
err := CreateJSONFile()
if err != nil {
panic(err)
}
return
}
if *objectType == nodePool {
err := CreateNodePool()
if err != nil {
panic(err)
}
return
}
help := "go run frontend/utils/create.go -type"
panic(fmt.Sprintf("invalid object type, run: '%v'", help))
}
// CreateJSONFile creates a base cluster JSON file for use with testing frontend to create clusters
func CreateJSONFile() error {
cluster := api.HCPOpenShiftCluster{
Properties: api.HCPOpenShiftClusterProperties{
Version: api.VersionProfile{
ID: "openshift-v4.17.0",
ChannelGroup: "stable",
},
DNS: api.DNSProfile{},
Network: api.NetworkProfile{
NetworkType: api.NetworkTypeOVNKubernetes,
PodCIDR: "10.128.0.0/14",
ServiceCIDR: "172.30.0.0/16",
MachineCIDR: "10.0.0.0/16",
HostPrefix: 23,
},
Console: api.ConsoleProfile{},
API: api.APIProfile{
Visibility: api.Visibility("public"),
},
EtcdEncryption: false,
DisableUserWorkloadMonitoring: false,
Proxy: api.ProxyProfile{},
Platform: api.PlatformProfile{
ManagedResourceGroup: "dev-test-mrg",
NetworkSecurityGroupID: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/dev-test-rg/providers/Microsoft.Network/networkSecurityGroups/xyz",
SubnetID: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/dev-test-rg/providers/Microsoft.Network/virtualNetworks/xyz/subnets/xyz",
OutboundType: api.OutboundType("loadBalancer"),
},
IssuerURL: "",
ExternalAuth: api.ExternalAuthConfigProfile{},
},
}
data, err := json.MarshalIndent(cluster, "", " ")
if err != nil {
return err
}
err = os.WriteFile("cluster.json", data, 0643)
if err != nil {
return err
}
return nil
}
func CreateNodePool() error {
nodePool := api.HCPOpenShiftClusterNodePool{
Properties: api.HCPOpenShiftClusterNodePoolProperties{
ProvisioningState: arm.ProvisioningState(""),
Version: api.VersionProfile{
ID: "openshift-v4.17.0",
ChannelGroup: "stable",
},
Platform: api.NodePoolPlatformProfile{
SubnetID: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/dev-test-rg/providers/Microsoft.Network/virtualNetworks/xyz/subnets/xyz",
DiskSizeGiB: 30,
// VMSize should match configs/cloud-resources/instance-types.yaml
// and configs/cloud-resource-constraints/instance-type-constraints.yaml
// in CS config files.
VMSize: "Standard_D8s_v3",
DiskStorageAccountType: "StandardSSD_LRS",
EphemeralOSDisk: false,
},
Replicas: 2,
},
}
data, err := json.MarshalIndent(nodePool, "", " ")
if err != nil {
return err
}
err = os.WriteFile("node_pool.json", data, 0643)
if err != nil {
return err
}
return nil
}