feat: use common lib

This commit is contained in:
Julien Cabillot 2021-12-30 16:29:26 -05:00
parent fc74da930e
commit af95c7cb14
10 changed files with 70 additions and 276 deletions

2
README.md Normal file
View File

@ -0,0 +1,2 @@
# ip-helm

View File

@ -14,10 +14,13 @@
*.swp *.swp
*.bak *.bak
*.tmp *.tmp
*.orig
*~ *~
# Various IDEs # Various IDEs
.project .project
.idea/ .idea/
*.tmproj *.tmproj
.vscode/ .vscode/
# OWNERS file for Kubernetes
OWNERS
# helm-docs templates
*.gotmpl

View File

@ -3,7 +3,7 @@ apiVersion: v2
description: Helm chart for ip description: Helm chart for ip
name: ip name: ip
type: application type: application
version: 0.1.11 version: 0.1.12
kubeVersion: ">=1.16.0-0" kubeVersion: ">=1.16.0-0"
keywords: keywords:
- ip - ip
@ -21,3 +21,8 @@ maintainers:
# It is recommended to use it with quotes. # It is recommended to use it with quotes.
#appVersion: "1.16.0" #appVersion: "1.16.0"
appVersion: "latest" appVersion: "latest"
dependencies:
- name: common
repository: "https://scm.docker.cabillot.eu/perso/helm-library-common/raw/branch/master/"
version: 4.2.0

View File

@ -1,22 +1 @@
1. Get the application URL by running these commands: {{- include "common.notes.defaultNotes" . -}}
{{- 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 "ip.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 the status of by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "ip.fullname" . }}'
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "ip.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 "ip.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 }}

View File

@ -1,62 +0,0 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "ip.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 "ip.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 "ip.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}
{{/*
Common labels
*/}}
{{- define "ip.labels" -}}
helm.sh/chart: {{ include "ip.chart" . }}
{{ include "ip.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}
{{/*
Selector labels
*/}}
{{- define "ip.selectorLabels" -}}
app.kubernetes.io/name: {{ include "ip.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}
{{/*
Create the name of the service account to use
*/}}
{{- define "ip.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "ip.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}

View File

@ -0,0 +1,5 @@
{{/* Make sure all variables are set properly */}}
{{- include "common.values.setup" . }}
{{/* Render the templates */}}
{{ include "common.all" . }}

View File

@ -1,61 +0,0 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "ip.fullname" . }}
labels:
{{- include "ip.labels" . | nindent 4 }}
spec:
{{- if not .Values.autoscaling.enabled }}
replicas: {{ .Values.replicaCount }}
{{- end }}
selector:
matchLabels:
{{- include "ip.selectorLabels" . | nindent 6 }}
template:
metadata:
{{- with .Values.podAnnotations }}
annotations:
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
{{- include "ip.selectorLabels" . | nindent 8 }}
spec:
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
automountServiceAccountToken: {{ .Values.automountServiceAccountToken }}
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 }}
ports:
- name: http
containerPort: 8080
protocol: TCP
livenessProbe:
httpGet:
path: /
port: http
readinessProbe:
httpGet:
path: /
port: http
resources:
{{- toYaml .Values.resources | nindent 12 }}
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.affinity }}
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}

View File

@ -1,41 +0,0 @@
{{- if .Values.ingress.enabled -}}
{{- $fullName := include "ip.fullname" . -}}
{{- $svcPort := .Values.service.port -}}
{{- 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 "ip.labels" . | nindent 4 }}
{{- with .Values.ingress.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
{{- 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 }}
backend:
serviceName: {{ $fullName }}
servicePort: {{ $svcPort }}
{{- end }}
{{- end }}
{{- end }}

View File

@ -1,15 +0,0 @@
apiVersion: v1
kind: Service
metadata:
name: {{ include "ip.fullname" . }}
labels:
{{- include "ip.labels" . | nindent 4 }}
spec:
type: {{ .Values.service.type }}
ports:
- port: {{ .Values.service.port }}
targetPort: http
protocol: TCP
name: http
selector:
{{- include "ip.selectorLabels" . | nindent 4 }}

View File

@ -1,84 +1,63 @@
# Default values for ip. #
# This is a YAML-formatted file. # IMPORTANT NOTE
# Declare variables to be passed into your templates. #
# This chart inherits from our common library chart. You can check the default values/options here:
replicaCount: 1 # https://scm.docker.cabillot.eu/perso/helm-library-common
#
image: image:
repository: docker.io/jcabillot/ip repository: docker.io/jcabillot/ip
pullPolicy: Always
# Overrides the image tag whose default is the chart appVersion.
tag: "" tag: ""
pullPolicy: Always
imagePullSecrets: [] env:
nameOverride: "" TZ: America/New_York
fullnameOverride: ""
automountServiceAccountToken: false
serviceAccount:
# Specifies whether a service account should be created
create: false
# 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: "ip"
podAnnotations: {}
podSecurityContext: {}
# fsGroup: 2000
securityContext: {}
# capabilities:
# drop:
# - ALL
# readOnlyRootFilesystem: true
# runAsNonRoot: true
# runAsUser: 1000
service: service:
type: "ClusterIP" main:
port: 80 ports:
http:
port: 8080
ingress: ingress:
enabled: false main:
annotations: enabled: false
kubernetes.io/ingress.class: "traefik" # Example
cert-manager.io/cluster-issuer: "letsencrypt-prod" # hosts:
hosts: # - host: "yy.xx.zz"
- host: "toto.opti.cabillot.eu" # paths:
paths: # - path: /
- path: / # tls:
backend: # - secretName: "ip-tls"
serviceName: "ip" # hosts:
servicePort: 80 # - "yy.xx.zz"
tls:
- secretName: "ip-tls"
hosts:
- "toto.opti.cabillot.eu"
resources: {} probes:
# We usually recommend not to specify default resources and to leave this as a conscious liveness:
# choice for the user. This also increases chances charts run on environments with little enabled: true
# resources, such as Minikube. If you do want to specify resources, uncomment the following custom: true
# lines, adjust them as necessary, and remove the curly braces after 'resources:'. spec:
# limits: httpGet:
# cpu: 100m path: /
# memory: 128Mi port: http
# requests: scheme: HTTP
# cpu: 100m timeoutSeconds: 1
# memory: 128Mi periodSeconds: 10
successThreshold: 1
failureThreshold: 3
readiness:
enabled: true
custom: true
spec:
httpGet:
path: /
port: http
scheme: HTTP
timeoutSeconds: 1
periodSeconds: 10
successThreshold: 1
failureThreshold: 3
startup:
enabled: false
autoscaling: automountServiceAccountToken: false
enabled: false
minReplicas: 1
maxReplicas: 1
targetCPUUtilizationPercentage: 80
# targetMemoryUtilizationPercentage: 80
nodeSelector: {}
tolerations: []
affinity: {}