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

Add user data support to MKS #255

Merged
merged 3 commits into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -10,7 +10,7 @@ require (
github.com/selectel/dbaas-go v0.10.0
github.com/selectel/domains-go v1.0.2
github.com/selectel/go-selvpcclient/v3 v3.1.1
github.com/selectel/mks-go v0.12.0
github.com/selectel/mks-go v0.14.0
github.com/stretchr/testify v1.8.4
)

Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,8 @@ github.com/selectel/domains-go v1.0.2 h1:Si6iGaMnTFJxwiJVI50DOdZnwcxc87kqaWrVQYW
github.com/selectel/domains-go v1.0.2/go.mod h1:SugRKfq4sTpnOHquslCpzda72wV8u0cMBHx0C0l+bzA=
github.com/selectel/go-selvpcclient/v3 v3.1.1 h1:C1q2LqqosiapoLpnGITGmysg0YCSQYDo2Gh69CioevM=
github.com/selectel/go-selvpcclient/v3 v3.1.1/go.mod h1:NM7IXhh1IzqZ88DOw1Qc5Ez3tULLViXo95l5+rKPuyQ=
github.com/selectel/mks-go v0.12.0 h1:nLWHK8BXkhFlXvjFqf7WRrdAfvmrOhQzDSLx7BGa6aM=
github.com/selectel/mks-go v0.12.0/go.mod h1:FcFqF3WvZIhztyAt1+ZySKf0zWmCEvg9e2gRwxVyQOw=
github.com/selectel/mks-go v0.14.0 h1:huNq/oTutPc3ezB8HRqlGN9WJubTDETpNKuIVqcZOn0=
github.com/selectel/mks-go v0.14.0/go.mod h1:VxtV3dzwgOEzZc+9VMQb9DvxfSlej2ZQ8jnT8kqIGgU=
github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
github.com/sergi/go-diff v1.2.0 h1:XU+rvMAioB0UC3q1MFrIQy4Vo5/4VsRDQQXHsEya6xQ=
github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q=
Expand Down
7 changes: 7 additions & 0 deletions selectel/resource_selectel_mks_nodegroup_v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,11 @@ func resourceMKSNodegroupV1() *schema.Resource {
Computed: true,
RequiredWith: []string{"enable_autoscale", "autoscale_min_nodes"},
},
"user_data": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
yaroslaver marked this conversation as resolved.
Show resolved Hide resolved
},
"nodegroup_type": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -230,6 +235,7 @@ func resourceMKSNodegroupV1Create(ctx context.Context, d *schema.ResourceData, m
KeypairName: d.Get("keypair_name").(string),
AffinityPolicy: d.Get("affinity_policy").(string),
AvailabilityZone: d.Get("availability_zone").(string),
UserData: d.Get("user_data").(string),
}

