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 handling for private kube API clusters #204

Merged
merged 4 commits into from
Aug 9, 2022
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 @@ -8,7 +8,7 @@ require (
github.com/selectel/dbaas-go v0.5.0
github.com/selectel/domains-go v0.3.0
github.com/selectel/go-selvpcclient v1.12.0
github.com/selectel/mks-go v0.11.0
github.com/selectel/mks-go v0.12.0
github.com/stretchr/testify v1.7.0
)

Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -295,8 +295,8 @@ github.com/selectel/domains-go v0.3.0 h1:0shjqQmpkWc6eM1SwgKqbTTNiT5G2BOEnvS7Jvu
github.com/selectel/domains-go v0.3.0/go.mod h1:AhXhwyMSTkpEWFiBLUvzFP76W+WN+ZblwmjLJLt7y58=
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.11.0 h1:O56dHiLVmw84kC2cXoDRDBO7OxOD+KzasvT+BAsjRjg=
github.com/selectel/mks-go v0.11.0/go.mod h1:FcFqF3WvZIhztyAt1+ZySKf0zWmCEvg9e2gRwxVyQOw=
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/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
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=
Expand Down
11 changes: 10 additions & 1 deletion selectel/resource_selectel_mks_cluster_v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,12 @@ func resourceMKSClusterV1() *schema.Resource {
},
Set: schema.HashString,
},
"private_kube_api": {
Type: schema.TypeBool,
Optional: true,
Default: false,
ForceNew: true,
},
},
}
}
Expand All @@ -178,6 +184,7 @@ func resourceMKSClusterV1Create(ctx context.Context, d *schema.ResourceData, met
enablePatchVersionAutoUpgrade := d.Get("enable_patch_version_auto_upgrade").(bool)
enablePodSecurityPolicy := d.Get("enable_pod_security_policy").(bool)
zonal := d.Get("zonal").(bool)
privateKubeAPI := d.Get("private_kube_api").(bool)

// Check if "enable_patch_version_auto_upgrade" and "zonal" arguments are both not set to true.
if enablePatchVersionAutoUpgrade && zonal {
Expand Down Expand Up @@ -209,7 +216,8 @@ func resourceMKSClusterV1Create(ctx context.Context, d *schema.ResourceData, met
FeatureGates: featureGates,
AdmissionControllers: admissionControllers,
},
Zonal: &zonal,
Zonal: &zonal,
PrivateKubeAPI: &privateKubeAPI,
}

projectQuotas, _, err := quotas.GetProjectQuotas(ctx, resellV2Client, d.Get("project_id").(string))
Expand Down Expand Up @@ -283,6 +291,7 @@ func resourceMKSClusterV1Read(ctx context.Context, d *schema.ResourceData, meta
d.Set("enable_patch_version_auto_upgrade", mksCluster.EnablePatchVersionAutoUpgrade)
d.Set("enable_pod_security_policy", mksCluster.KubernetesOptions.EnablePodSecurityPolicy)
d.Set("zonal", mksCluster.Zonal)
d.Set("private_kube_api", mksCluster.PrivateKubeAPI)

return nil
}
Expand Down
55 changes: 55 additions & 0 deletions selectel/resource_selectel_mks_cluster_v1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,43 @@ func TestAccMKSClusterV1Zonal(t *testing.T) {
resource.TestCheckResourceAttr("selectel_mks_cluster_v1.cluster_tf_acc_test_1", "enable_autorepair", "true"),
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", "zonal", "true"),
resource.TestCheckResourceAttr("selectel_mks_cluster_v1.cluster_tf_acc_test_1", "private_kube_api", "false"),
resource.TestCheckResourceAttr("selectel_mks_cluster_v1.cluster_tf_acc_test_1", "maintenance_window_start", maintenanceWindowStart),
resource.TestCheckResourceAttr("selectel_mks_cluster_v1.cluster_tf_acc_test_1", "status", "ACTIVE"),
),
},
},
})
}

func TestAccMKSClusterV1PrivateKubeAPI(t *testing.T) {
var (
mksCluster cluster.View
project projects.Project
)

projectName := acctest.RandomWithPrefix("tf-acc")
clusterName := acctest.RandomWithPrefix("tf-acc-cl")
kubeVersion := testAccMKSClusterV1GetDefaultKubeVersion(t)
maintenanceWindowStart := testAccMKSClusterV1GetMaintenanceWindowStart(12 * time.Hour)

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccSelectelPreCheck(t) },
ProviderFactories: testAccProviders,
CheckDestroy: testAccCheckVPCV2ProjectDestroy,
Steps: []resource.TestStep{
{
Config: testAccMKSClusterV1PrivateKubeAPI(projectName, clusterName, kubeVersion, maintenanceWindowStart),
Check: resource.ComposeTestCheckFunc(
testAccCheckVPCV2ProjectExists("selectel_vpc_project_v2.project_tf_acc_test_1", &project),
testAccCheckMKSClusterV1Exists("selectel_mks_cluster_v1.cluster_tf_acc_test_1", &mksCluster),
resource.TestCheckResourceAttr("selectel_mks_cluster_v1.cluster_tf_acc_test_1", "name", clusterName),
resource.TestCheckResourceAttr("selectel_mks_cluster_v1.cluster_tf_acc_test_1", "kube_version", kubeVersion),
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", "true"),
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", "zonal", "false"),
resource.TestCheckResourceAttr("selectel_mks_cluster_v1.cluster_tf_acc_test_1", "private_kube_api", "true"),
resource.TestCheckResourceAttr("selectel_mks_cluster_v1.cluster_tf_acc_test_1", "maintenance_window_start", maintenanceWindowStart),
resource.TestCheckResourceAttr("selectel_mks_cluster_v1.cluster_tf_acc_test_1", "status", "ACTIVE"),
),
Expand Down Expand Up @@ -291,6 +328,24 @@ func testAccMKSClusterV1Zonal(projectName, clusterName, kubeVersion, maintenance
}`, projectName, clusterName, kubeVersion, maintenanceWindowStart)
}

func testAccMKSClusterV1PrivateKubeAPI(projectName, clusterName, kubeVersion, maintenanceWindowStart string) string {
return fmt.Sprintf(`
resource "selectel_vpc_project_v2" "project_tf_acc_test_1" {
name = "%s"
auto_quotas = true
}
resource "selectel_mks_cluster_v1" "cluster_tf_acc_test_1" {
name = "%s"
kube_version = "%s"
project_id = "${selectel_vpc_project_v2.project_tf_acc_test_1.id}"
region = "ru-3"
maintenance_window_start = "%s"
enable_patch_version_auto_upgrade = false
zonal = false
private_kube_api = true
}`, projectName, clusterName, kubeVersion, maintenanceWindowStart)
}

func testDefaultFeatureGates(t *testing.T) []string {
var project projects.Project
featureGates := make([]string, 0)
Expand Down
4 changes: 4 additions & 0 deletions website/docs/r/mks_cluster_v1.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ The following arguments are supported:

* `admission_controllers` - (Optional) Represents a set of admission controllers names to be enabled in a Kubernetes cluster.

* `private_kube_api` - (Optional) Specifies if kube API should be available from the Internet or not.
When true kube API will be available only in clusters network. Default is false.
Changing this creates a new cluster.

## Attributes Reference

The following attributes are exported:
Expand Down