Skip to content

Commit

Permalink
Merge pull request #1 from adRise/extra_args_array
Browse files Browse the repository at this point in the history
Add extra_args_array Field rancher#1209
  • Loading branch information
hchen-tubi authored Feb 4, 2024
2 parents 6401180 + f1d3242 commit 61f6d25
Show file tree
Hide file tree
Showing 16 changed files with 259 additions and 6 deletions.
6 changes: 6 additions & 0 deletions docs/resources/cluster.md
Original file line number Diff line number Diff line change
Expand Up @@ -1227,6 +1227,7 @@ The following attributes are exported:
* `creation` - (Optional/Computed) Creation option for etcd service (string)
* `external_urls` - (Optional) External urls for etcd service (list)
* `extra_args` - (Optional/Computed) Extra arguments for etcd service (map)
* `extra_args_array` - (Optional/Computed) Extra arguments array for etcd service (list)
* `extra_binds` - (Optional) Extra binds for etcd service (list)
* `extra_env` - (Optional) Extra environment for etcd service (list)
* `gid` - (Optional) Etcd service GID. Default: `0`. For Rancher v2.3.x and above (int)
Expand Down Expand Up @@ -1269,6 +1270,7 @@ The following attributes are exported:
* `audit_log` - (Optional) K8s audit log configuration. (list maxitems: 1)
* `event_rate_limit` - (Optional) K8s event rate limit configuration. (list maxitems: 1)
* `extra_args` - (Optional/Computed) Extra arguments for kube API service (map)
* `extra_args_array` - (Optional/Computed) Extra arguments array for kube API service (list)
* `extra_binds` - (Optional) Extra binds for kube API service (list)
* `extra_env` - (Optional) Extra environment for kube API service (list)
* `image` - (Optional/Computed) Docker image for kube API service (string)
Expand Down Expand Up @@ -1391,6 +1393,7 @@ EOF

* `cluster_cidr` - (Optional/Computed) Cluster CIDR option for kube controller service (string)
* `extra_args` - (Optional/Computed) Extra arguments for kube controller service (map)
* `extra_args_array` - (Optional/Computed) Extra arguments array for kube controller service (list)
* `extra_binds` - (Optional) Extra binds for kube controller service (list)
* `extra_env` - (Optional) Extra environment for kube controller service (list)
* `image` - (Optional/Computed) Docker image for kube controller service (string)
Expand All @@ -1403,6 +1406,7 @@ EOF
* `cluster_dns_server` - (Optional/Computed) Cluster DNS Server option for kubelet service (string)
* `cluster_domain` - (Optional/Computed) Cluster Domain option for kubelet service (string)
* `extra_args` - (Optional/Computed) Extra arguments for kubelet service (map)
* `extra_args_array` - (Optional/Computed) Extra arguments array for kubelet service (list)
* `extra_binds` - (Optional) Extra binds for kubelet service (list)
* `extra_env` - (Optional) Extra environment for kubelet service (list)
* `fail_swap_on` - (Optional/Computed) Enable or disable failing when swap on is not supported (bool)
Expand All @@ -1415,6 +1419,7 @@ EOF
###### Arguments

* `extra_args` - (Optional/Computed) Extra arguments for kubeproxy service (map)
* `extra_args_array` - (Optional/Computed) Extra arguments array for kubeproxy service (list)
* `extra_binds` - (Optional) Extra binds for kubeproxy service (list)
* `extra_env` - (Optional) Extra environment for kubeproxy service (list)
* `image` - (Optional/Computed) Docker image for kubeproxy service (string)
Expand All @@ -1424,6 +1429,7 @@ EOF
###### Arguments

