-
Notifications
You must be signed in to change notification settings - Fork 131
/
types_cloud_project_kube.go
219 lines (189 loc) · 7.12 KB
/
types_cloud_project_kube.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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
package ovh
import (
"fmt"
"strings"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/ovh/terraform-provider-ovh/ovh/helpers"
)
type CloudProjectKubeUpdatePolicyOpts struct {
UpdatePolicy string `json:"updatePolicy"`
}
// CloudProjectKubePutOpts update cluster options
type CloudProjectKubePutOpts struct {
Name *string `json:"name,omitempty"`
}
type privateNetworkConfiguration struct {
DefaultVrackGateway string `json:"defaultVrackGateway"`
PrivateNetworkRoutingAsDefault bool `json:"privateNetworkRoutingAsDefault"`
}
type CloudProjectKubeCreateOpts struct {
Name *string `json:"name,omitempty"`
PrivateNetworkId *string `json:"privateNetworkId,omitempty"`
PrivateNetworkConfiguration *privateNetworkConfiguration `json:"privateNetworkConfiguration,omitempty"`
Region string `json:"region"`
Version *string `json:"version,omitempty"`
UpdatePolicy *string `json:"updatePolicy,omitempty"`
Customization *Customization `json:"customization,omitempty"`
}
type Customization struct {
APIServer *APIServer `json:"apiServer,omitempty"`
}
type APIServer struct {
AdmissionPlugins *AdmissionPlugins `json:"admissionPlugins,omitempty"`
}
type AdmissionPlugins struct {
Enabled *[]string `json:"enabled,omitempty"`
Disabled *[]string `json:"disabled,omitempty"`
}
func (opts *CloudProjectKubeCreateOpts) FromResource(d *schema.ResourceData) *CloudProjectKubeCreateOpts {
opts.Region = d.Get("region").(string)
opts.Version = helpers.GetNilStringPointerFromData(d, "version")
opts.Name = helpers.GetNilStringPointerFromData(d, "name")
opts.UpdatePolicy = helpers.GetNilStringPointerFromData(d, "update_policy")
opts.PrivateNetworkId = helpers.GetNilStringPointerFromData(d, "private_network_id")
opts.PrivateNetworkConfiguration = loadPrivateNetworkConfiguration(d.Get("private_network_configuration"))
opts.Customization = loadCustomization(d.Get("customization"))
return opts
}
func loadCustomization(i interface{}) *Customization {
if i == nil {
return nil
}
customizationOutput := Customization{
APIServer: &APIServer{
AdmissionPlugins: &AdmissionPlugins{},
},
}
customizationSet := i.(*schema.Set).List()
for _, customization := range customizationSet {
apiServerSet := customization.(map[string]interface{})["apiserver"].(*schema.Set).List()
for _, apiServer := range apiServerSet {
admissionPluginsSet := apiServer.(map[string]interface{})["admissionplugins"].(*schema.Set).List()
for _, admissionPlugins := range admissionPluginsSet {
stringArray := admissionPlugins.(map[string]interface{})["enabled"].([]interface{})
enabled := []string{}
for _, s := range stringArray {
enabled = append(enabled, s.(string))
}
customizationOutput.APIServer.AdmissionPlugins.Enabled = &enabled
stringArray = admissionPlugins.(map[string]interface{})["disabled"].([]interface{})
disabled := []string{}
for _, s := range stringArray {
disabled = append(disabled, s.(string))
}
customizationOutput.APIServer.AdmissionPlugins.Disabled = &disabled
}
}
}
return &customizationOutput
}
func loadPrivateNetworkConfiguration(i interface{}) *privateNetworkConfiguration {
if i == nil {
return nil
}
pncOutput := privateNetworkConfiguration{}
pncSet := i.(*schema.Set).List()
for _, pnc := range pncSet {
mapping := pnc.(map[string]interface{})
pncOutput.DefaultVrackGateway = mapping["default_vrack_gateway"].(string)
pncOutput.PrivateNetworkRoutingAsDefault = mapping["private_network_routing_as_default"].(bool)
}
return &pncOutput
}
func (s *CloudProjectKubeCreateOpts) String() string {
return fmt.Sprintf("%s(%s): %s", *s.Name, s.Region, *s.Version)
}
type CloudProjectKubeResponse struct {
ControlPlaneIsUpToDate bool `json:"controlPlaneIsUpToDate"`
Id string `json:"id"`
IsUpToDate bool `json:"isUpToDate"`
Name string `json:"name"`
NextUpgradeVersions []string `json:"nextUpgradeVersions"`
NodesUrl string `json:"nodesUrl"`
PrivateNetworkId string `json:"privateNetworkId"`
Region string `json:"region"`
Status string `json:"status"`
UpdatePolicy string `json:"updatePolicy"`
Url string `json:"url"`
Version string `json:"version"`
Customization Customization `json:"customization"`
}
func (v CloudProjectKubeResponse) ToMap() map[string]interface{} {
obj := make(map[string]interface{})
obj["control_plane_is_up_to_date"] = v.ControlPlaneIsUpToDate
obj["id"] = v.Id
obj["is_up_to_date"] = v.IsUpToDate
obj["name"] = v.Name
obj["next_upgrade_versions"] = v.NextUpgradeVersions
obj["nodes_url"] = v.NodesUrl
obj["private_network_id"] = v.PrivateNetworkId
obj["region"] = v.Region
obj["status"] = v.Status
obj["update_policy"] = v.UpdatePolicy
obj["url"] = v.Url
obj["version"] = v.Version[:strings.LastIndex(v.Version, ".")]
obj["customization"] = []map[string]interface{}{
{
"apiserver": []map[string]interface{}{
{
"admissionplugins": []map[string]interface{}{
{
"enabled": v.Customization.APIServer.AdmissionPlugins.Enabled,
"disabled": v.Customization.APIServer.AdmissionPlugins.Disabled,
},
},
},
},
},
}
return obj
}
func (s *CloudProjectKubeResponse) String() string {
return fmt.Sprintf("%s(%s): %s", s.Name, s.Id, s.Status)
}
type CloudProjectKubeKubeConfigResponse struct {
Content string `json:"content"`
}
type CloudProjectKubeUpdateOpts struct {
Strategy string `json:"strategy"`
}
type CloudProjectKubeResetOpts struct {
PrivateNetworkId *string `json:"privateNetworkId,omitempty"`
}
type CloudProjectKubeUpdatePNCOpts struct {
DefaultVrackGateway string `json:"defaultVrackGateway"`
PrivateNetworkRoutingAsDefault bool `json:"privateNetworkRoutingAsDefault"`
}
type CloudProjectKubeUpdateCustomizationOpts struct {
APIServer *APIServer `json:"apiServer"`
}
type CloudProjectKubeNodeResponse struct {
CreatedAt string `json:"createdAt"`
UpdatedAt string `json:"updatedAt"`
DeployedAt string `json:"deployedAt"`
Flavor string `json:"flavor"`
Id string `json:"id"`
InstanceId string `json:"instanceId"`
IsUpToDate bool `json:"isUpToDate"`
Name string `json:"name"`
NodePoolId string `json:"nodePoolId"`
ProjectId string `json:"projectId"`
Status string `json:"status"`
Version string `json:"version"`
}
func (v CloudProjectKubeNodeResponse) ToMap() map[string]interface{} {
obj := make(map[string]interface{})
obj["created_at"] = v.CreatedAt
obj["deployed_at"] = v.DeployedAt
obj["flavor"] = v.Flavor
obj["id"] = v.Id
obj["instance_id"] = v.InstanceId
obj["is_up_to_date"] = v.IsUpToDate
obj["name"] = v.Name
obj["node_pool_id"] = v.NodePoolId
obj["project_id"] = v.ProjectId
obj["status"] = v.Status
obj["updated_at"] = v.UpdatedAt
obj["version"] = v.Version
return obj
}