Skip to content

Commit

Permalink
introduce extra_args_array fields to services schema
Browse files Browse the repository at this point in the history
  • Loading branch information
HarrisonWAffel committed Nov 27, 2023
1 parent 2ac55f2 commit e89d7d0
Show file tree
Hide file tree
Showing 20 changed files with 575 additions and 56 deletions.
15 changes: 15 additions & 0 deletions rke/schema_rke_cluster_services_etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,21 @@ func rkeClusterServicesEtcdFields() map[string]*schema.Schema {
Optional: true,
Computed: true,
},
"windows_extra_args": {
Type: schema.TypeMap,
Optional: true,
Computed: true,
},
"extra_args_array": {
Type: schema.TypeString,
Optional: true,
Description: "A JSON Representation of extra kube-api service arguments which can be passed multiple times",
},
"windows_extra_args_array": {
Type: schema.TypeString,
Optional: true,
Description: "A JSON Representation of extra kube-api service arguments which can be passed multiple times for windows nodes",
},
"extra_binds": {
Type: schema.TypeList,
Optional: true,
Expand Down
15 changes: 15 additions & 0 deletions rke/schema_rke_cluster_services_kube_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,21 @@ func rkeClusterServicesKubeAPIFields() map[string]*schema.Schema {
Computed: true,
Description: "Extra arguments that are added to the kube-api services",
},
"windows_extra_args": {
Type: schema.TypeMap,
Optional: true,
Description: "Extra arguments that are added to the kube-api services",
},
"extra_args_array": {
Type: schema.TypeString,
Optional: true,
Description: "A JSON Representation of extra kube-api service arguments which can be passed multiple times",
},
"windows_extra_args_array": {
Type: schema.TypeString,
Optional: true,
Description: "A JSON Representation of extra kube-api service arguments which can be passed multiple times for windows nodes",
},
"extra_binds": {
Type: schema.TypeList,
Optional: true,
Expand Down
16 changes: 16 additions & 0 deletions rke/schema_rke_cluster_services_kube_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,22 @@ func rkeClusterServicesKubeControllerFields() map[string]*schema.Schema {
Computed: true,
Description: "Extra arguments that are added to the kube-controller service",
},
"windows_extra_args": {
Type: schema.TypeMap,
Optional: true,
Computed: true,
Description: "Extra arguments that are added to the kube-controller service",
},
"extra_args_array": {
Type: schema.TypeString,
Optional: true,
Description: "A JSON Representation of extra kube-api service arguments which can be passed multiple times",
},
"windows_extra_args_array": {
Type: schema.TypeString,
Optional: true,
Description: "A JSON Representation of extra kube-api service arguments which can be passed multiple times for windows nodes",
},
"extra_binds": {
Type: schema.TypeList,
Optional: true,
Expand Down
16 changes: 16 additions & 0 deletions rke/schema_rke_cluster_services_kubelet.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,22 @@ func rkeClusterServicesKubeletFields() map[string]*schema.Schema {
Computed: true,
Description: "Extra arguments that are added to the kubelet services",
},
"windows_extra_args": {
Type: schema.TypeMap,
Optional: true,
Computed: true,
Description: "Extra arguments that are added to the kubelet services",
},
"extra_args_array": {
Type: schema.TypeString,
Optional: true,
Description: "A JSON Representation of extra kube-api service arguments which can be passed multiple times",
},
"windows_extra_args_array": {
Type: schema.TypeString,
Optional: true,
Description: "A JSON Representation of extra kube-api service arguments which can be passed multiple times for windows nodes",
},
"extra_binds": {
Type: schema.TypeList,
Optional: true,
Expand Down
16 changes: 16 additions & 0 deletions rke/schema_rke_cluster_services_kubeproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,22 @@ func rkeClusterServicesKubeproxyFields() map[string]*schema.Schema {
Computed: true,
Description: "Extra arguments that are added to the kubeproxy services",
},
"windows_extra_args": {
Type: schema.TypeMap,
Optional: true,
Computed: true,
Description: "Extra arguments that are added to the kubeproxy services",
},
"extra_args_array": {
Type: schema.TypeString,
Optional: true,
Description: "A JSON Representation of extra kube-api service arguments which can be passed multiple times",
},
"windows_extra_args_array": {
Type: schema.TypeString,
Optional: true,
Description: "A JSON Representation of extra kube-api service arguments which can be passed multiple times for windows nodes",
},
"extra_binds": {
Type: schema.TypeList,
Optional: true,
Expand Down
16 changes: 16 additions & 0 deletions rke/schema_rke_cluster_services_scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,22 @@ func rkeClusterServicesSchedulerFields() map[string]*schema.Schema {
Computed: true,
Description: "Extra arguments that are added to the scheduler services",
},
"windows_extra_args": {
Type: schema.TypeMap,
Optional: true,
Computed: true,
Description: "Extra arguments that are added to the scheduler services",
},
"extra_args_array": {
Type: schema.TypeString,
Optional: true,
Description: "A JSON Representation of extra kube-api service arguments which can be passed multiple times",
},
"windows_extra_args_array": {
Type: schema.TypeString,
Optional: true,
Description: "A JSON Representation of extra kube-api service arguments which can be passed multiple times for windows nodes",
},
"extra_binds": {
Type: schema.TypeList,
Optional: true,
Expand Down
55 changes: 46 additions & 9 deletions rke/structure_rke_cluster_services.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,37 @@ func flattenRKEClusterServices(in rancher.RKEConfigServices, p []interface{}) ([
if !ok {
v = []interface{}{}
}
obj["etcd"] = flattenRKEClusterServicesEtcd(in.Etcd, v)
obj["etcd"], _ = flattenRKEClusterServicesEtcd(in.Etcd, v)

kubeAPI, err := flattenRKEClusterServicesKubeAPI(in.KubeAPI)
if err != nil {
return []interface{}{obj}, err
}
obj["kube_api"] = kubeAPI
obj["kube_controller"] = flattenRKEClusterServicesKubeController(in.KubeController)
obj["kubelet"] = flattenRKEClusterServicesKubelet(in.Kubelet)
obj["kubeproxy"] = flattenRKEClusterServicesKubeproxy(in.Kubeproxy)
obj["scheduler"] = flattenRKEClusterServicesScheduler(in.Scheduler)

kubeController, err := flattenRKEClusterServicesKubeController(in.KubeController)
if err != nil {
return []interface{}{obj}, err
}
obj["kube_controller"] = kubeController

kubelet, err := flattenRKEClusterServicesKubelet(in.Kubelet)
if err != nil {
return []interface{}{obj}, err
}
obj["kubelet"] = kubelet

kubeproxy, err := flattenRKEClusterServicesKubeproxy(in.Kubeproxy)
if err != nil {
return []interface{}{obj}, err
}
obj["kubeproxy"] = kubeproxy

scheduler, err := flattenRKEClusterServicesScheduler(in.Scheduler)
if err != nil {
return []interface{}{obj}, err
}
obj["scheduler"] = scheduler

return []interface{}{obj}, nil
}
Expand Down Expand Up @@ -58,19 +79,35 @@ func expandRKEClusterServices(p []interface{}) (rancher.RKEConfigServices, error
}

if v, ok := in["kube_controller"].([]interface{}); ok && len(v) > 0 {
obj.KubeController = expandRKEClusterServicesKubeController(v)
kubeController, err := expandRKEClusterServicesKubeController(v)
if err != nil {
return obj, err
}
obj.KubeController = kubeController
}

if v, ok := in["kubelet"].([]interface{}); ok && len(v) > 0 {
obj.Kubelet = expandRKEClusterServicesKubelet(v)
kubelet, err := expandRKEClusterServicesKubelet(v)
if err != nil {
return obj, err
}
obj.Kubelet = kubelet
}

if v, ok := in["kubeproxy"].([]interface{}); ok && len(v) > 0 {
obj.Kubeproxy = expandRKEClusterServicesKubeproxy(v)
kubeproxy, err := expandRKEClusterServicesKubeproxy(v)
if err != nil {
return obj, err
}
obj.Kubeproxy = kubeproxy
}

if v, ok := in["scheduler"].([]interface{}); ok && len(v) > 0 {
obj.Scheduler = expandRKEClusterServicesScheduler(v)
scheduler, err := expandRKEClusterServicesScheduler(v)
if err != nil {
return obj, err
}
obj.Scheduler = scheduler
}

return obj, nil
Expand Down
45 changes: 43 additions & 2 deletions rke/structure_rke_cluster_services_etcd.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package rke

import (
"encoding/json"
"fmt"

rancher "github.com/rancher/rke/types"
Expand Down Expand Up @@ -85,7 +86,7 @@ func flattenRKEClusterServicesEtcdBackupConfig(in *rancher.BackupConfig, p []int
return []interface{}{obj}
}

func flattenRKEClusterServicesEtcd(in rancher.ETCDService, p []interface{}) []interface{} {
func flattenRKEClusterServicesEtcd(in rancher.ETCDService, p []interface{}) ([]interface{}, error) {
var obj map[string]interface{}
if len(p) == 0 || p[0] == nil {
obj = make(map[string]interface{})
Expand Down Expand Up @@ -121,6 +122,26 @@ func flattenRKEClusterServicesEtcd(in rancher.ETCDService, p []interface{}) []in
obj["extra_args"] = toMapInterface(in.ExtraArgs)
}

if len(in.WindowsExtraArgs) > 0 {
obj["windows_extra_args"] = toMapInterface(in.WindowsExtraArgs)
}

if len(in.ExtraArgsArray) > 0 {
j, err := json.Marshal(in.ExtraArgsArray)
if err != nil {
return nil, err
}
obj["extra_args_array"] = string(j)
}

if len(in.WindowsExtraArgsArray) > 0 {
j, err := json.Marshal(in.WindowsExtraArgsArray)
if err != nil {
return nil, err
}
obj["windows_extra_args_array"] = string(j)
}

if len(in.ExtraBinds) > 0 {
obj["extra_binds"] = toArrayInterface(in.ExtraBinds)
}
Expand Down Expand Up @@ -155,7 +176,7 @@ func flattenRKEClusterServicesEtcd(in rancher.ETCDService, p []interface{}) []in

obj["snapshot"] = *in.Snapshot

return []interface{}{obj}
return []interface{}{obj}, nil
}

// Expanders
Expand Down Expand Up @@ -275,6 +296,26 @@ func expandRKEClusterServicesEtcd(p []interface{}) (rancher.ETCDService, error)
obj.ExtraArgs = toMapString(v)
}

if v, ok := in["windows_extra_args"].(map[string]interface{}); ok && len(v) > 0 {
obj.WindowsExtraArgs = toMapString(v)
}

if v, ok := in["extra_args_array"].(string); ok && len(v) != 0 {
array, err := jsonToMapStringSlice(v)
if err != nil {
return rancher.ETCDService{}, err
}
obj.ExtraArgsArray = array
}

if v, ok := in["windows_extra_args_array"].(string); ok && len(v) != 0 {
array, err := jsonToMapStringSlice(v)
if err != nil {
return rancher.ETCDService{}, err
}
obj.WindowsExtraArgsArray = array
}

if v, ok := in["extra_binds"].([]interface{}); ok && len(v) > 0 {
obj.ExtraBinds = toArrayString(v)
}
Expand Down
41 changes: 31 additions & 10 deletions rke/structure_rke_cluster_services_etcd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,18 @@ func init() {
"arg_one": "one",
"arg_two": "two",
}
testRKEClusterServicesETCDConf.WindowsExtraArgs = map[string]string{
"arg_one": "one",
"arg_two": "two",
}
testRKEClusterServicesETCDConf.ExtraArgsArray = map[string][]string{
"arg1": {"v1", "v2"},
"arg2": {"v1", "v2"},
}
testRKEClusterServicesETCDConf.WindowsExtraArgsArray = map[string][]string{
"arg1": {"v1", "v2"},
"arg2": {"v1", "v2"},
}
testRKEClusterServicesETCDConf.ExtraBinds = []string{"bind_one", "bind_two"}
testRKEClusterServicesETCDConf.ExtraEnv = []string{"env_one", "env_two"}
testRKEClusterServicesETCDConf.Image = "image"
Expand All @@ -84,15 +96,21 @@ func init() {
"arg_one": "one",
"arg_two": "two",
},
"extra_binds": []interface{}{"bind_one", "bind_two"},
"extra_env": []interface{}{"env_one", "env_two"},
"gid": 1001,
"image": "image",
"key": "ZZZZZZZZ",
"path": "/etcd",
"retention": "6h",
"snapshot": true,
"uid": 1001,
"win_extra_args": map[string]interface{}{
"arg_one": "one",
"arg_two": "two",
},
"extra_args_array": "{\"arg1\":[\"v1\",\"v2\"],\"arg2\":[\"v1\",\"v2\"]}",
"windows_extra_args_array": "{\"arg1\":[\"v1\",\"v2\"],\"arg2\":[\"v1\",\"v2\"]}",
"extra_binds": []interface{}{"bind_one", "bind_two"},
"extra_env": []interface{}{"env_one", "env_two"},
"gid": 1001,
"image": "image",
"key": "ZZZZZZZZ",
"path": "/etcd",
"retention": "6h",
"snapshot": true,
"uid": 1001,
},
}
}
Expand Down Expand Up @@ -152,7 +170,10 @@ func TestFlattenRKEClusterServicesEtcd(t *testing.T) {
}

for _, tc := range cases {
output := flattenRKEClusterServicesEtcd(tc.Input, testRKEClusterServicesETCDInterface)
output, err := flattenRKEClusterServicesEtcd(tc.Input, testRKEClusterServicesETCDInterface)
if err != nil {
t.Fatalf("Unexpected error from flattener: %v", err)
}
if !reflect.DeepEqual(output, tc.ExpectedOutput) {
t.Fatalf("Unexpected output from flattener.\nExpected: %#v\nGiven: %#v",
tc.ExpectedOutput, output)
Expand Down
Loading

0 comments on commit e89d7d0

Please sign in to comment.