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

Added the environment debugger chart. #8

Merged
merged 2 commits into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 3 additions & 3 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
Documentation:
documentation:
- changed-files:
- any-glob-to-any-file:
- "docs/*"
- "**/*.md"

Software:
software:
- changed-files:
- any-glob-to-any-file:
- "software/**/*"
- "stamp/**/*"
- "charts/**/*"

Infrastructure:
infrastructure:
- changed-files:
- any-glob-to-any-file:
- "bicep/**/*"
Expand Down
4 changes: 3 additions & 1 deletion charts/README.MD
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
# Helm Charts
# Helm Charts

This directory contains custom charts to be used by the solution.
1 change: 1 addition & 0 deletions charts/env-debug/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
custom_values.yaml
23 changes: 23 additions & 0 deletions charts/env-debug/.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/
23 changes: 23 additions & 0 deletions charts/env-debug/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
apiVersion: v2
name: env-debug
description: A Sample App with Ingress for accessing KV Secrets

# 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.0.2

# 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.
appVersion: 0.0.1
70 changes: 70 additions & 0 deletions charts/env-debug/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# Helm Chart for Environment Debuging

__Create a Custom Values__

_The following commands can help generate a prepopulated custom_values file._
```bash
# Setup Variables
RAND="<your_random_value>" # ie: bedfb

GROUP=$(az group list --query "[?contains(name, 'ctl${UNIQUE}')].name" -otsv)
ENV_VAULT=$(az keyvault list --resource-group $GROUP --query [].name -otsv)

# Translate Values File
cat > custom_values.yaml << EOF
replicaCount: 1

nameOverride: ""
fullnameOverride: ""

service:
type: ClusterIP
port: 80
targetPort: 8080

autoscaling:
enabled: false
minReplicas: 1
maxReplicas: 3
targetCPUUtilizationPercentage: 80

################################################################################
# Specify the azure environment specific values
#
azure:
enabled: true
tenant: $(az keyvault secret show --id https://${ENV_VAULT}.vault.azure.net/secrets/tenant-id --query value -otsv)
subscription: $(az keyvault secret show --id https://${ENV_VAULT}.vault.azure.net/secrets/subscription-id --query value -otsv)
resourcegroup: $(az keyvault secret show --id https://${ENV_VAULT}.vault.azure.net/secrets/base-name-cr --query value -otsv)-rg
identity: $(az keyvault secret show --id https://${ENV_VAULT}.vault.azure.net/secrets/base-name-cr --query value -otsv)-osdu-identity
identity_id: $(az keyvault secret show --id https://${ENV_VAULT}.vault.azure.net/secrets/osdu-identity-id --query value -otsv)
keyvault: $ENV_VAULT
appid: $(az keyvault secret show --id https://${ENV_VAULT}.vault.azure.net/secrets/aad-client-id --query value -otsv)

env:
- name: MESSAGE
value: Hello World!
- name: AZURE_TENANT_ID
secret:
name: active-directory
key: tenantid
- name: WORKSPACE_ID
secret:
name: central-logging
key: workspace-id

EOF


__Install Helm Chart__

Install the helm chart.

```bash
# Create Namespace
NAMESPACE=dev-sample
kubectl create namespace $NAMESPACE

