From 19c47982d6a4682f99c1b22065c68e7cf4be6028 Mon Sep 17 00:00:00 2001 From: raazadarsh Date: Wed, 26 Jun 2024 16:35:13 -0400 Subject: [PATCH 1/2] fix: refactored code --- postgres/.helmignore | 23 ---- postgres/Chart.yaml | 24 ---- postgres/templates/NOTES.txt | 62 ---------- postgres/templates/_helpers.tpl | 62 ---------- postgres/templates/postgres.yaml | 70 ----------- postgres/templates/secret.yaml | 9 -- postgres/templates/tests/test-connection.yaml | 15 --- postgres/values.yaml | 113 ------------------ templates/configmap.yaml | 9 -- templates/pod.yaml | 40 +------ templates/secret.yaml | 12 -- values.yaml | 7 +- 12 files changed, 2 insertions(+), 444 deletions(-) delete mode 100644 postgres/.helmignore delete mode 100644 postgres/Chart.yaml delete mode 100644 postgres/templates/NOTES.txt delete mode 100644 postgres/templates/_helpers.tpl delete mode 100644 postgres/templates/postgres.yaml delete mode 100644 postgres/templates/secret.yaml delete mode 100644 postgres/templates/tests/test-connection.yaml delete mode 100644 postgres/values.yaml delete mode 100644 templates/configmap.yaml diff --git a/postgres/.helmignore b/postgres/.helmignore deleted file mode 100644 index 0e8a0eb..0000000 --- a/postgres/.helmignore +++ /dev/null @@ -1,23 +0,0 @@ -# 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/postgres/Chart.yaml b/postgres/Chart.yaml deleted file mode 100644 index cfbe94c..0000000 --- a/postgres/Chart.yaml +++ /dev/null @@ -1,24 +0,0 @@ -apiVersion: v2 -name: postgres -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" diff --git a/postgres/templates/NOTES.txt b/postgres/templates/NOTES.txt deleted file mode 100644 index 1e16e1e..0000000 --- a/postgres/templates/NOTES.txt +++ /dev/null @@ -1,62 +0,0 @@ -######################################################### -# Postgres Helm Chart -######################################################### - -1. **Release Information** - - Release Name: {{ .Release.Name }} - - Namespace: {{ .Release.Namespace }} - - Chart Version: {{ .Chart.Version }} - - App Version: {{ .Chart.AppVersion }} - -2. **Service Information** - - Postgres Service: `postgres-svc` - - Port: `5432` - -3. **Accessing the Database** - - To connect to the PostgreSQL database, you can use the following command: - ``` - kubectl run -it --rm --image=postgres:14 --restart=Never pg-client -- psql -h postgres-svc -U {{ .Values.postgresql.username }} -d {{ .Values.postgresql.database }} - ``` - - Replace `{{ .Values.postgresql.username }}` and `{{ .Values.postgresql.database }}` with the actual values from your `values.yaml`. - -4. **Credentials** - - The PostgreSQL credentials are stored in the `postgres-credentials` secret. - - You can retrieve the credentials using the following commands: - ``` - kubectl get secret postgres-credentials -o jsonpath="{.data.POSTGRES_USER}" | base64 --decode - kubectl get secret postgres-credentials -o jsonpath="{.data.POSTGRES_PASSWORD}" | base64 --decode - kubectl get secret postgres-credentials -o jsonpath="{.data.POSTGRES_DB}" | base64 --decode - ``` - -5. **Persistent Volume Claims** - - The PVC for PostgreSQL storage is named `postgres-storage-postgres-0`. - - StorageClass: `ebs-csi-encrypted` - - Size: `8Gi` - -6. **Scaling** - - You can scale the PostgreSQL StatefulSet using the following command: - ``` - kubectl scale statefulset postgres --replicas= -n {{ .Release.Namespace }} - ``` - -7. **Logs** - - To view the logs of the PostgreSQL pod, use the following command: - ``` - kubectl logs -f postgres-0 -n {{ .Release.Namespace }} - ``` - -8. **Upgrading the Chart** - - To upgrade the Helm chart, use the following command: - ``` - helm upgrade {{ .Release.Name }} ./postgres -f values.yaml - ``` - -9. **Uninstalling the Chart** - - To uninstall the Helm chart, use the following command: - ``` - helm uninstall {{ .Release.Name }} -n {{ .Release.Namespace }} - ``` - -Thank you for using this PostgreSQL Helm Chart! - -######################################################### diff --git a/postgres/templates/_helpers.tpl b/postgres/templates/_helpers.tpl deleted file mode 100644 index d0bfd03..0000000 --- a/postgres/templates/_helpers.tpl +++ /dev/null @@ -1,62 +0,0 @@ -{{/* -Expand the name of the chart. -*/}} -{{- define "postgres.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 "postgres.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 "postgres.chart" -}} -{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} -{{- end }} - -{{/* -Common labels -*/}} -{{- define "postgres.labels" -}} -helm.sh/chart: {{ include "postgres.chart" . }} -{{ include "postgres.selectorLabels" . }} -{{- if .Chart.AppVersion }} -app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} -{{- end }} -app.kubernetes.io/managed-by: {{ .Release.Service }} -{{- end }} - -{{/* -Selector labels -*/}} -{{- define "postgres.selectorLabels" -}} -app.kubernetes.io/name: {{ include "postgres.name" . }} -app.kubernetes.io/instance: {{ .Release.Name }} -{{- end }} - -{{/* -Create the name of the service account to use -*/}} -{{- define "postgres.serviceAccountName" -}} -{{- if .Values.serviceAccount.create }} -{{- default (include "postgres.fullname" .) .Values.serviceAccount.name }} -{{- else }} -{{- default "default" .Values.serviceAccount.name }} -{{- end }} -{{- end }} diff --git a/postgres/templates/postgres.yaml b/postgres/templates/postgres.yaml deleted file mode 100644 index c9b0a0d..0000000 --- a/postgres/templates/postgres.yaml +++ /dev/null @@ -1,70 +0,0 @@ ---- -apiVersion: v1 -kind: Service -metadata: - name: postgres-svc - labels: - app: postgres - app.kubernetes.io/managed-by: Helm - annotations: - meta.helm.sh/release-name: postgres - meta.helm.sh/release-namespace: webapp -spec: - ports: - - port: 5432 - name: db - clusterIP: None - selector: - app: postgres ---- -apiVersion: apps/v1 -kind: StatefulSet -metadata: - name: postgres - labels: - app.kubernetes.io/managed-by: Helm - annotations: - meta.helm.sh/release-name: postgres - meta.helm.sh/release-namespace: webapp -spec: - selector: - matchLabels: - app: postgres - serviceName: postgres-svc - replicas: 1 - minReadySeconds: 10 - template: - metadata: - labels: - app: postgres - spec: - terminationGracePeriodSeconds: 10 - containers: - - name: postgres-container - image: postgres:14 - ports: - - containerPort: 5432 - name: db - envFrom: - - secretRef: - name: postgres-credentials - volumeMounts: - - name: postgres-storage - mountPath: /var/lib/postgresql/data - env: - - name: PGDATA - value: /var/lib/postgresql/data/pgdata/pgdata - volumeClaimTemplates: - - metadata: - name: postgres-storage - labels: - app.kubernetes.io/managed-by: Helm - annotations: - meta.helm.sh/release-name: postgres - meta.helm.sh/release-namespace: webapp - spec: - accessModes: [ "ReadWriteOnce" ] - storageClassName: "ebs-csi-encrypted" - resources: - requests: - storage: 8Gi diff --git a/postgres/templates/secret.yaml b/postgres/templates/secret.yaml deleted file mode 100644 index c4cc71c..0000000 --- a/postgres/templates/secret.yaml +++ /dev/null @@ -1,9 +0,0 @@ -apiVersion: v1 -kind: Secret -metadata: - name: postgres-credentials -type: Opaque -data: - POSTGRES_USER: {{ .Values.postgresql.username | b64enc }} - POSTGRES_PASSWORD: {{ .Values.postgresql.password | b64enc }} - POSTGRES_DB: {{ .Values.postgresql.database | b64enc }} \ No newline at end of file diff --git a/postgres/templates/tests/test-connection.yaml b/postgres/templates/tests/test-connection.yaml deleted file mode 100644 index 8289a4f..0000000 --- a/postgres/templates/tests/test-connection.yaml +++ /dev/null @@ -1,15 +0,0 @@ -apiVersion: v1 -kind: Pod -metadata: - name: "{{ include "postgres.fullname" . }}-test-connection" - labels: - {{- include "postgres.labels" . | nindent 4 }} - annotations: - "helm.sh/hook": test -spec: - containers: - - name: wget - image: busybox - command: ['wget'] - args: ['{{ include "postgres.fullname" . }}:{{ .Values.service.port }}'] - restartPolicy: Never diff --git a/postgres/values.yaml b/postgres/values.yaml deleted file mode 100644 index 6df8be7..0000000 --- a/postgres/values.yaml +++ /dev/null @@ -1,113 +0,0 @@ -# Default values for postgres. -# This is a YAML-formatted file. -# Declare variables to be passed into your templates. - -postgresql: - - username: "" - password: "" - database: "" - -replicaCount: 1 - -image: - repository: nginx - pullPolicy: IfNotPresent - # Overrides the image tag whose default is the chart appVersion. - tag: "" - -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: {} diff --git a/templates/configmap.yaml b/templates/configmap.yaml deleted file mode 100644 index 662e456..0000000 --- a/templates/configmap.yaml +++ /dev/null @@ -1,9 +0,0 @@ -apiVersion: v1 -kind: ConfigMap -metadata: - name: "{{ .Release.Name }}-flyway-config" -data: - flyway.conf: | - flyway.url={{ .Values.flyway.url }} - flyway.user={{ .Values.flyway.user }} - flyway.locations={{ .Values.flyway.locations }} diff --git a/templates/pod.yaml b/templates/pod.yaml index 7276186..d091982 100644 --- a/templates/pod.yaml +++ b/templates/pod.yaml @@ -12,44 +12,6 @@ spec: spec: imagePullSecrets: - name: regcred - initContainers: - - name: db-migration - image: "{{ .Values.initContainerImage.repository }}{{ .Values.initContainerImage.name }}:{{ .Values.initContainerImage.tag }}" - imagePullPolicy: {{ .Values.initContainerImage.pullPolicy }} - command: [ "/bin/sh", "-c" ] - args: - - | - sleep 20 - flyway migrate - env: - - name: DB_HOST - value: jdbc:postgresql://postgres-svc.{{ .Values.namespace }}.svc.cluster.local - - name: DB_PORT - value: {{ .Values.postgresql.port | quote }} - - name: DB_DATABASE - value: {{ .Values.postgresql.database | quote }} - - name: DB_USERNAME - valueFrom: - secretKeyRef: - name: "{{ .Release.Name }}-db-secret" - key: DB_USERNAME - - name: DB_PASSWORD - valueFrom: - secretKeyRef: - name: "{{ .Release.Name }}-db-secret" - key: DB_PASSWORD - - name: FLYWAY_URL - value: jdbc:postgresql://postgres-svc.{{ .Values.namespace }}.svc.cluster.local:{{ .Values.postgresql.port }}/{{ .Values.postgresql.database }} - - name: FLYWAY_USER - value: {{ .Values.secret.username | quote }} - - name: FLYWAY_PASSWORD - valueFrom: - secretKeyRef: - name: "{{ .Release.Name }}-db-secret" - key: FLYWAY_PASSWORD - - name: FLYWAY_LOCATIONS - value: {{ .Values.flyway.locations | quote }} - containers: - name: webapp image: "{{ .Values.image.repository }}{{ .Values.image.name }}:{{ .Values.image.tag }}" @@ -81,4 +43,4 @@ spec: memory: "3.5Gi" cpu: "2" - restartPolicy: OnFailure \ No newline at end of file + restartPolicy: OnFailure diff --git a/templates/secret.yaml b/templates/secret.yaml index a43d45b..f07a655 100644 --- a/templates/secret.yaml +++ b/templates/secret.yaml @@ -1,17 +1,5 @@ apiVersion: v1 kind: Secret -metadata: - name: "{{ .Release.Name }}-db-secret" - namespace: {{ .Values.namespace }} -type: Opaque -data: - DB_USERNAME: {{ .Values.postgresql.username | b64enc }} - DB_PASSWORD: {{ .Values.postgresql.password | b64enc }} - FLYWAY_PASSWORD: {{ .Values.secret.flyway_password | b64enc }} - ---- -apiVersion: v1 -kind: Secret metadata: name: regcred namespace: {{ .Values.namespace }} diff --git a/values.yaml b/values.yaml index 3b15cb9..8bcc603 100644 --- a/values.yaml +++ b/values.yaml @@ -9,11 +9,6 @@ image: pullPolicy: Always tag: "latest" -initContainerImage: - repository: girish332/flyway-migration - tag: latest - pullPolicy: Always - postgresql: # host: host.docker.internal username: "cve_user" @@ -68,4 +63,4 @@ resources: {} # persistence: # enabled: true # storageClass: "gp2" -# size: 8Gi \ No newline at end of file +# size: 8Gi From 7b803f45ff999cebc9816c37b43387ca2aeb142a Mon Sep 17 00:00:00 2001 From: raazadarsh Date: Wed, 26 Jun 2024 16:45:32 -0400 Subject: [PATCH 2/2] fix: fix for chart lint --- templates/NOTES.txt | 27 --------------------------- 1 file changed, 27 deletions(-) diff --git a/templates/NOTES.txt b/templates/NOTES.txt index 23f79fb..639dd0a 100644 --- a/templates/NOTES.txt +++ b/templates/NOTES.txt @@ -5,12 +5,6 @@ Chart Version: {{ .Chart.Version }} App Version: {{ .Chart.AppVersion }} Description: {{ .Chart.Description }} -Dependencies ------------- -PostgreSQL Chart: -- Version: 15.5.7 -- Repository: https://charts.bitnami.com/bitnami - Configuration Files ------------------- 1. configmap.yaml @@ -32,34 +26,13 @@ Image Configuration: - Tag: {{ .Values.image.tag }} - Pull Policy: {{ .Values.image.pullPolicy }} -Init Container Image Configuration: -- Repository: {{ .Values.initContainerImage.repository }} -- Tag: {{ .Values.initContainerImage.tag }} -- Pull Policy: {{ .Values.initContainerImage.pullPolicy }} - -PostgreSQL Configuration: -- Port: {{ .Values.postgresql.port }} -- Username, Password, Database: Configured via Helm values. -- Persistence: Enabled with storage class ebs-csi-encrypted and size 10Gi for both primary and secondary. - Namespace: {{ .Values.namespace }} Secrets: - Username: {{ .Values.secret.username }} - Password: {{ .Values.secret.password }} -- Flyway Password: {{ .Values.secret.flyway_password }} - Docker Config JSON: {{ .Values.secret.dockerconfigjson }} -Flyway Configuration: -- URL: {{ .Values.flyway.url }} -- User: {{ .Values.flyway.user }} -- Locations: {{ .Values.flyway.locations }} - -Resource Management -------------------- -PostgreSQL Resources: -- Requests: 500m CPU, 3Gi Memory -- Limits: 1000m CPU, 4Gi Memory Post-Installation Instructions ------------------------------