You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: modules/management/kubectl-apply/README.md
+73-1Lines changed: 73 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -13,6 +13,8 @@ This module simplifies the following functionality:
13
13
***Raw String:** Specify manifests directly within the module configuration using the `content: manifest_body` format.
14
14
***File/Template/Directory Reference:** Set `source` to the path to:
15
15
* A single URL to a manifest file. Ex.: `https://github.com/.../myrepo/manifest.yaml`.
16
+
17
+
> **Note:** Applying from a URL has important limitations. Please review the [Considerations & Callouts for Applying from URLs](#applying-manifests-from-urls-considerations--callouts) section below.
16
18
* A single local YAML manifest file (`.yaml`). Ex.: `./manifest.yaml`.
17
19
* A template file (`.tftpl`) to generate a manifest. Ex.: `./template.yaml.tftpl`. You can pass the variables to format the template file in `template_vars`.
18
20
* A directory containing multiple YAML or template files. Ex: `./manifests/`. You can pass the variables to format the template files in `template_vars`.
@@ -95,6 +97,73 @@ You can specify a particular kueue version that you would like to use using the
95
97
>
96
98
> Terraform may apply resources in parallel, leading to potential dependency issues. If a resource's dependencies aren't ready, it will be applied again up to 15 times.
97
99
100
+
## Callouts
101
+
102
+
### Applying Manifests from URLs: Considerations & Callouts
103
+
104
+
While this module supports applying manifests directly from remote `http://` or `https://` URLs, this method introduces complexities not present when using local files. For production environments, we recommend sourcing manifests from local paths or a version-controlled Git repository. Moreover, this method will be deprecated soon. Hence we recommend to use other methods to source manifests.
105
+
106
+
If you choose to use the URL method, be aware of the following potential issues and their solutions.
107
+
108
+
#### **1. Apply Order and Race Conditions**
109
+
110
+
The module applies manifests from the `apply_manifests` list in parallel. This can create a **race condition** if one manifest depends on another. The most common example is applying a manifest with custom resources (like a `ClusterQueue`) at the same time as the manifest that defines it (the `CustomResourceDefinition` or CRD).
111
+
112
+
There is **no guarantee** that the CRD will be applied before the resource that uses it. This can lead to non-deterministic deployment failures with errors like:
113
+
114
+
```Error: resource [kueue.x-k8s.io/v1beta1/ClusterQueue] isn't valid for cluster```
115
+
116
+
##### **Recommended Workaround: Two-Stage Apply**
117
+
118
+
To ensure a reliable deployment, you must manually enforce the correct order of operations.
119
+
120
+
1. **Initial Deployment:** In your blueprint, include **only** the manifest(s) containing the `CustomResourceDefinition` (CRD) resources in the `apply_manifests` list.
2. **Run the deployment** (`gcluster deploy` or `terraform apply`).
133
+
134
+
3. **Second Deployment:** Once the first apply is successful, **add** the manifests containing your custom resources (like `ClusterQueue`, `LocalQueue`) to the list.
- source: "https://gist.githubusercontent.com/YourUser/..." # Your configuration URL
147
+
server_side_apply: true
148
+
```
149
+
150
+
4. **Run the deployment command again.** Since the CRDs are now guaranteed to exist in the cluster, this second apply will succeed reliably.
151
+
152
+
#### **2. Large Manifests (CRDs)**
153
+
154
+
* **Issue:** Applying very large manifests can fail with a `metadata.annotations: Too long` error.
155
+
* **Solution:** Enable Server-Side Apply by setting `server_side_apply: true` for the manifest entry.
156
+
157
+
#### **3. Conflicts on Re-application**
158
+
159
+
* **Issue:** Re-running a deployment after a partial failure can cause server-side apply field manager `conflicts`.
160
+
* **Solution:** Forcibly take ownership of the resource fields by setting `force_conflicts: true`.
161
+
162
+
#### **4. Terraform Template Files (`.tftpl`)**
163
+
164
+
* **Limitation:** This module **cannot** render a template file (`.tftpl`) when sourced from a remote URL.
165
+
* **Workaround:** You must render the template into a pure YAML file locally, host that rendered file at a URL, and provide the URL of the rendered file in your blueprint.
166
+
98
167
## License
99
168
100
169
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
@@ -119,13 +188,15 @@ limitations under the License.
| <a name="input_apply_manifests"></a> [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). | <pre>list(object({<br/> enable = optional(bool, true)<br/> content = optional(string, null)<br/> source = optional(string, null)<br/> template_vars = optional(map(any), null)<br/> server_side_apply = optional(bool, false)<br/> wait_for_rollout = optional(bool, true)<br/> }))</pre> | `[]` | no |
230
+
| <a name="input_apply_manifests"></a> [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).<br/> NOTE: The `enable` input acts as a FF to apply a manifest or not. By default it is always set to `true`. | <pre>list(object({<br/> enable = optional(bool, true)<br/> content = optional(string, null)<br/> source = optional(string, null)<br/> template_vars = optional(map(any), null)<br/> server_side_apply = optional(bool, false)<br/> wait_for_rollout = optional(bool, true)<br/> }))</pre> | `[]` | no |
159
231
| <a name="input_cluster_id"></a> [cluster\_id](#input\_cluster\_id) | An identifier for the gke cluster resource with format projects/<project\_id>/locations/<region>/clusters/<name>. | `string` | n/a | yes |
| <a name="input_gke_cluster_exists"></a> [gke\_cluster\_exists](#input\_gke\_cluster\_exists) | A static flag that signals to downstream modules that a cluster has been created. Needed by community/modules/scripts/kubernetes-operations. | `bool` | `false` | no |
|[http_http.yaml_content](https://registry.terraform.io/providers/hashicorp/http/latest/docs/data-sources/http)| data source |
41
38
|[kubectl_path_documents.templates](https://registry.terraform.io/providers/gavinbunney/kubectl/latest/docs/data-sources/path_documents)| data source |
42
39
|[kubectl_path_documents.yamls](https://registry.terraform.io/providers/gavinbunney/kubectl/latest/docs/data-sources/path_documents)| data source |
yaml_body_docs=[fordocinsplit(local.yaml_separator, local.yaml_body) :trimspace(doc) iflength(trimspace(doc)) >0] # Split yaml to single docs because the kubectl provider only supports single resource
40
+
# --- CONSOLIDATE & PROCESS ---
41
+
# Coalesce finds the first non-null content from the methods above.
Copy file name to clipboardExpand all lines: modules/management/kubectl-apply/variables.tf
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -75,7 +75,7 @@ variable "cluster_id" {
75
75
}
76
76
77
77
variable"apply_manifests" {
78
-
description="A list of manifests to apply to GKE cluster using kubectl. For more details see [kubectl module's inputs](kubectl/README.md)."
78
+
description="A list of manifests to apply to GKE cluster using kubectl. For more details see [kubectl module's inputs](kubectl/README.md).\n NOTE: The `enable` input acts as a FF to apply a manifest or not. By default it is always set to `true`. "
0 commit comments