* `extra_args` - (Optional/Computed) Extra arguments for scheduler service (map)
* `extra_args_array` - (Optional/Computed) Extra arguments array for scheduler service (list)
* `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)
Expand Down
23 changes: 23 additions & 0 deletions rancher2/schema_cluster_rke_config_services.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,3 +186,26 @@ func clusterRKEConfigServicesFieldsData() map[string]*schema.Schema {
}
return s
}

func clusterRKEConfigServicesExtraArgsArrayFields() map[string]*schema.Schema {
return map[string]*schema.Schema{
"name": {
Required: true,
Type: schema.TypeString,
},
"value": {
Type: schema.TypeList,
Required: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
}
}

func clusterRKEConfigServicesExtraArgsArraySchemaSetFunc(v interface{}) int {
resource := &schema.Resource{
Schema: clusterRKEConfigServicesExtraArgsArrayFields(),
}
return schema.HashResource(resource)(v)
}
8 changes: 8 additions & 0 deletions rancher2/schema_cluster_rke_config_services_etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,14 @@ func clusterRKEConfigServicesEtcdFields() map[string]*schema.Schema {
Optional: true,
Computed: true,
},
"extra_args_array": {
Type: schema.TypeSet,
Optional: true,
Elem: &schema.Resource{
Schema: clusterRKEConfigServicesExtraArgsArrayFields(),
},
Set: clusterRKEConfigServicesExtraArgsArraySchemaSetFunc,
},
"extra_binds": {
Type: schema.TypeList,
Optional: true,
Expand Down
24 changes: 24 additions & 0 deletions rancher2/schema_cluster_rke_config_services_kube_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,14 @@ func clusterRKEConfigServicesKubeAPIFieldsV0() map[string]*schema.Schema {
Optional: true,
Computed: true,
},
"extra_args_array": {
Type: schema.TypeSet,
Optional: true,
Elem: &schema.Resource{
Schema: clusterRKEConfigServicesExtraArgsArrayFields(),
},
Set: clusterRKEConfigServicesExtraArgsArraySchemaSetFunc,
},
"extra_binds": {
Type: schema.TypeList,
Optional: true,
Expand Down Expand Up @@ -600,6 +608,14 @@ func clusterRKEConfigServicesKubeAPIFields() map[string]*schema.Schema {
Optional: true,
Computed: true,
},
"extra_args_array": {
Type: schema.TypeSet,
Optional: true,
Elem: &schema.Resource{
Schema: clusterRKEConfigServicesExtraArgsArrayFields(),
},
Set: clusterRKEConfigServicesExtraArgsArraySchemaSetFunc,
},
"extra_binds": {
Type: schema.TypeList,
Optional: true,
Expand Down Expand Up @@ -684,6 +700,14 @@ func clusterRKEConfigServicesKubeAPIFieldsData() map[string]*schema.Schema {
Optional: true,
Computed: true,
},
"extra_args_array": {
Type: schema.TypeSet,
Optional: true,
Elem: &schema.Resource{
Schema: clusterRKEConfigServicesExtraArgsArrayFields(),
},
Set: clusterRKEConfigServicesExtraArgsArraySchemaSetFunc,
},
"extra_binds": {
Type: schema.TypeList,
Optional: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ func clusterRKEConfigServicesKubeControllerFields() map[string]*schema.Schema {
Optional: true,
Computed: true,
},
"extra_args_array": {
Type: schema.TypeSet,
Optional: true,
Elem: &schema.Resource{
Schema: clusterRKEConfigServicesExtraArgsArrayFields(),
},
Set: clusterRKEConfigServicesExtraArgsArraySchemaSetFunc,
},
"extra_binds": {
Type: schema.TypeList,
Optional: true,
Expand Down
8 changes: 8 additions & 0 deletions rancher2/schema_cluster_rke_config_services_kubelet.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ func clusterRKEConfigServicesKubeletFields() map[string]*schema.Schema {
Optional: true,
Computed: true,
},
"extra_args_array": {
Type: schema.TypeSet,
Optional: true,
Elem: &schema.Resource{
Schema: clusterRKEConfigServicesExtraArgsArrayFields(),
},
Set: clusterRKEConfigServicesExtraArgsArraySchemaSetFunc,
},
"extra_binds": {
Type: schema.TypeList,
Optional: true,
Expand Down
8 changes: 8 additions & 0 deletions rancher2/schema_cluster_rke_config_services_kubeproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ func clusterRKEConfigServicesKubeproxyFields() map[string]*schema.Schema {
Optional: true,
Computed: true,
},
"extra_args_array": {
Type: schema.TypeSet,
Optional: true,
Elem: &schema.Resource{
Schema: clusterRKEConfigServicesExtraArgsArrayFields(),
},
Set: clusterRKEConfigServicesExtraArgsArraySchemaSetFunc,
},
"extra_binds": {
Type: schema.TypeList,
Optional: true,
Expand Down
8 changes: 8 additions & 0 deletions rancher2/schema_cluster_rke_config_services_scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ func clusterRKEConfigServicesSchedulerFields() map[string]*schema.Schema {
Optional: true,
Computed: true,
},
"extra_args_array": {
Type: schema.TypeSet,
Optional: true,
Elem: &schema.Resource{
Schema: clusterRKEConfigServicesExtraArgsArrayFields(),
},
Set: clusterRKEConfigServicesExtraArgsArraySchemaSetFunc,
},
"extra_binds": {
Type: schema.TypeList,
Optional: true,
Expand Down
9 changes: 9 additions & 0 deletions rancher2/structure_cluster_rke_config_services_etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package rancher2
import (
"fmt"

"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3"
)

Expand Down Expand Up @@ -123,6 +124,10 @@ func flattenClusterRKEConfigServicesEtcd(in *managementClient.ETCDService, p []i
obj["extra_args"] = toMapInterface(in.ExtraArgs)
}

if len(in.ExtraArgsArray) > 0 {
obj["extra_args_array"] = flattenExtraArgsArray(in.ExtraArgsArray)
}

if len(in.ExtraBinds) > 0 {
obj["extra_binds"] = toArrayInterface(in.ExtraBinds)
}
Expand Down Expand Up @@ -277,6 +282,10 @@ func expandClusterRKEConfigServicesEtcd(p []interface{}) (*managementClient.ETCD
obj.ExtraArgs = toMapString(v)
}

if v, ok := in["extra_args_array"].(*schema.Set); ok && len(v.List()) > 0 {
obj.ExtraArgsArray = expandExtraArgsArray(v)
}

if v, ok := in["extra_binds"].([]interface{}); ok && len(v) > 0 {
obj.ExtraBinds = toArrayString(v)
}
Expand Down
66 changes: 60 additions & 6 deletions rancher2/structure_cluster_rke_config_services_etcd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,20 @@ package rancher2
import (
"testing"

"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3"
"github.com/stretchr/testify/assert"
)

var (
testClusterRKEConfigServicesETCDBackupS3Conf *managementClient.S3BackupConfig
testClusterRKEConfigServicesETCDBackupS3Interface []interface{}
testClusterRKEConfigServicesETCDBackupConf *managementClient.BackupConfig
testClusterRKEConfigServicesETCDBackupInterface []interface{}
testClusterRKEConfigServicesETCDConf *managementClient.ETCDService
testClusterRKEConfigServicesETCDInterface []interface{}
testClusterRKEConfigServicesETCDBackupS3Conf *managementClient.S3BackupConfig
testClusterRKEConfigServicesETCDBackupS3Interface []interface{}
testClusterRKEConfigServicesETCDBackupConf *managementClient.BackupConfig
testClusterRKEConfigServicesETCDBackupInterface []interface{}
testClusterRKEConfigServicesETCDExtraArgsArrayConf map[string][]string
testClusterRKEConfigServicesETCDExtraArgsArrayInterface *schema.Set
testClusterRKEConfigServicesETCDConf *managementClient.ETCDService
testClusterRKEConfigServicesETCDInterface []interface{}
)

func init() {
Expand Down Expand Up @@ -53,6 +56,23 @@ func init() {
"timeout": 500,
},
}
testClusterRKEConfigServicesETCDExtraArgsArrayConf = map[string][]string{
"arg1": {"v1"},
"arg2": {"v2"},
}
testClusterRKEConfigServicesETCDExtraArgsArrayInterface = schema.NewSet(
clusterRKEConfigServicesExtraArgsArraySchemaSetFunc,
[]interface{}{
map[string]interface{}{
"name": "arg1",
"value": []interface{}{"v1"},
},
map[string]interface{}{
"name": "arg2",
"value": []interface{}{"v2"},
},
},
)
testClusterRKEConfigServicesETCDConf = &managementClient.ETCDService{
BackupConfig: testClusterRKEConfigServicesETCDBackupConf,
CACert: "XXXXXXXX",
Expand Down Expand Up @@ -132,6 +152,23 @@ func TestFlattenClusterRKEConfigServicesEtcdBackupConfig(t *testing.T) {
}
}

func TestFlattenClusterRKEConfigServicesEtcdExtraArgsArray(t *testing.T) {

cases := []struct {
Input map[string][]string
ExpectedOutput *schema.Set
}{
{
testClusterRKEConfigServicesETCDExtraArgsArrayConf,
testClusterRKEConfigServicesETCDExtraArgsArrayInterface,
},
}
for _, tc := range cases {
output := flattenExtraArgsArray(tc.Input)
assert.ElementsMatch(t, tc.ExpectedOutput.List(), output.List(), "Unexpected output from flattener.")
}
}

func TestFlattenClusterRKEConfigServicesEtcd(t *testing.T) {

cases := []struct {
Expand Down Expand Up @@ -192,6 +229,23 @@ func TestExpandClusterRKEConfigServicesEtcdBackupConfig(t *testing.T) {
}
}

func TestExpandClusterRKEConfigServicesEtcdExtraArgsArrayConfig(t *testing.T) {

cases := []struct {
Input *schema.Set
ExpectedOutput map[string][]string
}{
{
testClusterRKEConfigServicesETCDExtraArgsArrayInterface,
testClusterRKEConfigServicesETCDExtraArgsArrayConf,
},
}
for _, tc := range cases {
output := expandExtraArgsArray(tc.Input)
assert.Equal(t, tc.ExpectedOutput, output, "Unexpected output from expander.")
}
}

func TestExpandClusterRKEConfigServicesEtcd(t *testing.T) {

cases := []struct {
Expand Down
9 changes: 9 additions & 0 deletions rancher2/structure_cluster_rke_config_services_kube_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package rancher2
import (
"fmt"

"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3"
)

Expand Down Expand Up @@ -167,6 +168,10 @@ func flattenClusterRKEConfigServicesKubeAPI(in *managementClient.KubeAPIService)
obj["extra_args"] = toMapInterface(in.ExtraArgs)
}

if len(in.ExtraArgsArray) > 0 {
obj["extra_args_array"] = flattenExtraArgsArray(in.ExtraArgsArray)
}

if len(in.ExtraBinds) > 0 {
obj["extra_binds"] = toArrayInterface(in.ExtraBinds)
}
Expand Down Expand Up @@ -392,6 +397,10 @@ func expandClusterRKEConfigServicesKubeAPI(p []interface{}) (*managementClient.K
obj.ExtraArgs = toMapString(v)
}

if v, ok := in["extra_args_array"].(*schema.Set); ok && len(v.List()) > 0 {
obj.ExtraArgsArray = expandExtraArgsArray(v)
}

if v, ok := in["extra_binds"].([]interface{}); ok && len(v) > 0 {
obj.ExtraBinds = toArrayString(v)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package rancher2

import (
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3"
)

Expand All @@ -20,6 +21,10 @@ func flattenClusterRKEConfigServicesKubeController(in *managementClient.KubeCont
obj["extra_args"] = toMapInterface(in.ExtraArgs)
}

if len(in.ExtraArgsArray) > 0 {
obj["extra_args_array"] = flattenExtraArgsArray(in.ExtraArgsArray)
}

if len(in.ExtraBinds) > 0 {
obj["extra_binds"] = toArrayInterface(in.ExtraBinds)
}
Expand Down Expand Up @@ -56,6 +61,10 @@ func expandClusterRKEConfigServicesKubeController(p []interface{}) (*managementC
obj.ExtraArgs = toMapString(v)
}

if v, ok := in["extra_args_array"].(*schema.Set); ok && len(v.List()) > 0 {
obj.ExtraArgsArray = expandExtraArgsArray(v)
}

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

0 comments on commit 61f6d25

Please sign in to comment.