Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MKS Cluster v1: add "enable_pod_security_policy" option #115

Merged
merged 3 commits into from
Aug 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ require (
github.com/hashicorp/terraform-plugin-sdk v1.13.0
github.com/selectel/domains-go v0.2.0
github.com/selectel/go-selvpcclient v1.12.0
github.com/selectel/mks-go v0.4.0
github.com/selectel/mks-go v0.5.0
github.com/stretchr/testify v1.5.1
)
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,8 @@ github.com/selectel/domains-go v0.2.0 h1:UBm6tc45sXsziqG7MirfHxaoMf3yYpFb2vx3Gyg
github.com/selectel/domains-go v0.2.0/go.mod h1:aDinK5D/zztY4VhoqQgYaaOnU6hqjBcszUOgAe0kPYs=
github.com/selectel/go-selvpcclient v1.12.0 h1:LsT074HOVF1dWYapsAWjaaJDQhmDPpcsVjSwQ1r1fj0=
github.com/selectel/go-selvpcclient v1.12.0/go.mod h1:HNteVXevZMjUCRR6lImTsGZZSTeKu89S/qbEDWDqmgc=
github.com/selectel/mks-go v0.4.0 h1:zHY+eG+k8S8Jrfv8/nLUFDQSLR93usnhTcorsS54FTU=
github.com/selectel/mks-go v0.4.0/go.mod h1:OrlLnGes+HK7HNxUab/8Rll5iT0XQQnx4+dW1Ysph2o=
github.com/selectel/mks-go v0.5.0 h1:BqEi/XxvmNpE14gBwmLx4ArvvuU1YSBvD0opzolh9pw=
github.com/selectel/mks-go v0.5.0/go.mod h1:OrlLnGes+HK7HNxUab/8Rll5iT0XQQnx4+dW1Ysph2o=
github.com/sergi/go-diff v1.0.0 h1:Kpca3qRNrduNnOQeazBd0ysaKrUJiIuISHxogkT9RPQ=
github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
github.com/spf13/afero v1.2.2 h1:5jhuqJyZCZf2JRofRvN/nIFgIWNzPa3/Vz8mYylgbWc=
Expand Down
17 changes: 17 additions & 0 deletions selectel/resource_selectel_mks_cluster_v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@ func resourceMKSClusterV1() *schema.Resource {
Default: true,
ForceNew: false,
},
"enable_pod_security_policy": {
Type: schema.TypeBool,
Optional: true,
Default: false,
ForceNew: false,
},
"network_id": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -142,6 +148,7 @@ func resourceMKSClusterV1Create(d *schema.ResourceData, meta interface{}) error
// Prepare cluster create options.
enableAutorepair := d.Get("enable_autorepair").(bool)
enablePatchVersionAutoUpgrade := d.Get("enable_patch_version_auto_upgrade").(bool)
enablePodSecurityPolicy := d.Get("enable_pod_security_policy").(bool)
createOpts := &cluster.CreateOpts{
Name: d.Get("name").(string),
NetworkID: d.Get("network_id").(string),
Expand All @@ -151,6 +158,9 @@ func resourceMKSClusterV1Create(d *schema.ResourceData, meta interface{}) error
EnableAutorepair: &enableAutorepair,
EnablePatchVersionAutoUpgrade: &enablePatchVersionAutoUpgrade,
Region: region,
KubernetesOptions: &cluster.KubernetesOptions{
EnablePodSecurityPolicy: enablePodSecurityPolicy,
},
}

log.Print(msgCreate(objectCluster, createOpts))
Expand Down Expand Up @@ -214,6 +224,7 @@ func resourceMKSClusterV1Read(d *schema.ResourceData, meta interface{}) error {
d.Set("maintenance_window_end", mksCluster.MaintenanceWindowEnd)
d.Set("enable_autorepair", mksCluster.EnableAutorepair)
d.Set("enable_patch_version_auto_upgrade", mksCluster.EnablePatchVersionAutoUpgrade)
d.Set("enable_pod_security_policy", mksCluster.KubernetesOptions.EnablePodSecurityPolicy)

return nil
}
Expand Down Expand Up @@ -254,6 +265,12 @@ func resourceMKSClusterV1Update(d *schema.ResourceData, meta interface{}) error
v := d.Get("enable_patch_version_auto_upgrade").(bool)
updateOpts.EnablePatchVersionAutoUpgrade = &v
}
if d.HasChange("enable_pod_security_policy") {
v := d.Get("enable_pod_security_policy").(bool)
updateOpts.KubernetesOptions = &cluster.KubernetesOptions{
EnablePodSecurityPolicy: v,
}
}

if updateOpts != (cluster.UpdateOpts{}) {
log.Print(msgUpdate(objectCluster, d.Id(), updateOpts))
Expand Down
2 changes: 2 additions & 0 deletions selectel/resource_selectel_mks_cluster_v1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ func TestAccMKSClusterV1Basic(t *testing.T) {
resource.TestCheckResourceAttr("selectel_mks_cluster_v1.cluster_tf_acc_test_1", "region", "ru-3"),
resource.TestCheckResourceAttr("selectel_mks_cluster_v1.cluster_tf_acc_test_1", "enable_autorepair", "false"),
resource.TestCheckResourceAttr("selectel_mks_cluster_v1.cluster_tf_acc_test_1", "enable_patch_version_auto_upgrade", "false"),
resource.TestCheckResourceAttr("selectel_mks_cluster_v1.cluster_tf_acc_test_1", "enable_pod_security_policy", "false"),
resource.TestCheckResourceAttr("selectel_mks_cluster_v1.cluster_tf_acc_test_1", "maintenance_window_start", "02:00:00"),
resource.TestCheckResourceAttr("selectel_mks_cluster_v1.cluster_tf_acc_test_1", "maintenance_window_end", "04:00:00"),
resource.TestCheckResourceAttr("selectel_mks_cluster_v1.cluster_tf_acc_test_1", "status", "ACTIVE"),
Expand Down Expand Up @@ -208,5 +209,6 @@ resource "selectel_mks_cluster_v1" "cluster_tf_acc_test_1" {
maintenance_window_start = "02:00:00"
enable_autorepair = false
enable_patch_version_auto_upgrade = false
enable_pod_security_policy = false
}`, projectName, clusterName, kubeVersion)
}
3 changes: 3 additions & 0 deletions vendor/github.com/selectel/mks-go/pkg/v1/cluster/doc.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions vendor/github.com/selectel/mks-go/pkg/v1/cluster/requests_opts.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions vendor/github.com/selectel/mks-go/pkg/v1/cluster/schemas.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ github.com/selectel/go-selvpcclient/selvpcclient/resell/v2/subnets
github.com/selectel/go-selvpcclient/selvpcclient/resell/v2/tokens
github.com/selectel/go-selvpcclient/selvpcclient/resell/v2/users
github.com/selectel/go-selvpcclient/selvpcclient/resell/v2/vrrpsubnets
# github.com/selectel/mks-go v0.4.0
# github.com/selectel/mks-go v0.5.0
## explicit
github.com/selectel/mks-go/pkg/v1
github.com/selectel/mks-go/pkg/v1/cluster
Expand Down
3 changes: 3 additions & 0 deletions website/docs/r/mks_cluster_v1.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ The following arguments are supported:
will start its maintenance tasks.
Changing this updates maintenance window start time.

* `enable_pod_security_policy` - (Optional) Specifies if PodSecurityPolicy Kubernetes option has to be turned on/off.
Accepts true or false. Default is false.

## Attributes Reference

The following attributes are exported:
Expand Down