Skip to content

Commit

Permalink
Merge pull request rancher#39 from rawmind0/cluster
Browse files Browse the repository at this point in the history
Added scheduler argument to services-rke_config argument on rancher2_cluster resource
  • Loading branch information
rawmind0 authored Jun 24, 2019
2 parents 57dc9c1 + 4007a51 commit 2065c27
Show file tree
Hide file tree
Showing 5 changed files with 142 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ FEATURES:

ENHANCEMENTS:

* Added `scheduler` argument to `services`-`rke_config` argument on `rancher2_cluster` resource

BUG FIXES:

* Fix: index out of range issue on `vsphere_cloud_provider`-`cloud_provider`-`rke_config` argument on `rancher2_cluster` resource
Expand Down
39 changes: 39 additions & 0 deletions rancher2/schema_cluster_rke_config_services.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,36 @@ import (

//Schemas

func clusterRKEConfigServicesSchedulerFields() map[string]*schema.Schema {
s := map[string]*schema.Schema{
"extra_args": {
Type: schema.TypeMap,
Optional: true,
Computed: true,
},
"extra_binds": {
Type: schema.TypeList,
Optional: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"extra_env": {
Type: schema.TypeList,
Optional: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"image": {
Type: schema.TypeString,
Optional: true,
Computed: true,
},
}
return s
}

func clusterRKEConfigServicesKubeproxyFields() map[string]*schema.Schema {
s := map[string]*schema.Schema{
"extra_args": {
Expand Down Expand Up @@ -358,6 +388,15 @@ func clusterRKEConfigServicesFields() map[string]*schema.Schema {
Schema: clusterRKEConfigServicesKubeproxyFields(),
},
},
"scheduler": {
Type: schema.TypeList,
MaxItems: 1,
Optional: true,
Computed: true,
Elem: &schema.Resource{
Schema: clusterRKEConfigServicesSchedulerFields(),
},
},
}
return s
}
67 changes: 67 additions & 0 deletions rancher2/structure_cluster_rke_config_services.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,31 @@ import (

// Flatteners

func flattenClusterRKEConfigServicesScheduler(in *managementClient.SchedulerService) ([]interface{}, error) {
obj := make(map[string]interface{})
if in == nil {
return []interface{}{}, nil
}

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

if len(in.ExtraBinds) > 0 {
obj["extra_binds"] = toArrayInterface(in.ExtraBinds)
}

if len(in.ExtraEnv) > 0 {
obj["extra_env"] = toArrayInterface(in.ExtraEnv)
}

if len(in.Image) > 0 {
obj["image"] = in.Image
}

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

func flattenClusterRKEConfigServicesKubeproxy(in *managementClient.KubeproxyService) ([]interface{}, error) {
obj := make(map[string]interface{})
if in == nil {
Expand Down Expand Up @@ -320,11 +345,45 @@ func flattenClusterRKEConfigServices(in *managementClient.RKEConfigServices, p [
obj["kubeproxy"] = kubeproxy
}

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

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

// Expanders

func expandClusterRKEConfigServicesScheduler(p []interface{}) (*managementClient.SchedulerService, error) {
obj := &managementClient.SchedulerService{}
if len(p) == 0 || p[0] == nil {
return obj, nil
}
in := p[0].(map[string]interface{})

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

if v, ok := in["extra_binds"].([]interface{}); ok && len(v) > 0 {
obj.ExtraBinds = toArrayString(v)
}

if v, ok := in["extra_env"].([]interface{}); ok && len(v) > 0 {
obj.ExtraEnv = toArrayString(v)
}

if v, ok := in["image"].(string); ok && len(v) > 0 {
obj.Image = v
}

return obj, nil
}

func expandClusterRKEConfigServicesKubeproxy(p []interface{}) (*managementClient.KubeproxyService, error) {
obj := &managementClient.KubeproxyService{}
if len(p) == 0 || p[0] == nil {
Expand Down Expand Up @@ -630,5 +689,13 @@ func expandClusterRKEConfigServices(p []interface{}) (*managementClient.RKEConfi
obj.Kubeproxy = kubeproxy
}

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

return obj, nil
}
24 changes: 24 additions & 0 deletions rancher2/structure_cluster_rke_config_services_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
)

var (
testClusterRKEConfigServicesSchedulerConf *managementClient.SchedulerService
testClusterRKEConfigServicesSchedulerInterface []interface{}
testClusterRKEConfigServicesKubeproxyConf *managementClient.KubeproxyService
testClusterRKEConfigServicesKubeproxyInterface []interface{}
testClusterRKEConfigServicesKubeletConf *managementClient.KubeletService
Expand All @@ -27,6 +29,26 @@ var (
)

func init() {
testClusterRKEConfigServicesSchedulerConf = &managementClient.SchedulerService{
ExtraArgs: map[string]string{
"arg_one": "one",
"arg_two": "two",
},
ExtraBinds: []string{"bind_one", "bind_two"},
ExtraEnv: []string{"env_one", "env_two"},
Image: "image",
}
testClusterRKEConfigServicesSchedulerInterface = []interface{}{
map[string]interface{}{
"extra_args": map[string]interface{}{
"arg_one": "one",
"arg_two": "two",
},
"extra_binds": []interface{}{"bind_one", "bind_two"},
"extra_env": []interface{}{"env_one", "env_two"},
"image": "image",
},
}
testClusterRKEConfigServicesKubeproxyConf = &managementClient.KubeproxyService{
ExtraArgs: map[string]string{
"arg_one": "one",
Expand Down Expand Up @@ -197,6 +219,7 @@ func init() {
KubeController: testClusterRKEConfigServicesKubeControllerConf,
Kubelet: testClusterRKEConfigServicesKubeletConf,
Kubeproxy: testClusterRKEConfigServicesKubeproxyConf,
Scheduler: testClusterRKEConfigServicesSchedulerConf,
}
testClusterRKEConfigServicesInterface = []interface{}{
map[string]interface{}{
Expand All @@ -205,6 +228,7 @@ func init() {
"kube_controller": testClusterRKEConfigServicesKubeControllerInterface,
"kubelet": testClusterRKEConfigServicesKubeletInterface,
"kubeproxy": testClusterRKEConfigServicesKubeproxyInterface,
"scheduler": testClusterRKEConfigServicesSchedulerInterface,
},
}
}
Expand Down
10 changes: 10 additions & 0 deletions website/docs/r/cluster.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,7 @@ The following attributes are exported:
* `kube_controller` - (Optional/Computed) Kube Controller options for RKE services (list maxitems:1)
* `kubelet` - (Optional/Computed) Kubelet options for RKE services (list maxitems:1)
* `kubeproxy` - (Optional/Computed) Kubeproxy options for RKE services (list maxitems:1)
* `scheduler` - (Optional/Computed) Scheduler options for RKE services (list maxitems:1)

##### `etcd`

Expand Down Expand Up @@ -528,6 +529,15 @@ The following attributes are exported:
* `extra_env` - (Optional) Extra environment for kubeproxy service (list)
* `image` - (Optional/Computed) Docker image for kubeproxy service (string)

##### `scheduler`

###### Arguments

* `extra_args` - (Optional/Computed) Extra arguments for scheduler service (map)
* `extra_binds` - (Optional) Extra binds for scheduler service (list)
* `extra_env` - (Optional) Extra environment for scheduler service (list)
* `image` - (Optional/Computed) Docker image for scheduler service (string)

### `aks_config`

#### Arguments
Expand Down

0 comments on commit 2065c27

Please sign in to comment.