Skip to content

Commit

Permalink
improve deploy_observability for Tilt
Browse files Browse the repository at this point in the history
  • Loading branch information
fabriziopandini committed Feb 8, 2022
1 parent d38a4b1 commit a754ca3
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 29 deletions.
21 changes: 13 additions & 8 deletions Tiltfile
Original file line number Diff line number Diff line change
Expand Up @@ -322,11 +322,17 @@ def deploy_provider_crds():
)

def deploy_observability():
k8s_yaml(read_file("./.tiltbuild/yaml/observability.tools.yaml"))
if "promtail" in settings.get("deploy_observability", []):
k8s_yaml(read_file("./.tiltbuild/yaml/promtail.observability.yaml"), allow_duplicates = True)
k8s_resource(workload = "promtail", extra_pod_selectors = [{"app": "promtail"}], labels = ["observability"], resource_deps = ["loki"])

k8s_resource(workload = "promtail", extra_pod_selectors = [{"app": "promtail"}], labels = ["observability"])
k8s_resource(workload = "loki", extra_pod_selectors = [{"app": "loki"}], labels = ["observability"])
k8s_resource(workload = "grafana", port_forwards = "3000", extra_pod_selectors = [{"app": "grafana"}], labels = ["observability"])
if "loki" in settings.get("deploy_observability", []):
k8s_yaml(read_file("./.tiltbuild/yaml/loki.observability.yaml"), allow_duplicates = True)
k8s_resource(workload = "loki", extra_pod_selectors = [{"app": "loki"}], labels = ["observability"])

if "grafana" in settings.get("deploy_observability", []):
k8s_yaml(read_file("./.tiltbuild/yaml/grafana.observability.yaml"), allow_duplicates = True)
k8s_resource(workload = "grafana", port_forwards = "3000", extra_pod_selectors = [{"app": "grafana"}], labels = ["observability"])

def prepare_all():
allow_k8s_arg = ""
Expand All @@ -345,8 +351,8 @@ def prepare_all():
# Note: we are creating clusterctl CRDs using kustomize (vs using clusterctl) because we want to create
# a dependency between these resources and provider resources.
kustomize_build_arg = "--kustomize-builds clusterctl.crd:./cmd/clusterctl/config/crd/ "
if settings.get("deploy_observability"):
kustomize_build_arg = kustomize_build_arg + "--kustomize-builds observability.tools:./hack/observability/ "
for tool in settings.get("deploy_observability", []):
kustomize_build_arg = kustomize_build_arg + "--kustomize-builds {tool}.observability:./hack/observability/{tool}/ ".format(tool = tool)
providers_arg = ""
for name in get_providers():
p = providers.get(name)
Expand Down Expand Up @@ -382,7 +388,6 @@ prepare_all()

deploy_provider_crds()

if settings.get("deploy_observability"):
deploy_observability()
deploy_observability()

enable_providers()
4 changes: 2 additions & 2 deletions docs/book/src/developer/tilt.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ for more details.
**kustomize_substitutions** (Map{String: String}, default={}): An optional map of substitutions for `${}`-style placeholders in the
provider's yaml.
**deploy_observability** (Bool, default=false): If set to true, it will instrall grafana, loki and promtail in the dev
cluster. Grafana UI will be accessible via a link in the tilt console.
**deploy_observability** ([string], default=[]): If set, it will install in the dev cluster one of more observability
tools between `grafana`, `loki` or `promtail` (Note: the UI for `grafana` will be accessible via a link in the tilt console).
Important! This feature requires the `helm` command to be available in the user's path.

**debug** (Map{string: Map} default{}): A map of named configurations for the provider. The key is the name of the provider.
Expand Down
9 changes: 9 additions & 0 deletions hack/observability/grafana/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
resources:
- ../namespace.yaml

helmCharts:
- name: grafana
repo: https://grafana.github.io/helm-charts
releaseName: grafana
namespace: observability
valuesFile: values.yaml
19 changes: 0 additions & 19 deletions hack/observability/kustomization.yaml

This file was deleted.

9 changes: 9 additions & 0 deletions hack/observability/loki/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
resources:
- ../namespace.yaml

helmCharts:
- name: loki
repo: https://grafana.github.io/helm-charts
releaseName: loki
namespace: observability
valuesFile: values.yaml
9 changes: 9 additions & 0 deletions hack/observability/promtail/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
resources:
- ../namespace.yaml

helmCharts:
- name: promtail
repo: https://grafana.github.io/helm-charts
releaseName: promtail
namespace: observability
valuesFile: values.yaml
2 changes: 2 additions & 0 deletions hack/tools/tilt-prepare/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,8 @@ func kustomizeTask(path, out string) taskFunction {
path,
// enable helm to enable helmChartInflationGenerator.
"--enable-helm",
// to allow picking up resource files from a different folder.
"--load-restrictor=LoadRestrictionsNone",
)

var stdout, stderr bytes.Buffer
Expand Down

0 comments on commit a754ca3

Please sign in to comment.