diff --git a/.github/workflows/helm_checks.yml b/.github/workflows/helm_checks.yml index 8fd322f..5ceb784 100644 --- a/.github/workflows/helm_checks.yml +++ b/.github/workflows/helm_checks.yml @@ -34,7 +34,11 @@ jobs: fi - name: Run chart-testing (lint) if: steps.list-changed.outputs.changed == 'true' - run: ct lint --target-branch ${{ github.event.repository.default_branch }} + run: | + helm repo add eck-operator https://helm.elastic.co + helm repo add opensearch https://opensearch-project.github.io/helm-charts/ + helm dep build charts/netobserv + ct lint --target-branch ${{ github.event.repository.default_branch }} --validate-maintainers=false - name: Create kind cluster if: steps.list-changed.outputs.changed == 'true' diff --git a/.gitignore b/.gitignore index fcb7db5..c1ccfe1 100644 --- a/.gitignore +++ b/.gitignore @@ -7,4 +7,4 @@ # Misc tmp.* -charts/** +charts/netobserv/charts/** diff --git a/.helmignore b/charts/netobserv/.helmignore similarity index 100% rename from .helmignore rename to charts/netobserv/.helmignore diff --git a/Chart.lock b/charts/netobserv/Chart.lock similarity index 85% rename from Chart.lock rename to charts/netobserv/Chart.lock index 8bdf149..4f3e89f 100644 --- a/Chart.lock +++ b/charts/netobserv/Chart.lock @@ -6,4 +6,4 @@ dependencies: repository: https://opensearch-project.github.io/helm-charts/ version: 2.12.2 digest: sha256:64f09ea1ac0c6cd6ea15eb5b360dcfa97417c19d4f3bea5a7e901a1193ca7990 -generated: "2024-03-12T10:57:35.890043-04:00" +generated: "2024-03-13T17:31:53.787976-04:00" diff --git a/Chart.yaml b/charts/netobserv/Chart.yaml similarity index 95% rename from Chart.yaml rename to charts/netobserv/Chart.yaml index 909e8f4..ee409c9 100644 --- a/Chart.yaml +++ b/charts/netobserv/Chart.yaml @@ -28,4 +28,4 @@ dependencies: - name: opensearch repository: https://opensearch-project.github.io/helm-charts/ version: "2.12.*" - condition: opensearch.enabled \ No newline at end of file + condition: opensearch.enabled diff --git a/charts/netobserv/templates/_helpers.tpl b/charts/netobserv/templates/_helpers.tpl new file mode 100644 index 0000000..0b2a7a8 --- /dev/null +++ b/charts/netobserv/templates/_helpers.tpl @@ -0,0 +1,62 @@ +{{/* +Expand the name of the chart. +*/}} +{{- define "netobserv.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 "netobserv.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 "netobserv.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Common labels +*/}} +{{- define "netobserv.labels" -}} +helm.sh/chart: {{ include "netobserv.chart" . }} +{{ include "netobserv.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "netobserv.selectorLabels" -}} +app.kubernetes.io/name: {{ include "netobserv.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} + +{{/* +Create the name of the service account to use +*/}} +{{- define "netobserv.serviceAccountName" -}} +{{- if .Values.serviceAccount.create }} +{{- default (include "netobserv.fullname" .) .Values.serviceAccount.name }} +{{- else }} +{{- default "default" .Values.serviceAccount.name }} +{{- end }} +{{- end }} diff --git a/charts/netobserv/templates/deployment.yaml b/charts/netobserv/templates/deployment.yaml new file mode 100644 index 0000000..b7ea341 --- /dev/null +++ b/charts/netobserv/templates/deployment.yaml @@ -0,0 +1,76 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "netobserv.fullname" . }} + labels: + {{- include "netobserv.labels" . | nindent 4 }} +spec: + {{- if not .Values.autoscaling.enabled }} + replicas: {{ .Values.replicaCount }} + {{- end }} + selector: + matchLabels: + {{- include "netobserv.selectorLabels" . | nindent 6 }} + template: + metadata: + {{- with .Values.podAnnotations }} + annotations: + {{- toYaml . | nindent 8 }} + {{- end }} + labels: + {{- include "netobserv.labels" . | nindent 8 }} + {{- with .Values.podLabels }} + {{- toYaml . | nindent 8 }} + {{- end }} + spec: + {{- with .Values.imagePullSecrets }} + imagePullSecrets: + {{- toYaml . | nindent 8 }} + {{- end }} + serviceAccountName: {{ include "netobserv.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 }} + env: + {{- with .Values.env }} + {{- toYaml . | nindent 12 }} + {{- end }} + ports: + - name: udp + containerPort: {{ .Values.service.port }} + protocol: UDP + {{- if .Values.livenessProbe.enabled }} + livenessProbe: + {{- toYaml .Values.livenessProbe | nindent 12 }} + {{- end }} + {{- if .Values.readinessProbe.enabled }} + readinessProbe: + {{- toYaml .Values.readinessProbe | nindent 12 }} + {{- end }} + 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/netobserv/templates/hpa.yaml b/charts/netobserv/templates/hpa.yaml new file mode 100644 index 0000000..b8962c5 --- /dev/null +++ b/charts/netobserv/templates/hpa.yaml @@ -0,0 +1,32 @@ +{{- if .Values.autoscaling.enabled }} +apiVersion: autoscaling/v2 +kind: HorizontalPodAutoscaler +metadata: + name: {{ include "netobserv.fullname" . }} + labels: + {{- include "netobserv.labels" . | nindent 4 }} +spec: + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: {{ include "netobserv.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/netobserv/templates/ingress.yaml b/charts/netobserv/templates/ingress.yaml new file mode 100644 index 0000000..2e2725c --- /dev/null +++ b/charts/netobserv/templates/ingress.yaml @@ -0,0 +1,61 @@ +{{- if .Values.ingress.enabled -}} +{{- $fullName := include "netobserv.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 "netobserv.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/netobserv/templates/service.yaml b/charts/netobserv/templates/service.yaml new file mode 100644 index 0000000..0ddd53b --- /dev/null +++ b/charts/netobserv/templates/service.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ include "netobserv.fullname" . }} + labels: + {{- include "netobserv.labels" . | nindent 4 }} +spec: + type: {{ .Values.service.type }} + ports: + - port: {{ .Values.service.port }} + targetPort: 9995 + protocol: UDP + name: udp + selector: + {{- include "netobserv.selectorLabels" . | nindent 4 }} diff --git a/charts/netobserv/templates/serviceaccount.yaml b/charts/netobserv/templates/serviceaccount.yaml new file mode 100644 index 0000000..5037925 --- /dev/null +++ b/charts/netobserv/templates/serviceaccount.yaml @@ -0,0 +1,13 @@ +{{- if .Values.serviceAccount.create -}} +apiVersion: v1 +kind: ServiceAccount +metadata: + name: {{ include "netobserv.serviceAccountName" . }} + labels: + {{- include "netobserv.labels" . | nindent 4 }} + {{- with .Values.serviceAccount.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +automountServiceAccountToken: {{ .Values.serviceAccount.automount }} +{{- end }} diff --git a/values.yaml b/charts/netobserv/values.yaml similarity index 64% rename from values.yaml rename to charts/netobserv/values.yaml index 861c5db..3b7bd79 100644 --- a/values.yaml +++ b/charts/netobserv/values.yaml @@ -6,30 +6,13 @@ opensearch: elasticsearch: enabled: true -deployment: - env: [] - terminationGracePeriodSeconds: 60 - labels: {} - annotations: {} - replicaCount: 1 -strategy: - type: "RollingUpdate" - rollingUpdate: - maxSurge: "100%" - maxUnavailable: 0 - -serviceAccount: - create: false - name: "" - automountServiceAccountToken: false - imagePullSecrets: [] - annotations: {} - labels: {} - -podAnnotations: {} -args: {} +image: + repository: elastiflow/flow-collector + pullPolicy: IfNotPresent + # Overrides the image tag whose default is the chart appVersion. + tag: "" env: - name: EF_LICENSE_ACCEPTED @@ -84,60 +67,101 @@ env: # EF_OUTPUT_GENERIC_HTTP_ADDRESSES: '' # EF_OUTPUT_RISKIQ_ENABLE: 'false' + +imagePullSecrets: [] +nameOverride: "" +fullnameOverride: "" + +serviceAccount: + # Specifies whether a service account should be created + create: false + # Automatically mount a ServiceAccount's API credentials? + automount: 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: "" + +podAnnotations: {} +podLabels: {} + +podSecurityContext: + runAsNonRoot: true + runAsUser: 1000 + runAsGroup: 1000 + +securityContext: {} + # capabilities: + # drop: + # - ALL + # readOnlyRootFilesystem: true + # runAsNonRoot: true + # runAsUser: 1000 + service: - enabled: true type: ClusterIP - port: 9995 - targetPort: 9995 - nodePort: - annotations: {} - labels: {} + port: 80 -image: - registry: "" - repository: elastiflow/flow-collector - tag: "" - pullPolicy: IfNotPresent +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: limits: - cpu: 200m - memory: 256Mi + cpu: 100m + memory: 128Mi requests: cpu: 100m - memory: 256Mi - -netobserv: - livenessProbe: - enabled: false - httpGet: - path: /liveness - port: http - initialDelaySeconds: 0 - periodSeconds: 10 - failureThreshold: 3 - timeoutSeconds: 10 - successThreshold: 1 - startupProbe: - enabled: false - httpGet: - path: /startup - port: http - initialDelaySeconds: 0 - periodSeconds: 5 - failureThreshold: 10 - # https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/#configure-probes - # Must be 1 for liveness and startup Probes. - timeoutSeconds: 3 - successThreshold: 1 - readinessProbe: - enabled: false + memory: 128Mi -podSecurityContext: - runAsNonRoot: true - runAsUser: 1000 - runAsGroup: 1000 +livenessProbe: + enabled: false + httpGet: + path: / + port: http +readinessProbe: + enabled: false + 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: [] + +affinity: {} + topologySpreadConstraints: [] diff --git a/templates/_helpers.tpl b/templates/_helpers.tpl deleted file mode 100644 index c0a053e..0000000 --- a/templates/_helpers.tpl +++ /dev/null @@ -1,51 +0,0 @@ -{{/* -Expand the name of the chart. -*/}} -{{- define "netobserv.name" -}} -{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}} -{{- end }} - -{{/* -Create chart name and version as used by the chart label. -*/}} -{{- define "netobserv.chart" -}} -{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{/* -Common labels -*/}} -{{- define "netobserv.labels" -}} -helm.sh/chart: {{ include "netobserv.chart" . }} -app: {{ include "netobserv.name" . }} -{{ include "netobserv.selectorLabels" . }} -app.kubernetes.io/version: {{ .Values.image.tag | default .Chart.AppVersion | quote }} -version: {{ .Values.image.tag | default .Chart.AppVersion | quote }} -app.kubernetes.io/managed-by: {{ .Release.Service }} -{{- end -}} - -{{/* -Selector labels -*/}} -{{- define "netobserv.selectorLabels" -}} -app.kubernetes.io/name: {{ include "netobserv.name" . }} -app.kubernetes.io/instance: {{ .Release.Name }} -{{- end -}} - -{{/* -Create image name and tag used by the deployment. -*/}} -{{- define "netobserv.image" -}} -{{- $fullOverride := .Values.image.fullOverride | default "" -}} -{{- $registry := .Values.image.registry | default .Values.image.registry -}} -{{- $repository := .Values.image.repository -}} -{{- $separator := ":" -}} -{{- $tag := .Values.image.tag | default .Chart.AppVersion -}} -{{- if $fullOverride }} - {{- printf "%s" $fullOverride -}} -{{- else if $registry }} - {{- printf "%s/%s%s%s" $registry $repository $separator $tag -}} -{{- else -}} - {{- printf "%s%s%s" $repository $separator $tag -}} -{{- end -}} -{{- end -}} \ No newline at end of file diff --git a/templates/netobserv/deployment.yaml b/templates/netobserv/deployment.yaml deleted file mode 100644 index 1c6bb38..0000000 --- a/templates/netobserv/deployment.yaml +++ /dev/null @@ -1,93 +0,0 @@ -apiVersion: apps/v1 -kind: Deployment -metadata: - name: {{ include "netobserv.name" . }} - annotations: - {{- if .Values.deployment.annotations }} - {{- toYaml .Values.deployment.annotations | nindent 4 }} - {{- end }} - labels: - {{- include "netobserv.labels" . | nindent 4 }} -spec: - replicas: {{ .Values.replicaCount }} - strategy: - type: {{ .Values.strategy.type }} - {{- if eq .Values.strategy.type "RollingUpdate" }} - rollingUpdate: - maxUnavailable: {{ .Values.strategy.rollingUpdate.maxUnavailable }} - maxSurge: {{ .Values.strategy.rollingUpdate.maxSurge }} - {{- end }} - selector: - matchLabels: - {{- include "netobserv.selectorLabels" . | nindent 6 }} - {{- if .Values.deployment.labels }} - {{- toYaml .Values.deployment.labels | nindent 6 }} - {{- end }} - template: - metadata: - {{- with .Values.podAnnotations }} - annotations: - {{- toYaml . | nindent 8 }} - {{- end }} - labels: - {{- include "netobserv.labels" . | nindent 8 }} - {{- if .Values.deployment.labels }} - {{- toYaml .Values.deployment.labels | nindent 8 }} - {{- end }} - spec: - {{- if (or .Values.serviceAccount.create .Values.serviceAccount.name) }} - serviceAccountName: {{ include "gitea.serviceAccountName" . }} - {{- end }} - securityContext: - {{- toYaml .Values.podSecurityContext | nindent 8 }} - terminationGracePeriodSeconds: {{ .Values.deployment.terminationGracePeriodSeconds }} - restartPolicy: Always - containers: - - name: {{ include "netobserv.name" . }} - # image: "elastiflow/flow-collector:{{ .Values.image.tag }}" - image: "{{ include "netobserv.image" . }}" - imagePullPolicy: {{ .Values.image.pullPolicy }} - {{- if .Values.args }} - args: - {{- .Values.args | toYaml | nindent 12 }} - {{- end }} - env: - {{- with .Values.env }} - {{- toYaml . | nindent 12 }} - {{- end }} - ports: - - name: udp - containerPort: {{ .Values.service.port }} - protocol: UDP - {{- if .Values.netobserv.livenessProbe.enabled }} - livenessProbe: - {{- toYaml (omit .Values.netobserv.livenessProbe "enabled") | nindent 12 }} - {{- end }} - {{- if .Values.netobserv.readinessProbe.enabled }} - readinessProbe: - {{- toYaml (omit .Values.netobserv.readinessProbe "enabled") | nindent 12 }} - {{- end }} - {{- if .Values.netobserv.startupProbe.enabled }} - startupProbe: - {{- toYaml (omit .Values.netobserv.startupProbe "enabled") | nindent 12 }} - {{- end }} - resources: - {{- toYaml .Values.resources | nindent 12 }} - securityContext: - {{- toYaml .Values.securityContext | nindent 12 }} - {{- with .Values.nodeSelector }} - nodeSelector: - {{- toYaml . | nindent 8 }} - {{- end }} - {{- with .Values.affinity }} - affinity: - {{- toYaml . | nindent 8 }} - {{- end }} - {{- with .Values.topologySpreadConstraints }} - topologySpreadConstraints: - {{- toYaml . | nindent 8 }} - {{- end }} - {{- with .Values.tolerations }} - tolerations: - {{- toYaml . | nindent 8 }} - {{- end }} diff --git a/templates/netobserv/service.yaml b/templates/netobserv/service.yaml deleted file mode 100644 index dc3623b..0000000 --- a/templates/netobserv/service.yaml +++ /dev/null @@ -1,27 +0,0 @@ -{{- if .Values.service.enabled -}} -apiVersion: v1 -kind: Service -metadata: - name: {{ include "netobserv.name" . }} - labels: - {{- include "netobserv.labels" . | nindent 4 }} - {{- if .Values.service.labels }} - {{- toYaml .Values.service.labels | nindent 4 }} - {{- end }} - annotations: - {{- toYaml .Values.service.annotations | nindent 4 }} -spec: - type: {{ .Values.service.type }} - ports: - - name: udp - port: {{ .Values.service.port }} - {{- if .Values.service.targetPort }} - targetPort: {{ .Values.service.targetPort }} - {{- end }} - protocol: UDP - {{- if .Values.service.nodePort }} - nodePort: {{ .Values.service.nodePort }} - {{- end }} - selector: - {{- include "netobserv.selectorLabels" . | nindent 4 }} -{{- end }} diff --git a/templates/netobserv/serviceaccount.yaml b/templates/netobserv/serviceaccount.yaml deleted file mode 100644 index f12b708..0000000 --- a/templates/netobserv/serviceaccount.yaml +++ /dev/null @@ -1,21 +0,0 @@ -{{- if .Values.serviceAccount.create }} -apiVersion: v1 -kind: ServiceAccount -metadata: - name: {{ include "netobserv.serviceAccountName" . }} - namespace: {{ template "netobserv.namespace" . }} - labels: - {{- include "netobserv.labels" . | nindent 4 }} - {{- with .Values.serviceAccount.labels }} - {{- . | toYaml | nindent 4 }} - {{- end }} - {{- with .Values.serviceAccount.annotations }} - annotations: - {{- . | toYaml | nindent 4 }} - {{- end }} -automountServiceAccountToken: {{ .Values.serviceAccount.automountServiceAccountToken }} -{{- with .Values.serviceAccount.imagePullSecrets }} -imagePullSecrets: - {{- . | toYaml | nindent 2 }} -{{- end }} -{{- end }}