projectQuotas, _, err := quotas.GetProjectQuotas(selvpcClient, projectID, region)
Expand Down Expand Up @@ -336,6 +342,7 @@ func resourceMKSNodegroupV1Read(ctx context.Context, d *schema.ResourceData, met
d.Set("autoscale_min_nodes", mksNodegroup.AutoscaleMinNodes)
d.Set("autoscale_max_nodes", mksNodegroup.AutoscaleMaxNodes)
d.Set("nodegroup_type", mksNodegroup.NodegroupType)
d.Set("user_data", mksNodegroup.UserData)

if err := d.Set("labels", mksNodegroup.Labels); err != nil {
log.Print(errSettingComplexAttr("labels", err))
Expand Down
8 changes: 6 additions & 2 deletions selectel/resource_selectel_mks_nodegroup_v1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (

func TestAccMKSNodegroupV1Basic(t *testing.T) {
var (
mksNodegroup nodegroup.View
mksNodegroup nodegroup.GetView
project projects.Project
)

Expand Down Expand Up @@ -45,6 +45,7 @@ func TestAccMKSNodegroupV1Basic(t *testing.T) {
resource.TestCheckResourceAttr("selectel_mks_nodegroup_v1.nodegroup_tf_acc_test_1", "enable_autoscale", "true"),
resource.TestCheckResourceAttr("selectel_mks_nodegroup_v1.nodegroup_tf_acc_test_1", "autoscale_min_nodes", "2"),
resource.TestCheckResourceAttr("selectel_mks_nodegroup_v1.nodegroup_tf_acc_test_1", "autoscale_max_nodes", "3"),
resource.TestCheckResourceAttr("selectel_mks_nodegroup_v1.nodegroup_tf_acc_test_1", "user_data", "IyEvYmluL2Jhc2ggLXYKYXB0IC15IHVwZGF0ZQphcHQgLXkgaW5zdGFsbCBtdHI="),
resource.TestCheckResourceAttr("selectel_mks_nodegroup_v1.nodegroup_tf_acc_test_1", "labels.label-key0", "label-value0"),
resource.TestCheckResourceAttr("selectel_mks_nodegroup_v1.nodegroup_tf_acc_test_1", "labels.label-key1", "label-value1"),
resource.TestCheckResourceAttr("selectel_mks_nodegroup_v1.nodegroup_tf_acc_test_1", "labels.label-key2", "label-value2"),
Expand Down Expand Up @@ -74,6 +75,7 @@ func TestAccMKSNodegroupV1Basic(t *testing.T) {
resource.TestCheckResourceAttr("selectel_mks_nodegroup_v1.nodegroup_tf_acc_test_1", "enable_autoscale", "false"),
resource.TestCheckResourceAttr("selectel_mks_nodegroup_v1.nodegroup_tf_acc_test_1", "autoscale_min_nodes", "1"),
resource.TestCheckResourceAttr("selectel_mks_nodegroup_v1.nodegroup_tf_acc_test_1", "autoscale_max_nodes", "4"),
resource.TestCheckResourceAttr("selectel_mks_nodegroup_v1.nodegroup_tf_acc_test_1", "user_data", "IyEvYmluL2Jhc2ggLXYKYXB0IC15IHVwZGF0ZQphcHQgLXkgaW5zdGFsbCBtdHI="),
resource.TestCheckResourceAttr("selectel_mks_nodegroup_v1.nodegroup_tf_acc_test_1", "labels.label-key3", "label-value3"),
resource.TestCheckResourceAttr("selectel_mks_nodegroup_v1.nodegroup_tf_acc_test_1", "labels.label-key4", "label-value4"),
resource.TestCheckResourceAttr("selectel_mks_nodegroup_v1.nodegroup_tf_acc_test_1", "taints.#", "3"),
Expand All @@ -93,7 +95,7 @@ func TestAccMKSNodegroupV1Basic(t *testing.T) {
})
}

func testAccCheckMKSNodegroupV1Exists(n string, mksNodegroup *nodegroup.View) resource.TestCheckFunc {
func testAccCheckMKSNodegroupV1Exists(n string, mksNodegroup *nodegroup.GetView) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[n]
if !ok {
Expand Down Expand Up @@ -157,6 +159,7 @@ resource "selectel_mks_nodegroup_v1" "nodegroup_tf_acc_test_1" {
enable_autoscale = true
autoscale_min_nodes = 2
autoscale_max_nodes = 3
user_data = "IyEvYmluL2Jhc2ggLXYKYXB0IC15IHVwZGF0ZQphcHQgLXkgaW5zdGFsbCBtdHI="
labels = {
label-key0 = "label-value0"
label-key1 = "label-value1"
Expand Down Expand Up @@ -207,6 +210,7 @@ resource "selectel_mks_nodegroup_v1" "nodegroup_tf_acc_test_1" {
enable_autoscale = false
autoscale_min_nodes = 1
autoscale_max_nodes = 4
user_data = "IyEvYmluL2Jhc2ggLXYKYXB0IC15IHVwZGF0ZQphcHQgLXkgaW5zdGFsbCBtdHI="
labels = {
label-key3 = "label-value3"
label-key4 = "label-value4"
Expand Down
2 changes: 2 additions & 0 deletions website/docs/r/mks_nodegroup_v1.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ resource "selectel_mks_nodegroup_v1" "nodegroup_1" {

* `keypair_name` (Optional) Name of the SSH key added to all nodes. Changing this creates a new node group.

* `user_data` (Optional) Base64 data which is used to pass a script that worker nodes run on boot. Changing this creates a new node group.
yaroslaver marked this conversation as resolved.
Show resolved Hide resolved

* `affinity_policy` (Optional) Specifies affinity policy of the nodes. Changing this creates a new node group. Available values are `soft-anti-affinity` and `soft-affinity`. The default value is `soft-anti-affinity`. For more information about affinity and anti-affinity, see the [official Kubernetes documentation](https://kubernetes.io/docs/concepts/scheduling-eviction/assign-pod-node/#affinity-and-anti-affinity).

* `enable_autoscale` (Optional) Enables or disables autoscaling of the node group. Boolean flag, the default value is false. `autoscale_min_nodes` and `autoscale_max_nodes` must be specified. Learn more about [Autoscaling](https://docs.selectel.ru/cloud/managed-kubernetes/node-groups/cluster-autoscaler/).
Expand Down
Loading