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

Create 'pre-existing-gke-cluster' module #2704

Merged
merged 4 commits into from
Jun 26, 2024
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 community/modules/scheduler/gke-cluster/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ limitations under the License.

| Name | Description |
|------|-------------|
| <a name="output_cluster_id"></a> [cluster\_id](#output\_cluster\_id) | An identifier for the resource with format projects/<project\_id>/locations/<region>/clusters/<name>. |
| <a name="output_cluster_id"></a> [cluster\_id](#output\_cluster\_id) | An identifier for the resource with format projects/{{project\_id}}/locations/{{region}}/clusters/{{name}}. |
nick-stroud marked this conversation as resolved.
Show resolved Hide resolved
| <a name="output_gke_cluster_exists"></a> [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. |
| <a name="output_instructions"></a> [instructions](#output\_instructions) | Instructions on how to connect to the created cluster. |
| <a name="output_k8s_service_account_name"></a> [k8s\_service\_account\_name](#output\_k8s\_service\_account\_name) | Name of k8s service account. |
Expand Down
2 changes: 1 addition & 1 deletion community/modules/scheduler/gke-cluster/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

output "cluster_id" {
description = "An identifier for the resource with format projects/<project_id>/locations/<region>/clusters/<name>."
description = "An identifier for the resource with format projects/{{project_id}}/locations/{{region}}/clusters/{{name}}."
value = google_container_cluster.gke_cluster.id
}

Expand Down
88 changes: 88 additions & 0 deletions community/modules/scheduler/pre-existing-gke-cluster/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
## Description

This module discovers a Google Kubernetes Engine ([GKE](https://cloud.google.com/kubernetes-engine)) cluster that already exists in Google Cloud and
outputs cluster attributes that uniquely identify it for use by other modules.
The module outputs are aligned with the [gke-cluster module][gke-cluster] so that it can be used
as a drop-in substitute when a GKE cluster already exists.

The below sample blueprint discovers the existing GKE cluster named "my-gke-cluster" in "us-central1" region. With the `use` keyword, the
[gke-node-pool] module accepts the `cluser_id`
input variable that uniquely identifies the existing GKE cluster in which the
GKE node pool will be created.

[gke-cluster]: ../gke-cluster/README.md
[gke-node-pool]: ../../compute/gke-node-pool/README.md

### Example

```yaml
- id: existing-gke-cluster
source: community/modules/scheduler/pre-existing-gke-cluster
settings:
project_id: $(vars.project_id)
nick-stroud marked this conversation as resolved.
Show resolved Hide resolved
cluster_name: my-gke-cluster
region: us-central1

- id: compute_pool
source: community/modules/compute/gke-node-pool
use: [existing-gke-cluster]
```

> **_NOTE:_** The `project_id` and `region` settings would be inferred from the
> deployment variables of the same name, but they are included here for clarity.

## License

<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
Copyright 2024 Google LLC

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

## Requirements

| Name | Version |
|------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0.0 |
| <a name="requirement_google"></a> [google](#requirement\_google) | > 5.0 |

## Providers

| Name | Version |
|------|---------|
| <a name="provider_google"></a> [google](#provider\_google) | > 5.0 |

## Modules

No modules.

## Resources

| Name | Type |
|------|------|
| [google_container_cluster.existing_gke_cluster](https://registry.terraform.io/providers/hashicorp/google/latest/docs/data-sources/container_cluster) | data source |

## Inputs

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <a name="input_cluster_name"></a> [cluster\_name](#input\_cluster\_name) | Name of the existing cluster | `string` | n/a | yes |
| <a name="input_project_id"></a> [project\_id](#input\_project\_id) | Project that hosts the existing cluster | `string` | n/a | yes |
| <a name="input_region"></a> [region](#input\_region) | Region in which to search for the cluster | `string` | n/a | yes |

## Outputs

| Name | Description |
|------|-------------|
| <a name="output_cluster_id"></a> [cluster\_id](#output\_cluster\_id) | An identifier for the gke cluster with format projects/{{project\_id}}/locations/{{region}}/clusters/{{name}}. |
| <a name="output_gke_cluster_exists"></a> [gke\_cluster\_exists](#output\_gke\_cluster\_exists) | A static flag that signals to downstream modules that a cluster exists. |
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
21 changes: 21 additions & 0 deletions community/modules/scheduler/pre-existing-gke-cluster/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* Copyright 2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

data "google_container_cluster" "existing_gke_cluster" {
name = var.cluster_name
project = var.project_id
location = var.region
}
19 changes: 19 additions & 0 deletions community/modules/scheduler/pre-existing-gke-cluster/metadata.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Copyright 2024 "Google LLC"
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
---

spec:
requirements:
services:
- container.googleapis.com
28 changes: 28 additions & 0 deletions community/modules/scheduler/pre-existing-gke-cluster/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* Copyright 2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

output "cluster_id" {
description = "An identifier for the gke cluster with format projects/{{project_id}}/locations/{{region}}/clusters/{{name}}."
value = data.google_container_cluster.existing_gke_cluster.id
}

output "gke_cluster_exists" {
description = "A static flag that signals to downstream modules that a cluster exists."
value = true
depends_on = [
data.google_container_cluster.existing_gke_cluster
]
}
30 changes: 30 additions & 0 deletions community/modules/scheduler/pre-existing-gke-cluster/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* Copyright 2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

variable "project_id" {
description = "Project that hosts the existing cluster"
type = string
}

variable "cluster_name" {
description = "Name of the existing cluster"
type = string
}

variable "region" {
description = "Region in which to search for the cluster"
type = string
}
30 changes: 30 additions & 0 deletions community/modules/scheduler/pre-existing-gke-cluster/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* Copyright 2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

terraform {
required_providers {
google = {
source = "hashicorp/google"
version = "> 5.0"
}
}

provider_meta "google" {
module_name = "blueprints/terraform/hpc-toolkit:pre-existing-gke-cluster/v1.35.0"
}

required_version = ">= 1.0.0"
}
2 changes: 2 additions & 0 deletions modules/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ Pub/Sub subscription. Primarily used for [FSI - MonteCarlo Tutorial][fsi-monteca
submission of Google Cloud Batch jobs.
* **[gke-cluster]** ![community-badge] ![experimental-badge] : Creates a
Kubernetes cluster using GKE.
* **[pre-existing-gke-cluster]** ![community-badge] ![experimental-badge] : Retrieves an existing GKE cluster. Substitute for ([gke-cluster]) module.
* **[schedmd-slurm-gcp-v5-controller]** ![community-badge] :
Creates a Slurm controller node using [slurm-gcp-version-5].
* **[schedmd-slurm-gcp-v5-login]** ![community-badge] :
Expand All @@ -210,6 +211,7 @@ Pub/Sub subscription. Primarily used for [FSI - MonteCarlo Tutorial][fsi-monteca
[batch-job-template]: ../modules/scheduler/batch-job-template/README.md
[batch-login-node]: ../modules/scheduler/batch-login-node/README.md
[gke-cluster]: ../community/modules/scheduler/gke-cluster/README.md
[pre-existing-gke-cluster]: ../community/modules/scheduler/pre-existing-gke-cluster/README.md
[htcondor-setup]: ../community/modules/scheduler/htcondor-setup/README.md
[htcondor-pool-secrets]: ../community/modules/scheduler/htcondor-pool-secrets/README.md
[htcondor-access-point]: ../community/modules/scheduler/htcondor-access-point/README.md
Expand Down
Loading