generated from mrsimonemms/new
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(kubernetes): deploy the hcloud-csi to the cluster
A container storage interface (CSI) is used to kubernetes clusters to use volumes to store data. This uses the official Hetzner CSI to enable it in out cluster.
- Loading branch information
1 parent
24c2b1b
commit 4d8af5e
Showing
6 changed files
with
216 additions
and
4 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
# Copyright 2024 Simon Emms <[email protected]> | ||
# | ||
# 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 "github_release" "csi_driver" { | ||
repository = var.hetzner_csi_driver_repo | ||
owner = var.hetzner_csi_driver_owner | ||
|
||
retrieve_by = var.hetzner_csi_driver_version == "latest" ? var.hetzner_csi_driver_version : "tag" | ||
release_tag = var.hetzner_csi_driver_version != "latest" ? var.hetzner_csi_driver_version : null | ||
} | ||
|
||
data "github_repository_file" "csi_driver" { | ||
repository = "${var.hetzner_csi_driver_owner}/${var.hetzner_csi_driver_repo}" | ||
branch = data.github_release.csi_driver.release_tag | ||
file = "deploy/kubernetes/hcloud-csi.yml" | ||
} | ||
|
||
// This secret is required by the Hetzner CSI to create cloud resources | ||
resource "kubernetes_secret_v1" "hcloud_token" { | ||
metadata { | ||
name = "hcloud" | ||
namespace = "kube-system" | ||
} | ||
|
||
data = { | ||
token = var.hcloud_token | ||
} | ||
} | ||
|
||
resource "kubernetes_manifest" "csi_driver" { | ||
for_each = { | ||
for m in provider::kubernetes::manifest_decode_multi(data.github_repository_file.csi_driver.content) : | ||
"${m.apiVersion}.${m.kind}.${m.metadata.name}" => m | ||
} | ||
manifest = each.value | ||
|
||
// The hcloud-csi-controller deployment has 5 containers | ||
computed_fields = [ | ||
"spec.template.spec.containers[0].resources", | ||
"spec.template.spec.containers[1].resources", | ||
"spec.template.spec.containers[2].resources", | ||
"spec.template.spec.containers[3].resources", | ||
"spec.template.spec.containers[4].resources", | ||
] | ||
|
||
depends_on = [kubernetes_secret_v1.hcloud_token, kubernetes_annotations.restarts] | ||
} | ||
|
||
// Restart the core-dns pods as the CSI controller may be in a failed state | ||
// @link https://github.com/hetznercloud/csi-driver/issues/465#issuecomment-1649216197 | ||
resource "time_static" "restarted_at" {} | ||
|
||
resource "kubernetes_annotations" "restarts" { | ||
// The order is important | ||
for_each = toset(["coredns"]) | ||
|
||
api_version = "apps/v1" | ||
kind = "Deployment" | ||
metadata { | ||
name = each.key | ||
namespace = "kube-system" | ||
} | ||
template_annotations = { | ||
"kubectl.kubernetes.io/restartedAt" = time_static.restarted_at.rfc3339 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.