Skip to content

Commit

Permalink
Move custom resources to helm chart
Browse files Browse the repository at this point in the history
  • Loading branch information
mcgin314 committed Mar 6, 2025
1 parent 9923678 commit 61b9080
Show file tree
Hide file tree
Showing 10 changed files with 223 additions and 50 deletions.
84 changes: 59 additions & 25 deletions main.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
locals {
telemetry_ns = var.namespace

otel_internal_hostname = format("otel-daemonset-collector.%v.svc.cluster.local", local.telemetry_ns)
otel_internal_port_number = 4318
otel_internal_url = format("http://%v:%v/", local.otel_internal_hostname, local.otel_internal_port_number)
}

# Install opentelemetry-collector daemonset collector, handles collection of node and workload telemetry data
Expand Down Expand Up @@ -66,30 +70,60 @@ resource "helm_release" "opentelemetry-operator" {
timeout = 180
}

# SHOULD PROBABLY PUT THESE OBJECTS INTO A HELM CHART
# Create karpenter default
# resource "kubectl_manifest" "otelcol_daemonset" {
# depends_on = [
# helm_release.opentelemetry-operator,
# ]
# yaml_body = templatefile("${path.module}/otelcol_daemonset.yaml.tpl", {

# # cluster_name = var.cluster_name
# # tags = jsonencode(data.aws_default_tags.default_tags.tags)
# # amd_ami_family = "Bottlerocket"
# # amd_ami_alias = "bottlerocket"
# })
# }
# Install the opentelemetry collectors and instrumentation
resource "helm_release" "otel-resources" {
depends_on = [
helm_release.opentelemetry-operator,
]

# resource "kubectl_manifest" "otelcol_simple" {
# depends_on = [
# helm_release.opentelemetry-operator,
# ]
# yaml_body = templatefile("${path.module}/collector_simple.yaml", {
chart = "./otel"
name = "otel-resources"
namespace = local.telemetry_ns
version = local.module_version

# # cluster_name = var.cluster_name
# # tags = jsonencode(data.aws_default_tags.default_tags.tags)
# # amd_ami_family = "Bottlerocket"
# # amd_ami_alias = "bottlerocket"
# })
# }
set {
name = "collector.image"
value = format("%v/%v",
module.images.images[local.collector_key].dest_registry,
module.images.images[local.collector_key].dest_repository
)
}
set {
name = "collector.tag"
value = module.images.images[local.collector_key].tag
}
set {
name = "collectorContrib.image"
value = format("%v/%v",
module.images.images[local.collector_contrib_key].dest_registry,
module.images.images[local.collector_contrib_key].dest_repository
)
}
set {
name = "collectorContrib.tag"
value = module.images.images[local.collector_contrib_key].tag
}
set {
name = "loki.endpoint"
value = var.loki_endpoint
}
set {
name = "tempo.endpoint"
value = var.tempo_endpoint
}
set {
name = "otel.endpoint"
value = local.otel_internal_url
}
set {
name = "autoinstrumentation.java.image"
value = format("%v/%v",
module.images.images[local.auto_instrumentation_java_key].dest_registry,
module.images.images[local.auto_instrumentation_java_key].dest_repository
)
}
set {
name = "autoinstrumentation.java.tag"
value = module.images.images[local.auto_instrumentation_java_key].tag
}
}
23 changes: 23 additions & 0 deletions otel/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*.orig
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/
24 changes: 24 additions & 0 deletions otel/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apiVersion: v2
name: otel
description: A Helm chart for Kubernetes

# A chart can be either an 'application' or a 'library' chart.
#
# Application charts are a collection of templates that can be packaged into versioned archives
# to be deployed.
#
# Library charts provide useful utilities or functions for the chart developer. They're included as
# a dependency of application charts to inject those utilities and functions into the rendering
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
type: application

# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.1.0

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.
appVersion: "1.16.0"
1 change: 1 addition & 0 deletions otel/templates/NOTES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Open Telemetry Collectors and Instrumentation has been installed.
62 changes: 62 additions & 0 deletions otel/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "otel.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
If release name contains chart name it will be used as a full name.
*/}}
{{- define "otel.fullname" -}}
{{- if .Values.fullnameOverride }}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- $name := default .Chart.Name .Values.nameOverride }}
{{- if contains $name .Release.Name }}
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
{{- end }}
{{- end }}
{{- end }}

