From ea09687975d9a581eeb1ca60f2ee9ac5f96b064d Mon Sep 17 00:00:00 2001 From: michaeljguarino Date: Tue, 24 Dec 2024 21:33:20 -0500 Subject: [PATCH] add stateless helm chart --- assets/package.json | 2 +- assets/src/helpers/client.ts | 5 + assets/yarn.lock | 10 +- charts/stateless/.helmignore | 23 ++++ charts/stateless/Chart.yaml | 6 + charts/stateless/templates/NOTES.txt | 22 ++++ charts/stateless/templates/_helpers.tpl | 62 ++++++++++ charts/stateless/templates/deployment.yaml | 76 ++++++++++++ charts/stateless/templates/hpa.yaml | 32 +++++ charts/stateless/templates/ingress.yaml | 61 ++++++++++ charts/stateless/templates/service.yaml | 15 +++ .../stateless/templates/serviceaccount.yaml | 13 +++ charts/stateless/values.yaml | 109 ++++++++++++++++++ 13 files changed, 430 insertions(+), 6 deletions(-) create mode 100644 charts/stateless/.helmignore create mode 100644 charts/stateless/Chart.yaml create mode 100644 charts/stateless/templates/NOTES.txt create mode 100644 charts/stateless/templates/_helpers.tpl create mode 100644 charts/stateless/templates/deployment.yaml create mode 100644 charts/stateless/templates/hpa.yaml create mode 100644 charts/stateless/templates/ingress.yaml create mode 100644 charts/stateless/templates/service.yaml create mode 100644 charts/stateless/templates/serviceaccount.yaml create mode 100644 charts/stateless/values.yaml diff --git a/assets/package.json b/assets/package.json index dbdbeca2cb..8c64a33255 100644 --- a/assets/package.json +++ b/assets/package.json @@ -80,7 +80,7 @@ "kubernetes-resource-parser": "0.1.0", "lodash": "4.17.21", "moment": "2.29.4", - "phoenix": "1.7.3", + "phoenix": "1.7.14", "pluralize": "8.0.0", "pluralsh-absinthe-socket-apollo-link": "0.2.0", "query-string": "8.1.0", diff --git a/assets/src/helpers/client.ts b/assets/src/helpers/client.ts index 4cdf6dcf26..f0574e125a 100644 --- a/assets/src/helpers/client.ts +++ b/assets/src/helpers/client.ts @@ -122,6 +122,11 @@ export function buildClient(gqlUrl, wsUrl, fetchToken) { }) // socket.onOpen(() => maybeRejoin(absintheSocket.channel)) + socket.onOpen(() => { + setTimeout(() => { + socket.channels.forEach((c) => c.rejoinTimer.scheduleTimeout()) + }, 100) + }) socket.onClose(() => maybeReconnect(socket)) setInterval(() => maybeReconnect(socket), 5000) diff --git a/assets/yarn.lock b/assets/yarn.lock index 614cee0e1f..667aadd628 100644 --- a/assets/yarn.lock +++ b/assets/yarn.lock @@ -10196,7 +10196,7 @@ __metadata: moment: 2.29.4 moment-timezone: 0.5.43 npm-run-all: 4.1.5 - phoenix: 1.7.3 + phoenix: 1.7.14 pluralize: 8.0.0 pluralsh-absinthe-socket-apollo-link: 0.2.0 prettier: 3.3.3 @@ -17199,10 +17199,10 @@ __metadata: languageName: node linkType: hard -"phoenix@npm:1.7.3": - version: 1.7.3 - resolution: "phoenix@npm:1.7.3" - checksum: 039270c919e269412cbc40e46cbe667073506d387406856c3b03aa7ec338a710615f9ff3a2156e08877b851f5b29eaefb71da55d66ea1c7738a294761db04b93 +"phoenix@npm:1.7.14": + version: 1.7.14 + resolution: "phoenix@npm:1.7.14" + checksum: c687f340380df1ba9af5f526c76a06a445cb819d366873bee228a2151f66c9732d1e579dda5371be3c80674e5fd8003bc19549dbadec1fd25220bc8081e30440 languageName: node linkType: hard diff --git a/charts/stateless/.helmignore b/charts/stateless/.helmignore new file mode 100644 index 0000000000..0e8a0eb36f --- /dev/null +++ b/charts/stateless/.helmignore @@ -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/ diff --git a/charts/stateless/Chart.yaml b/charts/stateless/Chart.yaml new file mode 100644 index 0000000000..d3eeb03d1c --- /dev/null +++ b/charts/stateless/Chart.yaml @@ -0,0 +1,6 @@ +apiVersion: v2 +name: stateless +description: A Helm chart to deploy a basic stateless application +type: application +version: 0.1.0 +appVersion: "1.16.0" diff --git a/charts/stateless/templates/NOTES.txt b/charts/stateless/templates/NOTES.txt new file mode 100644 index 0000000000..3ff5dbf807 --- /dev/null +++ b/charts/stateless/templates/NOTES.txt @@ -0,0 +1,22 @@ +1. Get the application URL by running these commands: +{{- if .Values.ingress.enabled }} +{{- range $host := .Values.ingress.hosts }} + {{- range .paths }} + http{{ if $.Values.ingress.tls }}s{{ end }}://{{ $host.host }}{{ .path }} + {{- end }} +{{- end }} +{{- else if contains "NodePort" .Values.service.type }} + export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "stateless.fullname" . }}) + export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}") + echo http://$NODE_IP:$NODE_PORT +{{- else if contains "LoadBalancer" .Values.service.type }} + NOTE: It may take a few minutes for the LoadBalancer IP to be available. + You can watch its status by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "stateless.fullname" . }}' + export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "stateless.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}") + echo http://$SERVICE_IP:{{ .Values.service.port }} +{{- else if contains "ClusterIP" .Values.service.type }} + export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "stateless.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}") + export CONTAINER_PORT=$(kubectl get pod --namespace {{ .Release.Namespace }} $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}") + echo "Visit http://127.0.0.1:8080 to use your application" + kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 8080:$CONTAINER_PORT +{{- end }} diff --git a/charts/stateless/templates/_helpers.tpl b/charts/stateless/templates/_helpers.tpl new file mode 100644 index 0000000000..c2bc5b9827 --- /dev/null +++ b/charts/stateless/templates/_helpers.tpl @@ -0,0 +1,62 @@ +{{/* +Expand the name of the chart. +*/}} +{{- define "stateless.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 "stateless.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 "stateless.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Common labels +*/}} +{{- define "stateless.labels" -}} +helm.sh/chart: {{ include "stateless.chart" . }} +{{ include "stateless.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "stateless.selectorLabels" -}} +app.kubernetes.io/name: {{ include "stateless.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} + +{{/* +Create the name of the service account to use +*/}} +{{- define "stateless.serviceAccountName" -}} +{{- if .Values.serviceAccount.create }} +{{- default (include "stateless.fullname" .) .Values.serviceAccount.name }} +{{- else }} +{{- default "default" .Values.serviceAccount.name }} +{{- end }} +{{- end }} diff --git a/charts/stateless/templates/deployment.yaml b/charts/stateless/templates/deployment.yaml new file mode 100644 index 0000000000..d404f00a52 --- /dev/null +++ b/charts/stateless/templates/deployment.yaml @@ -0,0 +1,76 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "stateless.fullname" . }} + labels: + {{- include "stateless.labels" . | nindent 4 }} +spec: + {{- if not .Values.autoscaling.enabled }} + replicas: {{ .Values.replicaCount }} + {{- end }} + selector: + matchLabels: + {{- include "stateless.selectorLabels" . | nindent 6 }} + template: + metadata: + {{- with .Values.podAnnotations }} + annotations: + {{- toYaml . | nindent 8 }} + {{- end }} + labels: + {{- include "stateless.labels" . | nindent 8 }} + {{- with .Values.podLabels }} + {{- toYaml . | nindent 8 }} + {{- end }} + spec: + {{- with .Values.imagePullSecrets }} + imagePullSecrets: + {{- toYaml . | nindent 8 }} + {{- end }} + serviceAccountName: {{ include "stateless.serviceAccountName" . }} + securityContext: + {{- toYaml .Values.podSecurityContext | nindent 8 }} + containers: + - name: {{ .Chart.Name }} + securityContext: + {{- toYaml .Values.securityContext | nindent 12 }} + image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + {{ if .Values.env }} + env: + {{ toYaml .Values.env | nindent 12 }} + {{ end }} + {{ if .Values.envFrom }} + envFrom: + {{ toYaml .Values.envFrom | nindent 12 }} + {{ end }} + ports: + - name: http + containerPort: {{ .Values.service.port }} + protocol: TCP + livenessProbe: + {{- toYaml .Values.livenessProbe | nindent 12 }} + readinessProbe: + {{- toYaml .Values.readinessProbe | nindent 12 }} + resources: + {{- toYaml .Values.resources | nindent 12 }} + {{- with .Values.volumeMounts }} + volumeMounts: + {{- toYaml . | nindent 12 }} + {{- end }} + {{- with .Values.volumes }} + volumes: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.nodeSelector }} + nodeSelector: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.affinity }} + affinity: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.tolerations }} + tolerations: + {{- toYaml . | nindent 8 }} + {{- end }} diff --git a/charts/stateless/templates/hpa.yaml b/charts/stateless/templates/hpa.yaml new file mode 100644 index 0000000000..8367078b9f --- /dev/null +++ b/charts/stateless/templates/hpa.yaml @@ -0,0 +1,32 @@ +{{- if .Values.autoscaling.enabled }} +apiVersion: autoscaling/v2 +kind: HorizontalPodAutoscaler +metadata: + name: {{ include "stateless.fullname" . }} + labels: + {{- include "stateless.labels" . | nindent 4 }} +spec: + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: {{ include "stateless.fullname" . }} + minReplicas: {{ .Values.autoscaling.minReplicas }} + maxReplicas: {{ .Values.autoscaling.maxReplicas }} + metrics: + {{- if .Values.autoscaling.targetCPUUtilizationPercentage }} + - type: Resource + resource: + name: cpu + target: + type: Utilization + averageUtilization: {{ .Values.autoscaling.targetCPUUtilizationPercentage }} + {{- end }} + {{- if .Values.autoscaling.targetMemoryUtilizationPercentage }} + - type: Resource + resource: + name: memory + target: + type: Utilization + averageUtilization: {{ .Values.autoscaling.targetMemoryUtilizationPercentage }} + {{- end }} +{{- end }} diff --git a/charts/stateless/templates/ingress.yaml b/charts/stateless/templates/ingress.yaml new file mode 100644 index 0000000000..e885ccf1cb --- /dev/null +++ b/charts/stateless/templates/ingress.yaml @@ -0,0 +1,61 @@ +{{- if .Values.ingress.enabled -}} +{{- $fullName := include "stateless.fullname" . -}} +{{- $svcPort := .Values.service.port -}} +{{- if and .Values.ingress.className (not (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion)) }} + {{- if not (hasKey .Values.ingress.annotations "kubernetes.io/ingress.class") }} + {{- $_ := set .Values.ingress.annotations "kubernetes.io/ingress.class" .Values.ingress.className}} + {{- end }} +{{- end }} +{{- if semverCompare ">=1.19-0" .Capabilities.KubeVersion.GitVersion -}} +apiVersion: networking.k8s.io/v1 +{{- else if semverCompare ">=1.14-0" .Capabilities.KubeVersion.GitVersion -}} +apiVersion: networking.k8s.io/v1beta1 +{{- else -}} +apiVersion: extensions/v1beta1 +{{- end }} +kind: Ingress +metadata: + name: {{ $fullName }} + labels: + {{- include "stateless.labels" . | nindent 4 }} + {{- with .Values.ingress.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +spec: + {{- if and .Values.ingress.className (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion) }} + ingressClassName: {{ .Values.ingress.className }} + {{- end }} + {{- if .Values.ingress.tls }} + tls: + {{- range .Values.ingress.tls }} + - hosts: + {{- range .hosts }} + - {{ . | quote }} + {{- end }} + secretName: {{ .secretName }} + {{- end }} + {{- end }} + rules: + {{- range .Values.ingress.hosts }} + - host: {{ .host | quote }} + http: + paths: + {{- range .paths }} + - path: {{ .path }} + {{- if and .pathType (semverCompare ">=1.18-0" $.Capabilities.KubeVersion.GitVersion) }} + pathType: {{ .pathType }} + {{- end }} + backend: + {{- if semverCompare ">=1.19-0" $.Capabilities.KubeVersion.GitVersion }} + service: + name: {{ $fullName }} + port: + number: {{ $svcPort }} + {{- else }} + serviceName: {{ $fullName }} + servicePort: {{ $svcPort }} + {{- end }} + {{- end }} + {{- end }} +{{- end }} diff --git a/charts/stateless/templates/service.yaml b/charts/stateless/templates/service.yaml new file mode 100644 index 0000000000..aed1f758e0 --- /dev/null +++ b/charts/stateless/templates/service.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ include "stateless.fullname" . }} + labels: + {{- include "stateless.labels" . | nindent 4 }} +spec: + type: {{ .Values.service.type }} + ports: + - port: {{ .Values.service.port }} + targetPort: http + protocol: TCP + name: http + selector: + {{- include "stateless.selectorLabels" . | nindent 4 }} diff --git a/charts/stateless/templates/serviceaccount.yaml b/charts/stateless/templates/serviceaccount.yaml new file mode 100644 index 0000000000..72849888da --- /dev/null +++ b/charts/stateless/templates/serviceaccount.yaml @@ -0,0 +1,13 @@ +{{- if .Values.serviceAccount.create -}} +apiVersion: v1 +kind: ServiceAccount +metadata: + name: {{ include "stateless.serviceAccountName" . }} + labels: + {{- include "stateless.labels" . | nindent 4 }} + {{- with .Values.serviceAccount.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +automountServiceAccountToken: {{ .Values.serviceAccount.automount }} +{{- end }} diff --git a/charts/stateless/values.yaml b/charts/stateless/values.yaml new file mode 100644 index 0000000000..f8ed1fd103 --- /dev/null +++ b/charts/stateless/values.yaml @@ -0,0 +1,109 @@ +# Default values for stateless. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. + +replicaCount: 1 + +image: + repository: nginx + pullPolicy: IfNotPresent + # Overrides the image tag whose default is the chart appVersion. + tag: "" + +env: [] + +imagePullSecrets: [] +nameOverride: "" +fullnameOverride: "" + +serviceAccount: + # Specifies whether a service account should be created + create: true + # Automatically mount a ServiceAccount's API credentials? + automount: true + # Annotations to add to the service account + annotations: {} + # The name of the service account to use. + # If not set and create is true, a name is generated using the fullname template + name: "" + +podAnnotations: {} +podLabels: {} + +podSecurityContext: {} + # fsGroup: 2000 + +securityContext: {} + # capabilities: + # drop: + # - ALL + # readOnlyRootFilesystem: true + # runAsNonRoot: true + # runAsUser: 1000 + +service: + type: ClusterIP + port: 80 + +ingress: + enabled: false + className: "" + annotations: {} + # kubernetes.io/ingress.class: nginx + # kubernetes.io/tls-acme: "true" + hosts: + - host: chart-example.local + paths: + - path: / + pathType: ImplementationSpecific + tls: [] + # - secretName: chart-example-tls + # hosts: + # - chart-example.local + +resources: {} + # We usually recommend not to specify default resources and to leave this as a conscious + # choice for the user. This also increases chances charts run on environments with little + # resources, such as Minikube. If you do want to specify resources, uncomment the following + # lines, adjust them as necessary, and remove the curly braces after 'resources:'. + # limits: + # cpu: 100m + # memory: 128Mi + # requests: + # cpu: 100m + # memory: 128Mi + +livenessProbe: + httpGet: + path: / + port: http +readinessProbe: + httpGet: + path: / + port: http + +autoscaling: + enabled: false + minReplicas: 1 + maxReplicas: 100 + targetCPUUtilizationPercentage: 80 + # targetMemoryUtilizationPercentage: 80 + +# Additional volumes on the output Deployment definition. +volumes: [] +# - name: foo +# secret: +# secretName: mysecret +# optional: false + +# Additional volumeMounts on the output Deployment definition. +volumeMounts: [] +# - name: foo +# mountPath: "/etc/foo" +# readOnly: true + +nodeSelector: {} + +tolerations: [] + +affinity: {}