diff --git a/community/modules/compute/gke-topology-scheduler/README.md b/community/modules/compute/gke-topology-scheduler/README.md index 8d5b42913e..5aaa4fca98 100644 --- a/community/modules/compute/gke-topology-scheduler/README.md +++ b/community/modules/compute/gke-topology-scheduler/README.md @@ -45,7 +45,8 @@ No resources. | Name | Description | Type | Default | Required | |------|-------------|------|---------|:--------:| -| [gke\_cluster\_exists](#input\_gke\_cluster\_exists) | A static flag that signals to modules that a cluster has been created. | `bool` | `false` | no | +| [cluster\_id](#input\_cluster\_id) | projects/{{project}}/locations/{{location}}/clusters/{{cluster}} | `string` | n/a | yes | +| [project\_id](#input\_project\_id) | The project ID to host the cluster in. | `string` | n/a | yes | ## Outputs diff --git a/community/modules/compute/gke-topology-scheduler/main.tf b/community/modules/compute/gke-topology-scheduler/main.tf index 3a79befcf3..677595632b 100644 --- a/community/modules/compute/gke-topology-scheduler/main.tf +++ b/community/modules/compute/gke-topology-scheduler/main.tf @@ -15,7 +15,8 @@ module "kubectl_apply" { source = "../../../../modules/management/kubectl-apply" - gke_cluster_exists = var.gke_cluster_exists + cluster_id = var.cluster_id + project_id = var.project_id apply_manifests = [ { source = "${path.module}/manifests/topology-scheduler-scripts.yaml" }, diff --git a/community/modules/compute/gke-topology-scheduler/variables.tf b/community/modules/compute/gke-topology-scheduler/variables.tf index 2fcbb93d58..0766091223 100644 --- a/community/modules/compute/gke-topology-scheduler/variables.tf +++ b/community/modules/compute/gke-topology-scheduler/variables.tf @@ -12,8 +12,12 @@ # See the License for the specific language governing permissions and # limitations under the License. -variable "gke_cluster_exists" { - description = "A static flag that signals to modules that a cluster has been created." - type = bool - default = false +variable "project_id" { + description = "The project ID to host the cluster in." + type = string +} + +variable "cluster_id" { + description = "projects/{{project}}/locations/{{location}}/clusters/{{cluster}}" + type = string } diff --git a/modules/compute/gke-node-pool/README.md b/modules/compute/gke-node-pool/README.md index ac8de13eb7..a1fcaa8f01 100644 --- a/modules/compute/gke-node-pool/README.md +++ b/modules/compute/gke-node-pool/README.md @@ -323,7 +323,6 @@ limitations under the License. | [disk\_type](#input\_disk\_type) | Disk type for each node. | `string` | `null` | no | | [enable\_gcfs](#input\_enable\_gcfs) | Enable the Google Container Filesystem (GCFS). See [restrictions](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/container_cluster#gcfs_config). | `bool` | `false` | no | | [enable\_secure\_boot](#input\_enable\_secure\_boot) | Enable secure boot for the nodes. Keep enabled unless custom kernel modules need to be loaded. See [here](https://cloud.google.com/compute/shielded-vm/docs/shielded-vm#secure-boot) for more info. | `bool` | `true` | no | -| [gke\_cluster\_exists](#input\_gke\_cluster\_exists) | A static flag that signals to modules that a cluster has been created. | `bool` | `false` | no | | [gke\_version](#input\_gke\_version) | GKE version | `string` | n/a | yes | | [guest\_accelerator](#input\_guest\_accelerator) | List of the type and count of accelerator cards attached to the instance. |
list(object({
type = optional(string)
count = optional(number, 0)
gpu_driver_installation_config = optional(object({
gpu_driver_version = string
}), { gpu_driver_version = "DEFAULT" })
gpu_partition_size = optional(string)
gpu_sharing_config = optional(object({
gpu_sharing_strategy = string
max_shared_clients_per_gpu = number
}))
}))
| `[]` | no | | [host\_maintenance\_interval](#input\_host\_maintenance\_interval) | Specifies the frequency of planned maintenance events. | `string` | `""` | no | diff --git a/modules/compute/gke-node-pool/main.tf b/modules/compute/gke-node-pool/main.tf index 44a2b6f3a0..bcce7b04a0 100644 --- a/modules/compute/gke-node-pool/main.tf +++ b/modules/compute/gke-node-pool/main.tf @@ -375,7 +375,8 @@ resource "null_resource" "enable_tcpxo_in_workload" { module "kubectl_apply" { source = "../../management/kubectl-apply" - gke_cluster_exists = var.gke_cluster_exists + cluster_id = var.cluster_id + project_id = var.project_id apply_manifests = flatten([ for manifest in local.gpu_direct_setting.gpu_direct_manifests : [ diff --git a/modules/compute/gke-node-pool/variables.tf b/modules/compute/gke-node-pool/variables.tf index b15fc3f3ef..d3b403b564 100644 --- a/modules/compute/gke-node-pool/variables.tf +++ b/modules/compute/gke-node-pool/variables.tf @@ -24,12 +24,6 @@ variable "cluster_id" { type = string } -variable "gke_cluster_exists" { - description = "A static flag that signals to modules that a cluster has been created." - type = bool - default = false -} - variable "zones" { description = "A list of zones to be used. Zones must be in region of cluster. If null, cluster zones will be inherited. Note `zones` not `zone`; does not work with `zone` deployment variable." type = list(string) diff --git a/modules/file-system/gke-persistent-volume/README.md b/modules/file-system/gke-persistent-volume/README.md index b5967763c9..f4d94d8c3b 100644 --- a/modules/file-system/gke-persistent-volume/README.md +++ b/modules/file-system/gke-persistent-volume/README.md @@ -121,6 +121,7 @@ limitations under the License. | Name | Version | |------|---------| | [terraform](#requirement\_terraform) | >= 1.0 | +| [google](#requirement\_google) | >= 4.42 | | [kubectl](#requirement\_kubectl) | >= 1.7.0 | | [local](#requirement\_local) | >= 2.0.0 | @@ -128,6 +129,7 @@ limitations under the License. | Name | Version | |------|---------| +| [google](#provider\_google) | >= 4.42 | | [kubectl](#provider\_kubectl) | >= 1.7.0 | | [local](#provider\_local) | >= 2.0.0 | @@ -142,15 +144,17 @@ No modules. | [kubectl_manifest.pv](https://registry.terraform.io/providers/gavinbunney/kubectl/latest/docs/resources/manifest) | resource | | [kubectl_manifest.pvc](https://registry.terraform.io/providers/gavinbunney/kubectl/latest/docs/resources/manifest) | resource | | [local_file.debug_file](https://registry.terraform.io/providers/hashicorp/local/latest/docs/resources/file) | resource | +| [google_client_config.default](https://registry.terraform.io/providers/hashicorp/google/latest/docs/data-sources/client_config) | data source | +| [google_container_cluster.gke_cluster](https://registry.terraform.io/providers/hashicorp/google/latest/docs/data-sources/container_cluster) | data source | ## Inputs | Name | Description | Type | Default | Required | |------|-------------|------|---------|:--------:| | [capacity\_gb](#input\_capacity\_gb) | The storage capacity with which to create the persistent volume. | `number` | n/a | yes | +| [cluster\_id](#input\_cluster\_id) | An identifier for the GKE cluster in the format `projects/{{project}}/locations/{{location}}/clusters/{{cluster}}` | `string` | n/a | yes | | [filestore\_id](#input\_filestore\_id) | An identifier for a filestore with the format `projects/{{project}}/locations/{{location}}/instances/{{name}}`. | `string` | `null` | no | | [gcs\_bucket\_name](#input\_gcs\_bucket\_name) | The gcs bucket to be used with the persistent volume. | `string` | `null` | no | -| [gke\_cluster\_exists](#input\_gke\_cluster\_exists) | A static flag that signals to modules that a cluster has been created. | `bool` | `false` | no | | [labels](#input\_labels) | GCE resource labels to be applied to resources. Key-value pairs. | `map(string)` | n/a | yes | | [network\_storage](#input\_network\_storage) | Network attached storage mount to be configured. |
object({
server_ip = string,
remote_mount = string,
local_mount = string,
fs_type = string,
mount_options = string,
client_install_runner = map(string)
mount_runner = map(string)
})
| n/a | yes | diff --git a/modules/file-system/gke-persistent-volume/main.tf b/modules/file-system/gke-persistent-volume/main.tf index d12c5d6d39..5b52bcc950 100644 --- a/modules/file-system/gke-persistent-volume/main.tf +++ b/modules/file-system/gke-persistent-volume/main.tf @@ -77,6 +77,9 @@ locals { capacity = "${var.capacity_gb}Gi" } ) + + cluster_name = split("/", var.cluster_id)[5] + cluster_location = split("/", var.cluster_id)[3] } resource "local_file" "debug_file" { @@ -87,8 +90,21 @@ resource "local_file" "debug_file" { filename = "${path.root}/pv-pvc-debug-file-${local.filestore_name}.yaml" } +data "google_container_cluster" "gke_cluster" { + name = local.cluster_name + location = local.cluster_location +} + +data "google_client_config" "default" {} + +provider "kubectl" { + host = "https://${data.google_container_cluster.gke_cluster.endpoint}" + cluster_ca_certificate = base64decode(data.google_container_cluster.gke_cluster.master_auth[0].cluster_ca_certificate) + token = data.google_client_config.default.access_token + load_config_file = false +} + resource "kubectl_manifest" "pv" { - count = var.gke_cluster_exists ? 1 : 0 yaml_body = local.is_gcs ? local.gcs_pv_contents : local.filestore_pv_contents lifecycle { diff --git a/modules/file-system/gke-persistent-volume/variables.tf b/modules/file-system/gke-persistent-volume/variables.tf index 96e3f31949..a72fa3857f 100644 --- a/modules/file-system/gke-persistent-volume/variables.tf +++ b/modules/file-system/gke-persistent-volume/variables.tf @@ -14,10 +14,9 @@ * limitations under the License. */ -variable "gke_cluster_exists" { - description = "A static flag that signals to modules that a cluster has been created." - type = bool - default = false +variable "cluster_id" { + description = "An identifier for the GKE cluster in the format `projects/{{project}}/locations/{{location}}/clusters/{{cluster}}`" + type = string } variable "network_storage" { diff --git a/modules/file-system/gke-persistent-volume/versions.tf b/modules/file-system/gke-persistent-volume/versions.tf index 3fd6cf3c3a..2378b1d62b 100644 --- a/modules/file-system/gke-persistent-volume/versions.tf +++ b/modules/file-system/gke-persistent-volume/versions.tf @@ -15,6 +15,10 @@ terraform { required_version = ">= 1.0" required_providers { + google = { + source = "hashicorp/google" + version = ">= 4.42" + } kubectl = { source = "gavinbunney/kubectl" version = ">= 1.7.0" diff --git a/modules/file-system/gke-storage/README.md b/modules/file-system/gke-storage/README.md index 9d7a2fb428..ca628aaaeb 100644 --- a/modules/file-system/gke-storage/README.md +++ b/modules/file-system/gke-storage/README.md @@ -109,10 +109,11 @@ No resources. |------|-------------|------|---------|:--------:| | [access\_mode](#input\_access\_mode) | The access mode that the volume can be mounted to the host/pod. More details in [Access Modes](https://kubernetes.io/docs/concepts/storage/persistent-volumes/#access-modes)
Valid access modes:
- ReadWriteOnce
- ReadOnlyMany
- ReadWriteMany
- ReadWriteOncePod | `string` | n/a | yes | | [capacity\_gb](#input\_capacity\_gb) | The storage capacity with which to create the persistent volume. | `number` | n/a | yes | -| [gke\_cluster\_exists](#input\_gke\_cluster\_exists) | A static flag that signals to modules that a cluster has been created. | `bool` | `false` | no | +| [cluster\_id](#input\_cluster\_id) | An identifier for the GKE cluster in the format `projects/{{project}}/locations/{{location}}/clusters/{{cluster}}` | `string` | n/a | yes | | [labels](#input\_labels) | GCE resource labels to be applied to resources. Key-value pairs. | `map(string)` | n/a | yes | | [mount\_options](#input\_mount\_options) | Controls the mountOptions for dynamically provisioned PersistentVolumes of this storage class. | `string` | `null` | no | | [private\_vpc\_connection\_peering](#input\_private\_vpc\_connection\_peering) | The name of the VPC Network peering connection.
If using new VPC, please use community/modules/network/private-service-access to create private-service-access and
If using existing VPC with private-service-access enabled, set this manually follow [user guide](https://cloud.google.com/parallelstore/docs/vpc). | `string` | `null` | no | +| [project\_id](#input\_project\_id) | The project ID to host the cluster in. | `string` | n/a | yes | | [pv\_mount\_path](#input\_pv\_mount\_path) | Path within the container at which the volume should be mounted. Must not contain ':'. | `string` | `"/data"` | no | | [pvc\_count](#input\_pvc\_count) | How many PersistentVolumeClaims that will be created | `number` | `1` | no | | [sc\_reclaim\_policy](#input\_sc\_reclaim\_policy) | Indicate whether to keep the dynamically provisioned PersistentVolumes of this storage class after the bound PersistentVolumeClaim is deleted.
[More details about reclaiming](https://kubernetes.io/docs/concepts/storage/persistent-volumes/#reclaiming)
Supported value:
- Retain
- Delete | `string` | n/a | yes | diff --git a/modules/file-system/gke-storage/main.tf b/modules/file-system/gke-storage/main.tf index f26936de0c..18f85fa779 100644 --- a/modules/file-system/gke-storage/main.tf +++ b/modules/file-system/gke-storage/main.tf @@ -39,7 +39,8 @@ check "private_vpc_connection_peering" { module "kubectl_apply" { source = "../../management/kubectl-apply" - gke_cluster_exists = var.gke_cluster_exists + cluster_id = var.cluster_id + project_id = var.project_id # count = var.pvc_count apply_manifests = flatten( diff --git a/modules/file-system/gke-storage/variables.tf b/modules/file-system/gke-storage/variables.tf index b33203be0f..9f6224bbac 100644 --- a/modules/file-system/gke-storage/variables.tf +++ b/modules/file-system/gke-storage/variables.tf @@ -14,10 +14,14 @@ * limitations under the License. */ -variable "gke_cluster_exists" { - description = "A static flag that signals to modules that a cluster has been created." - type = bool - default = false +variable "project_id" { + description = "The project ID to host the cluster in." + type = string +} + +variable "cluster_id" { + description = "An identifier for the GKE cluster in the format `projects/{{project}}/locations/{{location}}/clusters/{{cluster}}`" + type = string } variable "labels" { diff --git a/modules/management/kubectl-apply/README.md b/modules/management/kubectl-apply/README.md index 47f0076618..360929da22 100644 --- a/modules/management/kubectl-apply/README.md +++ b/modules/management/kubectl-apply/README.md @@ -101,12 +101,15 @@ limitations under the License. | Name | Version | |------|---------| | [terraform](#requirement\_terraform) | >= 1.3 | +| [google](#requirement\_google) | > 5.0 | | [http](#requirement\_http) | ~> 3.0 | +| [kubectl](#requirement\_kubectl) | >= 1.7.0 | ## Providers | Name | Version | |------|---------| +| [google](#provider\_google) | > 5.0 | | [terraform](#provider\_terraform) | n/a | ## Modules @@ -124,15 +127,18 @@ limitations under the License. |------|------| | [terraform_data.jobset_validations](https://registry.terraform.io/providers/hashicorp/terraform/latest/docs/resources/data) | resource | | [terraform_data.kueue_validations](https://registry.terraform.io/providers/hashicorp/terraform/latest/docs/resources/data) | resource | +| [google_client_config.default](https://registry.terraform.io/providers/hashicorp/google/latest/docs/data-sources/client_config) | data source | +| [google_container_cluster.gke_cluster](https://registry.terraform.io/providers/hashicorp/google/latest/docs/data-sources/container_cluster) | data source | ## Inputs | Name | Description | Type | Default | Required | |------|-------------|------|---------|:--------:| | [apply\_manifests](#input\_apply\_manifests) | A list of manifests to apply to GKE cluster using kubectl. For more details see [kubectl module's inputs](kubectl/README.md). |
list(object({
content = optional(string, null)
source = optional(string, null)
template_vars = optional(map(any), null)
server_side_apply = optional(bool, false)
wait_for_rollout = optional(bool, true)
}))
| `[]` | no | -| [gke\_cluster\_exists](#input\_gke\_cluster\_exists) | A static flag that signals to modules that a cluster has been created. | `bool` | `false` | no | +| [cluster\_id](#input\_cluster\_id) | An identifier for the gke cluster resource with format projects//locations//clusters/. | `string` | n/a | yes | | [jobset](#input\_jobset) | Install [Jobset](https://github.com/kubernetes-sigs/jobset) which manages a group of K8s [jobs](https://kubernetes.io/docs/concepts/workloads/controllers/job/) as a unit. |
object({
install = optional(bool, false)
version = optional(string, "v0.5.2")
})
| `{}` | no | | [kueue](#input\_kueue) | Install and configure [Kueue](https://kueue.sigs.k8s.io/docs/overview/) workload scheduler. A configuration yaml/template file can be provided with config\_path to be applied right after kueue installation. If a template file provided, its variables can be set to config\_template\_vars. |
object({
install = optional(bool, false)
version = optional(string, "v0.8.1")
config_path = optional(string, null)
config_template_vars = optional(map(any), null)
})
| `{}` | no | +| [project\_id](#input\_project\_id) | The project ID that hosts the gke cluster. | `string` | n/a | yes | ## Outputs diff --git a/modules/management/kubectl-apply/main.tf b/modules/management/kubectl-apply/main.tf index cc1abd05f0..5663e01580 100644 --- a/modules/management/kubectl-apply/main.tf +++ b/modules/management/kubectl-apply/main.tf @@ -15,6 +15,11 @@ */ locals { + cluster_id_parts = split("/", var.cluster_id) + cluster_name = local.cluster_id_parts[5] + cluster_location = local.cluster_id_parts[3] + project_id = var.project_id != null ? var.project_id : local.cluster_id_parts[1] + apply_manifests_map = tomap({ for index, manifest in var.apply_manifests : index => manifest }) @@ -25,8 +30,16 @@ locals { jobset_install_source = format("${path.module}/manifests/jobset-%s.yaml", try(var.jobset.version, "")) } +data "google_container_cluster" "gke_cluster" { + project = local.project_id + name = local.cluster_name + location = local.cluster_location +} + +data "google_client_config" "default" {} + module "kubectl_apply_manifests" { - for_each = var.gke_cluster_exists ? local.apply_manifests_map : {} + for_each = local.apply_manifests_map source = "./kubectl" content = each.value.content @@ -36,34 +49,34 @@ module "kubectl_apply_manifests" { wait_for_rollout = each.value.wait_for_rollout providers = { - http = http.h + kubectl = kubectl + http = http.h } } module "install_kueue" { - count = var.gke_cluster_exists ? 1 : 0 source = "./kubectl" source_path = local.install_kueue ? local.kueue_install_source : null server_side_apply = true providers = { - http = http.h + kubectl = kubectl + http = http.h } } module "install_jobset" { - count = var.gke_cluster_exists ? 1 : 0 source = "./kubectl" source_path = local.install_jobset ? local.jobset_install_source : null server_side_apply = true providers = { - http = http.h + kubectl = kubectl + http = http.h } } module "configure_kueue" { - count = var.gke_cluster_exists ? 1 : 0 source = "./kubectl" source_path = local.install_kueue ? try(var.kueue.config_path, "") : null template_vars = local.install_kueue ? try(var.kueue.config_template_vars, null) : null @@ -73,6 +86,7 @@ module "configure_kueue" { wait_for_rollout = true providers = { - http = http.h + kubectl = kubectl + http = http.h } } diff --git a/modules/management/kubectl-apply/providers.tf b/modules/management/kubectl-apply/providers.tf index d5577975f3..74d157b93b 100644 --- a/modules/management/kubectl-apply/providers.tf +++ b/modules/management/kubectl-apply/providers.tf @@ -14,6 +14,14 @@ * limitations under the License. */ +provider "kubectl" { + host = "https://${data.google_container_cluster.gke_cluster.endpoint}" + token = data.google_client_config.default.access_token + cluster_ca_certificate = base64decode(data.google_container_cluster.gke_cluster.master_auth[0].cluster_ca_certificate) + load_config_file = false + apply_retry_count = 15 # Terraform may apply resources in parallel, leading to potential dependency issues. This retry mechanism ensures that if a resource's dependencies aren't ready, Terraform will attempt to apply it again. +} + provider "http" { alias = "h" } diff --git a/modules/management/kubectl-apply/variables.tf b/modules/management/kubectl-apply/variables.tf index 0b2f469d50..e1bd91aa97 100644 --- a/modules/management/kubectl-apply/variables.tf +++ b/modules/management/kubectl-apply/variables.tf @@ -37,10 +37,15 @@ resource "terraform_data" "jobset_validations" { } } -variable "gke_cluster_exists" { - description = "A static flag that signals to modules that a cluster has been created." - type = bool - default = false +variable "project_id" { + description = "The project ID that hosts the gke cluster." + type = string +} + +variable "cluster_id" { + description = "An identifier for the gke cluster resource with format projects//locations//clusters/." + type = string + nullable = false } variable "apply_manifests" { diff --git a/modules/management/kubectl-apply/versions.tf b/modules/management/kubectl-apply/versions.tf index 774cddd7ff..227838747c 100644 --- a/modules/management/kubectl-apply/versions.tf +++ b/modules/management/kubectl-apply/versions.tf @@ -16,6 +16,14 @@ terraform { required_providers { + google = { + source = "hashicorp/google" + version = "> 5.0" + } + kubectl = { + source = "gavinbunney/kubectl" + version = ">= 1.7.0" + } http = { source = "hashicorp/http" version = "~> 3.0" diff --git a/modules/scheduler/gke-cluster/README.md b/modules/scheduler/gke-cluster/README.md index 84dfed0d7e..fe668c3df7 100644 --- a/modules/scheduler/gke-cluster/README.md +++ b/modules/scheduler/gke-cluster/README.md @@ -200,12 +200,9 @@ limitations under the License. | Name | Description | |------|-------------| -| [access\_token](#output\_access\_token) | Google client config access token. | -| [cluster\_ca\_certificate](#output\_cluster\_ca\_certificate) | GKE cluster CA certificate. | | [cluster\_id](#output\_cluster\_id) | An identifier for the resource with format projects/{{project\_id}}/locations/{{region}}/clusters/{{name}}. | | [gke\_cluster\_exists](#output\_gke\_cluster\_exists) | A static flag that signals to downstream modules that a cluster has been created. Needed by community/modules/scripts/kubernetes-operations. | | [gke\_version](#output\_gke\_version) | GKE cluster's version. | -| [host\_endpoint](#output\_host\_endpoint) | GKE cluster endpoint. | | [instructions](#output\_instructions) | Instructions on how to connect to the created cluster. | | [k8s\_service\_account\_name](#output\_k8s\_service\_account\_name) | Name of k8s service account. | diff --git a/modules/scheduler/gke-cluster/main.tf b/modules/scheduler/gke-cluster/main.tf index 21dfc1c40e..bdc16b1cbd 100644 --- a/modules/scheduler/gke-cluster/main.tf +++ b/modules/scheduler/gke-cluster/main.tf @@ -380,7 +380,8 @@ module "workload_identity" { module "kubectl_apply" { source = "../../management/kubectl-apply" - gke_cluster_exists = true + cluster_id = google_container_cluster.gke_cluster.id + project_id = var.project_id apply_manifests = flatten([ for idx, network_info in var.additional_networks : [ @@ -399,6 +400,4 @@ module "kubectl_apply" { } ] ]) - - depends_on = [google_container_cluster.gke_cluster] } diff --git a/modules/scheduler/gke-cluster/outputs.tf b/modules/scheduler/gke-cluster/outputs.tf index 087462049a..28e00171ff 100644 --- a/modules/scheduler/gke-cluster/outputs.tf +++ b/modules/scheduler/gke-cluster/outputs.tf @@ -79,18 +79,3 @@ output "gke_version" { description = "GKE cluster's version." value = google_container_cluster.gke_cluster.master_version } - -output "host_endpoint" { - description = "GKE cluster endpoint." - value = "https://${google_container_cluster.gke_cluster.endpoint}" -} - -output "cluster_ca_certificate" { - description = "GKE cluster CA certificate." - value = base64decode(google_container_cluster.gke_cluster.master_auth[0].cluster_ca_certificate) -} - -output "access_token" { - description = "Google client config access token." - value = data.google_client_config.default.access_token -} diff --git a/modules/scheduler/pre-existing-gke-cluster/README.md b/modules/scheduler/pre-existing-gke-cluster/README.md index c0715c472d..aaac5a547f 100644 --- a/modules/scheduler/pre-existing-gke-cluster/README.md +++ b/modules/scheduler/pre-existing-gke-cluster/README.md @@ -94,7 +94,6 @@ limitations under the License. | Name | Type | |------|------| -| [google_client_config.default](https://registry.terraform.io/providers/hashicorp/google/latest/docs/data-sources/client_config) | data source | | [google_container_cluster.existing_gke_cluster](https://registry.terraform.io/providers/hashicorp/google/latest/docs/data-sources/container_cluster) | data source | ## Inputs @@ -111,10 +110,7 @@ limitations under the License. | Name | Description | |------|-------------| -| [access\_token](#output\_access\_token) | Google client config access token. | -| [cluster\_ca\_certificate](#output\_cluster\_ca\_certificate) | GKE cluster CA certificate. | | [cluster\_id](#output\_cluster\_id) | An identifier for the gke cluster with format projects/{{project\_id}}/locations/{{region}}/clusters/{{name}}. | | [gke\_cluster\_exists](#output\_gke\_cluster\_exists) | A static flag that signals to downstream modules that a cluster exists. | | [gke\_version](#output\_gke\_version) | GKE cluster's version. | -| [host\_endpoint](#output\_host\_endpoint) | GKE cluster endpoint. | diff --git a/modules/scheduler/pre-existing-gke-cluster/main.tf b/modules/scheduler/pre-existing-gke-cluster/main.tf index 800ed87a51..926d2be100 100644 --- a/modules/scheduler/pre-existing-gke-cluster/main.tf +++ b/modules/scheduler/pre-existing-gke-cluster/main.tf @@ -60,14 +60,11 @@ locals { ]) } -data "google_client_config" "default" {} - module "kubectl_apply" { source = "../../management/kubectl-apply" - gke_cluster_exists = true + cluster_id = data.google_container_cluster.existing_gke_cluster.id + project_id = var.project_id apply_manifests = concat(local.apply_manifests_non_rdma_networks, local.apply_manifests_rdma_networks) - - depends_on = [data.google_container_cluster.existing_gke_cluster] } diff --git a/modules/scheduler/pre-existing-gke-cluster/outputs.tf b/modules/scheduler/pre-existing-gke-cluster/outputs.tf index 880928d21b..8884ee30b0 100644 --- a/modules/scheduler/pre-existing-gke-cluster/outputs.tf +++ b/modules/scheduler/pre-existing-gke-cluster/outputs.tf @@ -31,18 +31,3 @@ output "gke_version" { description = "GKE cluster's version." value = data.google_container_cluster.existing_gke_cluster.master_version } - -output "host_endpoint" { - description = "GKE cluster endpoint." - value = "https://${data.google_container_cluster.existing_gke_cluster.endpoint}" -} - -output "cluster_ca_certificate" { - description = "GKE cluster CA certificate." - value = base64decode(data.google_container_cluster.existing_gke_cluster.master_auth[0].cluster_ca_certificate) -} - -output "access_token" { - description = "Google client config access token." - value = data.google_client_config.default.access_token -} diff --git a/pkg/config/expand.go b/pkg/config/expand.go index 0bb74bc930..95ad1de52e 100644 --- a/pkg/config/expand.go +++ b/pkg/config/expand.go @@ -17,7 +17,6 @@ package config import ( "errors" "fmt" - "strings" "hpc-toolkit/pkg/modulereader" "hpc-toolkit/pkg/sourcereader" @@ -187,33 +186,6 @@ func (bp Blueprint) expandBackend(grp *Group) { } } -func kubectlProviderRequiredModule(grp *Group) (bool, Module) { - for _, mod := range grp.Modules { - if strings.Contains(mod.Source, "modules/scheduler/gke-cluster") || strings.Contains(mod.Source, "modules/scheduler/pre-existing-gke-cluster") { - return true, mod - } - } - return false, Module{} -} - -func getModuleKubectlProviders(mod Module) map[string]TerraformProvider { - kubectlConf := Dict{} - for s, v := range map[string]string{ - "cluster_ca_certificate": "cluster_ca_certificate", - "host": "host_endpoint", - "token": "access_token"} { - kubectlConf = kubectlConf.With(s, ModuleRef(mod.ID, v).AsValue()) - } - kubectlConf = kubectlConf. - With("apply_retry_count", cty.NumberIntVal(15)). - With("load_config_file", cty.BoolVal(false)) - return map[string]TerraformProvider{ - "kubectl": { - Source: "gavinbunney/kubectl", - Version: ">= 1.7.0", - Configuration: kubectlConf}} -} - func getDefaultGoogleProviders(bp Blueprint) map[string]TerraformProvider { gglConf := Dict{} for s, v := range map[string]string{ @@ -248,9 +220,6 @@ func (bp Blueprint) expandProviders(grp *Group) { if (*pv) == nil { (*pv) = maps.Clone(defaults) } - if ok, mod := kubectlProviderRequiredModule(grp); ok { - maps.Copy((*pv), getModuleKubectlProviders(mod)) - } } func getModuleInputMap(inputs []modulereader.VarInfo) map[string]cty.Type { diff --git a/pkg/config/expand_test.go b/pkg/config/expand_test.go index 38633f818f..73f321cef0 100644 --- a/pkg/config/expand_test.go +++ b/pkg/config/expand_test.go @@ -87,64 +87,16 @@ func (s *zeroSuite) TestExpandProviders(c *C) { With("zone", cty.StringVal("zone1")). With("universe_domain", cty.StringVal("test-universe.com"))}} - testGKEClusterModuleID := ModuleID("dummy_cluster") - - testKubectlConf := Dict{} - for s, v := range map[string]string{ - "cluster_ca_certificate": "cluster_ca_certificate", - "host": "host_endpoint", - "token": "access_token"} { - testKubectlConf = testKubectlConf.With(s, ModuleRef(testGKEClusterModuleID, v).AsValue()) - } - testKubectlConf = testKubectlConf. - With("apply_retry_count", cty.NumberIntVal(15)). - With("load_config_file", cty.BoolVal(false)) - - testKubectlProvider := PR{ - Source: "gavinbunney/kubectl", - Version: ">= 1.7.0", - Configuration: testKubectlConf} - - testGKEClusterModule := Module{ - Source: "modules/scheduler/gke-cluster", - ID: testGKEClusterModuleID} - - testPreExistingGKEClusterModule := Module{ - Source: "modules/scheduler/pre-existing-gke-cluster", - ID: testGKEClusterModuleID} - - defaultProvider := map[string]PR{ - "google": TerraformProvider{ - Source: "hashicorp/google", - Version: "~> 6.14.0"}, - "google-beta": TerraformProvider{ - Source: "hashicorp/google-beta", - Version: "~> 6.14.0"}} - { // no def PR, no group PR - match default values g := Group{Name: "clown"} noDefPr.expandProviders(&g) - c.Check(g.TerraformProviders, DeepEquals, defaultProvider) - } - - { // no def PR, no group PR, group only have gke cluster module - g := Group{ - Name: "clown", - Modules: []Module{testGKEClusterModule}} - defaultProvider["kubectl"] = testKubectlProvider - noDefPr.expandProviders(&g) - c.Check(g.TerraformProviders, DeepEquals, defaultProvider) - delete(defaultProvider, "kubectl") - } - - { // no def PR, no group PR, group only have pre existing gke cluster module - g := Group{ - Name: "clown", - Modules: []Module{testPreExistingGKEClusterModule}} - defaultProvider["kubectl"] = testKubectlProvider - noDefPr.expandProviders(&g) - c.Check(g.TerraformProviders, DeepEquals, defaultProvider) - delete(defaultProvider, "kubectl") + c.Check(g.TerraformProviders, DeepEquals, map[string]PR{ + "google": TerraformProvider{ + Source: "hashicorp/google", + Version: "~> 6.14.0"}, + "google-beta": TerraformProvider{ + Source: "hashicorp/google-beta", + Version: "~> 6.14.0"}}) } { // no def PR, group PR