{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "otel.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Common labels
*/}}
{{- define "otel.labels" -}}
helm.sh/chart: {{ include "otel.chart" . }}
{{ include "otel.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}

{{/*
Selector labels
*/}}
{{- define "otel.selectorLabels" -}}
app.kubernetes.io/name: {{ include "otel.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}

{{/*
Create the name of the service account to use
*/}}
{{- define "otel.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "otel.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@ apiVersion: opentelemetry.io/v1alpha1
kind: Instrumentation
metadata:
name: java-instrumentation
namespace: telemetry
spec:
exporter:
endpoint: http://otel-daemonset-collector.telemetry.svc.cluster.local:4318
endpoint: {{ .Values.otel.endpoint }}
propagators:
- tracecontext
- baggage
sampler:
type: parentbased_traceidratio
argument: "1"
java:
image: 224384469011.dkr.ecr.us-gov-east-1.amazonaws.com/platform-test-z/autoinstrumentation-java:2.9.0
image: "{{ .Values.autoinstrumentation.java.image }}:{{ .Values.autoinstrumentation.java.tag | default .Chart.AppVersion }}"
11 changes: 4 additions & 7 deletions otelcol_daemonset.yaml → otel/templates/otelcol_daemonset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ apiVersion: opentelemetry.io/v1beta1
kind: OpenTelemetryCollector
metadata:
name: otel-daemonset
namespace: telemetry
spec:
mode: daemonset
config:
Expand Down Expand Up @@ -155,9 +154,9 @@ spec:
exporters:
debug: {}
otlphttp:
endpoint: http://loki-gateway.loki.svc.cluster.local:80/otlp
endpoint: "{{ .Values.loki.endpoint }}/otlp"
otlp:
endpoint: http://tempo.tempo.svc.cluster.local:4317
endpoint: {{ .Values.tempo.endpoint }}
tls:
insecure: true
# prometheusremotewrite:
Expand Down Expand Up @@ -189,8 +188,7 @@ spec:
# receivers: [otlp, kubeletstats, spanmetrics]
# processors: [memory_limiter, k8sattributes, batch]
# exporters: [debug, prometheusremotewrite]
# image: 224384469011.dkr.ecr.us-gov-east-1.amazonaws.com/platform-test-z/opentelemetry-collector-k8s:0.111.0-amd64
image: 224384469011.dkr.ecr.us-gov-east-1.amazonaws.com/platform-test-z/opentelemetry-collector-contrib:0.113.0-amd64
image: "{{ .Values.collectorContrib.image }}:{{ .Values.collectorContrib.tag | default .Chart.AppVersion }}"
serviceAccount: otel-daemon
env:
- name: K8S_NODE_NAME
Expand Down Expand Up @@ -218,7 +216,6 @@ apiVersion: v1
kind: ServiceAccount
metadata:
name: otel-daemon
namespace: telemetry
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
Expand Down Expand Up @@ -267,4 +264,4 @@ roleRef:
subjects:
- kind: ServiceAccount
name: otel-daemon
namespace: telemetry
namespace: {{ .Release.Namespace }}
28 changes: 13 additions & 15 deletions otelcol_deployment.yaml → otel/templates/otelcol_deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
apiVersion: opentelemetry.io/v1beta1
kind: OpenTelemetryCollector
metadata:
name: otel-deploy
namespace: telemetry
name: otel-deployment
spec:
mode: deployment
config:
Expand All @@ -22,7 +21,7 @@ spec:
exporters:
debug: {}
otlphttp:
endpoint: http://loki-gateway.loki.svc.cluster.local:80/otlp
endpoint: "{{ .Values.loki.endpoint }}/otlp"
service:
pipelines:
metrics:
Expand All @@ -31,23 +30,22 @@ spec:
logs/entity_events:
receivers: [k8s_cluster, k8sobjects]
exporters: [debug, otlphttp]
image: 224384469011.dkr.ecr.us-gov-east-1.amazonaws.com/platform-test-z/opentelemetry-collector-k8s:0.111.0-amd64
serviceAccount: otel-deploy
image: "{{ .Values.collector.image }}:{{ .Values.collector.tag | default .Chart.AppVersion }}"
serviceAccount: otel-deployment
---
apiVersion: v1
kind: ServiceAccount
metadata:
labels:
app: otel-deploy
name: otel-deploy
namespace: telemetry
app: otel-deployment
name: otel-deployment
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: otel-deploy
name: otel-deployment
labels:
app: otel-deploy
app: otel-deployment
rules:
- apiGroups:
- ""
Expand Down Expand Up @@ -116,14 +114,14 @@ rules:
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: otel-deploy
name: otel-deployment
labels:
app: otel-deploy
app: otel-deployment
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: otel-deploy
name: otel-deployment
subjects:
- kind: ServiceAccount
name: otel-deploy
namespace: telemetry
name: otel-deployment
namespace: {{ .Release.Namespace }}
25 changes: 25 additions & 0 deletions otel/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Default values for otel.
# This is a YAML-formatted file.
# Declare variables to be passed into your templates.

collector:
image: ""
tag: ""

collectorContrib:
image: ""
tag: ""

loki:
endpoint: ""

tempo:
endpoint: ""

otel:
endpoint: ""

autoinstrumentation:
java:
image: ""
tag: ""
10 changes: 10 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@ variable "otel_helm_version" {
default = "0.71.2"
}

variable "loki_endpoint" {
description = "The internal endpoint for the loki service"
type = string
}

variable "tempo_endpoint" {
description = "Internal otlp endpoint of tempo"
type = string
}

# tflint-ignore: terraform_unused_declarations
variable "tags" {
description = "AWS Tags to apply to appropriate resources"
Expand Down

0 comments on commit 61b9080

Please sign in to comment.