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

template the kustomization.yaml file #2667

Merged
merged 6 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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: 2 additions & 0 deletions src/_nebari/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
# https://www.hashicorp.com/license-faq
TERRAFORM_VERSION = "1.5.7"

KUBERHEALTHY_HELM_VERSION = "100"

# 04-kubernetes-ingress
DEFAULT_TRAEFIK_IMAGE_TAG = "2.9.1"

Expand Down
17 changes: 15 additions & 2 deletions src/_nebari/stages/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import tempfile
from typing import Any, Dict, List, Tuple

from jinja2 import Environment, FileSystemLoader
aktech marked this conversation as resolved.
Show resolved Hide resolved
from kubernetes import client, config
from kubernetes.client.rest import ApiException

Expand All @@ -24,6 +25,10 @@ def template_directory(self):
def stage_prefix(self):
return pathlib.Path("stages") / self.name

@property
def kustomize_vars(self):
return {}

failed_to_create = False
error_message = ""

Expand Down Expand Up @@ -68,13 +73,19 @@ def check(
sys.exit(1)

def render(self) -> Dict[pathlib.Path, str]:
env = Environment(loader=FileSystemLoader(self.template_directory))

contents = {}
if not (self.template_directory / "kustomization.yaml").exists():
if not (self.template_directory / "kustomization.yaml.tmpl").exists():
raise FileNotFoundError(
f"ERROR: After stage={self.name} "
"kustomization.yaml file not found in template directory"
"kustomization.yaml.tmpl template file not found in template directory"
)
kustomize_template = env.get_template("kustomization.yaml.tmpl")
aktech marked this conversation as resolved.
Show resolved Hide resolved
rendered_kustomization = kustomize_template.render(**self.kustomize_vars)
with open(self.template_directory / "kustomization.yaml", "w") as f:
f.write(rendered_kustomization)

with tempfile.TemporaryDirectory() as temp_dir:
kustomize.run_kustomize_subprocess(
[
Expand Down Expand Up @@ -113,6 +124,8 @@ def render(self) -> Dict[pathlib.Path, str]:
),
)
] = f.read()
# cleanup generated kustomization.yaml
pathlib.Path(self.template_directory, "kustomization.yaml").unlink()

# clean up downloaded helm charts
charts_dir = pathlib.Path(self.template_directory, "charts")
Expand Down
7 changes: 7 additions & 0 deletions src/_nebari/stages/kubernetes_kuberhealthy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ class KuberHealthyStage(NebariKustomizeStage):
input_schema = InputSchema
output_schema = OutputSchema

@property
def kustomize_vars(self):
return {
"namespace": self.config.namespace,
"kuberhealthy_helm_version": self.config.monitoring.healthchecks.kuberhealthy_helm_version,
}

@contextlib.contextmanager
def deploy(
self, stage_outputs: Dict[str, Dict[str, Any]], disable_prompt: bool = False
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ helmCharts:
- name: kuberhealthy
repo: https://kuberhealthy.github.io/kuberhealthy/helm-repos
releaseName: kuberhealthy
namespace: dev
version: "100" # v.2.7.1
namespace: {{ namespace }}
version: "{{ kuberhealthy_version }}" # v.2.7.1
aktech marked this conversation as resolved.
Show resolved Hide resolved
valuesFile: values.yaml
valuesInline:
prometheus:
serviceMonitor:
namespace: {{ namespace }}
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
prometheus:
enabled: true

serviceMonitor:
enabled: true
namespace: dev
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ class KuberHealthyStage(NebariKustomizeStage):
input_schema = InputSchema
output_schema = OutputSchema

@property
def kustomize_vars(self):
return {
"namespace": self.config.namespace,
}

@contextlib.contextmanager
def deploy(
self, stage_outputs: Dict[str, Dict[str, Any]], disable_prompt: bool = False
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ patches:
patch: |-
- op: replace
path: /metadata/namespace
value: "dev"
value: "{{ namespace }}"
1 change: 1 addition & 0 deletions src/_nebari/stages/kubernetes_services/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ class MonitoringOverrides(schema.Base):

class Healthchecks(schema.Base):
enabled: bool = False
kuberhealthy_helm_version: str = constants.KUBERHEALTHY_HELM_VERSION


class Monitoring(schema.Base):
Expand Down
Loading