/
osa.go
116 lines (108 loc) · 4.26 KB
/
osa.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
package sdk
import (
"context"
"encoding/json"
"log"
"time"
"github.com/Azure/azure-sdk-for-go/services/preview/containerservice/mgmt/2018-09-30-preview/containerservice"
"github.com/julienstroheker/sandbox/pkg/auth"
"github.com/julienstroheker/azure-golang-sdk-sandbox/pkg/config"
)
type OSA struct {
client *containerservice.OpenShiftManagedClustersClient
}
func newOSAClient() (*OSA, error) {
osaClient := containerservice.NewOpenShiftManagedClustersClient(config.SubID)
authosa, _ := auth.GetResourceManagementAuthorizer()
osaClient.Authorizer = authosa
osaClient.PollingDuration = time.Hour * 1
osa := &OSA{
client: &osaClient,
}
return osa, nil
}
func (osa *OSA) ListOSAinSub() error {
i, err := osa.client.List(context.Background())
if err != nil {
log.Fatal("Error: " + err.Error())
return err
}
// for i.NotDone() {
// r = append(r, i.Values())
// i.Next()
// }
d := i.Values()
data, _ := json.Marshal(d)
log.Printf("ListOSA: %s", data)
return nil
}
func (osa *OSA) ListOSAinRG(rgName string) error {
var r []containerservice.OpenShiftManagedCluster
i, err := osa.client.ListByResourceGroupComplete(context.Background(), rgName)
if err != nil {
log.Fatal("Error: " + err.Error())
return err
}
for i.NotDone() {
r = append(r, i.Value())
i.Next()
}
data, _ := json.Marshal(r)
log.Printf("ListOSA in RG: %s", data)
return nil
}
func renderOSACluster(name string) containerservice.OpenShiftManagedCluster {
fqdn := (func(s string) *string { return &s })(name + ".westcentralus.cloudapp.azure.com")
return containerservice.OpenShiftManagedCluster{
Location: (func(s string) *string { return &s })("westcentralus"),
Name: (func(s string) *string { return &s })(name),
OpenShiftManagedClusterProperties: &containerservice.OpenShiftManagedClusterProperties{
OpenShiftVersion: (func(s string) *string { return &s })("v3.11"),
Fqdn: fqdn,
AgentPoolProfiles: &[]containerservice.OpenShiftManagedClusterAgentPoolProfile{
containerservice.OpenShiftManagedClusterAgentPoolProfile{
Name: (func(s string) *string { return &s })("compute"),
Count: (func(i int32) *int32 { return &i })(5),
VMSize: containerservice.OpenShiftContainerServiceVMSize(containerservice.StandardD4sV3),
SubnetCidr: (func(s string) *string { return &s })("10.0.0.0/24"),
Role: containerservice.OpenShiftAgentPoolProfileRole(containerservice.Compute),
OsType: containerservice.OSType(containerservice.Linux),
},
containerservice.OpenShiftManagedClusterAgentPoolProfile{
Name: (func(s string) *string { return &s })("infra"),
Count: (func(i int32) *int32 { return &i })(2),
VMSize: containerservice.OpenShiftContainerServiceVMSize(containerservice.StandardD4sV3),
SubnetCidr: (func(s string) *string { return &s })("10.0.0.0/24"),
Role: containerservice.OpenShiftAgentPoolProfileRole(containerservice.Infra),
OsType: containerservice.OSType(containerservice.Linux),
},
},
MasterPoolProfile: &containerservice.OpenShiftManagedClusterMasterPoolProfile{
Count: (func(i int32) *int32 { return &i })(3),
VMSize: containerservice.OpenShiftContainerServiceVMSize(containerservice.StandardD4sV3),
SubnetCidr: (func(s string) *string { return &s })("10.0.0.0/24"),
},
NetworkProfile: &containerservice.NetworkProfile{
VnetCidr: (func(s string) *string { return &s })("10.0.0.0/8"),
},
RouterProfiles: &[]containerservice.OpenShiftRouterProfile{
containerservice.OpenShiftRouterProfile{
Name: (func(s string) *string { return &s })("default"),
},
},
AuthProfile: &containerservice.OpenShiftManagedClusterAuthProfile{
IdentityProviders: &[]containerservice.OpenShiftManagedClusterIdentityProvider{
containerservice.OpenShiftManagedClusterIdentityProvider{
Name: (func(s string) *string { return &s })("Azure AD"),
Provider: containerservice.OpenShiftManagedClusterAADIdentityProvider{
ClientID: (func(s string) *string { return &s })(config.ClientID),
Secret: (func(s string) *string { return &s })(config.Secret),
TenantID: (func(s string) *string { return &s })(config.TenantID),
Kind: containerservice.KindAADIdentityProvider,
},
},
},
},
},
}
}