This repository has been archived by the owner on Jun 21, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
azure.go
176 lines (147 loc) · 4.91 KB
/
azure.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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
package azure
import (
"errors"
"github.com/banzaicloud/banzai-types/constants"
)
// Values describes a list of Azure clusters
type Values struct {
Value []Value `json:"value"`
}
// Value describes an Azure cluster
type Value struct {
Id string `json:"id"`
Location string `json:"location"`
Name string `json:"name"`
Properties Properties `json:"properties"`
}
// Properties describes an Azure cluster properties
type Properties struct {
ProvisioningState string `json:"provisioningState"`
AgentPoolProfiles []Profile `json:"agentPoolProfiles"`
Fqdn string `json:"fqdn"`
}
// Profile describes an Azure agent pool
type Profile struct {
Name string `json:"name"`
Autoscaling bool `json:"autoscaling"`
MinCount int `json:"minCount"`
MaxCount int `json:"maxCount"`
Count int `json:"count"`
VmSize string `json:"vmSize"`
}
// ResponseWithValue describes an Azure cluster
type ResponseWithValue struct {
StatusCode int `json:"status_code"`
Value Value `json:"message,omitempty"`
}
// ListResponse describes an Azure cluster list
type ListResponse struct {
StatusCode int `json:"status_code"`
Value Values `json:"message"`
}
// CreateClusterAzure describes Azure fields of a CreateCluster request
type CreateClusterAzure struct {
ResourceGroup string `json:"resourceGroup"`
KubernetesVersion string `json:"kubernetesVersion"`
NodePools map[string]*NodePoolCreate `json:"nodePools,omitempty"`
}
// NodePoolCreate describes Azure's node fields of a CreateCluster request
type NodePoolCreate struct {
Autoscaling bool `json:"autoscaling"`
MinCount int `json:"minCount"`
MaxCount int `json:"maxCount"`
Count int `json:"count"`
NodeInstanceType string `json:"instanceType"`
}
// NodePoolUpdate describes Azure's node count of a UpdateCluster request
type NodePoolUpdate struct {
Autoscaling bool `json:"autoscaling"`
MinCount int `json:"minCount"`
MaxCount int `json:"maxCount"`
Count int `json:"count"`
}
// UpdateClusterAzure describes Azure's node fields of an UpdateCluster request
type UpdateClusterAzure struct {
NodePools map[string]*NodePoolUpdate `json:"nodePools,omitempty"`
}
// Validate validates azure cluster create request
func (azure *CreateClusterAzure) Validate() error {
if azure == nil {
return errors.New("Azure is <nil>")
}
if azure == nil {
msg := "Required field 'azure' is empty."
return errors.New(msg)
}
// ---- [ NodePool check ] ---- //
if azure.NodePools == nil {
msg := "Required field 'nodePools' is empty."
return errors.New(msg)
}
if len(azure.ResourceGroup) == 0 {
msg := "Required field 'resourceGroup' is empty."
return errors.New(msg)
}
for _, np := range azure.NodePools {
// ---- [ Min & Max count fields are required in case of autoscaling ] ---- //
if np.Autoscaling {
if np.MinCount == 0 {
return constants.ErrorMinFieldRequiredError
}
if np.MaxCount == 0 {
return constants.ErrorMaxFieldRequiredError
}
if np.MaxCount < np.MinCount {
return constants.ErrorNodePoolMinMaxFieldError
}
}
if np.Count == 0 {
np.Count = constants.DefaultNodeMinCount
}
if len(np.NodeInstanceType) == 0 {
return errors.New("required field `NodeInstanceType` is empty")
}
}
if len(azure.KubernetesVersion) == 0 {
azure.KubernetesVersion = constants.AzureDefaultKubernetesVersion
}
return nil
}
// Validate validates the update request (only azure part). If any of the fields is missing, the method fills
// with stored data.
func (a *UpdateClusterAzure) Validate() error {
// ---- [ Azure field check ] ---- //
if a == nil {
return errors.New("'azure' field is empty")
}
return nil
}
// Update updates `ResponseWithValue` with the given response code and value
func (r *ResponseWithValue) Update(code int, Value Value) {
r.Value = Value
r.StatusCode = code
}
// Config describes an Azure kubeconfig
type Config struct {
Location string `json:"location"`
Name string `json:"name"`
Properties struct {
KubeConfig string `json:"kubeConfig"`
} `json:"properties"`
}
// ClusterProfileAzure describes an Azure profile
type ClusterProfileAzure struct {
KubernetesVersion string `json:"kubernetesVersion"`
NodePools map[string]*NodePoolCreate `json:"nodePools,omitempty"`
}
// CreateAzureObjectStoreBucketProperties describes an Azure ObjectStore Container Creation request
type CreateAzureObjectStoreBucketProperties struct {
Location string `json:"location" binding:"required"`
StorageAccount string `json:"storageAccount"`
ResourceGroup string `json:"resourceGroup"`
}
// BlobStoragePropsForAzure describes the Azure specific properties
type BlobStoragePropsForAzure struct {
ResourceGroup string `json:"resourceGroup" binding:"required"`
StorageAccount string `json:"storageAccount" binding:"required"`
}