Skip to content

Commit

Permalink
Add support for image type configuration on the GKE NAP (GoogleCloudP…
Browse files Browse the repository at this point in the history
…latform#5644)

* Add support for image type configuration on the GKE NAP

* Add GA and Beta changes for image_type support on NAP

* Update validation for image_type on NAP

* Put image_type support on GA and change default its value to containerd

* Set ignoreCase as true on Validation function for image_type

Co-authored-by: megan07 <[email protected]>

* Image_type Capitalization

Co-authored-by: megan07 <[email protected]>
  • Loading branch information
2 people authored and lcaggio committed Mar 16, 2022
1 parent 0514ccf commit 116460e
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,13 @@ func resourceContainerCluster() *schema.Resource {
Default: "default",
Description: `The Google Cloud Platform Service Account to be used by the node VMs.`,
},
"image_type": {
Type: schema.TypeString,
Optional: true,
Default: "COS_CONTAINERD",
Description: `The default image type used by NAP once a new node pool is being created.`,
ValidateFunc: validation.StringInSlice([]string{"COS_CONTAINERD", "COS", "UBUNTU_CONTAINERD", "UBUNTU"}, false),
},
<% unless version == 'ga' -%>
"min_cpu_platform": {
Type: schema.TypeString,
Expand Down Expand Up @@ -3283,6 +3290,7 @@ func expandAutoProvisioningDefaults(configured interface{}, d *schema.ResourceDa
npd := &container.AutoprovisioningNodePoolDefaults{
OauthScopes: convertStringArr(config["oauth_scopes"].([]interface{})),
ServiceAccount: config["service_account"].(string),
ImageType: config["image_type"].(string),
}

<% unless version == 'ga' -%>
Expand Down Expand Up @@ -4023,6 +4031,7 @@ func flattenAutoProvisioningDefaults(a *container.AutoprovisioningNodePoolDefaul
r := make(map[string]interface{})
r["oauth_scopes"] = a.OauthScopes
r["service_account"] = a.ServiceAccount
r["image_type"] = a.ImageType
<% unless version == 'ga' -%>
r["min_cpu_platform"] = a.MinCpuPlatform
<% end -%>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2037,6 +2037,39 @@ func TestAccContainerCluster_withFlexiblePodCIDR(t *testing.T) {
}
<% end -%>

func TestAccContainerCluster_nodeAutoprovisioningDefaultsImageType(t *testing.T) {
t.Parallel()

clusterName := fmt.Sprintf("tf-test-cluster-%s", randString(t, 10))
includeImageType := true

vcrTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckContainerClusterDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccContainerCluster_autoprovisioningDefaultsImageType(clusterName, includeImageType),
},
{
ResourceName: "google_container_cluster.with_autoprovisioning",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"min_master_version"},
},
{
Config: testAccContainerCluster_autoprovisioningDefaultsImageType(clusterName, !includeImageType),
},
{
ResourceName: "google_container_cluster.with_autoprovisioning",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"min_master_version"},
},
},
})
}

func TestAccContainerCluster_errorCleanDanglingCluster(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -3779,6 +3812,38 @@ resource "google_container_cluster" "with_autoprovisioning" {
}
<% end -%>

func testAccContainerCluster_autoprovisioningDefaultsImageType(cluster string, includeImageType bool) string {
imageTypeCfg := ""
if includeImageType {
imageTypeCfg = `image_type = "COS_CONTAINERD"`
}

return fmt.Sprintf(`
data "google_container_engine_versions" "central1a" {
location = "us-central1-a"
}
resource "google_container_cluster" "with_autoprovisioning" {
name = "%s"
location = "us-central1-a"
initial_node_count = 1
min_master_version = data.google_container_engine_versions.central1a.latest_master_version
cluster_autoscaling {
enabled = true
resource_limits {
resource_type = "cpu"
maximum = 2
}
resource_limits {
resource_type = "memory"
maximum = 2048
}
auto_provisioning_defaults {
%s
}
}
}`, cluster, imageTypeCfg)
}

func testAccContainerCluster_withNodePoolAutoscaling(cluster, np string) string {
return fmt.Sprintf(`
resource "google_container_cluster" "with_node_pool" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ and requires the `ip_allocation_policy` block to be defined. By default when thi
* `master_auth` - (Optional) The authentication information for accessing the
Kubernetes master. Some values in this block are only returned by the API if
your service account has permission to get credentials for your GKE cluster. If
you see an unexpected diff unsetting your client cert, ensure you have the
you see an unexpected diff unsetting your client cert, ensure you have the
`container.clusters.getCredentials` permission.
Structure is [documented below](#nested_master_auth).

Expand Down Expand Up @@ -473,6 +473,8 @@ as "Intel Haswell" or "Intel Sandy Bridge".

* `service_account` - (Optional) The Google Cloud Platform Service Account to be used by the node VMs.

* `image_type` - (Optional) The default image type used by NAP once a new node pool is being created. Please note that according to the [official documentation](https://cloud.google.com/kubernetes-engine/docs/how-to/node-auto-provisioning#default-image-type) the value must be one of the [COS_CONTAINERD, COS, UBUNTU_CONTAINERD, UBUNTU].

<a name="nested_authenticator_groups_config"></a>The `authenticator_groups_config` block supports:

* `security_group` - (Required) The name of the RBAC security group for use with Google security groups in Kubernetes RBAC. Group name must be in format `[email protected]`.
Expand Down Expand Up @@ -687,7 +689,7 @@ gcfs_config {
are preemptible. See the [official documentation](https://cloud.google.com/container-engine/docs/preemptible-vm)
for more information. Defaults to false.

* `spot` - (Optional, [Beta](https://terraform.io/docs/providers/google/guides/provider_versions.html)) A boolean
* `spot` - (Optional, [Beta](https://terraform.io/docs/providers/google/guides/provider_versions.html)) A boolean
that represents whether the underlying node VMs are spot. See the [official documentation](https://cloud.google.com/kubernetes-engine/docs/concepts/spot-vms)
for more information. Defaults to false.

Expand Down

0 comments on commit 116460e

Please sign in to comment.