# Install Charts
helm install env-tool . -n $NAMESPACE -f custom_values.yaml
```
53 changes: 53 additions & 0 deletions charts/env-debug/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{{/* vim: set filetype=mustache: */}}
{{/*
Expand the name of the chart.
*/}}
{{- define "env-debug.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 "env-debug.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 "env-debug.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

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

{{/*
Selector labels
*/}}
{{- define "env-debug.selectorLabels" -}}
app.kubernetes.io/name: {{ include "env-debug.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
aadpodidbinding: osdu-identity
{{- end }}
8 changes: 8 additions & 0 deletions charts/env-debug/templates/config-map.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{{- $namespace := .Release.Namespace }}
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ include "env-debug.fullname" . }}-config
namespace: {{ $namespace }}
data:
MESSAGE: "From config-map.yaml"
116 changes: 116 additions & 0 deletions charts/env-debug/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
{{- $namespace := .Release.Namespace }}
{{- $nodePool := .Values.nodePool}}
{{- $toleration := .Values.toleration}}
{{- $affinity := .Values.affinity}}
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "env-debug.fullname" . }}
labels:
{{- include "env-debug.labels" . | nindent 4 }}
spec:
{{- if not .Values.autoscaling.enabled }}
replicas: {{ .Values.replicaCount }}
{{- end }}
selector:
matchLabels:
{{- include "env-debug.selectorLabels" . | nindent 6 }}
template:
metadata:
{{- with .Values.podAnnotations }}
annotations:
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
{{- include "env-debug.selectorLabels" . | nindent 8 }}
spec:
{{- if $nodePool }}
nodeSelector:
nodepool: {{ $nodePool }}
{{- end }}
{{- if $affinity }}
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
{{- if $affinity.zones }}
- key: topology.kubernetes.io/zone
operator: In
values:
{{- range $affinity.zones }}
- {{ . }}
{{- end }}
{{- end }}
{{- if $affinity.pools }}
- key: agentpool
operator: In
values:
{{- range $affinity.pools }}
- {{ . }}
{{- end }}
{{- end }}
{{- end }}
{{- if $toleration }}
tolerations:
- key: "app"
operator: "Equal"
value: {{ $toleration }}
effect: "NoSchedule"
{{- end }}
{{- if .Values.azure.enabled }}
volumes:
- name: azure-keyvault
csi:
driver: secrets-store.csi.k8s.io
readOnly: true
volumeAttributes:
secretProviderClass: azure-keyvault
- name: azure-share
persistentVolumeClaim:
claimName: {{ include "env-debug.fullname" . }}-pvc
{{- end }}
containers:
- image: gcr.io/kuar-demo/kuard-amd64:1
name: kuard
ports:
- containerPort: 8080
name: http
protocol: TCP
{{- if .Values.azure.enabled }}
volumeMounts:
- name: azure-keyvault
mountPath: "/mnt/azure-keyvault"
readOnly: true
- name: azure-share
mountPath: "/mnt/azure-share"
readOnly: true
{{- end }}
env:
- name: STATIC_ENV_VALUE
value: "From Deployment.yaml"
- name: CONFIG_ENV_VALUE
valueFrom:
configMapKeyRef:
name: {{ include "env-debug.fullname" . }}-config
key: MESSAGE
{{- if .Values.env }}
{{- range .Values.env }}
- name: {{ .name }}
{{- if .value }}
value: {{ .value | quote }}
{{- end }}
{{- if .config }}
valueFrom:
configMapKeyRef:
name: {{ include "env-debug.fullname" . }}-config
key: {{ .config.key | quote }}
{{- end }}
{{- if .secret }}
valueFrom:
secretKeyRef:
name: {{ .secret.name | quote }}
key: {{ .secret.key | quote }}
{{- end }}
{{- end }}
{{- end }}
28 changes: 28 additions & 0 deletions charts/env-debug/templates/hpa.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{{- if .Values.autoscaling.enabled }}
apiVersion: autoscaling/v2beta1
kind: HorizontalPodAutoscaler
metadata:
name: {{ include "env-debug.fullname" . }}
labels:
{{- include "env-debug.labels" . | nindent 4 }}
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: {{ include "env-debug.fullname" . }}
minReplicas: {{ .Values.autoscaling.minReplicas }}
maxReplicas: {{ .Values.autoscaling.maxReplicas }}
metrics:
{{- if .Values.autoscaling.targetCPUUtilizationPercentage }}
- type: Resource
resource:
name: cpu
targetAverageUtilization: {{ .Values.autoscaling.targetCPUUtilizationPercentage }}
{{- end }}
{{- if .Values.autoscaling.targetMemoryUtilizationPercentage }}
- type: Resource
resource:
name: memory
targetAverageUtilization: {{ .Values.autoscaling.targetMemoryUtilizationPercentage }}
{{- end }}
{{- end }}
19 changes: 19 additions & 0 deletions charts/env-debug/templates/identity.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{{- $namespace := .Release.Namespace }}
apiVersion: aadpodidentity.k8s.io/v1
kind: AzureIdentity
metadata:
name: osdu-identity
namespace: {{ $namespace }}
spec:
type: 0
resourceID: "/subscriptions/{{ .Values.azure.subscription }}/resourcegroups/{{ .Values.azure.resourcegroup }}/providers/Microsoft.ManagedIdentity/userAssignedIdentities/{{ .Values.azure.identity }}"
clientID: "{{ .Values.azure.identity_id }}"
---
apiVersion: aadpodidentity.k8s.io/v1
kind: AzureIdentityBinding
metadata:
name: osdu-identity-binding
namespace: {{ $namespace }}
spec:
azureIdentity: osdu-identity
selector: osdu-identity
17 changes: 17 additions & 0 deletions charts/env-debug/templates/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{{- $serviceType := .Values.service.type }}
{{- $servicePort := .Values.service.port }}
apiVersion: v1
kind: Service
metadata:
name: {{ include "env-debug.fullname" . }}
labels:
{{- include "env-debug.labels" . | nindent 4 }}
spec:
type: {{ $serviceType }}
ports:
- port: {{ $servicePort }}
targetPort: http
protocol: TCP
name: http
selector:
{{- include "env-debug.selectorLabels" . | nindent 4 }}
Loading