diff --git a/hack/build-image.sh b/hack/build-image.sh index a1a70e1f..5477cfa6 100755 --- a/hack/build-image.sh +++ b/hack/build-image.sh @@ -16,4 +16,4 @@ # COMMIT_ID=$(git rev-parse --short HEAD) -docker build -t quay.io/redhat-certification/chart-verifier:"$COMMIT_ID" . +podman build -t quay.io/redhat-certification/chart-verifier:"$COMMIT_ID" . diff --git a/internal/chartverifier/checks/chart-0.1.0-v3.with-crd/testchart/.helmignore b/internal/chartverifier/checks/chart-0.1.0-v3.with-crd/testchart/.helmignore new file mode 100644 index 00000000..0e8a0eb3 --- /dev/null +++ b/internal/chartverifier/checks/chart-0.1.0-v3.with-crd/testchart/.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/internal/chartverifier/checks/chart-0.1.0-v3.with-crd/testchart/Chart.yaml b/internal/chartverifier/checks/chart-0.1.0-v3.with-crd/testchart/Chart.yaml new file mode 100644 index 00000000..28f9a92b --- /dev/null +++ b/internal/chartverifier/checks/chart-0.1.0-v3.with-crd/testchart/Chart.yaml @@ -0,0 +1,7 @@ +apiVersion: v2 +appVersion: 1.16.0 +description: A Helm chart for Kubernetes +name: testchart +type: application +version: 0.1.0 +kubeVersion: 1.20.0 diff --git a/internal/chartverifier/checks/chart-0.1.0-v3.with-crd/testchart/crds/backend.yaml b/internal/chartverifier/checks/chart-0.1.0-v3.with-crd/testchart/crds/backend.yaml new file mode 100644 index 00000000..e6b427a7 --- /dev/null +++ b/internal/chartverifier/checks/chart-0.1.0-v3.with-crd/testchart/crds/backend.yaml @@ -0,0 +1,16 @@ +kind: CustomResourceDefinition +metadata: + name: backservs.service.example.com +spec: + group: service.example.com + versions: + - name: v1 + served: true + storage: true + scope: Namespaced + names: + plural: backservs + singular: backserv + kind: Backserv + shortNames: + - bs diff --git a/internal/chartverifier/checks/chart-0.1.0-v3.with-crd/testchart/templates/NOTES.txt b/internal/chartverifier/checks/chart-0.1.0-v3.with-crd/testchart/templates/NOTES.txt new file mode 100644 index 00000000..9ca33635 --- /dev/null +++ b/internal/chartverifier/checks/chart-0.1.0-v3.with-crd/testchart/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 }}{{ . }} + {{- 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 "testchart.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 "testchart.fullname" . }}' + export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "testchart.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 "testchart.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/internal/chartverifier/checks/chart-0.1.0-v3.with-crd/testchart/templates/_helpers.tpl b/internal/chartverifier/checks/chart-0.1.0-v3.with-crd/testchart/templates/_helpers.tpl new file mode 100644 index 00000000..4b0db05b --- /dev/null +++ b/internal/chartverifier/checks/chart-0.1.0-v3.with-crd/testchart/templates/_helpers.tpl @@ -0,0 +1,62 @@ +{{/* +Expand the name of the chart. +*/}} +{{- define "testchart.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 "testchart.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 "testchart.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Common labels +*/}} +{{- define "testchart.labels" -}} +helm.sh/chart: {{ include "testchart.chart" . }} +{{ include "testchart.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "testchart.selectorLabels" -}} +app.kubernetes.io/name: {{ include "testchart.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} + +{{/* +Create the name of the service account to use +*/}} +{{- define "testchart.serviceAccountName" -}} +{{- if .Values.serviceAccount.create }} +{{- default (include "testchart.fullname" .) .Values.serviceAccount.name }} +{{- else }} +{{- default "default" .Values.serviceAccount.name }} +{{- end }} +{{- end }} diff --git a/internal/chartverifier/checks/chart-0.1.0-v3.with-crd/testchart/templates/deployment.yaml b/internal/chartverifier/checks/chart-0.1.0-v3.with-crd/testchart/templates/deployment.yaml new file mode 100644 index 00000000..cde22bc4 --- /dev/null +++ b/internal/chartverifier/checks/chart-0.1.0-v3.with-crd/testchart/templates/deployment.yaml @@ -0,0 +1,61 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "testchart.fullname" . }} + labels: + {{- include "testchart.labels" . | nindent 4 }} +spec: + {{- if not .Values.autoscaling.enabled }} + replicas: {{ .Values.replicaCount }} + {{- end }} + selector: + matchLabels: + {{- include "testchart.selectorLabels" . | nindent 6 }} + template: + metadata: + {{- with .Values.podAnnotations }} + annotations: + {{- toYaml . | nindent 8 }} + {{- end }} + labels: + {{- include "testchart.selectorLabels" . | nindent 8 }} + spec: + {{- with .Values.imagePullSecrets }} + imagePullSecrets: + {{- toYaml . | nindent 8 }} + {{- end }} + serviceAccountName: {{ include "testchart.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 }} + ports: + - name: http + containerPort: 80 + 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 }} diff --git a/internal/chartverifier/checks/chart-0.1.0-v3.with-crd/testchart/templates/hpa.yaml b/internal/chartverifier/checks/chart-0.1.0-v3.with-crd/testchart/templates/hpa.yaml new file mode 100644 index 00000000..51734471 --- /dev/null +++ b/internal/chartverifier/checks/chart-0.1.0-v3.with-crd/testchart/templates/hpa.yaml @@ -0,0 +1,28 @@ +{{- if .Values.autoscaling.enabled }} +apiVersion: autoscaling/v2beta1 +kind: HorizontalPodAutoscaler +metadata: + name: {{ include "testchart.fullname" . }} + labels: + {{- include "testchart.labels" . | nindent 4 }} +spec: + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: {{ include "testchart.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 }} diff --git a/internal/chartverifier/checks/chart-0.1.0-v3.with-crd/testchart/templates/ingress.yaml b/internal/chartverifier/checks/chart-0.1.0-v3.with-crd/testchart/templates/ingress.yaml new file mode 100644 index 00000000..4f349af2 --- /dev/null +++ b/internal/chartverifier/checks/chart-0.1.0-v3.with-crd/testchart/templates/ingress.yaml @@ -0,0 +1,41 @@ +{{- if .Values.ingress.enabled -}} +{{- $fullName := include "testchart.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 "testchart.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: {{ . }} + backend: + serviceName: {{ $fullName }} + servicePort: {{ $svcPort }} + {{- end }} + {{- end }} + {{- end }} diff --git a/internal/chartverifier/checks/chart-0.1.0-v3.with-crd/testchart/templates/service.yaml b/internal/chartverifier/checks/chart-0.1.0-v3.with-crd/testchart/templates/service.yaml new file mode 100644 index 00000000..86baf148 --- /dev/null +++ b/internal/chartverifier/checks/chart-0.1.0-v3.with-crd/testchart/templates/service.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ include "testchart.fullname" . }} + labels: + {{- include "testchart.labels" . | nindent 4 }} +spec: + type: {{ .Values.service.type }} + ports: + - port: {{ .Values.service.port }} + targetPort: http + protocol: TCP + name: http + selector: + {{- include "testchart.selectorLabels" . | nindent 4 }} diff --git a/internal/chartverifier/checks/chart-0.1.0-v3.with-crd/testchart/templates/serviceaccount.yaml b/internal/chartverifier/checks/chart-0.1.0-v3.with-crd/testchart/templates/serviceaccount.yaml new file mode 100644 index 00000000..f728deb2 --- /dev/null +++ b/internal/chartverifier/checks/chart-0.1.0-v3.with-crd/testchart/templates/serviceaccount.yaml @@ -0,0 +1,12 @@ +{{- if .Values.serviceAccount.create -}} +apiVersion: v1 +kind: ServiceAccount +metadata: + name: {{ include "testchart.serviceAccountName" . }} + labels: + {{- include "testchart.labels" . | nindent 4 }} + {{- with .Values.serviceAccount.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +{{- end }} diff --git a/internal/chartverifier/checks/chart-0.1.0-v3.with-crd/testchart/templates/tests/test-connection.yaml b/internal/chartverifier/checks/chart-0.1.0-v3.with-crd/testchart/templates/tests/test-connection.yaml new file mode 100644 index 00000000..a391ef1c --- /dev/null +++ b/internal/chartverifier/checks/chart-0.1.0-v3.with-crd/testchart/templates/tests/test-connection.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Pod +metadata: + name: "{{ include "testchart.fullname" . }}-test-connection" + labels: + {{- include "testchart.labels" . | nindent 4 }} + annotations: + "helm.sh/hook": test +spec: + containers: + - name: wget + image: busybox + command: ['wget'] + args: ['{{ include "testchart.fullname" . }}:{{ .Values.service.port }}'] + restartPolicy: Never diff --git a/internal/chartverifier/checks/chart-0.1.0-v3.with-crd/testchart/values.schema.json b/internal/chartverifier/checks/chart-0.1.0-v3.with-crd/testchart/values.schema.json new file mode 100644 index 00000000..6cb29dbd --- /dev/null +++ b/internal/chartverifier/checks/chart-0.1.0-v3.with-crd/testchart/values.schema.json @@ -0,0 +1,545 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema", + "$id": "http://example.com/example.json", + "type": "object", + "title": "The root schema", + "description": "The root schema comprises the entire JSON document.", + "default": {}, + "examples": [ + { + "replicaCount": 1, + "image": { + "repository": "nginx", + "pullPolicy": "IfNotPresent", + "tag": "" + }, + "imagePullSecrets": [], + "nameOverride": "", + "fullnameOverride": "", + "serviceAccount": { + "create": true, + "annotations": {}, + "name": "" + }, + "podAnnotations": {}, + "podSecurityContext": {}, + "securityContext": {}, + "service": { + "type": "ClusterIP", + "port": 80 + }, + "ingress": { + "enabled": false, + "annotations": {}, + "hosts": [ + { + "host": "chart-example.local", + "paths": [] + } + ], + "tls": [] + }, + "resources": {}, + "autoscaling": { + "enabled": false, + "minReplicas": 1, + "maxReplicas": 100, + "targetCPUUtilizationPercentage": 80 + }, + "nodeSelector": {}, + "tolerations": [], + "affinity": {} + } + ], + "required": [ + "replicaCount", + "image", + "imagePullSecrets", + "nameOverride", + "fullnameOverride", + "serviceAccount", + "podAnnotations", + "podSecurityContext", + "securityContext", + "service", + "ingress", + "resources", + "autoscaling", + "nodeSelector", + "tolerations", + "affinity" + ], + "properties": { + "replicaCount": { + "$id": "#/properties/replicaCount", + "type": "integer", + "title": "The replicaCount schema", + "description": "An explanation about the purpose of this instance.", + "default": 0, + "examples": [ + 1 + ] + }, + "image": { + "$id": "#/properties/image", + "type": "object", + "title": "The image schema", + "description": "An explanation about the purpose of this instance.", + "default": {}, + "examples": [ + { + "repository": "nginx", + "pullPolicy": "IfNotPresent", + "tag": "" + } + ], + "required": [ + "repository", + "pullPolicy", + "tag" + ], + "properties": { + "repository": { + "$id": "#/properties/image/properties/repository", + "type": "string", + "title": "The repository schema", + "description": "An explanation about the purpose of this instance.", + "default": "", + "examples": [ + "nginx" + ] + }, + "pullPolicy": { + "$id": "#/properties/image/properties/pullPolicy", + "type": "string", + "title": "The pullPolicy schema", + "description": "An explanation about the purpose of this instance.", + "default": "", + "examples": [ + "IfNotPresent" + ] + }, + "tag": { + "$id": "#/properties/image/properties/tag", + "type": "string", + "title": "The tag schema", + "description": "An explanation about the purpose of this instance.", + "default": "", + "examples": [ + "" + ] + } + }, + "additionalProperties": true + }, + "imagePullSecrets": { + "$id": "#/properties/imagePullSecrets", + "type": "array", + "title": "The imagePullSecrets schema", + "description": "An explanation about the purpose of this instance.", + "default": [], + "examples": [ + [] + ], + "additionalItems": true, + "items": { + "$id": "#/properties/imagePullSecrets/items" + } + }, + "nameOverride": { + "$id": "#/properties/nameOverride", + "type": "string", + "title": "The nameOverride schema", + "description": "An explanation about the purpose of this instance.", + "default": "", + "examples": [ + "" + ] + }, + "fullnameOverride": { + "$id": "#/properties/fullnameOverride", + "type": "string", + "title": "The fullnameOverride schema", + "description": "An explanation about the purpose of this instance.", + "default": "", + "examples": [ + "" + ] + }, + "serviceAccount": { + "$id": "#/properties/serviceAccount", + "type": "object", + "title": "The serviceAccount schema", + "description": "An explanation about the purpose of this instance.", + "default": {}, + "examples": [ + { + "create": true, + "annotations": {}, + "name": "" + } + ], + "required": [ + "create", + "annotations", + "name" + ], + "properties": { + "create": { + "$id": "#/properties/serviceAccount/properties/create", + "type": "boolean", + "title": "The create schema", + "description": "An explanation about the purpose of this instance.", + "default": false, + "examples": [ + true + ] + }, + "annotations": { + "$id": "#/properties/serviceAccount/properties/annotations", + "type": "object", + "title": "The annotations schema", + "description": "An explanation about the purpose of this instance.", + "default": {}, + "examples": [ + {} + ], + "required": [], + "additionalProperties": true + }, + "name": { + "$id": "#/properties/serviceAccount/properties/name", + "type": "string", + "title": "The name schema", + "description": "An explanation about the purpose of this instance.", + "default": "", + "examples": [ + "" + ] + } + }, + "additionalProperties": true + }, + "podAnnotations": { + "$id": "#/properties/podAnnotations", + "type": "object", + "title": "The podAnnotations schema", + "description": "An explanation about the purpose of this instance.", + "default": {}, + "examples": [ + {} + ], + "required": [], + "additionalProperties": true + }, + "podSecurityContext": { + "$id": "#/properties/podSecurityContext", + "type": "object", + "title": "The podSecurityContext schema", + "description": "An explanation about the purpose of this instance.", + "default": {}, + "examples": [ + {} + ], + "required": [], + "additionalProperties": true + }, + "securityContext": { + "$id": "#/properties/securityContext", + "type": "object", + "title": "The securityContext schema", + "description": "An explanation about the purpose of this instance.", + "default": {}, + "examples": [ + {} + ], + "required": [], + "additionalProperties": true + }, + "service": { + "$id": "#/properties/service", + "type": "object", + "title": "The service schema", + "description": "An explanation about the purpose of this instance.", + "default": {}, + "examples": [ + { + "type": "ClusterIP", + "port": 80 + } + ], + "required": [ + "type", + "port" + ], + "properties": { + "type": { + "$id": "#/properties/service/properties/type", + "type": "string", + "title": "The type schema", + "description": "An explanation about the purpose of this instance.", + "default": "", + "examples": [ + "ClusterIP" + ] + }, + "port": { + "$id": "#/properties/service/properties/port", + "type": "integer", + "title": "The port schema", + "description": "An explanation about the purpose of this instance.", + "default": 0, + "examples": [ + 80 + ] + } + }, + "additionalProperties": true + }, + "ingress": { + "$id": "#/properties/ingress", + "type": "object", + "title": "The ingress schema", + "description": "An explanation about the purpose of this instance.", + "default": {}, + "examples": [ + { + "enabled": false, + "annotations": {}, + "hosts": [ + { + "host": "chart-example.local", + "paths": [] + } + ], + "tls": [] + } + ], + "required": [ + "enabled", + "annotations", + "hosts", + "tls" + ], + "properties": { + "enabled": { + "$id": "#/properties/ingress/properties/enabled", + "type": "boolean", + "title": "The enabled schema", + "description": "An explanation about the purpose of this instance.", + "default": false, + "examples": [ + false + ] + }, + "annotations": { + "$id": "#/properties/ingress/properties/annotations", + "type": "object", + "title": "The annotations schema", + "description": "An explanation about the purpose of this instance.", + "default": {}, + "examples": [ + {} + ], + "required": [], + "additionalProperties": true + }, + "hosts": { + "$id": "#/properties/ingress/properties/hosts", + "type": "array", + "title": "The hosts schema", + "description": "An explanation about the purpose of this instance.", + "default": [], + "examples": [ + [ + { + "host": "chart-example.local", + "paths": [] + } + ] + ], + "additionalItems": true, + "items": { + "$id": "#/properties/ingress/properties/hosts/items", + "anyOf": [ + { + "$id": "#/properties/ingress/properties/hosts/items/anyOf/0", + "type": "object", + "title": "The first anyOf schema", + "description": "An explanation about the purpose of this instance.", + "default": {}, + "examples": [ + { + "host": "chart-example.local", + "paths": [] + } + ], + "required": [ + "host", + "paths" + ], + "properties": { + "host": { + "$id": "#/properties/ingress/properties/hosts/items/anyOf/0/properties/host", + "type": "string", + "title": "The host schema", + "description": "An explanation about the purpose of this instance.", + "default": "", + "examples": [ + "chart-example.local" + ] + }, + "paths": { + "$id": "#/properties/ingress/properties/hosts/items/anyOf/0/properties/paths", + "type": "array", + "title": "The paths schema", + "description": "An explanation about the purpose of this instance.", + "default": [], + "examples": [ + [] + ], + "additionalItems": true, + "items": { + "$id": "#/properties/ingress/properties/hosts/items/anyOf/0/properties/paths/items" + } + } + }, + "additionalProperties": true + } + ] + } + }, + "tls": { + "$id": "#/properties/ingress/properties/tls", + "type": "array", + "title": "The tls schema", + "description": "An explanation about the purpose of this instance.", + "default": [], + "examples": [ + [] + ], + "additionalItems": true, + "items": { + "$id": "#/properties/ingress/properties/tls/items" + } + } + }, + "additionalProperties": true + }, + "resources": { + "$id": "#/properties/resources", + "type": "object", + "title": "The resources schema", + "description": "An explanation about the purpose of this instance.", + "default": {}, + "examples": [ + {} + ], + "required": [], + "additionalProperties": true + }, + "autoscaling": { + "$id": "#/properties/autoscaling", + "type": "object", + "title": "The autoscaling schema", + "description": "An explanation about the purpose of this instance.", + "default": {}, + "examples": [ + { + "enabled": false, + "minReplicas": 1, + "maxReplicas": 100, + "targetCPUUtilizationPercentage": 80 + } + ], + "required": [ + "enabled", + "minReplicas", + "maxReplicas", + "targetCPUUtilizationPercentage" + ], + "properties": { + "enabled": { + "$id": "#/properties/autoscaling/properties/enabled", + "type": "boolean", + "title": "The enabled schema", + "description": "An explanation about the purpose of this instance.", + "default": false, + "examples": [ + false + ] + }, + "minReplicas": { + "$id": "#/properties/autoscaling/properties/minReplicas", + "type": "integer", + "title": "The minReplicas schema", + "description": "An explanation about the purpose of this instance.", + "default": 0, + "examples": [ + 1 + ] + }, + "maxReplicas": { + "$id": "#/properties/autoscaling/properties/maxReplicas", + "type": "integer", + "title": "The maxReplicas schema", + "description": "An explanation about the purpose of this instance.", + "default": 0, + "examples": [ + 100 + ] + }, + "targetCPUUtilizationPercentage": { + "$id": "#/properties/autoscaling/properties/targetCPUUtilizationPercentage", + "type": "integer", + "title": "The targetCPUUtilizationPercentage schema", + "description": "An explanation about the purpose of this instance.", + "default": 0, + "examples": [ + 80 + ] + } + }, + "additionalProperties": true + }, + "nodeSelector": { + "$id": "#/properties/nodeSelector", + "type": "object", + "title": "The nodeSelector schema", + "description": "An explanation about the purpose of this instance.", + "default": {}, + "examples": [ + {} + ], + "required": [], + "additionalProperties": true + }, + "tolerations": { + "$id": "#/properties/tolerations", + "type": "array", + "title": "The tolerations schema", + "description": "An explanation about the purpose of this instance.", + "default": [], + "examples": [ + [] + ], + "additionalItems": true, + "items": { + "$id": "#/properties/tolerations/items" + } + }, + "affinity": { + "$id": "#/properties/affinity", + "type": "object", + "title": "The affinity schema", + "description": "An explanation about the purpose of this instance.", + "default": {}, + "examples": [ + {} + ], + "required": [], + "additionalProperties": true + } + }, + "additionalProperties": true +} diff --git a/internal/chartverifier/checks/chart-0.1.0-v3.with-crd/testchart/values.yaml b/internal/chartverifier/checks/chart-0.1.0-v3.with-crd/testchart/values.yaml new file mode 100644 index 00000000..6c45a415 --- /dev/null +++ b/internal/chartverifier/checks/chart-0.1.0-v3.with-crd/testchart/values.yaml @@ -0,0 +1,79 @@ +# Default values for testchart. +# 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: "" + +imagePullSecrets: [] +nameOverride: "" +fullnameOverride: "" + +serviceAccount: + # Specifies whether a service account should be created + create: 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: {} + +podSecurityContext: {} + # fsGroup: 2000 + +securityContext: {} + # capabilities: + # drop: + # - ALL + # readOnlyRootFilesystem: true + # runAsNonRoot: true + # runAsUser: 1000 + +service: + type: ClusterIP + port: 80 + +ingress: + enabled: false + annotations: {} + # kubernetes.io/ingress.class: nginx + # kubernetes.io/tls-acme: "true" + hosts: + - host: chart-example.local + paths: [] + 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 + +autoscaling: + enabled: false + minReplicas: 1 + maxReplicas: 100 + targetCPUUtilizationPercentage: 80 + # targetMemoryUtilizationPercentage: 80 + +nodeSelector: {} + +tolerations: [] + +affinity: {} diff --git a/internal/chartverifier/checks/chart-0.1.0-v3.with-subchart/testchart/.helmignore b/internal/chartverifier/checks/chart-0.1.0-v3.with-subchart/testchart/.helmignore new file mode 100644 index 00000000..0e8a0eb3 --- /dev/null +++ b/internal/chartverifier/checks/chart-0.1.0-v3.with-subchart/testchart/.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/internal/chartverifier/checks/chart-0.1.0-v3.with-subchart/testchart/Chart.lock b/internal/chartverifier/checks/chart-0.1.0-v3.with-subchart/testchart/Chart.lock new file mode 100644 index 00000000..2da12689 --- /dev/null +++ b/internal/chartverifier/checks/chart-0.1.0-v3.with-subchart/testchart/Chart.lock @@ -0,0 +1,6 @@ +dependencies: +- name: testchart + repository: file://../../chart-0.1.0-v3.with-crd/testchart + version: 0.1.0 +digest: sha256:12a5104c556ef2707f843181c0a156359e6edab238ff70dfde80eda5c34ccc07 +generated: "2023-02-28T08:55:10.964621187+01:00" diff --git a/internal/chartverifier/checks/chart-0.1.0-v3.with-subchart/testchart/Chart.yaml b/internal/chartverifier/checks/chart-0.1.0-v3.with-subchart/testchart/Chart.yaml new file mode 100644 index 00000000..6d6f22b7 --- /dev/null +++ b/internal/chartverifier/checks/chart-0.1.0-v3.with-subchart/testchart/Chart.yaml @@ -0,0 +1,14 @@ +apiVersion: v2 +appVersion: 1.16.0 +description: A Helm chart for Kubernetes +icon: https://www.example.com/chart-icon.png +kubeVersion: '>=1.20.0' +name: chart +type: application +version: 0.1.0-v3.subchart +dependencies: + - name: testchart + alias: subchart + version: 0.1.0 + repository: file://../../chart-0.1.0-v3.with-crd/testchart + condition: subchart.enabled diff --git a/internal/chartverifier/checks/chart-0.1.0-v3.with-subchart/testchart/README.md b/internal/chartverifier/checks/chart-0.1.0-v3.with-subchart/testchart/README.md new file mode 100644 index 00000000..e845566c --- /dev/null +++ b/internal/chartverifier/checks/chart-0.1.0-v3.with-subchart/testchart/README.md @@ -0,0 +1 @@ +README diff --git a/internal/chartverifier/checks/chart-0.1.0-v3.with-subchart/testchart/charts/testchart-0.1.0.tgz b/internal/chartverifier/checks/chart-0.1.0-v3.with-subchart/testchart/charts/testchart-0.1.0.tgz new file mode 100644 index 00000000..5b4ca630 Binary files /dev/null and b/internal/chartverifier/checks/chart-0.1.0-v3.with-subchart/testchart/charts/testchart-0.1.0.tgz differ diff --git a/internal/chartverifier/checks/chart-0.1.0-v3.with-subchart/testchart/templates/NOTES.txt b/internal/chartverifier/checks/chart-0.1.0-v3.with-subchart/testchart/templates/NOTES.txt new file mode 100644 index 00000000..319f01bd --- /dev/null +++ b/internal/chartverifier/checks/chart-0.1.0-v3.with-subchart/testchart/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 "chart.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 "chart.fullname" . }}' + export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "chart.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 "chart.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/internal/chartverifier/checks/chart-0.1.0-v3.with-subchart/testchart/templates/_helpers.tpl b/internal/chartverifier/checks/chart-0.1.0-v3.with-subchart/testchart/templates/_helpers.tpl new file mode 100644 index 00000000..7ba5edc2 --- /dev/null +++ b/internal/chartverifier/checks/chart-0.1.0-v3.with-subchart/testchart/templates/_helpers.tpl @@ -0,0 +1,62 @@ +{{/* +Expand the name of the chart. +*/}} +{{- define "chart.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 "chart.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 "chart.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Common labels +*/}} +{{- define "chart.labels" -}} +helm.sh/chart: {{ include "chart.chart" . }} +{{ include "chart.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "chart.selectorLabels" -}} +app.kubernetes.io/name: {{ include "chart.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} + +{{/* +Create the name of the service account to use +*/}} +{{- define "chart.serviceAccountName" -}} +{{- if .Values.serviceAccount.create }} +{{- default (include "chart.fullname" .) .Values.serviceAccount.name }} +{{- else }} +{{- default "default" .Values.serviceAccount.name }} +{{- end }} +{{- end }} diff --git a/internal/chartverifier/checks/chart-0.1.0-v3.with-subchart/testchart/templates/deployment.yaml b/internal/chartverifier/checks/chart-0.1.0-v3.with-subchart/testchart/templates/deployment.yaml new file mode 100644 index 00000000..a5de2152 --- /dev/null +++ b/internal/chartverifier/checks/chart-0.1.0-v3.with-subchart/testchart/templates/deployment.yaml @@ -0,0 +1,61 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "chart.fullname" . }} + labels: + {{- include "chart.labels" . | nindent 4 }} +spec: + {{- if not .Values.autoscaling.enabled }} + replicas: {{ .Values.replicaCount }} + {{- end }} + selector: + matchLabels: + {{- include "chart.selectorLabels" . | nindent 6 }} + template: + metadata: + {{- with .Values.podAnnotations }} + annotations: + {{- toYaml . | nindent 8 }} + {{- end }} + labels: + {{- include "chart.selectorLabels" . | nindent 8 }} + spec: + {{- with .Values.imagePullSecrets }} + imagePullSecrets: + {{- toYaml . | nindent 8 }} + {{- end }} + serviceAccountName: {{ include "chart.serviceAccountName" . }} + securityContext: + {{- toYaml .Values.podSecurityContext | nindent 8 }} + containers: + - name: {{ .Chart.Name }} + securityContext: + {{- toYaml .Values.securityContext | nindent 12 }} + image: '{{ .Values.image.repository }}{{ .Values.image.name }}:{{ .Values.image.tag }}' + imagePullPolicy: {{ .Values.image.pullPolicy }} + ports: + - name: http + containerPort: 80 + 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 }} diff --git a/internal/chartverifier/checks/chart-0.1.0-v3.with-subchart/testchart/templates/hpa.yaml b/internal/chartverifier/checks/chart-0.1.0-v3.with-subchart/testchart/templates/hpa.yaml new file mode 100644 index 00000000..548ee03b --- /dev/null +++ b/internal/chartverifier/checks/chart-0.1.0-v3.with-subchart/testchart/templates/hpa.yaml @@ -0,0 +1,28 @@ +{{- if .Values.autoscaling.enabled }} +apiVersion: autoscaling/v2beta1 +kind: HorizontalPodAutoscaler +metadata: + name: {{ include "chart.fullname" . }} + labels: + {{- include "chart.labels" . | nindent 4 }} +spec: + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: {{ include "chart.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 }} diff --git a/internal/chartverifier/checks/chart-0.1.0-v3.with-subchart/testchart/templates/ingress.yaml b/internal/chartverifier/checks/chart-0.1.0-v3.with-subchart/testchart/templates/ingress.yaml new file mode 100644 index 00000000..38de004c --- /dev/null +++ b/internal/chartverifier/checks/chart-0.1.0-v3.with-subchart/testchart/templates/ingress.yaml @@ -0,0 +1,41 @@ +{{- if .Values.ingress.enabled -}} +{{- $fullName := include "chart.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 "chart.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 }} diff --git a/internal/chartverifier/checks/chart-0.1.0-v3.with-subchart/testchart/templates/service.yaml b/internal/chartverifier/checks/chart-0.1.0-v3.with-subchart/testchart/templates/service.yaml new file mode 100644 index 00000000..dfc5b3a3 --- /dev/null +++ b/internal/chartverifier/checks/chart-0.1.0-v3.with-subchart/testchart/templates/service.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ include "chart.fullname" . }} + labels: + {{- include "chart.labels" . | nindent 4 }} +spec: + type: {{ .Values.service.type }} + ports: + - port: {{ .Values.service.port }} + targetPort: http + protocol: TCP + name: http + selector: + {{- include "chart.selectorLabels" . | nindent 4 }} diff --git a/internal/chartverifier/checks/chart-0.1.0-v3.with-subchart/testchart/templates/serviceaccount.yaml b/internal/chartverifier/checks/chart-0.1.0-v3.with-subchart/testchart/templates/serviceaccount.yaml new file mode 100644 index 00000000..26a57fa8 --- /dev/null +++ b/internal/chartverifier/checks/chart-0.1.0-v3.with-subchart/testchart/templates/serviceaccount.yaml @@ -0,0 +1,12 @@ +{{- if .Values.serviceAccount.create -}} +apiVersion: v1 +kind: ServiceAccount +metadata: + name: {{ include "chart.serviceAccountName" . }} + labels: + {{- include "chart.labels" . | nindent 4 }} + {{- with .Values.serviceAccount.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +{{- end }} diff --git a/internal/chartverifier/checks/chart-0.1.0-v3.with-subchart/testchart/templates/tests/test-connection.yaml b/internal/chartverifier/checks/chart-0.1.0-v3.with-subchart/testchart/templates/tests/test-connection.yaml new file mode 100644 index 00000000..7735b9bf --- /dev/null +++ b/internal/chartverifier/checks/chart-0.1.0-v3.with-subchart/testchart/templates/tests/test-connection.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Pod +metadata: + name: "{{ include "chart.fullname" . }}-test-connection" + labels: + {{- include "chart.labels" . | nindent 4 }} + annotations: + "helm.sh/hook": test +spec: + containers: + - name: wget + image: 'docker.io/library/busybox' + command: ['wget'] + args: ['{{ include "chart.fullname" . }}:{{ .Values.service.port }}'] + restartPolicy: Never diff --git a/internal/chartverifier/checks/chart-0.1.0-v3.with-subchart/testchart/values.schema.json b/internal/chartverifier/checks/chart-0.1.0-v3.with-subchart/testchart/values.schema.json new file mode 100644 index 00000000..86f5230b --- /dev/null +++ b/internal/chartverifier/checks/chart-0.1.0-v3.with-subchart/testchart/values.schema.json @@ -0,0 +1,35 @@ +{ + "$schema": "https://json-schema.org/draft-07/schema#", + "properties": { + "image": { + "description": "Container Image", + "properties": { + "repo": { + "type": "string" + }, + "tag": { + "type": "string" + } + }, + "type": "object" + }, + "name": { + "description": "Service name", + "type": "string" + }, + "port": { + "description": "Port", + "minimum": 0, + "type": "integer" + }, + "protocol": { + "type": "string" + } + }, + "required": [ + "protocol", + "port" + ], + "title": "Values", + "type": "object" +} diff --git a/internal/chartverifier/checks/chart-0.1.0-v3.with-subchart/testchart/values.yaml b/internal/chartverifier/checks/chart-0.1.0-v3.with-subchart/testchart/values.yaml new file mode 100644 index 00000000..8b858ce8 --- /dev/null +++ b/internal/chartverifier/checks/chart-0.1.0-v3.with-subchart/testchart/values.yaml @@ -0,0 +1,85 @@ +# Default values for chart. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. + +replicaCount: 1 + +image: + name: /library/nginx + repository: docker.io + pullPolicy: IfNotPresent + tag: "1.23" + +imagePullSecrets: [] +nameOverride: "" +fullnameOverride: "" + +serviceAccount: + # Specifies whether a service account should be created + create: 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: {} + +podSecurityContext: {} + # fsGroup: 2000 + +securityContext: {} + # capabilities: + # drop: + # - ALL + # readOnlyRootFilesystem: true + # runAsNonRoot: true + # runAsUser: 1000 + +service: + type: ClusterIP + port: 80 + +ingress: + enabled: false + annotations: {} + # kubernetes.io/ingress.class: nginx + # kubernetes.io/tls-acme: "true" + hosts: + - host: chart-example.local + paths: [] + 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 + +autoscaling: + enabled: false + minReplicas: 1 + maxReplicas: 100 + targetCPUUtilizationPercentage: 80 + # targetMemoryUtilizationPercentage: 80 + +nodeSelector: {} + +tolerations: [] + +affinity: {} + +protocol: http +port: 80 + +subchart: + enabled: false diff --git a/internal/chartverifier/checks/checks.go b/internal/chartverifier/checks/checks.go index 9004dcdc..b6e6039d 100644 --- a/internal/chartverifier/checks/checks.go +++ b/internal/chartverifier/checks/checks.go @@ -29,6 +29,7 @@ import ( "github.com/pkg/errors" "golang.org/x/mod/semver" "helm.sh/helm/v3/pkg/action" + "helm.sh/helm/v3/pkg/chartutil" "helm.sh/helm/v3/pkg/lint" "helm.sh/helm/v3/pkg/lint/support" @@ -216,6 +217,8 @@ func NotContainCRDs(opts *CheckOptions) (Result, error) { return NewResult(false, err.Error()), err } + chartutil.ProcessDependencies(c, c.Values) + r := NewResult(true, ChartDoesNotContainCRDs) if len(c.CRDObjects()) > 0 {