diff --git a/.travis.yml b/.travis.yml index 6dd975b83..3c864b2a0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -31,4 +31,4 @@ jobs: # Set KUBECONFIG environment variable - export KUBECONFIG="$(kind get kubeconfig-path)" - script: crystal spec + script: crystal spec -v diff --git a/USAGE.md b/USAGE.md index 93e754463..17a08e4ab 100644 --- a/USAGE.md +++ b/USAGE.md @@ -218,5 +218,15 @@ crystal src/cnf-conformance.cr direct_hugepages ``` crystal src/cnf-conformance.cr performance ``` + +## Platform Tests +#### (PoC) Run all platform tests +``` +crystal src/cnf-conformance.cr platform +``` +#### (PoC) Run the K8s conformance tests +``` +crystal src/cnf-conformance.cr k8s_conformance +``` diff --git a/sample-cnfs/sample_privileged_cnf_setup_coredns/chart/Chart.yaml b/sample-cnfs/sample-bad_helm_coredns-cnf/chart/Chart.yaml similarity index 100% rename from sample-cnfs/sample_privileged_cnf_setup_coredns/chart/Chart.yaml rename to sample-cnfs/sample-bad_helm_coredns-cnf/chart/Chart.yaml diff --git a/sample-cnfs/sample_privileged_cnf_setup_coredns/chart/README.md b/sample-cnfs/sample-bad_helm_coredns-cnf/chart/README.md similarity index 100% rename from sample-cnfs/sample_privileged_cnf_setup_coredns/chart/README.md rename to sample-cnfs/sample-bad_helm_coredns-cnf/chart/README.md diff --git a/sample-cnfs/sample_privileged_cnf_setup_coredns/chart/templates/NOTES.txt b/sample-cnfs/sample-bad_helm_coredns-cnf/chart/templates/NOTES.txt similarity index 100% rename from sample-cnfs/sample_privileged_cnf_setup_coredns/chart/templates/NOTES.txt rename to sample-cnfs/sample-bad_helm_coredns-cnf/chart/templates/NOTES.txt diff --git a/sample-cnfs/sample_privileged_cnf_setup_coredns/chart/templates/_helpers.tpl b/sample-cnfs/sample-bad_helm_coredns-cnf/chart/templates/_helpers.tpl similarity index 100% rename from sample-cnfs/sample_privileged_cnf_setup_coredns/chart/templates/_helpers.tpl rename to sample-cnfs/sample-bad_helm_coredns-cnf/chart/templates/_helpers.tpl diff --git a/sample-cnfs/sample_privileged_cnf_setup_coredns/chart/templates/clusterrole-autoscaler.yaml b/sample-cnfs/sample-bad_helm_coredns-cnf/chart/templates/clusterrole-autoscaler.yaml similarity index 100% rename from sample-cnfs/sample_privileged_cnf_setup_coredns/chart/templates/clusterrole-autoscaler.yaml rename to sample-cnfs/sample-bad_helm_coredns-cnf/chart/templates/clusterrole-autoscaler.yaml diff --git a/sample-cnfs/sample_privileged_cnf_setup_coredns/chart/templates/clusterrole.yaml b/sample-cnfs/sample-bad_helm_coredns-cnf/chart/templates/clusterrole.yaml similarity index 100% rename from sample-cnfs/sample_privileged_cnf_setup_coredns/chart/templates/clusterrole.yaml rename to sample-cnfs/sample-bad_helm_coredns-cnf/chart/templates/clusterrole.yaml diff --git a/sample-cnfs/sample_privileged_cnf_setup_coredns/chart/templates/clusterrolebinding-autoscaler.yaml b/sample-cnfs/sample-bad_helm_coredns-cnf/chart/templates/clusterrolebinding-autoscaler.yaml similarity index 100% rename from sample-cnfs/sample_privileged_cnf_setup_coredns/chart/templates/clusterrolebinding-autoscaler.yaml rename to sample-cnfs/sample-bad_helm_coredns-cnf/chart/templates/clusterrolebinding-autoscaler.yaml diff --git a/sample-cnfs/sample_privileged_cnf_setup_coredns/chart/templates/clusterrolebinding.yaml b/sample-cnfs/sample-bad_helm_coredns-cnf/chart/templates/clusterrolebinding.yaml similarity index 100% rename from sample-cnfs/sample_privileged_cnf_setup_coredns/chart/templates/clusterrolebinding.yaml rename to sample-cnfs/sample-bad_helm_coredns-cnf/chart/templates/clusterrolebinding.yaml diff --git a/sample-cnfs/sample_privileged_cnf_setup_coredns/chart/templates/configmap-autoscaler.yaml b/sample-cnfs/sample-bad_helm_coredns-cnf/chart/templates/configmap-autoscaler.yaml similarity index 100% rename from sample-cnfs/sample_privileged_cnf_setup_coredns/chart/templates/configmap-autoscaler.yaml rename to sample-cnfs/sample-bad_helm_coredns-cnf/chart/templates/configmap-autoscaler.yaml diff --git a/sample-cnfs/sample_privileged_cnf_setup_coredns/chart/templates/configmap.yaml b/sample-cnfs/sample-bad_helm_coredns-cnf/chart/templates/configmap.yaml similarity index 100% rename from sample-cnfs/sample_privileged_cnf_setup_coredns/chart/templates/configmap.yaml rename to sample-cnfs/sample-bad_helm_coredns-cnf/chart/templates/configmap.yaml diff --git a/sample-cnfs/sample_privileged_cnf_setup_coredns/chart/templates/deployment-autoscaler.yaml b/sample-cnfs/sample-bad_helm_coredns-cnf/chart/templates/deployment-autoscaler.yaml similarity index 100% rename from sample-cnfs/sample_privileged_cnf_setup_coredns/chart/templates/deployment-autoscaler.yaml rename to sample-cnfs/sample-bad_helm_coredns-cnf/chart/templates/deployment-autoscaler.yaml diff --git a/sample-cnfs/sample-bad_helm_coredns-cnf/chart/templates/deployment.yaml b/sample-cnfs/sample-bad_helm_coredns-cnf/chart/templates/deployment.yaml new file mode 100755 index 000000000..809cc660d --- /dev/null +++ b/sample-cnfs/sample-bad_helm_coredns-cnf/chart/templates/deployment.yaml @@ -0,0 +1,124 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ template "coredns.fullname" . }} + labels: + app.kubernetes.io/managed-by: {{ .Release.Service | quote }} + app.kubernetes.io/instance: {{ .Release.Name | quote }} + helm.sh/chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}" + {{- if .Values.isClusterService }} + k8s-app: {{ .Chart.Name | quote }} + kubernetes.io/cluster-service: "true" + kubernetes.io/name: "CoreDNS" + {{- end }} + app.kubernetes.io/name: {{ template "coredns.name" . }} +{{- if .Values.customLabels }} +{{ sdfskfsdf .Values.customLabels | indent 4 }} +{{- end }} +spec: + {{- if not .Values.autoscaler.enabled }} + replicas: {{ .Values.replicaCount }} + {{- end }} + strategy: + type: RollingUpdate + rollingUpdate: + maxUnavailable: 1 + maxSurge: 10% + selector: + matchLabels: + app.kubernetes.io/instance: {{ .Release.Name | quote }} + {{- if .Values.isClusterService }} + k8s-app: {{ .Chart.Name | quote }} + {{- end }} + app.kubernetes.io/name: {{ template "coredns.name" . }} + template: + metadata: + labels: + {{- if .Values.isClusterService }} + k8s-app: {{ .Chart.Name | quote }} + {{- end }} + app.kubernetes.io/name: {{ template "coredns.name" . }} + app.kubernetes.io/instance: {{ .Release.Name | quote }} +{{- if .Values.customLabels }} +{{ sdfskfsdf .Values.customLabels | indent 8 }} +{{- end }} + annotations: + checksum/config: {{ include (print $.Template.BasePath "/configmap.yaml") . | sha256sum }} + {{- if .Values.isClusterService }} + scheduler.alpha.kubernetes.io/critical-pod: '' + scheduler.alpha.kubernetes.io/tolerations: '[{"key":"CriticalAddonsOnly", "operator":"Exists"}]' + {{- end }} + spec: + serviceAccountName: {{ template "coredns.serviceAccountName" . }} + {{- if .Values.priorityClassName }} + priorityClassName: {{ .Values.priorityClassName | quote }} + {{- end }} + {{- if .Values.isClusterService }} + dnsPolicy: Default + {{- end }} + {{- if .Values.affinity }} + affinity: +{{ sdfskfsdf .Values.affinity | indent 8 }} + {{- end }} + {{- if .Values.tolerations }} + tolerations: +{{ sdfskfsdf .Values.tolerations | indent 8 }} + {{- end }} + {{- if .Values.nodeSelector }} + nodeSelector: +{{ sdfskfsdf .Values.nodeSelector | indent 8 }} + {{- end }} + containers: + - name: "coredns" + image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" + securityContext: + privileged: true + imagePullPolicy: {{ .Values.image.pullPolicy }} + args: [ "-conf", "/etc/coredns/Corefile" ] + volumeMounts: + - name: config-volume + mountPath: /etc/coredns +{{- range .Values.extraSecrets }} + - name: {{ .name }} + mountPath: {{ .mountPath }} + readOnly: true +{{- end }} + resources: +{{ sdfskfsdf .Values.resources | indent 10 }} + ports: +{{ include "coredns.containerPorts" . | indent 8 }} + livenessProbe: + httpGet: + path: /health + port: 8080 + scheme: HTTP + initialDelaySeconds: 60 + timeoutSeconds: 5 + successThreshold: 1 + failureThreshold: 5 + readinessProbe: + httpGet: + path: /ready + port: 8181 + scheme: HTTP + initialDelaySeconds: 10 + timeoutSeconds: 5 + successThreshold: 1 + failureThreshold: 5 + volumes: + - name: config-volume + configMap: + name: {{ template "coredns.fullname" . }} + items: + - key: Corefile + path: Corefile + {{ range .Values.zoneFiles }} + - key: {{ .filename }} + path: {{ .filename }} + {{ end }} +{{- range .Values.extraSecrets }} + - name: {{ .name }} + secret: + secretName: {{ .name }} + defaultMode: 400 +{{- end }} diff --git a/sample-cnfs/sample_privileged_cnf_setup_coredns/chart/templates/podsecuritypolicy.yaml b/sample-cnfs/sample-bad_helm_coredns-cnf/chart/templates/podsecuritypolicy.yaml similarity index 100% rename from sample-cnfs/sample_privileged_cnf_setup_coredns/chart/templates/podsecuritypolicy.yaml rename to sample-cnfs/sample-bad_helm_coredns-cnf/chart/templates/podsecuritypolicy.yaml diff --git a/sample-cnfs/sample_privileged_cnf_setup_coredns/chart/templates/service-metrics.yaml b/sample-cnfs/sample-bad_helm_coredns-cnf/chart/templates/service-metrics.yaml similarity index 100% rename from sample-cnfs/sample_privileged_cnf_setup_coredns/chart/templates/service-metrics.yaml rename to sample-cnfs/sample-bad_helm_coredns-cnf/chart/templates/service-metrics.yaml diff --git a/sample-cnfs/sample_privileged_cnf_setup_coredns/chart/templates/service.yaml b/sample-cnfs/sample-bad_helm_coredns-cnf/chart/templates/service.yaml similarity index 100% rename from sample-cnfs/sample_privileged_cnf_setup_coredns/chart/templates/service.yaml rename to sample-cnfs/sample-bad_helm_coredns-cnf/chart/templates/service.yaml diff --git a/sample-cnfs/sample_privileged_cnf_setup_coredns/chart/templates/serviceaccount-autoscaler.yaml b/sample-cnfs/sample-bad_helm_coredns-cnf/chart/templates/serviceaccount-autoscaler.yaml similarity index 100% rename from sample-cnfs/sample_privileged_cnf_setup_coredns/chart/templates/serviceaccount-autoscaler.yaml rename to sample-cnfs/sample-bad_helm_coredns-cnf/chart/templates/serviceaccount-autoscaler.yaml diff --git a/sample-cnfs/sample_privileged_cnf_setup_coredns/chart/templates/serviceaccount.yaml b/sample-cnfs/sample-bad_helm_coredns-cnf/chart/templates/serviceaccount.yaml similarity index 100% rename from sample-cnfs/sample_privileged_cnf_setup_coredns/chart/templates/serviceaccount.yaml rename to sample-cnfs/sample-bad_helm_coredns-cnf/chart/templates/serviceaccount.yaml diff --git a/sample-cnfs/sample_privileged_cnf_setup_coredns/chart/templates/servicemonitor.yaml b/sample-cnfs/sample-bad_helm_coredns-cnf/chart/templates/servicemonitor.yaml similarity index 100% rename from sample-cnfs/sample_privileged_cnf_setup_coredns/chart/templates/servicemonitor.yaml rename to sample-cnfs/sample-bad_helm_coredns-cnf/chart/templates/servicemonitor.yaml diff --git a/sample-cnfs/sample_privileged_cnf_setup_coredns/chart/values.yaml b/sample-cnfs/sample-bad_helm_coredns-cnf/chart/values.yaml similarity index 100% rename from sample-cnfs/sample_privileged_cnf_setup_coredns/chart/values.yaml rename to sample-cnfs/sample-bad_helm_coredns-cnf/chart/values.yaml diff --git a/sample-cnfs/sample-bad_helm_coredns-cnf/cnf-conformance.yml b/sample-cnfs/sample-bad_helm_coredns-cnf/cnf-conformance.yml index b07726780..5b37d5d6c 100644 --- a/sample-cnfs/sample-bad_helm_coredns-cnf/cnf-conformance.yml +++ b/sample-cnfs/sample-bad_helm_coredns-cnf/cnf-conformance.yml @@ -1,6 +1,8 @@ --- -helm_directory: cnfs/bad_helm_coredns/helm_chart/coredns -install_script: cnfs/bad_helm_coredns/Makefile +helm_directory: chart +git_clone_url: +install_script: +release_name: bad-helm-coredns-coredns deployment_name: bad-helm-coredns-coredns application_deployment_names: [bad-helm-coredns] helm_chart: stable/coredns diff --git a/sample-cnfs/sample_privileged_cnf_setup_coredns/README.md b/sample-cnfs/sample-coredns-cnf-source/README.md similarity index 100% rename from sample-cnfs/sample_privileged_cnf_setup_coredns/README.md rename to sample-cnfs/sample-coredns-cnf-source/README.md diff --git a/sample-cnfs/sample-coredns-cnf-source/cnf-conformance.yml b/sample-cnfs/sample-coredns-cnf-source/cnf-conformance.yml new file mode 100644 index 000000000..5e16eb8f5 --- /dev/null +++ b/sample-cnfs/sample-coredns-cnf-source/cnf-conformance.yml @@ -0,0 +1,11 @@ +--- +helm_directory: cnfs/coredns/helm_chart/coredns +# helm_directory: helm_chart +git_clone_url: https://github.com/coredns/coredns.git +install_script: coredns/Makefile +release_name: coredns +deployment_name: coredns-coredns +application_deployment_names: [coredns-coredns] +helm_chart: stable/coredns +helm_chart_container_name: coredns +white_list_helm_chart_container_names: [falco, nginx, coredns, calico-node, kube-proxy, nginx-proxy] diff --git a/sample-cnfs/sample-coredns-cnf/cnf-conformance.yml b/sample-cnfs/sample-coredns-cnf/cnf-conformance.yml index 54431ae1d..5cf6e6ef8 100644 --- a/sample-cnfs/sample-coredns-cnf/cnf-conformance.yml +++ b/sample-cnfs/sample-coredns-cnf/cnf-conformance.yml @@ -1,11 +1,12 @@ --- helm_directory: cnfs/coredns/helm_chart/coredns # helm_directory: helm_chart -git_clone_url: https://github.com/coredns/coredns.git -install_script: cnfs/coredns/Makefile +git_clone_url: +install_script: coredns/Makefile release_name: coredns deployment_name: coredns-coredns application_deployment_names: [coredns-coredns] helm_chart: stable/coredns helm_chart_container_name: coredns +cnf_image_version: latest white_list_helm_chart_container_names: [falco, nginx, coredns, calico-node, kube-proxy, nginx-proxy] diff --git a/sample-cnfs/sample_coredns/cnf-conformance.yml b/sample-cnfs/sample_coredns/cnf-conformance.yml index b3d011943..6ee417b27 100644 --- a/sample-cnfs/sample_coredns/cnf-conformance.yml +++ b/sample-cnfs/sample_coredns/cnf-conformance.yml @@ -1,8 +1,11 @@ --- -helm_directory: cnfs/sample_coredns/chart -install_script: cnfs/sample_coredns/chart +helm_directory: chart +git_clone_url: +install_script: chart +release_name: coredns deployment_name: coredns-coredns application_deployment_names: [coredns-coredns] helm_chart: stable/coredns helm_chart_container_name: coredns-coredns +cnf_image_version: latest white_list_helm_chart_container_names: [] diff --git a/sample-cnfs/sample_coredns_bad_liveness/chart/templates/deployment.yaml b/sample-cnfs/sample_coredns_bad_liveness/chart/templates/deployment.yaml index fd1d89aa8..edf22b182 100755 --- a/sample-cnfs/sample_coredns_bad_liveness/chart/templates/deployment.yaml +++ b/sample-cnfs/sample_coredns_bad_liveness/chart/templates/deployment.yaml @@ -85,15 +85,6 @@ spec: {{ toYaml .Values.resources | indent 10 }} ports: {{ include "coredns.containerPorts" . | indent 8 }} - readinessProbe: - httpGet: - path: /ready - port: 8181 - scheme: HTTP - initialDelaySeconds: 10 - timeoutSeconds: 5 - successThreshold: 1 - failureThreshold: 5 volumes: - name: config-volume configMap: diff --git a/sample-cnfs/sample_coredns_bad_liveness/cnf-conformance.yml b/sample-cnfs/sample_coredns_bad_liveness/cnf-conformance.yml index 88fb77cc6..9a3c51d33 100644 --- a/sample-cnfs/sample_coredns_bad_liveness/cnf-conformance.yml +++ b/sample-cnfs/sample_coredns_bad_liveness/cnf-conformance.yml @@ -1,6 +1,8 @@ --- -helm_directory: cnfs/sample_coredns_bad_liveness/chart -install_script: cnfs/sample_coredns_bad_liveness/chart +helm_directory: chart +git_clone_url: +install_script: chart +release_name: bad-liveness deployment_name: bad-liveness-coredns application_deployment_names: [bad-liveness-coredns] helm_chart: stable/coredns diff --git a/sample-cnfs/sample_privileged_cnf/README.md b/sample-cnfs/sample_privileged_cnf/README.md new file mode 100644 index 000000000..12981cc93 --- /dev/null +++ b/sample-cnfs/sample_privileged_cnf/README.md @@ -0,0 +1,39 @@ +# Set up Sample CoreDNS CNF +./sample-cnfs/sample-coredns-cnf/readme.md +# Prerequistes +### Install helm +``` +curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 +chmod 700 get_helm.sh +./get_helm.sh +``` +### Optional: Use a helm version manager +https://github.com/yuya-takeyama/helmenv +Check out helmenv into any path (here is ${HOME}/.helmenv) +``` +${HOME}/.helmenv) +$ git clone https://github.com/yuya-takeyama/helmenv.git ~/.helmenv +``` +Add ~/.helmenv/bin to your $PATH any way you like +``` +$ echo 'export PATH="$HOME/.helmenv/bin:$PATH"' >> ~/.bash_profile +``` +``` +helmenv versions +helmenv install +``` + +### core-dns installation +``` +helm install coredns stable/coredns +``` +### Pull down the helm chart code, untar it, and put it in the cnfs/coredns directory +``` +helm pull stable/coredns +``` +### Example cnf-conformance config file for sample-core-dns-cnf +In ./cnfs/sample-core-dns-cnf/cnf-conformance.yml +``` +--- +container_names: [coredns-coredns] +``` diff --git a/sample-cnfs/sample_privileged_cnf/chart/Chart.yaml b/sample-cnfs/sample_privileged_cnf/chart/Chart.yaml new file mode 100755 index 000000000..77de0c04f --- /dev/null +++ b/sample-cnfs/sample_privileged_cnf/chart/Chart.yaml @@ -0,0 +1,23 @@ +apiVersion: v1 +appVersion: 1.6.7 +description: CoreDNS is a DNS server that chains plugins and provides Kubernetes DNS + Services +home: https://coredns.io +icon: https://coredns.io/images/CoreDNS_Colour_Horizontal.png +keywords: +- coredns +- dns +- kubedns +maintainers: +- email: hello@acale.ph + name: Acaleph +- email: shashidhara.huawei@gmail.com + name: shashidharatd +- email: andor44@gmail.com + name: andor44 +- email: manuel@rueg.eu + name: mrueg +name: coredns +sources: +- https://github.com/coredns/coredns +version: 1.9.3 diff --git a/sample-cnfs/sample_privileged_cnf/chart/README.md b/sample-cnfs/sample_privileged_cnf/chart/README.md new file mode 100755 index 000000000..dc00ca26b --- /dev/null +++ b/sample-cnfs/sample_privileged_cnf/chart/README.md @@ -0,0 +1,137 @@ +# CoreDNS + +[CoreDNS](https://coredns.io/) is a DNS server that chains plugins and provides DNS Services + +# TL;DR; + +```console +$ helm install --name coredns --namespace=kube-system stable/coredns +``` + +## Introduction + +This chart bootstraps a [CoreDNS](https://github.com/coredns/coredns) deployment on a [Kubernetes](http://kubernetes.io) cluster using the [Helm](https://helm.sh) package manager. This chart will provide DNS Services and can be deployed in multiple configuration to support various scenarios listed below: + + - CoreDNS as a cluster dns service and a drop-in replacement for Kube/SkyDNS. This is the default mode and CoreDNS is deployed as cluster-service in kube-system namespace. This mode is chosen by setting `isClusterService` to true. + - CoreDNS as an external dns service. In this mode CoreDNS is deployed as any kubernetes app in user specified namespace. The CoreDNS service can be exposed outside the cluster by using using either the NodePort or LoadBalancer type of service. This mode is chosen by setting `isClusterService` to false. + - CoreDNS as an external dns provider for kubernetes federation. This is a sub case of 'external dns service' which uses etcd plugin for CoreDNS backend. This deployment mode as a dependency on `etcd-operator` chart, which needs to be pre-installed. + +## Prerequisites + +- Kubernetes 1.10 or later + +## Installing the Chart + +The chart can be installed as follows: + +```console +$ helm install --name coredns --namespace=kube-system stable/coredns +``` + +The command deploys CoreDNS on the Kubernetes cluster in the default configuration. The [configuration](#configuration) section lists various ways to override default configuration during deployment. + +> **Tip**: List all releases using `helm list` + +## Uninstalling the Chart + +To uninstall/delete the `my-release` deployment: + +```console +$ helm delete coredns +``` + +The command removes all the Kubernetes components associated with the chart and deletes the release. + +## Configuration + +| Parameter | Description | Default | +|:----------------------------------------|:--------------------------------------------------------------------------------------|:------------------------------------------------------------| +| `image.repository` | The image repository to pull from | coredns/coredns | +| `image.tag` | The image tag to pull from | `v1.6.7` | +| `image.pullPolicy` | Image pull policy | IfNotPresent | +| `replicaCount` | Number of replicas | 1 | +| `resources.limits.cpu` | Container maximum CPU | `100m` | +| `resources.limits.memory` | Container maximum memory | `128Mi` | +| `resources.requests.cpu` | Container requested CPU | `100m` | +| `resources.requests.memory` | Container requested memory | `128Mi` | +| `serviceType` | Kubernetes Service type | `ClusterIP` | +| `prometheus.monitor.enabled` | Set this to `true` to create ServiceMonitor for Prometheus operator | `false` | +| `prometheus.monitor.additionalLabels` | Additional labels that can be used so ServiceMonitor will be discovered by Prometheus | {} | +| `prometheus.monitor.namespace` | Selector to select which namespaces the Endpoints objects are discovered from. | `""` | +| `service.clusterIP` | IP address to assign to service | `""` | +| `service.loadBalancerIP` | IP address to assign to load balancer (if supported) | `""` | +| `service.externalTrafficPolicy` | Enable client source IP preservation | `[]` | +| `service.annotations` | Annotations to add to service | `{prometheus.io/scrape: "true", prometheus.io/port: "9153"}`| +| `serviceAccount.create` | If true, create & use serviceAccount | false | +| `serviceAccount.name` | If not set & create is true, use template fullname | | +| `rbac.create` | If true, create & use RBAC resources | true | +| `rbac.pspEnable` | Specifies whether a PodSecurityPolicy should be created. | `false` | +| `isClusterService` | Specifies whether chart should be deployed as cluster-service or normal k8s app. | true | +| `priorityClassName` | Name of Priority Class to assign pods | `""` | +| `servers` | Configuration for CoreDNS and plugins | See values.yml | +| `affinity` | Affinity settings for pod assignment | {} | +| `nodeSelector` | Node labels for pod assignment | {} | +| `tolerations` | Tolerations for pod assignment | [] | +| `zoneFiles` | Configure custom Zone files | [] | +| `extraSecrets` | Optional array of secrets to mount inside the CoreDNS container | [] | +| `customLabels` | Optional labels for Deployment(s), Pod, Service, ServiceMonitor objects | {} | +| `autoscaler.enabled` | Optionally enabled a cluster-proportional-autoscaler for CoreDNS | `false` | +| `autoscaler.coresPerReplica` | Number of cores in the cluster per CoreDNS replica | `256` | +| `autoscaler.nodesPerReplica` | Number of nodes in the cluster per CoreDNS replica | `16` | +| `autoscaler.image.repository` | The image repository to pull autoscaler from | k8s.gcr.io/cluster-proportional-autoscaler-amd64 | +| `autoscaler.image.tag` | The image tag to pull autoscaler from | `1.7.1` | +| `autoscaler.image.pullPolicy` | Image pull policy for the autoscaler | IfNotPresent | +| `autoscaler.priorityClassName` | Optional priority class for the autoscaler pod. `priorityClassName` used if not set. | `""` | +| `autoscaler.affinity` | Affinity settings for pod assignment for autoscaler | {} | +| `autoscaler.nodeSelector` | Node labels for pod assignment for autoscaler | {} | +| `autoscaler.tolerations` | Tolerations for pod assignment for autoscaler | [] | +| `autoscaler.resources.limits.cpu` | Container maximum CPU for cluster-proportional-autoscaler | `20m` | +| `autoscaler.resources.limits.memory` | Container maximum memory for cluster-proportional-autoscaler | `10Mi` | +| `autoscaler.resources.requests.cpu` | Container requested CPU for cluster-proportional-autoscaler | `20m` | +| `autoscaler.resources.requests.memory` | Container requested memory for cluster-proportional-autoscaler | `10Mi` | +| `autoscaler.configmap.annotations` | Annotations to add to autoscaler config map. For example to stop CI renaming them | {} | + +See `values.yaml` for configuration notes. Specify each parameter using the `--set key=value[,key=value]` argument to `helm install`. For example, + +```console +$ helm install --name coredns \ + --set rbac.create=false \ + stable/coredns +``` + +The above command disables automatic creation of RBAC rules. + +Alternatively, a YAML file that specifies the values for the above parameters can be provided while installing the chart. For example, + +```console +$ helm install --name coredns -f values.yaml stable/coredns +``` + +> **Tip**: You can use the default [values.yaml](values.yaml) + + +## Caveats + +The chart will automatically determine which protocols to listen on based on +the protocols you define in your zones. This means that you could potentially +use both "TCP" and "UDP" on a single port. +Some cloud environments like "GCE" or "Azure container service" cannot +create external loadbalancers with both "TCP" and "UDP" protocols. So +When deploying CoreDNS with `serviceType="LoadBalancer"` on such cloud +environments, make sure you do not attempt to use both protocols at the same +time. + +## Autoscaling + +By setting `autoscaler.enabled = true` a +[cluster-proportional-autoscaler](https://github.com/kubernetes-incubator/cluster-proportional-autoscaler) +will be deployed. This will default to a coredns replica for every 256 cores, or +16 nodes in the cluster. These can be changed with `autoscaler.coresPerReplica` +and `autoscaler.nodesPerReplica`. When cluster is using large nodes (with more +cores), `coresPerReplica` should dominate. If using small nodes, +`nodesPerReplica` should dominate. + +This also creates a ServiceAccount, ClusterRole, and ClusterRoleBinding for +the autoscaler deployment. + +`replicaCount` is ignored if this is enabled. diff --git a/sample-cnfs/sample_privileged_cnf/chart/templates/NOTES.txt b/sample-cnfs/sample_privileged_cnf/chart/templates/NOTES.txt new file mode 100755 index 000000000..3a1883b3a --- /dev/null +++ b/sample-cnfs/sample_privileged_cnf/chart/templates/NOTES.txt @@ -0,0 +1,30 @@ +{{- if .Values.isClusterService }} +CoreDNS is now running in the cluster as a cluster-service. +{{- else }} +CoreDNS is now running in the cluster. +It can be accessed using the below endpoint +{{- if contains "NodePort" .Values.serviceType }} + export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ template "coredns.fullname" . }}) + export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}") + echo "$NODE_IP:$NODE_PORT" +{{- else if contains "LoadBalancer" .Values.serviceType }} + NOTE: It may take a few minutes for the LoadBalancer IP to be available. + You can watch the status by running 'kubectl get svc -w {{ template "coredns.fullname" . }}' + + export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ template "coredns.fullname" . }} -o jsonpath='{.status.loadBalancer.ingress[0].ip}') + echo $SERVICE_IP +{{- else if contains "ClusterIP" .Values.serviceType }} + "{{ template "coredns.fullname" . }}.{{ .Release.Namespace }}.svc.cluster.local" + from within the cluster +{{- end }} +{{- end }} + +It can be tested with the following: + +1. Launch a Pod with DNS tools: + +kubectl run -it --rm --restart=Never --image=infoblox/dnstools:latest dnstools + +2. Query the DNS server: + +/ # host kubernetes diff --git a/sample-cnfs/sample_privileged_cnf/chart/templates/_helpers.tpl b/sample-cnfs/sample_privileged_cnf/chart/templates/_helpers.tpl new file mode 100755 index 000000000..a2efcb43e --- /dev/null +++ b/sample-cnfs/sample_privileged_cnf/chart/templates/_helpers.tpl @@ -0,0 +1,149 @@ +{{/* vim: set filetype=mustache: */}} +{{/* +Expand the name of the chart. +*/}} +{{- define "coredns.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). +*/}} +{{- define "coredns.fullname" -}} +{{- if .Values.fullnameOverride -}} +{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}} +{{- else -}} +{{- $name := default .Chart.Name .Values.nameOverride -}} +{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}} +{{- end -}} +{{- end -}} + +{{/* +Generate the list of ports automatically from the server definitions +*/}} +{{- define "coredns.servicePorts" -}} + {{/* Set ports to be an empty dict */}} + {{- $ports := dict -}} + {{/* Iterate through each of the server blocks */}} + {{- range .Values.servers -}} + {{/* Capture port to avoid scoping awkwardness */}} + {{- $port := toString .port -}} + + {{/* If none of the server blocks has mentioned this port yet take note of it */}} + {{- if not (hasKey $ports $port) -}} + {{- $ports := set $ports $port (dict "istcp" false "isudp" false) -}} + {{- end -}} + {{/* Retrieve the inner dict that holds the protocols for a given port */}} + {{- $innerdict := index $ports $port -}} + + {{/* + Look at each of the zones and check which protocol they serve + At the moment the following are supported by CoreDNS: + UDP: dns:// + TCP: tls://, grpc:// + */}} + {{- range .zones -}} + {{- if has (default "" .scheme) (list "dns://") -}} + {{/* Optionally enable tcp for this service as well */}} + {{- if eq .use_tcp true }} + {{- $innerdict := set $innerdict "istcp" true -}} + {{- end }} + {{- $innerdict := set $innerdict "isudp" true -}} + {{- end -}} + + {{- if has (default "" .scheme) (list "tls://" "grpc://") -}} + {{- $innerdict := set $innerdict "istcp" true -}} + {{- end -}} + {{- end -}} + + {{/* If none of the zones specify scheme, default to dns:// on both tcp & udp */}} + {{- if and (not (index $innerdict "istcp")) (not (index $innerdict "isudp")) -}} + {{- $innerdict := set $innerdict "isudp" true -}} + {{- $innerdict := set $innerdict "istcp" true -}} + {{- end -}} + + {{/* Write the dict back into the outer dict */}} + {{- $ports := set $ports $port $innerdict -}} + {{- end -}} + + {{/* Write out the ports according to the info collected above */}} + {{- range $port, $innerdict := $ports -}} + {{- if index $innerdict "isudp" -}} + {{- printf "- {port: %v, protocol: UDP, name: udp-%s}\n" $port $port -}} + {{- end -}} + {{- if index $innerdict "istcp" -}} + {{- printf "- {port: %v, protocol: TCP, name: tcp-%s}\n" $port $port -}} + {{- end -}} + {{- end -}} +{{- end -}} + +{{/* +Generate the list of ports automatically from the server definitions +*/}} +{{- define "coredns.containerPorts" -}} + {{/* Set ports to be an empty dict */}} + {{- $ports := dict -}} + {{/* Iterate through each of the server blocks */}} + {{- range .Values.servers -}} + {{/* Capture port to avoid scoping awkwardness */}} + {{- $port := toString .port -}} + + {{/* If none of the server blocks has mentioned this port yet take note of it */}} + {{- if not (hasKey $ports $port) -}} + {{- $ports := set $ports $port (dict "istcp" false "isudp" false) -}} + {{- end -}} + {{/* Retrieve the inner dict that holds the protocols for a given port */}} + {{- $innerdict := index $ports $port -}} + + {{/* + Look at each of the zones and check which protocol they serve + At the moment the following are supported by CoreDNS: + UDP: dns:// + TCP: tls://, grpc:// + */}} + {{- range .zones -}} + {{- if has (default "" .scheme) (list "dns://") -}} + {{/* Optionally enable tcp for this service as well */}} + {{- if eq .use_tcp true }} + {{- $innerdict := set $innerdict "istcp" true -}} + {{- end }} + {{- $innerdict := set $innerdict "isudp" true -}} + {{- end -}} + + {{- if has (default "" .scheme) (list "tls://" "grpc://") -}} + {{- $innerdict := set $innerdict "istcp" true -}} + {{- end -}} + {{- end -}} + + {{/* If none of the zones specify scheme, default to dns:// on both tcp & udp */}} + {{- if and (not (index $innerdict "istcp")) (not (index $innerdict "isudp")) -}} + {{- $innerdict := set $innerdict "isudp" true -}} + {{- $innerdict := set $innerdict "istcp" true -}} + {{- end -}} + + {{/* Write the dict back into the outer dict */}} + {{- $ports := set $ports $port $innerdict -}} + {{- end -}} + + {{/* Write out the ports according to the info collected above */}} + {{- range $port, $innerdict := $ports -}} + {{- if index $innerdict "isudp" -}} + {{- printf "- {containerPort: %v, protocol: UDP, name: udp-%s}\n" $port $port -}} + {{- end -}} + {{- if index $innerdict "istcp" -}} + {{- printf "- {containerPort: %v, protocol: TCP, name: tcp-%s}\n" $port $port -}} + {{- end -}} + {{- end -}} +{{- end -}} + +{{/* +Create the name of the service account to use +*/}} +{{- define "coredns.serviceAccountName" -}} +{{- if .Values.serviceAccount.create -}} + {{ default (include "coredns.fullname" .) .Values.serviceAccount.name }} +{{- else -}} + {{ default "default" .Values.serviceAccount.name }} +{{- end -}} +{{- end -}} diff --git a/sample-cnfs/sample_privileged_cnf/chart/templates/clusterrole-autoscaler.yaml b/sample-cnfs/sample_privileged_cnf/chart/templates/clusterrole-autoscaler.yaml new file mode 100755 index 000000000..748c62bf7 --- /dev/null +++ b/sample-cnfs/sample_privileged_cnf/chart/templates/clusterrole-autoscaler.yaml @@ -0,0 +1,35 @@ +{{- if and .Values.autoscaler.enabled .Values.rbac.create }} +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + name: {{ template "coredns.fullname" . }}-autoscaler + labels: + app.kubernetes.io/managed-by: {{ .Release.Service | quote }} + app.kubernetes.io/instance: {{ .Release.Name | quote }} + helm.sh/chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}" + {{- if .Values.isClusterService }} + k8s-app: {{ .Chart.Name }}-autoscaler + kubernetes.io/cluster-service: "true" + kubernetes.io/name: "CoreDNS" + {{- end }} + app.kubernetes.io/name: {{ template "coredns.name" . }}-autoscaler +{{- if .Values.customLabels }} +{{ toYaml .Values.customLabels | indent 4 }} +{{- end }} +rules: + - apiGroups: [""] + resources: ["nodes"] + verbs: ["list","watch"] + - apiGroups: [""] + resources: ["replicationcontrollers/scale"] + verbs: ["get", "update"] + - apiGroups: ["extensions", "apps"] + resources: ["deployments/scale", "replicasets/scale"] + verbs: ["get", "update"] +# Remove the configmaps rule once below issue is fixed: +# kubernetes-incubator/cluster-proportional-autoscaler#16 + - apiGroups: [""] + resources: ["configmaps"] + verbs: ["get", "create"] +{{- end }} diff --git a/sample-cnfs/sample_privileged_cnf/chart/templates/clusterrole.yaml b/sample-cnfs/sample_privileged_cnf/chart/templates/clusterrole.yaml new file mode 100755 index 000000000..029d13e27 --- /dev/null +++ b/sample-cnfs/sample_privileged_cnf/chart/templates/clusterrole.yaml @@ -0,0 +1,38 @@ +{{- if .Values.rbac.create }} +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + name: {{ template "coredns.fullname" . }} + labels: + app.kubernetes.io/managed-by: {{ .Release.Service | quote }} + app.kubernetes.io/instance: {{ .Release.Name | quote }} + helm.sh/chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}" + {{- if .Values.isClusterService }} + k8s-app: {{ .Chart.Name | quote }} + kubernetes.io/cluster-service: "true" + kubernetes.io/name: "CoreDNS" + {{- end }} + app.kubernetes.io/name: {{ template "coredns.name" . }} +rules: +- apiGroups: + - "" + resources: + - endpoints + - services + - pods + - namespaces + verbs: + - list + - watch +{{- if .Values.rbac.pspEnable }} +- apiGroups: + - policy + - extensions + resources: + - podsecuritypolicies + verbs: + - use + resourceNames: + - {{ template "coredns.fullname" . }} +{{- end }} +{{- end }} diff --git a/sample-cnfs/sample_privileged_cnf/chart/templates/clusterrolebinding-autoscaler.yaml b/sample-cnfs/sample_privileged_cnf/chart/templates/clusterrolebinding-autoscaler.yaml new file mode 100755 index 000000000..eafb38f9e --- /dev/null +++ b/sample-cnfs/sample_privileged_cnf/chart/templates/clusterrolebinding-autoscaler.yaml @@ -0,0 +1,28 @@ +{{- if and .Values.autoscaler.enabled .Values.rbac.create }} +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRoleBinding +metadata: + name: {{ template "coredns.fullname" . }}-autoscaler + labels: + app.kubernetes.io/managed-by: {{ .Release.Service | quote }} + app.kubernetes.io/instance: {{ .Release.Name | quote }} + helm.sh/chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}" + {{- if .Values.isClusterService }} + k8s-app: {{ .Chart.Name }}-autoscaler + kubernetes.io/cluster-service: "true" + kubernetes.io/name: "CoreDNS" + {{- end }} + app.kubernetes.io/name: {{ template "coredns.name" . }}-autoscaler +{{- if .Values.customLabels }} +{{ toYaml .Values.customLabels | indent 4 }} +{{- end }} +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: ClusterRole + name: {{ template "coredns.fullname" . }}-autoscaler +subjects: +- kind: ServiceAccount + name: {{ template "coredns.fullname" . }}-autoscaler + namespace: {{ .Release.Namespace }} +{{- end }} diff --git a/sample-cnfs/sample_privileged_cnf/chart/templates/clusterrolebinding.yaml b/sample-cnfs/sample_privileged_cnf/chart/templates/clusterrolebinding.yaml new file mode 100755 index 000000000..49da9b548 --- /dev/null +++ b/sample-cnfs/sample_privileged_cnf/chart/templates/clusterrolebinding.yaml @@ -0,0 +1,24 @@ +{{- if .Values.rbac.create }} +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRoleBinding +metadata: + name: {{ template "coredns.fullname" . }} + labels: + app.kubernetes.io/managed-by: {{ .Release.Service | quote }} + app.kubernetes.io/instance: {{ .Release.Name | quote }} + helm.sh/chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}" + {{- if .Values.isClusterService }} + k8s-app: {{ .Chart.Name | quote }} + kubernetes.io/cluster-service: "true" + kubernetes.io/name: "CoreDNS" + {{- end }} + app.kubernetes.io/name: {{ template "coredns.name" . }} +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: ClusterRole + name: {{ template "coredns.fullname" . }} +subjects: +- kind: ServiceAccount + name: {{ template "coredns.serviceAccountName" . }} + namespace: {{ .Release.Namespace }} +{{- end }} diff --git a/sample-cnfs/sample_privileged_cnf/chart/templates/configmap-autoscaler.yaml b/sample-cnfs/sample_privileged_cnf/chart/templates/configmap-autoscaler.yaml new file mode 100755 index 000000000..50895ae5b --- /dev/null +++ b/sample-cnfs/sample_privileged_cnf/chart/templates/configmap-autoscaler.yaml @@ -0,0 +1,34 @@ +{{- if .Values.autoscaler.enabled }} +--- +kind: ConfigMap +apiVersion: v1 +metadata: + name: {{ template "coredns.fullname" . }}-autoscaler + namespace: {{ .Release.Namespace }} + labels: + app.kubernetes.io/managed-by: {{ .Release.Service | quote }} + app.kubernetes.io/instance: {{ .Release.Name | quote }} + helm.sh/chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}" + {{- if .Values.isClusterService }} + k8s-app: {{ .Chart.Name }}-autoscaler + kubernetes.io/cluster-service: "true" + kubernetes.io/name: "CoreDNS" + {{- end }} + app.kubernetes.io/name: {{ template "coredns.name" . }}-autoscaler + {{- if .Values.customLabels }} + {{- toYaml .Values.customLabels | nindent 4 }} + {{- end }} + {{- if .Values.autoscaler.configmap.annotations }} + annotations: + {{- toYaml .Values.autoscaler.configmap.annotations | nindent 4 }} + {{- end }} +data: + # When cluster is using large nodes(with more cores), "coresPerReplica" should dominate. + # If using small nodes, "nodesPerReplica" should dominate. + linear: |- + { + "coresPerReplica": {{ .Values.autoscaler.coresPerReplica | float64 }}, + "nodesPerReplica": {{ .Values.autoscaler.nodesPerReplica | float64 }}, + "preventSinglePointFailure": true + } +{{- end }} diff --git a/sample-cnfs/sample_privileged_cnf/chart/templates/configmap.yaml b/sample-cnfs/sample_privileged_cnf/chart/templates/configmap.yaml new file mode 100755 index 000000000..b7e1a667f --- /dev/null +++ b/sample-cnfs/sample_privileged_cnf/chart/templates/configmap.yaml @@ -0,0 +1,30 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: {{ template "coredns.fullname" . }} + labels: + app.kubernetes.io/managed-by: {{ .Release.Service | quote }} + app.kubernetes.io/instance: {{ .Release.Name | quote }} + helm.sh/chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}" + {{- if .Values.isClusterService }} + k8s-app: {{ .Chart.Name | quote }} + kubernetes.io/cluster-service: "true" + kubernetes.io/name: "CoreDNS" + {{- end }} + app.kubernetes.io/name: {{ template "coredns.name" . }} +data: + Corefile: |- + {{ range .Values.servers }} + {{- range $idx, $zone := .zones }}{{ if $idx }} {{ else }}{{ end }}{{ default "" $zone.scheme }}{{ default "." $zone.zone }}{{ else }}.{{ end -}} + {{- if .port }}:{{ .port }} {{ end -}} + { + {{- range .plugins }} + {{ .name }}{{ if .parameters }} {{ .parameters }}{{ end }}{{ if .configBlock }} { +{{ .configBlock | indent 12 }} + }{{ end }} + {{- end }} + } + {{ end }} + {{- range .Values.zoneFiles }} + {{ .filename }}: {{ toYaml .contents | indent 4 }} + {{- end }} diff --git a/sample-cnfs/sample_privileged_cnf/chart/templates/deployment-autoscaler.yaml b/sample-cnfs/sample_privileged_cnf/chart/templates/deployment-autoscaler.yaml new file mode 100755 index 000000000..7ca185239 --- /dev/null +++ b/sample-cnfs/sample_privileged_cnf/chart/templates/deployment-autoscaler.yaml @@ -0,0 +1,77 @@ +{{- if .Values.autoscaler.enabled }} +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ template "coredns.fullname" . }}-autoscaler + namespace: {{ .Release.Namespace }} + labels: + app.kubernetes.io/managed-by: {{ .Release.Service | quote }} + app.kubernetes.io/instance: {{ .Release.Name | quote }} + helm.sh/chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}" + {{- if .Values.isClusterService }} + k8s-app: {{ .Chart.Name }}-autoscaler + kubernetes.io/cluster-service: "true" + kubernetes.io/name: "CoreDNS" + {{- end }} + app.kubernetes.io/name: {{ template "coredns.name" . }}-autoscaler +{{- if .Values.customLabels }} +{{ toYaml .Values.customLabels | indent 4 }} +{{- end }} +spec: + selector: + matchLabels: + app.kubernetes.io/instance: {{ .Release.Name | quote }} + {{- if .Values.isClusterService }} + k8s-app: {{ .Chart.Name }}-autoscaler + {{- end }} + app.kubernetes.io/name: {{ template "coredns.name" . }}-autoscaler + template: + metadata: + labels: + {{- if .Values.isClusterService }} + k8s-app: {{ .Chart.Name }}-autoscaler + {{- end }} + app.kubernetes.io/name: {{ template "coredns.name" . }}-autoscaler + app.kubernetes.io/instance: {{ .Release.Name | quote }} + {{- if .Values.customLabels }} + {{ toYaml .Values.customLabels | nindent 8 }} + {{- end }} + annotations: + checksum/configmap: {{ include (print $.Template.BasePath "/configmap-autoscaler.yaml") . | sha256sum }} + {{- if .Values.isClusterService }} + scheduler.alpha.kubernetes.io/critical-pod: '' + scheduler.alpha.kubernetes.io/tolerations: '[{"key":"CriticalAddonsOnly", "operator":"Exists"}]' + {{- end }} + spec: + serviceAccountName: {{ template "coredns.fullname" . }}-autoscaler + {{- $priorityClassName := default .Values.priorityClassName .Values.autoscaler.priorityClassName }} + {{- if $priorityClassName }} + priorityClassName: {{ $priorityClassName | quote }} + {{- end }} + {{- if .Values.autoscaler.affinity }} + affinity: +{{ toYaml .Values.autoscaler.affinity | indent 8 }} + {{- end }} + {{- if .Values.autoscaler.tolerations }} + tolerations: +{{ toYaml .Values.autoscaler.tolerations | indent 8 }} + {{- end }} + {{- if .Values.autoscaler.nodeSelector }} + nodeSelector: +{{ toYaml .Values.autoscaler.nodeSelector | indent 8 }} + {{- end }} + containers: + - name: autoscaler + image: "{{ .Values.autoscaler.image.repository }}:{{ .Values.autoscaler.image.tag }}" + imagePullPolicy: {{ .Values.autoscaler.image.pullPolicy }} + resources: +{{ toYaml .Values.autoscaler.resources | indent 10 }} + command: + - /cluster-proportional-autoscaler + - --namespace={{ .Release.Namespace }} + - --configmap={{ template "coredns.fullname" . }}-autoscaler + - --target=Deployment/{{ template "coredns.fullname" . }} + - --logtostderr=true + - --v=2 +{{- end }} diff --git a/sample-cnfs/sample_privileged_cnf_setup_coredns/chart/templates/deployment.yaml b/sample-cnfs/sample_privileged_cnf/chart/templates/deployment.yaml similarity index 100% rename from sample-cnfs/sample_privileged_cnf_setup_coredns/chart/templates/deployment.yaml rename to sample-cnfs/sample_privileged_cnf/chart/templates/deployment.yaml diff --git a/sample-cnfs/sample_privileged_cnf/chart/templates/podsecuritypolicy.yaml b/sample-cnfs/sample_privileged_cnf/chart/templates/podsecuritypolicy.yaml new file mode 100755 index 000000000..754943fe5 --- /dev/null +++ b/sample-cnfs/sample_privileged_cnf/chart/templates/podsecuritypolicy.yaml @@ -0,0 +1,57 @@ +{{- if .Values.rbac.pspEnable }} +{{ if .Capabilities.APIVersions.Has "policy/v1beta1" }} +apiVersion: policy/v1beta1 +{{ else }} +apiVersion: extensions/v1beta1 +{{ end -}} +kind: PodSecurityPolicy +metadata: + name: {{ template "coredns.fullname" . }} + labels: + app.kubernetes.io/managed-by: {{ .Release.Service | quote }} + app.kubernetes.io/instance: {{ .Release.Name | quote }} + helm.sh/chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}" + {{- if .Values.isClusterService }} + k8s-app: {{ .Chart.Name | quote }} + kubernetes.io/cluster-service: "true" + kubernetes.io/name: "CoreDNS" + {{- else }} + app.kubernetes.io/name: {{ template "coredns.name" . }} + {{- end }} +spec: + privileged: false + # Required to prevent escalations to root. + allowPrivilegeEscalation: false + # Add back CAP_NET_BIND_SERVICE so that coredns can run on port 53 + allowedCapabilities: + - CAP_NET_BIND_SERVICE + # Allow core volume types. + volumes: + - 'configMap' + - 'emptyDir' + - 'projected' + - 'secret' + - 'downwardAPI' + hostNetwork: false + hostIPC: false + hostPID: false + runAsUser: + # Require the container to run without root privileges. + rule: 'RunAsAny' + seLinux: + # This policy assumes the nodes are using AppArmor rather than SELinux. + rule: 'RunAsAny' + supplementalGroups: + rule: 'MustRunAs' + ranges: + # Forbid adding the root group. + - min: 1 + max: 65535 + fsGroup: + rule: 'MustRunAs' + ranges: + # Forbid adding the root group. + - min: 1 + max: 65535 + readOnlyRootFilesystem: false +{{- end }} diff --git a/sample-cnfs/sample_privileged_cnf/chart/templates/service-metrics.yaml b/sample-cnfs/sample_privileged_cnf/chart/templates/service-metrics.yaml new file mode 100755 index 000000000..ae213c043 --- /dev/null +++ b/sample-cnfs/sample_privileged_cnf/chart/templates/service-metrics.yaml @@ -0,0 +1,33 @@ +{{- if .Values.prometheus.monitor.enabled }} +apiVersion: v1 +kind: Service +metadata: + name: {{ template "coredns.fullname" . }}-metrics + labels: + app.kubernetes.io/managed-by: {{ .Release.Service | quote }} + app.kubernetes.io/instance: {{ .Release.Name | quote }} + helm.sh/chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}" + {{- if .Values.isClusterService }} + k8s-app: {{ .Chart.Name | quote }} + kubernetes.io/cluster-service: "true" + kubernetes.io/name: "CoreDNS" + {{- end }} + app.kubernetes.io/name: {{ template "coredns.name" . }} + app.kubernetes.io/component: metrics +{{- if .Values.customLabels }} +{{ toYaml .Values.customLabels | indent 4 }} +{{- end }} + annotations: +{{ toYaml .Values.service.annotations | indent 4 }} +spec: + selector: + app.kubernetes.io/instance: {{ .Release.Name | quote }} + {{- if .Values.isClusterService }} + k8s-app: {{ .Chart.Name | quote }} + {{- end }} + app.kubernetes.io/name: {{ template "coredns.name" . }} + ports: + - name: metrics + port: 9153 + targetPort: 9153 +{{- end }} diff --git a/sample-cnfs/sample_privileged_cnf/chart/templates/service.yaml b/sample-cnfs/sample_privileged_cnf/chart/templates/service.yaml new file mode 100755 index 000000000..4098664bb --- /dev/null +++ b/sample-cnfs/sample_privileged_cnf/chart/templates/service.yaml @@ -0,0 +1,38 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ template "coredns.fullname" . }} + labels: + app.kubernetes.io/managed-by: {{ .Release.Service | quote }} + app.kubernetes.io/instance: {{ .Release.Name | quote }} + helm.sh/chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}" + {{- if .Values.isClusterService }} + k8s-app: {{ .Chart.Name | quote }} + kubernetes.io/cluster-service: "true" + kubernetes.io/name: "CoreDNS" + {{- end }} + app.kubernetes.io/name: {{ template "coredns.name" . }} +{{- if .Values.customLabels }} +{{ toYaml .Values.customLabels | indent 4 }} +{{- end }} + annotations: +{{ toYaml .Values.service.annotations | indent 4 }} +spec: + selector: + app.kubernetes.io/instance: {{ .Release.Name | quote }} + {{- if .Values.isClusterService }} + k8s-app: {{ .Chart.Name | quote }} + {{- end }} + app.kubernetes.io/name: {{ template "coredns.name" . }} + {{- if .Values.service.clusterIP }} + clusterIP: {{ .Values.service.clusterIP }} + {{- end }} + {{- if .Values.service.externalTrafficPolicy }} + externalTrafficPolicy: {{ .Values.service.externalTrafficPolicy }} + {{- end }} + {{- if .Values.service.loadBalancerIP }} + loadBalancerIP: {{ .Values.service.loadBalancerIP }} + {{- end }} + ports: +{{ include "coredns.servicePorts" . | indent 2 -}} + type: {{ default "ClusterIP" .Values.serviceType }} diff --git a/sample-cnfs/sample_privileged_cnf/chart/templates/serviceaccount-autoscaler.yaml b/sample-cnfs/sample_privileged_cnf/chart/templates/serviceaccount-autoscaler.yaml new file mode 100755 index 000000000..972c74612 --- /dev/null +++ b/sample-cnfs/sample_privileged_cnf/chart/templates/serviceaccount-autoscaler.yaml @@ -0,0 +1,21 @@ +{{- if and .Values.autoscaler.enabled .Values.rbac.create }} +--- +apiVersion: v1 +kind: ServiceAccount +metadata: + name: {{ template "coredns.fullname" . }}-autoscaler + namespace: {{ .Release.Namespace }} + labels: + app.kubernetes.io/managed-by: {{ .Release.Service | quote }} + app.kubernetes.io/instance: {{ .Release.Name | quote }} + helm.sh/chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}" + {{- if .Values.isClusterService }} + k8s-app: {{ .Chart.Name }}-autoscaler + kubernetes.io/cluster-service: "true" + kubernetes.io/name: "CoreDNS" + {{- end }} + app.kubernetes.io/name: {{ template "coredns.name" . }}-autoscaler +{{- if .Values.customLabels }} +{{ toYaml .Values.customLabels | indent 4 }} +{{- end }} +{{- end }} diff --git a/sample-cnfs/sample_privileged_cnf/chart/templates/serviceaccount.yaml b/sample-cnfs/sample_privileged_cnf/chart/templates/serviceaccount.yaml new file mode 100755 index 000000000..bced7ca3d --- /dev/null +++ b/sample-cnfs/sample_privileged_cnf/chart/templates/serviceaccount.yaml @@ -0,0 +1,16 @@ +{{- if .Values.serviceAccount.create }} +apiVersion: v1 +kind: ServiceAccount +metadata: + name: {{ template "coredns.serviceAccountName" . }} + labels: + app.kubernetes.io/managed-by: {{ .Release.Service | quote }} + app.kubernetes.io/instance: {{ .Release.Name | quote }} + helm.sh/chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}" + {{- if .Values.isClusterService }} + k8s-app: {{ .Chart.Name | quote }} + kubernetes.io/cluster-service: "true" + kubernetes.io/name: "CoreDNS" + {{- end }} + app.kubernetes.io/name: {{ template "coredns.name" . }} +{{- end }} diff --git a/sample-cnfs/sample_privileged_cnf/chart/templates/servicemonitor.yaml b/sample-cnfs/sample_privileged_cnf/chart/templates/servicemonitor.yaml new file mode 100755 index 000000000..0a4ffb581 --- /dev/null +++ b/sample-cnfs/sample_privileged_cnf/chart/templates/servicemonitor.yaml @@ -0,0 +1,33 @@ +{{- if .Values.prometheus.monitor.enabled }} +apiVersion: monitoring.coreos.com/v1 +kind: ServiceMonitor +metadata: + name: {{ template "coredns.fullname" . }} + {{- if .Values.prometheus.monitor.namespace }} + namespace: {{ .Values.prometheus.monitor.namespace }} + {{- end }} + labels: + app.kubernetes.io/managed-by: {{ .Release.Service | quote }} + app.kubernetes.io/instance: {{ .Release.Name | quote }} + helm.sh/chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}" + {{- if .Values.isClusterService }} + k8s-app: {{ .Chart.Name | quote }} + kubernetes.io/cluster-service: "true" + kubernetes.io/name: "CoreDNS" + {{- end }} + app.kubernetes.io/name: {{ template "coredns.name" . }} + {{- if .Values.prometheus.monitor.additionalLabels }} +{{ toYaml .Values.prometheus.monitor.additionalLabels | indent 4 }} + {{- end }} +spec: + selector: + matchLabels: + app.kubernetes.io/instance: {{ .Release.Name | quote }} + {{- if .Values.isClusterService }} + k8s-app: {{ .Chart.Name | quote }} + {{- end }} + app.kubernetes.io/name: {{ template "coredns.name" . }} + app.kubernetes.io/component: metrics + endpoints: + - port: metrics +{{- end }} diff --git a/sample-cnfs/sample_privileged_cnf/chart/values.yaml b/sample-cnfs/sample_privileged_cnf/chart/values.yaml new file mode 100755 index 000000000..becf13564 --- /dev/null +++ b/sample-cnfs/sample_privileged_cnf/chart/values.yaml @@ -0,0 +1,195 @@ +# Default values for coredns. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. + +image: + repository: coredns/coredns + tag: "1.6.7" + pullPolicy: IfNotPresent + +replicaCount: 1 + +resources: + limits: + cpu: 100m + memory: 128Mi + requests: + cpu: 100m + memory: 128Mi + +serviceType: "ClusterIP" + +prometheus: + monitor: + enabled: false + additionalLabels: {} + namespace: "" + +service: +# clusterIP: "" +# loadBalancerIP: "" +# externalTrafficPolicy: "" + annotations: + prometheus.io/scrape: "true" + prometheus.io/port: "9153" + +serviceAccount: + create: false + # The name of the ServiceAccount to use + # If not set and create is true, a name is generated using the fullname template + name: + +rbac: + # If true, create & use RBAC resources + create: true + # If true, create and use PodSecurityPolicy + pspEnable: false + # The name of the ServiceAccount to use. + # If not set and create is true, a name is generated using the fullname template + # name: + +# isClusterService specifies whether chart should be deployed as cluster-service or normal k8s app. +isClusterService: true + +# Optional priority class to be used for the coredns pods. Used for autoscaler if autoscaler.priorityClassName not set. +priorityClassName: "" + +# Default zone is what Kubernetes recommends: +# https://kubernetes.io/docs/tasks/administer-cluster/dns-custom-nameservers/#coredns-configmap-options +servers: +- zones: + - zone: . + port: 53 + plugins: + - name: errors + # Serves a /health endpoint on :8080, required for livenessProbe + - name: health + configBlock: |- + lameduck 5s + # Serves a /ready endpoint on :8181, required for readinessProbe + - name: ready + # Required to query kubernetes API for data + - name: kubernetes + parameters: cluster.local in-addr.arpa ip6.arpa + configBlock: |- + pods insecure + fallthrough in-addr.arpa ip6.arpa + ttl 30 + # Serves a /metrics endpoint on :9153, required for serviceMonitor + - name: prometheus + parameters: 0.0.0.0:9153 + - name: forward + parameters: . /etc/resolv.conf + - name: cache + parameters: 30 + - name: loop + - name: reload + - name: loadbalance + +# Complete example with all the options: +# - zones: # the `zones` block can be left out entirely, defaults to "." +# - zone: hello.world. # optional, defaults to "." +# scheme: tls:// # optional, defaults to "" (which equals "dns://" in CoreDNS) +# - zone: foo.bar. +# scheme: dns:// +# use_tcp: true # set this parameter to optionally expose the port on tcp as well as udp for the DNS protocol +# # Note that this will not work if you are also exposing tls or grpc on the same server +# port: 12345 # optional, defaults to "" (which equals 53 in CoreDNS) +# plugins: # the plugins to use for this server block +# - name: kubernetes # name of plugin, if used multiple times ensure that the plugin supports it! +# parameters: foo bar # list of parameters after the plugin +# configBlock: |- # if the plugin supports extra block style config, supply it here +# hello world +# foo bar + +# expects input structure as per specification https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.11/#affinity-v1-core +# for example: +# affinity: +# nodeAffinity: +# requiredDuringSchedulingIgnoredDuringExecution: +# nodeSelectorTerms: +# - matchExpressions: +# - key: foo.bar.com/role +# operator: In +# values: +# - master +affinity: {} + +# Node labels for pod assignment +# Ref: https://kubernetes.io/docs/user-guide/node-selection/ +nodeSelector: {} + +# expects input structure as per specification https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.11/#toleration-v1-core +# for example: +# tolerations: +# - key: foo.bar.com/role +# operator: Equal +# value: master +# effect: NoSchedule +tolerations: [] + +# configure custom zone files as per https://coredns.io/2017/05/08/custom-dns-entries-for-kubernetes/ +zoneFiles: [] +# - filename: example.db +# domain: example.com +# contents: | +# example.com. IN SOA sns.dns.icann.com. noc.dns.icann.com. 2015082541 7200 3600 1209600 3600 +# example.com. IN NS b.iana-servers.net. +# example.com. IN NS a.iana-servers.net. +# example.com. IN A 192.168.99.102 +# *.example.com. IN A 192.168.99.102 + +# optional array of secrets to mount inside coredns container +# possible usecase: need for secure connection with etcd backend +extraSecrets: [] +# - name: etcd-client-certs +# mountPath: /etc/coredns/tls/etcd +# - name: some-fancy-secret +# mountPath: /etc/wherever + +# Custom labels to apply to Deployment, Pod, Service, ServiceMonitor. Including autoscaler if enabled. +customLabels: {} + +## Configue a cluster-proportional-autoscaler for coredns +# See https://github.com/kubernetes-incubator/cluster-proportional-autoscaler +autoscaler: + # Enabled the cluster-proportional-autoscaler + enabled: false + + # Number of cores in the cluster per coredns replica + coresPerReplica: 256 + # Number of nodes in the cluster per coredns replica + nodesPerReplica: 16 + + image: + repository: k8s.gcr.io/cluster-proportional-autoscaler-amd64 + tag: "1.7.1" + pullPolicy: IfNotPresent + + # Optional priority class to be used for the autoscaler pods. priorityClassName used if not set. + priorityClassName: "" + + # expects input structure as per specification https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.11/#affinity-v1-core + affinity: {} + + # Node labels for pod assignment + # Ref: https://kubernetes.io/docs/user-guide/node-selection/ + nodeSelector: {} + + # expects input structure as per specification https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.11/#toleration-v1-core + tolerations: [] + + # resources for autoscaler pod + resources: + requests: + cpu: "20m" + memory: "10Mi" + limits: + cpu: "20m" + memory: "10Mi" + + # Options for autoscaler configmap + configmap: + ## Annotations for the coredns-autoscaler configmap + # i.e. strategy.spinnaker.io/versioned: "false" to ensure configmap isn't renamed + annotations: {} diff --git a/sample-cnfs/sample_privileged_cnf_setup_coredns/cnf-conformance.yml b/sample-cnfs/sample_privileged_cnf/cnf-conformance.yml similarity index 70% rename from sample-cnfs/sample_privileged_cnf_setup_coredns/cnf-conformance.yml rename to sample-cnfs/sample_privileged_cnf/cnf-conformance.yml index adcd43cbb..6f42928a5 100644 --- a/sample-cnfs/sample_privileged_cnf_setup_coredns/cnf-conformance.yml +++ b/sample-cnfs/sample_privileged_cnf/cnf-conformance.yml @@ -1,8 +1,7 @@ --- -# helm_directory: cnfs/sample_privileged_cnf_setup_coredns/chart helm_directory: chart git_clone_url: -install_script: cnfs/sample_privileged_cnf_setup_coredns/chart +install_script: release_name: privileged-coredns deployment_name: privileged-coredns-coredns application_deployment_names: [privileged-coredns-coredns] diff --git a/sample-cnfs/sample_privileged_cnf_setup_coredns/non-whitelisted-conformance.yml b/sample-cnfs/sample_privileged_cnf_setup_coredns/non-whitelisted-conformance.yml deleted file mode 100644 index be15c9da8..000000000 --- a/sample-cnfs/sample_privileged_cnf_setup_coredns/non-whitelisted-conformance.yml +++ /dev/null @@ -1,8 +0,0 @@ ---- -helm_directory: cnfs/sample_privileged_cnf_setup_coredns/chart -install_script: cnfs/sample_privileged_cnf_setup_coredns/chart -deployment_name: privileged-coredns-coredns -application_deployment_names: [privileged-coredns-coredns] -helm_chart: stable/coredns -helm_chart_container_name: privileged-coredns-coredns -white_list_helm_chart_container_names: [] diff --git a/sample-cnfs/sample_whitelisted_privileged_cnf/README.md b/sample-cnfs/sample_whitelisted_privileged_cnf/README.md new file mode 100644 index 000000000..12981cc93 --- /dev/null +++ b/sample-cnfs/sample_whitelisted_privileged_cnf/README.md @@ -0,0 +1,39 @@ +# Set up Sample CoreDNS CNF +./sample-cnfs/sample-coredns-cnf/readme.md +# Prerequistes +### Install helm +``` +curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 +chmod 700 get_helm.sh +./get_helm.sh +``` +### Optional: Use a helm version manager +https://github.com/yuya-takeyama/helmenv +Check out helmenv into any path (here is ${HOME}/.helmenv) +``` +${HOME}/.helmenv) +$ git clone https://github.com/yuya-takeyama/helmenv.git ~/.helmenv +``` +Add ~/.helmenv/bin to your $PATH any way you like +``` +$ echo 'export PATH="$HOME/.helmenv/bin:$PATH"' >> ~/.bash_profile +``` +``` +helmenv versions +helmenv install +``` + +### core-dns installation +``` +helm install coredns stable/coredns +``` +### Pull down the helm chart code, untar it, and put it in the cnfs/coredns directory +``` +helm pull stable/coredns +``` +### Example cnf-conformance config file for sample-core-dns-cnf +In ./cnfs/sample-core-dns-cnf/cnf-conformance.yml +``` +--- +container_names: [coredns-coredns] +``` diff --git a/sample-cnfs/sample_whitelisted_privileged_cnf/chart/Chart.yaml b/sample-cnfs/sample_whitelisted_privileged_cnf/chart/Chart.yaml new file mode 100755 index 000000000..77de0c04f --- /dev/null +++ b/sample-cnfs/sample_whitelisted_privileged_cnf/chart/Chart.yaml @@ -0,0 +1,23 @@ +apiVersion: v1 +appVersion: 1.6.7 +description: CoreDNS is a DNS server that chains plugins and provides Kubernetes DNS + Services +home: https://coredns.io +icon: https://coredns.io/images/CoreDNS_Colour_Horizontal.png +keywords: +- coredns +- dns +- kubedns +maintainers: +- email: hello@acale.ph + name: Acaleph +- email: shashidhara.huawei@gmail.com + name: shashidharatd +- email: andor44@gmail.com + name: andor44 +- email: manuel@rueg.eu + name: mrueg +name: coredns +sources: +- https://github.com/coredns/coredns +version: 1.9.3 diff --git a/sample-cnfs/sample_whitelisted_privileged_cnf/chart/README.md b/sample-cnfs/sample_whitelisted_privileged_cnf/chart/README.md new file mode 100755 index 000000000..dc00ca26b --- /dev/null +++ b/sample-cnfs/sample_whitelisted_privileged_cnf/chart/README.md @@ -0,0 +1,137 @@ +# CoreDNS + +[CoreDNS](https://coredns.io/) is a DNS server that chains plugins and provides DNS Services + +# TL;DR; + +```console +$ helm install --name coredns --namespace=kube-system stable/coredns +``` + +## Introduction + +This chart bootstraps a [CoreDNS](https://github.com/coredns/coredns) deployment on a [Kubernetes](http://kubernetes.io) cluster using the [Helm](https://helm.sh) package manager. This chart will provide DNS Services and can be deployed in multiple configuration to support various scenarios listed below: + + - CoreDNS as a cluster dns service and a drop-in replacement for Kube/SkyDNS. This is the default mode and CoreDNS is deployed as cluster-service in kube-system namespace. This mode is chosen by setting `isClusterService` to true. + - CoreDNS as an external dns service. In this mode CoreDNS is deployed as any kubernetes app in user specified namespace. The CoreDNS service can be exposed outside the cluster by using using either the NodePort or LoadBalancer type of service. This mode is chosen by setting `isClusterService` to false. + - CoreDNS as an external dns provider for kubernetes federation. This is a sub case of 'external dns service' which uses etcd plugin for CoreDNS backend. This deployment mode as a dependency on `etcd-operator` chart, which needs to be pre-installed. + +## Prerequisites + +- Kubernetes 1.10 or later + +## Installing the Chart + +The chart can be installed as follows: + +```console +$ helm install --name coredns --namespace=kube-system stable/coredns +``` + +The command deploys CoreDNS on the Kubernetes cluster in the default configuration. The [configuration](#configuration) section lists various ways to override default configuration during deployment. + +> **Tip**: List all releases using `helm list` + +## Uninstalling the Chart + +To uninstall/delete the `my-release` deployment: + +```console +$ helm delete coredns +``` + +The command removes all the Kubernetes components associated with the chart and deletes the release. + +## Configuration + +| Parameter | Description | Default | +|:----------------------------------------|:--------------------------------------------------------------------------------------|:------------------------------------------------------------| +| `image.repository` | The image repository to pull from | coredns/coredns | +| `image.tag` | The image tag to pull from | `v1.6.7` | +| `image.pullPolicy` | Image pull policy | IfNotPresent | +| `replicaCount` | Number of replicas | 1 | +| `resources.limits.cpu` | Container maximum CPU | `100m` | +| `resources.limits.memory` | Container maximum memory | `128Mi` | +| `resources.requests.cpu` | Container requested CPU | `100m` | +| `resources.requests.memory` | Container requested memory | `128Mi` | +| `serviceType` | Kubernetes Service type | `ClusterIP` | +| `prometheus.monitor.enabled` | Set this to `true` to create ServiceMonitor for Prometheus operator | `false` | +| `prometheus.monitor.additionalLabels` | Additional labels that can be used so ServiceMonitor will be discovered by Prometheus | {} | +| `prometheus.monitor.namespace` | Selector to select which namespaces the Endpoints objects are discovered from. | `""` | +| `service.clusterIP` | IP address to assign to service | `""` | +| `service.loadBalancerIP` | IP address to assign to load balancer (if supported) | `""` | +| `service.externalTrafficPolicy` | Enable client source IP preservation | `[]` | +| `service.annotations` | Annotations to add to service | `{prometheus.io/scrape: "true", prometheus.io/port: "9153"}`| +| `serviceAccount.create` | If true, create & use serviceAccount | false | +| `serviceAccount.name` | If not set & create is true, use template fullname | | +| `rbac.create` | If true, create & use RBAC resources | true | +| `rbac.pspEnable` | Specifies whether a PodSecurityPolicy should be created. | `false` | +| `isClusterService` | Specifies whether chart should be deployed as cluster-service or normal k8s app. | true | +| `priorityClassName` | Name of Priority Class to assign pods | `""` | +| `servers` | Configuration for CoreDNS and plugins | See values.yml | +| `affinity` | Affinity settings for pod assignment | {} | +| `nodeSelector` | Node labels for pod assignment | {} | +| `tolerations` | Tolerations for pod assignment | [] | +| `zoneFiles` | Configure custom Zone files | [] | +| `extraSecrets` | Optional array of secrets to mount inside the CoreDNS container | [] | +| `customLabels` | Optional labels for Deployment(s), Pod, Service, ServiceMonitor objects | {} | +| `autoscaler.enabled` | Optionally enabled a cluster-proportional-autoscaler for CoreDNS | `false` | +| `autoscaler.coresPerReplica` | Number of cores in the cluster per CoreDNS replica | `256` | +| `autoscaler.nodesPerReplica` | Number of nodes in the cluster per CoreDNS replica | `16` | +| `autoscaler.image.repository` | The image repository to pull autoscaler from | k8s.gcr.io/cluster-proportional-autoscaler-amd64 | +| `autoscaler.image.tag` | The image tag to pull autoscaler from | `1.7.1` | +| `autoscaler.image.pullPolicy` | Image pull policy for the autoscaler | IfNotPresent | +| `autoscaler.priorityClassName` | Optional priority class for the autoscaler pod. `priorityClassName` used if not set. | `""` | +| `autoscaler.affinity` | Affinity settings for pod assignment for autoscaler | {} | +| `autoscaler.nodeSelector` | Node labels for pod assignment for autoscaler | {} | +| `autoscaler.tolerations` | Tolerations for pod assignment for autoscaler | [] | +| `autoscaler.resources.limits.cpu` | Container maximum CPU for cluster-proportional-autoscaler | `20m` | +| `autoscaler.resources.limits.memory` | Container maximum memory for cluster-proportional-autoscaler | `10Mi` | +| `autoscaler.resources.requests.cpu` | Container requested CPU for cluster-proportional-autoscaler | `20m` | +| `autoscaler.resources.requests.memory` | Container requested memory for cluster-proportional-autoscaler | `10Mi` | +| `autoscaler.configmap.annotations` | Annotations to add to autoscaler config map. For example to stop CI renaming them | {} | + +See `values.yaml` for configuration notes. Specify each parameter using the `--set key=value[,key=value]` argument to `helm install`. For example, + +```console +$ helm install --name coredns \ + --set rbac.create=false \ + stable/coredns +``` + +The above command disables automatic creation of RBAC rules. + +Alternatively, a YAML file that specifies the values for the above parameters can be provided while installing the chart. For example, + +```console +$ helm install --name coredns -f values.yaml stable/coredns +``` + +> **Tip**: You can use the default [values.yaml](values.yaml) + + +## Caveats + +The chart will automatically determine which protocols to listen on based on +the protocols you define in your zones. This means that you could potentially +use both "TCP" and "UDP" on a single port. +Some cloud environments like "GCE" or "Azure container service" cannot +create external loadbalancers with both "TCP" and "UDP" protocols. So +When deploying CoreDNS with `serviceType="LoadBalancer"` on such cloud +environments, make sure you do not attempt to use both protocols at the same +time. + +## Autoscaling + +By setting `autoscaler.enabled = true` a +[cluster-proportional-autoscaler](https://github.com/kubernetes-incubator/cluster-proportional-autoscaler) +will be deployed. This will default to a coredns replica for every 256 cores, or +16 nodes in the cluster. These can be changed with `autoscaler.coresPerReplica` +and `autoscaler.nodesPerReplica`. When cluster is using large nodes (with more +cores), `coresPerReplica` should dominate. If using small nodes, +`nodesPerReplica` should dominate. + +This also creates a ServiceAccount, ClusterRole, and ClusterRoleBinding for +the autoscaler deployment. + +`replicaCount` is ignored if this is enabled. diff --git a/sample-cnfs/sample_whitelisted_privileged_cnf/chart/templates/NOTES.txt b/sample-cnfs/sample_whitelisted_privileged_cnf/chart/templates/NOTES.txt new file mode 100755 index 000000000..3a1883b3a --- /dev/null +++ b/sample-cnfs/sample_whitelisted_privileged_cnf/chart/templates/NOTES.txt @@ -0,0 +1,30 @@ +{{- if .Values.isClusterService }} +CoreDNS is now running in the cluster as a cluster-service. +{{- else }} +CoreDNS is now running in the cluster. +It can be accessed using the below endpoint +{{- if contains "NodePort" .Values.serviceType }} + export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ template "coredns.fullname" . }}) + export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}") + echo "$NODE_IP:$NODE_PORT" +{{- else if contains "LoadBalancer" .Values.serviceType }} + NOTE: It may take a few minutes for the LoadBalancer IP to be available. + You can watch the status by running 'kubectl get svc -w {{ template "coredns.fullname" . }}' + + export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ template "coredns.fullname" . }} -o jsonpath='{.status.loadBalancer.ingress[0].ip}') + echo $SERVICE_IP +{{- else if contains "ClusterIP" .Values.serviceType }} + "{{ template "coredns.fullname" . }}.{{ .Release.Namespace }}.svc.cluster.local" + from within the cluster +{{- end }} +{{- end }} + +It can be tested with the following: + +1. Launch a Pod with DNS tools: + +kubectl run -it --rm --restart=Never --image=infoblox/dnstools:latest dnstools + +2. Query the DNS server: + +/ # host kubernetes diff --git a/sample-cnfs/sample_whitelisted_privileged_cnf/chart/templates/_helpers.tpl b/sample-cnfs/sample_whitelisted_privileged_cnf/chart/templates/_helpers.tpl new file mode 100755 index 000000000..a2efcb43e --- /dev/null +++ b/sample-cnfs/sample_whitelisted_privileged_cnf/chart/templates/_helpers.tpl @@ -0,0 +1,149 @@ +{{/* vim: set filetype=mustache: */}} +{{/* +Expand the name of the chart. +*/}} +{{- define "coredns.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). +*/}} +{{- define "coredns.fullname" -}} +{{- if .Values.fullnameOverride -}} +{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}} +{{- else -}} +{{- $name := default .Chart.Name .Values.nameOverride -}} +{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}} +{{- end -}} +{{- end -}} + +{{/* +Generate the list of ports automatically from the server definitions +*/}} +{{- define "coredns.servicePorts" -}} + {{/* Set ports to be an empty dict */}} + {{- $ports := dict -}} + {{/* Iterate through each of the server blocks */}} + {{- range .Values.servers -}} + {{/* Capture port to avoid scoping awkwardness */}} + {{- $port := toString .port -}} + + {{/* If none of the server blocks has mentioned this port yet take note of it */}} + {{- if not (hasKey $ports $port) -}} + {{- $ports := set $ports $port (dict "istcp" false "isudp" false) -}} + {{- end -}} + {{/* Retrieve the inner dict that holds the protocols for a given port */}} + {{- $innerdict := index $ports $port -}} + + {{/* + Look at each of the zones and check which protocol they serve + At the moment the following are supported by CoreDNS: + UDP: dns:// + TCP: tls://, grpc:// + */}} + {{- range .zones -}} + {{- if has (default "" .scheme) (list "dns://") -}} + {{/* Optionally enable tcp for this service as well */}} + {{- if eq .use_tcp true }} + {{- $innerdict := set $innerdict "istcp" true -}} + {{- end }} + {{- $innerdict := set $innerdict "isudp" true -}} + {{- end -}} + + {{- if has (default "" .scheme) (list "tls://" "grpc://") -}} + {{- $innerdict := set $innerdict "istcp" true -}} + {{- end -}} + {{- end -}} + + {{/* If none of the zones specify scheme, default to dns:// on both tcp & udp */}} + {{- if and (not (index $innerdict "istcp")) (not (index $innerdict "isudp")) -}} + {{- $innerdict := set $innerdict "isudp" true -}} + {{- $innerdict := set $innerdict "istcp" true -}} + {{- end -}} + + {{/* Write the dict back into the outer dict */}} + {{- $ports := set $ports $port $innerdict -}} + {{- end -}} + + {{/* Write out the ports according to the info collected above */}} + {{- range $port, $innerdict := $ports -}} + {{- if index $innerdict "isudp" -}} + {{- printf "- {port: %v, protocol: UDP, name: udp-%s}\n" $port $port -}} + {{- end -}} + {{- if index $innerdict "istcp" -}} + {{- printf "- {port: %v, protocol: TCP, name: tcp-%s}\n" $port $port -}} + {{- end -}} + {{- end -}} +{{- end -}} + +{{/* +Generate the list of ports automatically from the server definitions +*/}} +{{- define "coredns.containerPorts" -}} + {{/* Set ports to be an empty dict */}} + {{- $ports := dict -}} + {{/* Iterate through each of the server blocks */}} + {{- range .Values.servers -}} + {{/* Capture port to avoid scoping awkwardness */}} + {{- $port := toString .port -}} + + {{/* If none of the server blocks has mentioned this port yet take note of it */}} + {{- if not (hasKey $ports $port) -}} + {{- $ports := set $ports $port (dict "istcp" false "isudp" false) -}} + {{- end -}} + {{/* Retrieve the inner dict that holds the protocols for a given port */}} + {{- $innerdict := index $ports $port -}} + + {{/* + Look at each of the zones and check which protocol they serve + At the moment the following are supported by CoreDNS: + UDP: dns:// + TCP: tls://, grpc:// + */}} + {{- range .zones -}} + {{- if has (default "" .scheme) (list "dns://") -}} + {{/* Optionally enable tcp for this service as well */}} + {{- if eq .use_tcp true }} + {{- $innerdict := set $innerdict "istcp" true -}} + {{- end }} + {{- $innerdict := set $innerdict "isudp" true -}} + {{- end -}} + + {{- if has (default "" .scheme) (list "tls://" "grpc://") -}} + {{- $innerdict := set $innerdict "istcp" true -}} + {{- end -}} + {{- end -}} + + {{/* If none of the zones specify scheme, default to dns:// on both tcp & udp */}} + {{- if and (not (index $innerdict "istcp")) (not (index $innerdict "isudp")) -}} + {{- $innerdict := set $innerdict "isudp" true -}} + {{- $innerdict := set $innerdict "istcp" true -}} + {{- end -}} + + {{/* Write the dict back into the outer dict */}} + {{- $ports := set $ports $port $innerdict -}} + {{- end -}} + + {{/* Write out the ports according to the info collected above */}} + {{- range $port, $innerdict := $ports -}} + {{- if index $innerdict "isudp" -}} + {{- printf "- {containerPort: %v, protocol: UDP, name: udp-%s}\n" $port $port -}} + {{- end -}} + {{- if index $innerdict "istcp" -}} + {{- printf "- {containerPort: %v, protocol: TCP, name: tcp-%s}\n" $port $port -}} + {{- end -}} + {{- end -}} +{{- end -}} + +{{/* +Create the name of the service account to use +*/}} +{{- define "coredns.serviceAccountName" -}} +{{- if .Values.serviceAccount.create -}} + {{ default (include "coredns.fullname" .) .Values.serviceAccount.name }} +{{- else -}} + {{ default "default" .Values.serviceAccount.name }} +{{- end -}} +{{- end -}} diff --git a/sample-cnfs/sample_whitelisted_privileged_cnf/chart/templates/clusterrole-autoscaler.yaml b/sample-cnfs/sample_whitelisted_privileged_cnf/chart/templates/clusterrole-autoscaler.yaml new file mode 100755 index 000000000..748c62bf7 --- /dev/null +++ b/sample-cnfs/sample_whitelisted_privileged_cnf/chart/templates/clusterrole-autoscaler.yaml @@ -0,0 +1,35 @@ +{{- if and .Values.autoscaler.enabled .Values.rbac.create }} +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + name: {{ template "coredns.fullname" . }}-autoscaler + labels: + app.kubernetes.io/managed-by: {{ .Release.Service | quote }} + app.kubernetes.io/instance: {{ .Release.Name | quote }} + helm.sh/chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}" + {{- if .Values.isClusterService }} + k8s-app: {{ .Chart.Name }}-autoscaler + kubernetes.io/cluster-service: "true" + kubernetes.io/name: "CoreDNS" + {{- end }} + app.kubernetes.io/name: {{ template "coredns.name" . }}-autoscaler +{{- if .Values.customLabels }} +{{ toYaml .Values.customLabels | indent 4 }} +{{- end }} +rules: + - apiGroups: [""] + resources: ["nodes"] + verbs: ["list","watch"] + - apiGroups: [""] + resources: ["replicationcontrollers/scale"] + verbs: ["get", "update"] + - apiGroups: ["extensions", "apps"] + resources: ["deployments/scale", "replicasets/scale"] + verbs: ["get", "update"] +# Remove the configmaps rule once below issue is fixed: +# kubernetes-incubator/cluster-proportional-autoscaler#16 + - apiGroups: [""] + resources: ["configmaps"] + verbs: ["get", "create"] +{{- end }} diff --git a/sample-cnfs/sample_whitelisted_privileged_cnf/chart/templates/clusterrole.yaml b/sample-cnfs/sample_whitelisted_privileged_cnf/chart/templates/clusterrole.yaml new file mode 100755 index 000000000..029d13e27 --- /dev/null +++ b/sample-cnfs/sample_whitelisted_privileged_cnf/chart/templates/clusterrole.yaml @@ -0,0 +1,38 @@ +{{- if .Values.rbac.create }} +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + name: {{ template "coredns.fullname" . }} + labels: + app.kubernetes.io/managed-by: {{ .Release.Service | quote }} + app.kubernetes.io/instance: {{ .Release.Name | quote }} + helm.sh/chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}" + {{- if .Values.isClusterService }} + k8s-app: {{ .Chart.Name | quote }} + kubernetes.io/cluster-service: "true" + kubernetes.io/name: "CoreDNS" + {{- end }} + app.kubernetes.io/name: {{ template "coredns.name" . }} +rules: +- apiGroups: + - "" + resources: + - endpoints + - services + - pods + - namespaces + verbs: + - list + - watch +{{- if .Values.rbac.pspEnable }} +- apiGroups: + - policy + - extensions + resources: + - podsecuritypolicies + verbs: + - use + resourceNames: + - {{ template "coredns.fullname" . }} +{{- end }} +{{- end }} diff --git a/sample-cnfs/sample_whitelisted_privileged_cnf/chart/templates/clusterrolebinding-autoscaler.yaml b/sample-cnfs/sample_whitelisted_privileged_cnf/chart/templates/clusterrolebinding-autoscaler.yaml new file mode 100755 index 000000000..eafb38f9e --- /dev/null +++ b/sample-cnfs/sample_whitelisted_privileged_cnf/chart/templates/clusterrolebinding-autoscaler.yaml @@ -0,0 +1,28 @@ +{{- if and .Values.autoscaler.enabled .Values.rbac.create }} +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRoleBinding +metadata: + name: {{ template "coredns.fullname" . }}-autoscaler + labels: + app.kubernetes.io/managed-by: {{ .Release.Service | quote }} + app.kubernetes.io/instance: {{ .Release.Name | quote }} + helm.sh/chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}" + {{- if .Values.isClusterService }} + k8s-app: {{ .Chart.Name }}-autoscaler + kubernetes.io/cluster-service: "true" + kubernetes.io/name: "CoreDNS" + {{- end }} + app.kubernetes.io/name: {{ template "coredns.name" . }}-autoscaler +{{- if .Values.customLabels }} +{{ toYaml .Values.customLabels | indent 4 }} +{{- end }} +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: ClusterRole + name: {{ template "coredns.fullname" . }}-autoscaler +subjects: +- kind: ServiceAccount + name: {{ template "coredns.fullname" . }}-autoscaler + namespace: {{ .Release.Namespace }} +{{- end }} diff --git a/sample-cnfs/sample_whitelisted_privileged_cnf/chart/templates/clusterrolebinding.yaml b/sample-cnfs/sample_whitelisted_privileged_cnf/chart/templates/clusterrolebinding.yaml new file mode 100755 index 000000000..49da9b548 --- /dev/null +++ b/sample-cnfs/sample_whitelisted_privileged_cnf/chart/templates/clusterrolebinding.yaml @@ -0,0 +1,24 @@ +{{- if .Values.rbac.create }} +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRoleBinding +metadata: + name: {{ template "coredns.fullname" . }} + labels: + app.kubernetes.io/managed-by: {{ .Release.Service | quote }} + app.kubernetes.io/instance: {{ .Release.Name | quote }} + helm.sh/chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}" + {{- if .Values.isClusterService }} + k8s-app: {{ .Chart.Name | quote }} + kubernetes.io/cluster-service: "true" + kubernetes.io/name: "CoreDNS" + {{- end }} + app.kubernetes.io/name: {{ template "coredns.name" . }} +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: ClusterRole + name: {{ template "coredns.fullname" . }} +subjects: +- kind: ServiceAccount + name: {{ template "coredns.serviceAccountName" . }} + namespace: {{ .Release.Namespace }} +{{- end }} diff --git a/sample-cnfs/sample_whitelisted_privileged_cnf/chart/templates/configmap-autoscaler.yaml b/sample-cnfs/sample_whitelisted_privileged_cnf/chart/templates/configmap-autoscaler.yaml new file mode 100755 index 000000000..50895ae5b --- /dev/null +++ b/sample-cnfs/sample_whitelisted_privileged_cnf/chart/templates/configmap-autoscaler.yaml @@ -0,0 +1,34 @@ +{{- if .Values.autoscaler.enabled }} +--- +kind: ConfigMap +apiVersion: v1 +metadata: + name: {{ template "coredns.fullname" . }}-autoscaler + namespace: {{ .Release.Namespace }} + labels: + app.kubernetes.io/managed-by: {{ .Release.Service | quote }} + app.kubernetes.io/instance: {{ .Release.Name | quote }} + helm.sh/chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}" + {{- if .Values.isClusterService }} + k8s-app: {{ .Chart.Name }}-autoscaler + kubernetes.io/cluster-service: "true" + kubernetes.io/name: "CoreDNS" + {{- end }} + app.kubernetes.io/name: {{ template "coredns.name" . }}-autoscaler + {{- if .Values.customLabels }} + {{- toYaml .Values.customLabels | nindent 4 }} + {{- end }} + {{- if .Values.autoscaler.configmap.annotations }} + annotations: + {{- toYaml .Values.autoscaler.configmap.annotations | nindent 4 }} + {{- end }} +data: + # When cluster is using large nodes(with more cores), "coresPerReplica" should dominate. + # If using small nodes, "nodesPerReplica" should dominate. + linear: |- + { + "coresPerReplica": {{ .Values.autoscaler.coresPerReplica | float64 }}, + "nodesPerReplica": {{ .Values.autoscaler.nodesPerReplica | float64 }}, + "preventSinglePointFailure": true + } +{{- end }} diff --git a/sample-cnfs/sample_whitelisted_privileged_cnf/chart/templates/configmap.yaml b/sample-cnfs/sample_whitelisted_privileged_cnf/chart/templates/configmap.yaml new file mode 100755 index 000000000..b7e1a667f --- /dev/null +++ b/sample-cnfs/sample_whitelisted_privileged_cnf/chart/templates/configmap.yaml @@ -0,0 +1,30 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: {{ template "coredns.fullname" . }} + labels: + app.kubernetes.io/managed-by: {{ .Release.Service | quote }} + app.kubernetes.io/instance: {{ .Release.Name | quote }} + helm.sh/chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}" + {{- if .Values.isClusterService }} + k8s-app: {{ .Chart.Name | quote }} + kubernetes.io/cluster-service: "true" + kubernetes.io/name: "CoreDNS" + {{- end }} + app.kubernetes.io/name: {{ template "coredns.name" . }} +data: + Corefile: |- + {{ range .Values.servers }} + {{- range $idx, $zone := .zones }}{{ if $idx }} {{ else }}{{ end }}{{ default "" $zone.scheme }}{{ default "." $zone.zone }}{{ else }}.{{ end -}} + {{- if .port }}:{{ .port }} {{ end -}} + { + {{- range .plugins }} + {{ .name }}{{ if .parameters }} {{ .parameters }}{{ end }}{{ if .configBlock }} { +{{ .configBlock | indent 12 }} + }{{ end }} + {{- end }} + } + {{ end }} + {{- range .Values.zoneFiles }} + {{ .filename }}: {{ toYaml .contents | indent 4 }} + {{- end }} diff --git a/sample-cnfs/sample_whitelisted_privileged_cnf/chart/templates/deployment-autoscaler.yaml b/sample-cnfs/sample_whitelisted_privileged_cnf/chart/templates/deployment-autoscaler.yaml new file mode 100755 index 000000000..7ca185239 --- /dev/null +++ b/sample-cnfs/sample_whitelisted_privileged_cnf/chart/templates/deployment-autoscaler.yaml @@ -0,0 +1,77 @@ +{{- if .Values.autoscaler.enabled }} +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ template "coredns.fullname" . }}-autoscaler + namespace: {{ .Release.Namespace }} + labels: + app.kubernetes.io/managed-by: {{ .Release.Service | quote }} + app.kubernetes.io/instance: {{ .Release.Name | quote }} + helm.sh/chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}" + {{- if .Values.isClusterService }} + k8s-app: {{ .Chart.Name }}-autoscaler + kubernetes.io/cluster-service: "true" + kubernetes.io/name: "CoreDNS" + {{- end }} + app.kubernetes.io/name: {{ template "coredns.name" . }}-autoscaler +{{- if .Values.customLabels }} +{{ toYaml .Values.customLabels | indent 4 }} +{{- end }} +spec: + selector: + matchLabels: + app.kubernetes.io/instance: {{ .Release.Name | quote }} + {{- if .Values.isClusterService }} + k8s-app: {{ .Chart.Name }}-autoscaler + {{- end }} + app.kubernetes.io/name: {{ template "coredns.name" . }}-autoscaler + template: + metadata: + labels: + {{- if .Values.isClusterService }} + k8s-app: {{ .Chart.Name }}-autoscaler + {{- end }} + app.kubernetes.io/name: {{ template "coredns.name" . }}-autoscaler + app.kubernetes.io/instance: {{ .Release.Name | quote }} + {{- if .Values.customLabels }} + {{ toYaml .Values.customLabels | nindent 8 }} + {{- end }} + annotations: + checksum/configmap: {{ include (print $.Template.BasePath "/configmap-autoscaler.yaml") . | sha256sum }} + {{- if .Values.isClusterService }} + scheduler.alpha.kubernetes.io/critical-pod: '' + scheduler.alpha.kubernetes.io/tolerations: '[{"key":"CriticalAddonsOnly", "operator":"Exists"}]' + {{- end }} + spec: + serviceAccountName: {{ template "coredns.fullname" . }}-autoscaler + {{- $priorityClassName := default .Values.priorityClassName .Values.autoscaler.priorityClassName }} + {{- if $priorityClassName }} + priorityClassName: {{ $priorityClassName | quote }} + {{- end }} + {{- if .Values.autoscaler.affinity }} + affinity: +{{ toYaml .Values.autoscaler.affinity | indent 8 }} + {{- end }} + {{- if .Values.autoscaler.tolerations }} + tolerations: +{{ toYaml .Values.autoscaler.tolerations | indent 8 }} + {{- end }} + {{- if .Values.autoscaler.nodeSelector }} + nodeSelector: +{{ toYaml .Values.autoscaler.nodeSelector | indent 8 }} + {{- end }} + containers: + - name: autoscaler + image: "{{ .Values.autoscaler.image.repository }}:{{ .Values.autoscaler.image.tag }}" + imagePullPolicy: {{ .Values.autoscaler.image.pullPolicy }} + resources: +{{ toYaml .Values.autoscaler.resources | indent 10 }} + command: + - /cluster-proportional-autoscaler + - --namespace={{ .Release.Namespace }} + - --configmap={{ template "coredns.fullname" . }}-autoscaler + - --target=Deployment/{{ template "coredns.fullname" . }} + - --logtostderr=true + - --v=2 +{{- end }} diff --git a/sample-cnfs/sample_whitelisted_privileged_cnf/chart/templates/deployment.yaml b/sample-cnfs/sample_whitelisted_privileged_cnf/chart/templates/deployment.yaml new file mode 100755 index 000000000..02ed35fd8 --- /dev/null +++ b/sample-cnfs/sample_whitelisted_privileged_cnf/chart/templates/deployment.yaml @@ -0,0 +1,124 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ template "coredns.fullname" . }} + labels: + app.kubernetes.io/managed-by: {{ .Release.Service | quote }} + app.kubernetes.io/instance: {{ .Release.Name | quote }} + helm.sh/chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}" + {{- if .Values.isClusterService }} + k8s-app: {{ .Chart.Name | quote }} + kubernetes.io/cluster-service: "true" + kubernetes.io/name: "CoreDNS" + {{- end }} + app.kubernetes.io/name: {{ template "coredns.name" . }} +{{- if .Values.customLabels }} +{{ toYaml .Values.customLabels | indent 4 }} +{{- end }} +spec: + {{- if not .Values.autoscaler.enabled }} + replicas: {{ .Values.replicaCount }} + {{- end }} + strategy: + type: RollingUpdate + rollingUpdate: + maxUnavailable: 1 + maxSurge: 10% + selector: + matchLabels: + app.kubernetes.io/instance: {{ .Release.Name | quote }} + {{- if .Values.isClusterService }} + k8s-app: {{ .Chart.Name | quote }} + {{- end }} + app.kubernetes.io/name: {{ template "coredns.name" . }} + template: + metadata: + labels: + {{- if .Values.isClusterService }} + k8s-app: {{ .Chart.Name | quote }} + {{- end }} + app.kubernetes.io/name: {{ template "coredns.name" . }} + app.kubernetes.io/instance: {{ .Release.Name | quote }} +{{- if .Values.customLabels }} +{{ toYaml .Values.customLabels | indent 8 }} +{{- end }} + annotations: + checksum/config: {{ include (print $.Template.BasePath "/configmap.yaml") . | sha256sum }} + {{- if .Values.isClusterService }} + scheduler.alpha.kubernetes.io/critical-pod: '' + scheduler.alpha.kubernetes.io/tolerations: '[{"key":"CriticalAddonsOnly", "operator":"Exists"}]' + {{- end }} + spec: + serviceAccountName: {{ template "coredns.serviceAccountName" . }} + {{- if .Values.priorityClassName }} + priorityClassName: {{ .Values.priorityClassName | quote }} + {{- end }} + {{- if .Values.isClusterService }} + dnsPolicy: Default + {{- end }} + {{- if .Values.affinity }} + affinity: +{{ toYaml .Values.affinity | indent 8 }} + {{- end }} + {{- if .Values.tolerations }} + tolerations: +{{ toYaml .Values.tolerations | indent 8 }} + {{- end }} + {{- if .Values.nodeSelector }} + nodeSelector: +{{ toYaml .Values.nodeSelector | indent 8 }} + {{- end }} + containers: + - name: "coredns" + image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" + securityContext: + privileged: true + imagePullPolicy: {{ .Values.image.pullPolicy }} + args: [ "-conf", "/etc/coredns/Corefile" ] + volumeMounts: + - name: config-volume + mountPath: /etc/coredns +{{- range .Values.extraSecrets }} + - name: {{ .name }} + mountPath: {{ .mountPath }} + readOnly: true +{{- end }} + resources: +{{ toYaml .Values.resources | indent 10 }} + ports: +{{ include "coredns.containerPorts" . | indent 8 }} + livenessProbe: + httpGet: + path: /health + port: 8080 + scheme: HTTP + initialDelaySeconds: 60 + timeoutSeconds: 5 + successThreshold: 1 + failureThreshold: 5 + readinessProbe: + httpGet: + path: /ready + port: 8181 + scheme: HTTP + initialDelaySeconds: 10 + timeoutSeconds: 5 + successThreshold: 1 + failureThreshold: 5 + volumes: + - name: config-volume + configMap: + name: {{ template "coredns.fullname" . }} + items: + - key: Corefile + path: Corefile + {{ range .Values.zoneFiles }} + - key: {{ .filename }} + path: {{ .filename }} + {{ end }} +{{- range .Values.extraSecrets }} + - name: {{ .name }} + secret: + secretName: {{ .name }} + defaultMode: 400 +{{- end }} diff --git a/sample-cnfs/sample_whitelisted_privileged_cnf/chart/templates/podsecuritypolicy.yaml b/sample-cnfs/sample_whitelisted_privileged_cnf/chart/templates/podsecuritypolicy.yaml new file mode 100755 index 000000000..754943fe5 --- /dev/null +++ b/sample-cnfs/sample_whitelisted_privileged_cnf/chart/templates/podsecuritypolicy.yaml @@ -0,0 +1,57 @@ +{{- if .Values.rbac.pspEnable }} +{{ if .Capabilities.APIVersions.Has "policy/v1beta1" }} +apiVersion: policy/v1beta1 +{{ else }} +apiVersion: extensions/v1beta1 +{{ end -}} +kind: PodSecurityPolicy +metadata: + name: {{ template "coredns.fullname" . }} + labels: + app.kubernetes.io/managed-by: {{ .Release.Service | quote }} + app.kubernetes.io/instance: {{ .Release.Name | quote }} + helm.sh/chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}" + {{- if .Values.isClusterService }} + k8s-app: {{ .Chart.Name | quote }} + kubernetes.io/cluster-service: "true" + kubernetes.io/name: "CoreDNS" + {{- else }} + app.kubernetes.io/name: {{ template "coredns.name" . }} + {{- end }} +spec: + privileged: false + # Required to prevent escalations to root. + allowPrivilegeEscalation: false + # Add back CAP_NET_BIND_SERVICE so that coredns can run on port 53 + allowedCapabilities: + - CAP_NET_BIND_SERVICE + # Allow core volume types. + volumes: + - 'configMap' + - 'emptyDir' + - 'projected' + - 'secret' + - 'downwardAPI' + hostNetwork: false + hostIPC: false + hostPID: false + runAsUser: + # Require the container to run without root privileges. + rule: 'RunAsAny' + seLinux: + # This policy assumes the nodes are using AppArmor rather than SELinux. + rule: 'RunAsAny' + supplementalGroups: + rule: 'MustRunAs' + ranges: + # Forbid adding the root group. + - min: 1 + max: 65535 + fsGroup: + rule: 'MustRunAs' + ranges: + # Forbid adding the root group. + - min: 1 + max: 65535 + readOnlyRootFilesystem: false +{{- end }} diff --git a/sample-cnfs/sample_whitelisted_privileged_cnf/chart/templates/service-metrics.yaml b/sample-cnfs/sample_whitelisted_privileged_cnf/chart/templates/service-metrics.yaml new file mode 100755 index 000000000..ae213c043 --- /dev/null +++ b/sample-cnfs/sample_whitelisted_privileged_cnf/chart/templates/service-metrics.yaml @@ -0,0 +1,33 @@ +{{- if .Values.prometheus.monitor.enabled }} +apiVersion: v1 +kind: Service +metadata: + name: {{ template "coredns.fullname" . }}-metrics + labels: + app.kubernetes.io/managed-by: {{ .Release.Service | quote }} + app.kubernetes.io/instance: {{ .Release.Name | quote }} + helm.sh/chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}" + {{- if .Values.isClusterService }} + k8s-app: {{ .Chart.Name | quote }} + kubernetes.io/cluster-service: "true" + kubernetes.io/name: "CoreDNS" + {{- end }} + app.kubernetes.io/name: {{ template "coredns.name" . }} + app.kubernetes.io/component: metrics +{{- if .Values.customLabels }} +{{ toYaml .Values.customLabels | indent 4 }} +{{- end }} + annotations: +{{ toYaml .Values.service.annotations | indent 4 }} +spec: + selector: + app.kubernetes.io/instance: {{ .Release.Name | quote }} + {{- if .Values.isClusterService }} + k8s-app: {{ .Chart.Name | quote }} + {{- end }} + app.kubernetes.io/name: {{ template "coredns.name" . }} + ports: + - name: metrics + port: 9153 + targetPort: 9153 +{{- end }} diff --git a/sample-cnfs/sample_whitelisted_privileged_cnf/chart/templates/service.yaml b/sample-cnfs/sample_whitelisted_privileged_cnf/chart/templates/service.yaml new file mode 100755 index 000000000..4098664bb --- /dev/null +++ b/sample-cnfs/sample_whitelisted_privileged_cnf/chart/templates/service.yaml @@ -0,0 +1,38 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ template "coredns.fullname" . }} + labels: + app.kubernetes.io/managed-by: {{ .Release.Service | quote }} + app.kubernetes.io/instance: {{ .Release.Name | quote }} + helm.sh/chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}" + {{- if .Values.isClusterService }} + k8s-app: {{ .Chart.Name | quote }} + kubernetes.io/cluster-service: "true" + kubernetes.io/name: "CoreDNS" + {{- end }} + app.kubernetes.io/name: {{ template "coredns.name" . }} +{{- if .Values.customLabels }} +{{ toYaml .Values.customLabels | indent 4 }} +{{- end }} + annotations: +{{ toYaml .Values.service.annotations | indent 4 }} +spec: + selector: + app.kubernetes.io/instance: {{ .Release.Name | quote }} + {{- if .Values.isClusterService }} + k8s-app: {{ .Chart.Name | quote }} + {{- end }} + app.kubernetes.io/name: {{ template "coredns.name" . }} + {{- if .Values.service.clusterIP }} + clusterIP: {{ .Values.service.clusterIP }} + {{- end }} + {{- if .Values.service.externalTrafficPolicy }} + externalTrafficPolicy: {{ .Values.service.externalTrafficPolicy }} + {{- end }} + {{- if .Values.service.loadBalancerIP }} + loadBalancerIP: {{ .Values.service.loadBalancerIP }} + {{- end }} + ports: +{{ include "coredns.servicePorts" . | indent 2 -}} + type: {{ default "ClusterIP" .Values.serviceType }} diff --git a/sample-cnfs/sample_whitelisted_privileged_cnf/chart/templates/serviceaccount-autoscaler.yaml b/sample-cnfs/sample_whitelisted_privileged_cnf/chart/templates/serviceaccount-autoscaler.yaml new file mode 100755 index 000000000..972c74612 --- /dev/null +++ b/sample-cnfs/sample_whitelisted_privileged_cnf/chart/templates/serviceaccount-autoscaler.yaml @@ -0,0 +1,21 @@ +{{- if and .Values.autoscaler.enabled .Values.rbac.create }} +--- +apiVersion: v1 +kind: ServiceAccount +metadata: + name: {{ template "coredns.fullname" . }}-autoscaler + namespace: {{ .Release.Namespace }} + labels: + app.kubernetes.io/managed-by: {{ .Release.Service | quote }} + app.kubernetes.io/instance: {{ .Release.Name | quote }} + helm.sh/chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}" + {{- if .Values.isClusterService }} + k8s-app: {{ .Chart.Name }}-autoscaler + kubernetes.io/cluster-service: "true" + kubernetes.io/name: "CoreDNS" + {{- end }} + app.kubernetes.io/name: {{ template "coredns.name" . }}-autoscaler +{{- if .Values.customLabels }} +{{ toYaml .Values.customLabels | indent 4 }} +{{- end }} +{{- end }} diff --git a/sample-cnfs/sample_whitelisted_privileged_cnf/chart/templates/serviceaccount.yaml b/sample-cnfs/sample_whitelisted_privileged_cnf/chart/templates/serviceaccount.yaml new file mode 100755 index 000000000..bced7ca3d --- /dev/null +++ b/sample-cnfs/sample_whitelisted_privileged_cnf/chart/templates/serviceaccount.yaml @@ -0,0 +1,16 @@ +{{- if .Values.serviceAccount.create }} +apiVersion: v1 +kind: ServiceAccount +metadata: + name: {{ template "coredns.serviceAccountName" . }} + labels: + app.kubernetes.io/managed-by: {{ .Release.Service | quote }} + app.kubernetes.io/instance: {{ .Release.Name | quote }} + helm.sh/chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}" + {{- if .Values.isClusterService }} + k8s-app: {{ .Chart.Name | quote }} + kubernetes.io/cluster-service: "true" + kubernetes.io/name: "CoreDNS" + {{- end }} + app.kubernetes.io/name: {{ template "coredns.name" . }} +{{- end }} diff --git a/sample-cnfs/sample_whitelisted_privileged_cnf/chart/templates/servicemonitor.yaml b/sample-cnfs/sample_whitelisted_privileged_cnf/chart/templates/servicemonitor.yaml new file mode 100755 index 000000000..0a4ffb581 --- /dev/null +++ b/sample-cnfs/sample_whitelisted_privileged_cnf/chart/templates/servicemonitor.yaml @@ -0,0 +1,33 @@ +{{- if .Values.prometheus.monitor.enabled }} +apiVersion: monitoring.coreos.com/v1 +kind: ServiceMonitor +metadata: + name: {{ template "coredns.fullname" . }} + {{- if .Values.prometheus.monitor.namespace }} + namespace: {{ .Values.prometheus.monitor.namespace }} + {{- end }} + labels: + app.kubernetes.io/managed-by: {{ .Release.Service | quote }} + app.kubernetes.io/instance: {{ .Release.Name | quote }} + helm.sh/chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}" + {{- if .Values.isClusterService }} + k8s-app: {{ .Chart.Name | quote }} + kubernetes.io/cluster-service: "true" + kubernetes.io/name: "CoreDNS" + {{- end }} + app.kubernetes.io/name: {{ template "coredns.name" . }} + {{- if .Values.prometheus.monitor.additionalLabels }} +{{ toYaml .Values.prometheus.monitor.additionalLabels | indent 4 }} + {{- end }} +spec: + selector: + matchLabels: + app.kubernetes.io/instance: {{ .Release.Name | quote }} + {{- if .Values.isClusterService }} + k8s-app: {{ .Chart.Name | quote }} + {{- end }} + app.kubernetes.io/name: {{ template "coredns.name" . }} + app.kubernetes.io/component: metrics + endpoints: + - port: metrics +{{- end }} diff --git a/sample-cnfs/sample_whitelisted_privileged_cnf/chart/values.yaml b/sample-cnfs/sample_whitelisted_privileged_cnf/chart/values.yaml new file mode 100755 index 000000000..becf13564 --- /dev/null +++ b/sample-cnfs/sample_whitelisted_privileged_cnf/chart/values.yaml @@ -0,0 +1,195 @@ +# Default values for coredns. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. + +image: + repository: coredns/coredns + tag: "1.6.7" + pullPolicy: IfNotPresent + +replicaCount: 1 + +resources: + limits: + cpu: 100m + memory: 128Mi + requests: + cpu: 100m + memory: 128Mi + +serviceType: "ClusterIP" + +prometheus: + monitor: + enabled: false + additionalLabels: {} + namespace: "" + +service: +# clusterIP: "" +# loadBalancerIP: "" +# externalTrafficPolicy: "" + annotations: + prometheus.io/scrape: "true" + prometheus.io/port: "9153" + +serviceAccount: + create: false + # The name of the ServiceAccount to use + # If not set and create is true, a name is generated using the fullname template + name: + +rbac: + # If true, create & use RBAC resources + create: true + # If true, create and use PodSecurityPolicy + pspEnable: false + # The name of the ServiceAccount to use. + # If not set and create is true, a name is generated using the fullname template + # name: + +# isClusterService specifies whether chart should be deployed as cluster-service or normal k8s app. +isClusterService: true + +# Optional priority class to be used for the coredns pods. Used for autoscaler if autoscaler.priorityClassName not set. +priorityClassName: "" + +# Default zone is what Kubernetes recommends: +# https://kubernetes.io/docs/tasks/administer-cluster/dns-custom-nameservers/#coredns-configmap-options +servers: +- zones: + - zone: . + port: 53 + plugins: + - name: errors + # Serves a /health endpoint on :8080, required for livenessProbe + - name: health + configBlock: |- + lameduck 5s + # Serves a /ready endpoint on :8181, required for readinessProbe + - name: ready + # Required to query kubernetes API for data + - name: kubernetes + parameters: cluster.local in-addr.arpa ip6.arpa + configBlock: |- + pods insecure + fallthrough in-addr.arpa ip6.arpa + ttl 30 + # Serves a /metrics endpoint on :9153, required for serviceMonitor + - name: prometheus + parameters: 0.0.0.0:9153 + - name: forward + parameters: . /etc/resolv.conf + - name: cache + parameters: 30 + - name: loop + - name: reload + - name: loadbalance + +# Complete example with all the options: +# - zones: # the `zones` block can be left out entirely, defaults to "." +# - zone: hello.world. # optional, defaults to "." +# scheme: tls:// # optional, defaults to "" (which equals "dns://" in CoreDNS) +# - zone: foo.bar. +# scheme: dns:// +# use_tcp: true # set this parameter to optionally expose the port on tcp as well as udp for the DNS protocol +# # Note that this will not work if you are also exposing tls or grpc on the same server +# port: 12345 # optional, defaults to "" (which equals 53 in CoreDNS) +# plugins: # the plugins to use for this server block +# - name: kubernetes # name of plugin, if used multiple times ensure that the plugin supports it! +# parameters: foo bar # list of parameters after the plugin +# configBlock: |- # if the plugin supports extra block style config, supply it here +# hello world +# foo bar + +# expects input structure as per specification https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.11/#affinity-v1-core +# for example: +# affinity: +# nodeAffinity: +# requiredDuringSchedulingIgnoredDuringExecution: +# nodeSelectorTerms: +# - matchExpressions: +# - key: foo.bar.com/role +# operator: In +# values: +# - master +affinity: {} + +# Node labels for pod assignment +# Ref: https://kubernetes.io/docs/user-guide/node-selection/ +nodeSelector: {} + +# expects input structure as per specification https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.11/#toleration-v1-core +# for example: +# tolerations: +# - key: foo.bar.com/role +# operator: Equal +# value: master +# effect: NoSchedule +tolerations: [] + +# configure custom zone files as per https://coredns.io/2017/05/08/custom-dns-entries-for-kubernetes/ +zoneFiles: [] +# - filename: example.db +# domain: example.com +# contents: | +# example.com. IN SOA sns.dns.icann.com. noc.dns.icann.com. 2015082541 7200 3600 1209600 3600 +# example.com. IN NS b.iana-servers.net. +# example.com. IN NS a.iana-servers.net. +# example.com. IN A 192.168.99.102 +# *.example.com. IN A 192.168.99.102 + +# optional array of secrets to mount inside coredns container +# possible usecase: need for secure connection with etcd backend +extraSecrets: [] +# - name: etcd-client-certs +# mountPath: /etc/coredns/tls/etcd +# - name: some-fancy-secret +# mountPath: /etc/wherever + +# Custom labels to apply to Deployment, Pod, Service, ServiceMonitor. Including autoscaler if enabled. +customLabels: {} + +## Configue a cluster-proportional-autoscaler for coredns +# See https://github.com/kubernetes-incubator/cluster-proportional-autoscaler +autoscaler: + # Enabled the cluster-proportional-autoscaler + enabled: false + + # Number of cores in the cluster per coredns replica + coresPerReplica: 256 + # Number of nodes in the cluster per coredns replica + nodesPerReplica: 16 + + image: + repository: k8s.gcr.io/cluster-proportional-autoscaler-amd64 + tag: "1.7.1" + pullPolicy: IfNotPresent + + # Optional priority class to be used for the autoscaler pods. priorityClassName used if not set. + priorityClassName: "" + + # expects input structure as per specification https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.11/#affinity-v1-core + affinity: {} + + # Node labels for pod assignment + # Ref: https://kubernetes.io/docs/user-guide/node-selection/ + nodeSelector: {} + + # expects input structure as per specification https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.11/#toleration-v1-core + tolerations: [] + + # resources for autoscaler pod + resources: + requests: + cpu: "20m" + memory: "10Mi" + limits: + cpu: "20m" + memory: "10Mi" + + # Options for autoscaler configmap + configmap: + ## Annotations for the coredns-autoscaler configmap + # i.e. strategy.spinnaker.io/versioned: "false" to ensure configmap isn't renamed + annotations: {} diff --git a/sample-cnfs/sample_privileged_cnf_setup_coredns/whitelisted-conformance.yml b/sample-cnfs/sample_whitelisted_privileged_cnf/cnf-conformance.yml similarity index 65% rename from sample-cnfs/sample_privileged_cnf_setup_coredns/whitelisted-conformance.yml rename to sample-cnfs/sample_whitelisted_privileged_cnf/cnf-conformance.yml index 73d9f96ec..50bae9ec2 100644 --- a/sample-cnfs/sample_privileged_cnf_setup_coredns/whitelisted-conformance.yml +++ b/sample-cnfs/sample_whitelisted_privileged_cnf/cnf-conformance.yml @@ -1,6 +1,8 @@ --- -helm_directory: cnfs/sample_privileged_cnf_setup_coredns/chart -install_script: cnfs/sample_privileged_cnf_setup_coredns/chart +helm_directory: chart +git_clone_url: +install_script: +release_name: privileged-coredns deployment_name: privileged-coredns-coredns application_deployment_names: [privileged-coredns-coredns] helm_chart: stable/coredns diff --git a/spec/cnf_conformance_spec.cr b/spec/cnf_conformance_spec.cr index f8dc39a0a..2b9dc4dd0 100644 --- a/spec/cnf_conformance_spec.cr +++ b/spec/cnf_conformance_spec.cr @@ -9,6 +9,8 @@ describe CnfConformance do $?.success?.should be_true `crystal src/cnf-conformance.cr setup` $?.success?.should be_true + `crystal src/cnf-conformance.cr sample_coredns_with_wait_setup` + $?.success?.should be_true end after_all do @@ -21,15 +23,11 @@ describe CnfConformance do it "'all' should run the whole test suite" do # puts `pwd` # puts `echo $KUBECONFIG` - `crystal src/cnf-conformance.cr sample_coredns_setup` - $?.success?.should be_true response_s = `crystal src/cnf-conformance.cr all verbose` puts response_s $?.success?.should be_true (/PASSED: Helm readiness probe found/ =~ response_s).should_not be_nil (/PASSED: Helm liveness probe/ =~ response_s).should_not be_nil - (/FAILURE: Helm not found in install script/ =~ response_s).should_not be_nil - (/FAILURE: IP addresses found/ =~ response_s).should_not be_nil (/Lint Passed/ =~ response_s).should_not be_nil (/PASSED: Replicas increased to 3/ =~ response_s).should_not be_nil (/PASSED: Replicas decreased to 1/ =~ response_s).should_not be_nil @@ -45,21 +43,5 @@ describe CnfConformance do (/PASSED: Replicas decreased to 1/ =~ response_s).should_not be_nil end - it "'helm_chart_valid' should fail on a bad helm chart" do - # puts `pwd` - # puts `echo $KUBECONFIG` - `crystal src/cnf-conformance.cr sample_coredns_cleanup` - $?.success?.should be_true - `crystal src/cnf-conformance.cr bad_helm_cnf_setup` - $?.success?.should be_true - response_s = `crystal src/cnf-conformance.cr helm_chart_valid` - puts response_s - $?.success?.should be_true - (/Lint Failed/ =~ response_s).should_not be_nil - `crystal src/cnf-conformance.cr bad_helm_cnf_cleanup` - $?.success?.should be_true - `crystal src/cnf-conformance.cr sample_coredns_setup` - $?.success?.should be_true - end end diff --git a/spec/configuration_lifecycle_spec.cr b/spec/configuration_lifecycle_spec.cr index 3cc122f80..719fdb0ae 100644 --- a/spec/configuration_lifecycle_spec.cr +++ b/spec/configuration_lifecycle_spec.cr @@ -12,6 +12,18 @@ describe CnfConformance do # `crystal src/cnf-conformance.cr setup` # $?.success?.should be_true end + it "'ip_addresses' should fail when ip addresses are found in source is set", tags: "liveness" do + begin + `crystal src/cnf-conformance.cr sample_coredns_source_setup` + $?.success?.should be_true + response_s = `crystal src/cnf-conformance.cr ip_addresses verbose` + puts response_s + $?.success?.should be_true + (/FAILURE: IP addresses found/ =~ response_s).should_not be_nil + ensure + `crystal src/cnf-conformance.cr sample_coredns_source_cleanup verbose` + end + end it "'liveness' should pass when livenessProbe is set", tags: "liveness" do begin `crystal src/cnf-conformance.cr sample_coredns` @@ -21,7 +33,7 @@ describe CnfConformance do $?.success?.should be_true (/PASSED: Helm liveness probe/ =~ response_s).should_not be_nil ensure - `crystal src/cnf-conformance.cr cleanup_sample_coredns` + `crystal src/cnf-conformance.cr cleanup_sample_coredns verbose` end end it "'liveness' should fail when livenessProbe is not set", tags: "liveness" do @@ -36,4 +48,52 @@ describe CnfConformance do `crystal src/cnf-conformance.cr sample_coredns_bad_liveness_cleanup` end end + it "'readiness' should pass when readinessProbe is set", tags: "readiness" do + begin + `crystal src/cnf-conformance.cr sample_coredns` + $?.success?.should be_true + response_s = `crystal src/cnf-conformance.cr readiness verbose` + puts response_s + $?.success?.should be_true + (/PASSED: Helm readiness probe/ =~ response_s).should_not be_nil + ensure + `crystal src/cnf-conformance.cr cleanup_sample_coredns verbose` + end + end + it "'readiness' should fail when readinessProbe is not set", tags: "readiness" do + begin + `crystal src/cnf-conformance.cr sample_coredns_bad_liveness` + $?.success?.should be_true + response_s = `crystal src/cnf-conformance.cr readiness verbose` + puts response_s + $?.success?.should be_true + (/FAILURE: No readinessProbe found/ =~ response_s).should_not be_nil + ensure + `crystal src/cnf-conformance.cr sample_coredns_bad_liveness_cleanup` + end + end + it "'rolling_update' should pass when valid version is given", tags: "rolling_update" do + begin + `crystal src/cnf-conformance.cr sample_coredns` + $?.success?.should be_true + response_s = `crystal src/cnf-conformance.cr rolling_update verbose` + puts response_s + $?.success?.should be_true + (/Rolling Update Passed/ =~ response_s).should_not be_nil + ensure + `crystal src/cnf-conformance.cr cleanup_sample_coredns` + end + end + it "'rolling_update' should fail when invalid version is given", tags: "rolling_update" do + begin + `crystal src/cnf-conformance.cr sample_coredns` + $?.success?.should be_true + response_s = `crystal src/cnf-conformance.cr rolling_update verbose version_tag=this_is_not_real_version` + puts response_s + $?.success?.should be_true + (/Rolling Update Failed/ =~ response_s).should_not be_nil + ensure + `crystal src/cnf-conformance.cr cleanup_sample_coredns` + end + end end diff --git a/spec/installability_spec.cr b/spec/installability_spec.cr new file mode 100644 index 000000000..78f12f495 --- /dev/null +++ b/spec/installability_spec.cr @@ -0,0 +1,59 @@ +require "./spec_helper" +require "colorize" + +describe CnfConformance do + before_all do + # puts `pwd` + # puts `echo $KUBECONFIG` + + `crystal src/cnf-conformance.cr samples_cleanup` + $?.success?.should be_true + + # `crystal src/cnf-conformance.cr setup` + # $?.success?.should be_true + end + + it "'install_script_helm' should fail if install script does not have helm" do + # puts `pwd` + # puts `echo $KUBECONFIG` + # `crystal src/cnf-conformance.cr cleanup` + # $?.success?.should be_true + `crystal src/cnf-conformance.cr sample_coredns_source_setup` + $?.success?.should be_true + response_s = `crystal src/cnf-conformance.cr install_script_helm` + #puts response_s + $?.success?.should be_true + (/FAILURE: Helm not found in supplied install script/ =~ response_s).should_not be_nil + `crystal src/cnf-conformance.cr sample_coredns_source_cleanup` + end + + it "'helm_chart_valid' should pass on a good helm chart" do + # puts `pwd` + # puts `echo $KUBECONFIG` + # `crystal src/cnf-conformance.cr cleanup` + # $?.success?.should be_true + `crystal src/cnf-conformance.cr sample_coredns_setup` + $?.success?.should be_true + response_s = `crystal src/cnf-conformance.cr helm_chart_valid` + puts response_s + $?.success?.should be_true + (/Lint Passed/ =~ response_s).should_not be_nil + end + + it "'helm_chart_valid' should fail on a bad helm chart" do + # puts `pwd` + # puts `echo $KUBECONFIG` + `crystal src/cnf-conformance.cr sample_coredns_cleanup` + $?.success?.should be_true + `crystal src/cnf-conformance.cr bad_helm_cnf_setup` + $?.success?.should be_true + response_s = `crystal src/cnf-conformance.cr helm_chart_valid` + puts response_s + $?.success?.should be_true + (/Lint Failed/ =~ response_s).should_not be_nil + `crystal src/cnf-conformance.cr bad_helm_cnf_cleanup` + $?.success?.should be_true + `crystal src/cnf-conformance.cr sample_coredns_setup` + $?.success?.should be_true + end +end diff --git a/spec/platform/platform_spec.cr b/spec/platform/platform_spec.cr new file mode 100644 index 000000000..5fb06cef6 --- /dev/null +++ b/spec/platform/platform_spec.cr @@ -0,0 +1,21 @@ +require "./../spec_helper" +require "colorize" + +describe "Platform" do + before_all do + # puts `pwd` + # puts `echo $KUBECONFIG` + `crystal src/cnf-conformance.cr samples_cleanup` + $?.success?.should be_true + `crystal src/cnf-conformance.cr setup` + $?.success?.should be_true + `crystal src/cnf-conformance.cr sample_coredns_with_wait_setup` + $?.success?.should be_true + end + it "'k8s_conformance' should pass if the sonobuoy tests pass" do + response_s = `crystal src/cnf-conformance.cr k8s_conformance` + puts response_s + (/PASSED: K8s conformance test has no failures/ =~ response_s).should_not be_nil + end +end + diff --git a/spec/sample_coredns_setup_spec.cr b/spec/sample_coredns_setup_spec.cr index 4f9a54247..349c6ce18 100644 --- a/spec/sample_coredns_setup_spec.cr +++ b/spec/sample_coredns_setup_spec.cr @@ -45,9 +45,9 @@ describe "Utils" do (current_replicas.to_i > 0).should be_true end - it "'sample_setup' should set up a sample cnf", tags: "WIP" do + it "'sample_setup' should set up a sample cnf" do args = Sam::Args.new - sample_setup(sample_dir: "sample-cnfs/sample-generic-cnf", release_name: "coredns", deployment_name: "coredns-coredns", helm_chart: "stable/coredns", helm_directory: "helm_chart", git_clone_url: "https://github.com/coredns/coredns.git" ) + sample_setup(sample_dir: "sample-cnfs/sample-generic-cnf", release_name: "coredns", deployment_name: "coredns-coredns", helm_chart: "stable/coredns", helm_directory: "helm_chart", git_clone_url: "https://github.com/coredns/coredns.git", wait_count: 0 ) # check if directory exists (Dir.exists? "sample-cnfs/sample-generic-cnf").should be_true (File.exists?("cnfs/sample-generic-cnf/cnf-conformance.yml")).should be_true @@ -55,9 +55,9 @@ describe "Utils" do sample_cleanup(sample_dir: "sample-cnfs/sample-generic-cnf", verbose: true) end # - it "'sample_setup_args' should set up a sample cnf from a argument", tags: "WIP" do + it "'sample_setup_args' should set up a sample cnf from a argument" do args = Sam::Args.new - sample_setup_args(sample_dir: "sample-cnfs/sample-generic-cnf", args: args, verbose: true ) + sample_setup_args(sample_dir: "sample-cnfs/sample-generic-cnf", args: args, verbose: true, wait_count: 0 ) # check if directory exists (Dir.exists? "sample-cnfs/sample-generic-cnf").should be_true (File.exists?("cnfs/sample-generic-cnf/cnf-conformance.yml")).should be_true @@ -65,11 +65,11 @@ describe "Utils" do sample_cleanup(sample_dir: "sample-cnfs/sample-generic-cnf", verbose: true) end - it "'sample_cleanup' should clean up a sample cnf from a argument", tags: "WIP" do + it "'sample_cleanup' should clean up a sample cnf from a argument" do args = Sam::Args.new - sample_setup_args(sample_dir: "sample-cnfs/sample-generic-cnf", args: args, verbose: true ) - sample_cleanup(sample_dir: "sample-cnfs/sample-generic-cnf", verbose: true) - # check if directory exists + sample_setup_args(sample_dir: "sample-cnfs/sample-generic-cnf", args: args, verbose: true, wait_count: 0 ) + cleanup = sample_cleanup(sample_dir: "sample-cnfs/sample-generic-cnf", verbose: true) + (cleanup.success?).should be_true (Dir.exists? "cnfs/sample-generic-cnf").should be_false (File.exists?("cnfs/sample-generic-cnf/cnf-conformance.yml")).should be_false (File.exists?("cnfs/sample-generic-cnf/helm_chart/Chart.yaml")).should be_false @@ -77,12 +77,22 @@ describe "Utils" do it "'sample_setup_args' should be able to deploy using a helm_directory" do args = Sam::Args.new - sample_setup_args(sample_dir: "sample-cnfs/sample_privileged_cnf_setup_coredns", deploy_with_chart: false, args: args, verbose: true ) - # check if directory exists - (Dir.exists? "cnfs/sample_privileged_cnf_setup_coredns").should be_true + sample_setup_args(sample_dir: "sample-cnfs/sample_privileged_cnf", deploy_with_chart: false, args: args, verbose: true, wait_count: 0 ) + (Dir.exists? "cnfs/sample_privileged_cnf").should be_true # should not clone - (Dir.exists? "cnfs/sample_privileged_cnf_setup_coredns/privileged-coredns").should be_false - (File.exists? "cnfs/sample_privileged_cnf_setup_coredns/cnf-conformance.yml").should be_true - (File.exists? "cnfs/sample_privileged_cnf_setup_coredns/chart/Chart.yaml").should be_true + (Dir.exists? "cnfs/sample_privileged_cnf/privileged-coredns").should be_false + (File.exists? "cnfs/sample_privileged_cnf/cnf-conformance.yml").should be_true + (File.exists? "cnfs/sample_privileged_cnf/chart/Chart.yaml").should be_true + end + + it "'cnf_conformance_yml' should return the short name of the destination cnf directory", tags: "WIP" do + args = Sam::Args.new + sample_setup_args(sample_dir: "sample-cnfs/sample-generic-cnf", args: args, verbose: true, wait_count: 0 ) + (cnf_conformance_dir).should eq("sample-generic-cnf") + end + + it "'sample_destination_dir' should return the full path of the potential destination cnf directory based on the source sample cnf directory", tags: "WIP" do + args = Sam::Args.new + sample_destination_dir("sample-generic-cnf").should contain("cnf-conformance/cnfs/sample-generic-cnf") end end diff --git a/spec/spec_helper.cr b/spec/spec_helper.cr index 548dd0a20..35e7fa4ae 100644 --- a/spec/spec_helper.cr +++ b/spec/spec_helper.cr @@ -1,2 +1,4 @@ require "spec" require "../src/cnf_conformance" + +ENV["CRYSTAL_ENV"] = "TEST" diff --git a/src/tasks/cleanup.cr b/src/tasks/cleanup.cr index f2d922e21..6752f8d43 100644 --- a/src/tasks/cleanup.cr +++ b/src/tasks/cleanup.cr @@ -7,10 +7,10 @@ desc "Cleans up the CNF Conformance test suite, the K8s cluster, and upstream pr task "cleanup", ["samples_cleanup"] do |_, args| end -task "samples_cleanup", ["sample_coredns_cleanup", "bad_helm_cnf_cleanup", "sample_privileged_cnf_non_whitelisted_cleanup", "sample_privileged_cnf_whitelisted_cleanup"] do |_, args| +task "samples_cleanup", ["sample_coredns_cleanup", "cleanup_sample_coredns", "bad_helm_cnf_cleanup", "sample_privileged_cnf_non_whitelisted_cleanup", "sample_privileged_cnf_whitelisted_cleanup", "sample_coredns_bad_liveness_cleanup", "sample_coredns_source_cleanup"] do |_, args| end -task "tools_cleanup", ["helm_local_cleanup"] do |_, args| +task "tools_cleanup", ["helm_local_cleanup", "sonobuoy_cleanup"] do |_, args| end task "cleanup_all", ["cleanup_samples", "tools_cleanup"] do |_, args| diff --git a/src/tasks/configuration_lifecycle.cr b/src/tasks/configuration_lifecycle.cr index a6e60dcf6..43bda4b9a 100644 --- a/src/tasks/configuration_lifecycle.cr +++ b/src/tasks/configuration_lifecycle.cr @@ -2,6 +2,7 @@ require "sam" require "file_utils" require "colorize" require "totem" +require "json" require "./utils.cr" desc "Configuration and lifecycle should be managed in a declarative manner, using ConfigMaps, Operators, or other declarative interfaces." @@ -14,6 +15,7 @@ task "ip_addresses" do |_, args| cdir = FileUtils.pwd() response = String::Builder.new Dir.cd(CNF_DIR) + # TODO ignore *example*, *.md, *.txt Process.run("grep -rnw -E -o '([0-9]{1,3}[\.]){3}[0-9]{1,3}'", shell: true) do |proc| # Process.run("grep -rnw -E -o 'hithere'", shell: true) do |proc| while line = proc.output.gets @@ -49,8 +51,12 @@ task "liveness", ["retrieve_manifest"] do |_, args| puts "FAILURE: helm directory not found".colorize(:red) puts ex.message if check_args(args) end - puts "helm_directory: #{helm_directory}/manifest.yml" if check_verbose(args) - deployment = Totem.from_file "#{helm_directory}/manifest.yml" + current_cnf_dir_short_name = cnf_conformance_dir + puts current_cnf_dir_short_name if check_verbose(args) + destination_cnf_dir = sample_destination_dir(current_cnf_dir_short_name) + puts destination_cnf_dir if check_verbose(args) + puts "helm_directory: #{destination_cnf_dir}/#{helm_directory}/manifest.yml" if check_verbose(args) + deployment = Totem.from_file "#{destination_cnf_dir}/#{helm_directory}/manifest.yml" puts deployment.inspect if check_verbose(args) containers = deployment.get("spec").as_h["template"].as_h["spec"].as_h["containers"].as_a containers.each do |container| @@ -87,8 +93,12 @@ task "readiness", ["retrieve_manifest"] do |_, args| puts "FAILURE: helm directory not found".colorize(:red) puts ex.message if check_args(args) end - puts "helm_directory: #{helm_directory}/manifest.yml" if check_verbose(args) - deployment = Totem.from_file "#{helm_directory}/manifest.yml" + current_cnf_dir_short_name = cnf_conformance_dir + puts current_cnf_dir_short_name if check_verbose(args) + destination_cnf_dir = sample_destination_dir(current_cnf_dir_short_name) + puts destination_cnf_dir if check_verbose(args) + puts "helm_directory: #{destination_cnf_dir}/#{helm_directory}/manifest.yml" if check_verbose(args) + deployment = Totem.from_file "#{destination_cnf_dir}/#{helm_directory}/manifest.yml" puts deployment.inspect if check_verbose(args) containers = deployment.get("spec").as_h["template"].as_h["spec"].as_h["containers"].as_a containers.each do |container| @@ -115,10 +125,17 @@ end desc "Retrieve the manifest for the CNF's helm chart" task "retrieve_manifest" do |_, args| begin + puts "retrieve_manifest" if check_verbose(args) config = cnf_conformance_yml deployment_name = config.get("deployment_name").as_s + puts deployment_name if check_verbose(args) helm_directory = config.get("helm_directory").as_s - manifest = `kubectl get deployment #{deployment_name} -o yaml > #{helm_directory}/manifest.yml` + puts helm_directory if check_verbose(args) + current_cnf_dir_short_name = cnf_conformance_dir + puts current_cnf_dir_short_name if check_verbose(args) + destination_cnf_dir = sample_destination_dir(current_cnf_dir_short_name) + puts destination_cnf_dir if check_verbose(args) + manifest = `kubectl get deployment #{deployment_name} -o yaml > #{destination_cnf_dir}/#{helm_directory}/manifest.yml` puts manifest if check_verbose(args) rescue ex puts ex.message @@ -127,3 +144,56 @@ task "retrieve_manifest" do |_, args| end end end + +desc "Test if the CNF can perform a rolling update" +task "rolling_update" do |_, args| + begin + puts "rolling_update" if check_verbose(args) + config = cnf_conformance_yml + + version_tag = nil + + if config.has_key? "cnf_image_version" + version_tag = config.get("cnf_image_version").as_s + end + + if args.named.has_key? "version_tag" + version_tag = args.named["version_tag"] + end + + unless version_tag + raise "FAILURE: please specify a version of the CNF's release's image with the option version_tag or with cnf_conformance_yml option 'cnf_image_version'" + end + + release_name = config.get("release_name").as_s + deployment_name = config.get("deployment_name").as_s + + helm_chart_values = JSON.parse(`#{tools_helm} get values #{release_name} -a --output json`) + puts "helm_chart_values" if check_verbose(args) + puts helm_chart_values if check_verbose(args) + image_name = helm_chart_values["image"]["repository"] + + puts "image_name: #{image_name}" if check_verbose(args) + + puts "rolling_update: setting new version" if check_verbose(args) + #do_update = `kubectl set image deployment/coredns-coredns coredns=coredns/coredns:latest --record` + puts "kubectl set image deployment/#{deployment_name} #{release_name}=#{image_name}:#{version_tag} --record" if check_verbose(args) + do_update = `kubectl set image deployment/#{deployment_name} #{release_name}=#{image_name}:#{version_tag} --record` + + # https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands#rolling-update + puts "rolling_update: checking status new version" if check_verbose(args) + puts `kubectl rollout status deployment/#{deployment_name} --timeout=30s` + + if $?.success? + puts "PASSED: CNF #{deployment_name} Rolling Update Passed".colorize(:green) + else + puts "FAILURE: CNF #{deployment_name} Rolling Update Failed".colorize(:red) + end + + rescue ex + puts ex.message + ex.backtrace.each do |x| + puts x + end + end +end \ No newline at end of file diff --git a/src/tasks/installability.cr b/src/tasks/installability.cr index d78f94c53..fd803acd5 100644 --- a/src/tasks/installability.cr +++ b/src/tasks/installability.cr @@ -15,9 +15,13 @@ task "install_script_helm" do |_, args| config = cnf_conformance_yml found = 0 + current_cnf_dir_short_name = cnf_conformance_dir + puts current_cnf_dir_short_name if check_verbose(args) + destination_cnf_dir = sample_destination_dir(current_cnf_dir_short_name) + puts destination_cnf_dir if check_verbose(args) install_script = config.get("install_script").as_s response = String::Builder.new - content = File.open(install_script) do |file| + content = File.open("#{destination_cnf_dir}/#{install_script}") do |file| file.gets_to_end end # puts content @@ -25,9 +29,9 @@ task "install_script_helm" do |_, args| found = 1 end if found < 1 - puts "FAILURE: Helm not found in install script".colorize(:red) + puts "FAILURE: Helm not found in supplied install script".colorize(:red) else - puts "PASSED: Helm found in install script".colorize(:green) + puts "PASSED: Helm found in supplied install script".colorize(:green) end rescue ex puts ex.message @@ -53,14 +57,20 @@ task "helm_chart_valid", ["helm_local_install"] do |_, args| end puts "helm_directory: #{helm_directory}" if check_verbose(args) - ls_helm_directory = `ls -al #{helm_directory}` - puts "ls -al of helm_directory: #{ls_helm_directory}" if check_verbose(args) puts "helm_chart_repo: #{helm_chart_repo}" if check_verbose(args) current_dir = FileUtils.pwd puts current_dir if check_verbose(args) helm = "#{current_dir}/#{TOOLS_DIR}/helm/linux-amd64/helm" - helm_lint = `#{helm} lint #{helm_directory}` + + current_cnf_dir_short_name = cnf_conformance_dir + puts current_cnf_dir_short_name if check_verbose(args) + destination_cnf_dir = sample_destination_dir(current_cnf_dir_short_name) + puts destination_cnf_dir if check_verbose(args) + ls_helm_directory = `ls -al #{destination_cnf_dir}/#{helm_directory}` + puts "ls -al of helm_directory: #{ls_helm_directory}" if check_verbose(args) + + helm_lint = `#{helm} lint #{destination_cnf_dir}/#{helm_directory}` puts "helm_lint: #{helm_lint}" if check_verbose(args) # Process.run("helm lint #{helm_directory}", shell: true) do |proc| diff --git a/src/tasks/platform/platform.cr b/src/tasks/platform/platform.cr new file mode 100644 index 000000000..3bb3516b9 --- /dev/null +++ b/src/tasks/platform/platform.cr @@ -0,0 +1,48 @@ +desc "Platform Tests" +task "platform", ["k8s_conformance"] do |_, args| +end + +desc "Does the platform pass the K8s conformance tests?" +task "k8s_conformance" do |_, args| + begin + #TODO enable full test with production mode + #sonobuoy = `sonobuoy run --wait` if PRODUCTION_MODE and not in test_mode + current_dir = FileUtils.pwd + puts current_dir if check_verbose(args) + sonobuoy = "#{current_dir}/#{TOOLS_DIR}/sonobuoy/sonobuoy" + + # Clean up old results + delete = `#{sonobuoy} delete --wait` + puts delete if check_verbose(args) + + # Run the tests + #TODO when in test mode --mode quick, prod mode no quick + testrun = "" + puts ENV["CRYSTAL_ENV"]? if check_verbose(args) + if ENV["CRYSTAL_ENV"]? == "TEST" + testrun = `#{sonobuoy} run --wait --mode quick` + else + testrun = `#{sonobuoy} run --wait` + end + puts testrun if check_verbose(args) + + results = `results=$(#{sonobuoy} retrieve); #{sonobuoy} results $results` + puts results if check_verbose(args) + + # Grab the failed line from the results + failed_count = ((results.match(/Failed: (.*)/)).try &.[1]) + if failed_count.to_s.to_i > 0 + puts "FAILURE: K8s conformance test has #{failed_count} failure(s)!".colorize(:red) + else + puts "PASSED: K8s conformance test has no failures".colorize(:green) + end + rescue ex + puts ex.message + ex.backtrace.each do |x| + puts x + end + ensure + remove_tar = `rm *sonobuoy*.tar.gz` + puts remove_tar if check_verbose(args) + end +end diff --git a/src/tasks/sample_coredns_setup.cr b/src/tasks/sample_coredns_setup.cr index 358eb3dc7..c9930755c 100644 --- a/src/tasks/sample_coredns_setup.cr +++ b/src/tasks/sample_coredns_setup.cr @@ -2,397 +2,73 @@ require "sam" require "file_utils" require "colorize" require "totem" -# require "commander" require "./utils.cr" - desc "Sets up sample CoreDNS CNF" task "sample_coredns_setup", ["helm_local_install"] do |_, args| - current_dir = FileUtils.pwd - puts current_dir if check_verbose(args) - - # Retrieve the cnf source - # TODO enable recloning/fetching etc - git_clone = `git clone https://github.com/coredns/coredns.git #{current_dir}/#{CNF_DIR}/coredns` - puts git_clone if check_verbose(args) - - # Copy the cnf-conformance.yml - yml_cp = `cp sample-cnfs/sample-coredns-cnf/cnf-conformance.yml #{current_dir}/#{CNF_DIR}/coredns` - puts yml_cp if check_verbose(args) - - # Parse the cnf-conformance.yml - config = cnf_conformance_yml - - if args.named.keys.includes? "deployment_name" - deployment_name = args.named["deployment_name"] - else - deployment_name = config.get("deployment_name").as_s - end - puts "deployment_name: #{deployment_name}" if check_verbose(args) - - if args.named.keys.includes? "helm_chart" - helm_chart = args.named["helm_chart"] - else - helm_chart = config.get("helm_chart").as_s - end - puts "helm_chart: #{helm_chart}" if check_verbose(args) - - begin - - helm = "#{current_dir}/#{TOOLS_DIR}/helm/linux-amd64/helm" - puts helm if check_verbose(args) - helm_install = `#{helm} install coredns #{helm_chart}` - puts helm_install if check_verbose(args) + sample_setup_args(sample_dir: "sample-cnfs/sample-coredns-cnf", args: args, verbose: true, wait_count: 0 ) +end +task "sample_coredns_with_wait_setup", ["helm_local_install"] do |_, args| + sample_setup_args(sample_dir: "sample-cnfs/sample-coredns-cnf", args: args, verbose: true) +end - # Retrieve the helm chart source - FileUtils.mkdir_p("#{current_dir}/#{CNF_DIR}/coredns/helm_chart") - helm_pull = `#{helm} pull #{helm_chart}` - puts helm_pull if check_verbose(args) - core_mv = `mv coredns-*.tgz #{current_dir}/#{CNF_DIR}/coredns/helm_chart` - puts core_mv if check_verbose(args) - tar = `cd #{current_dir}/#{CNF_DIR}/coredns/helm_chart; tar -xvf #{current_dir}/#{CNF_DIR}/coredns/helm_chart/coredns-*.tgz` - puts tar if check_verbose(args) - # coredns-coredns deployment must exist before running the next line (must already be installed) - # # TODO get deployment name from previous install - # manifest = `kubectl get deployment coredns-coredns -o yaml > #{CNF_DIR}/coredns/helm_chart/coredns/manifest.yml` - # puts manifest if check_verbose(args) - wait_for_install(deployment_name) - if helm_install.to_s.size > 0 && helm_pull.to_s.size > 0 - puts "Successfully setup coredns".colorize(:green) - end - ensure - cd = `cd #{current_dir}` - puts cd if check_verbose(args) - end +desc "Sets up sample CoreDNS CNF with source" +task "sample_coredns_source_setup", ["helm_local_install"] do |_, args| + sample_setup_args(sample_dir: "sample-cnfs/sample-coredns-cnf-source", args: args, verbose: true, wait_count: 0 ) end +desc "Sets up an alternate sample CoreDNS CNF" task "sample_coredns", ["helm_local_install"] do |_, args| - current_dir = FileUtils.pwd - puts current_dir if check_verbose(args) - - # Copy the chart into the cnfs directory and use the correct cnf-conformance.yml - chart_cp = `cp -r #{current_dir}/sample-cnfs/sample_coredns #{current_dir}/#{CNF_DIR}/` - puts chart_cp if check_verbose(args) - - # Parse the cnf-conformance.yml - config = cnf_conformance_yml - - if args.named.keys.includes? "deployment_name" - deployment_name = args.named["deployment_name"] - else - deployment_name = config.get("deployment_name").as_s - end - puts "deployment_name: #{deployment_name}" if check_verbose(args) - - if args.named.keys.includes? "helm_chart" - helm_chart = args.named["helm_chart"] - else - helm_chart = config.get("helm_chart").as_s - end - puts "helm_chart: #{helm_chart}" if check_verbose(args) - - if args.named.keys.includes? "helm_directory" - helm_directory = args.named["helm_directory"] - else - helm_directory = config.get("helm_directory").as_s - end - puts "helm_directory: #{helm_directory}" if check_verbose(args) - - begin - - helm = "#{current_dir}/#{TOOLS_DIR}/helm/linux-amd64/helm" - puts helm if check_verbose(args) - helm_install = `#{helm} install coredns #{helm_directory}` - puts helm_install if check_verbose(args) - - wait_for_install(deployment_name) - if helm_install.to_s.size > 0 - puts "Successfully setup sample_coredns".colorize(:green) - end - ensure - cd = `cd #{current_dir}` - puts cd if check_verbose(args) - end + puts "sample_coredns new setup" if check_verbose(args) + sample_setup_args(sample_dir: "sample-cnfs/sample_coredns", deploy_with_chart: false, args: args, verbose: true, wait_count: 0 ) end - +desc "Sets up a Bad helm CNF Setup" task "bad_helm_cnf_setup", ["helm_local_install"] do |_, args| - current_dir = FileUtils.pwd - puts current_dir if check_verbose(args) - - # Retrieve the cnf source - # TODO enable recloning/fetching etc - git_clone = `git clone https://github.com/coredns/coredns.git #{current_dir}/#{CNF_DIR}/bad_helm_coredns` - puts git_clone if check_verbose(args) - - # Copy the cnf-conformance.yml - yml_cp = `cp sample-cnfs/sample-bad_helm_coredns-cnf/cnf-conformance.yml #{current_dir}/#{CNF_DIR}/bad_helm_coredns` - puts yml_cp if check_verbose(args) - - # Parse the cnf-conformance.yml - config = cnf_conformance_yml - - if args.named.keys.includes? "deployment_name" - deployment_name = args.named["deployment_name"] - else - deployment_name = config.get("deployment_name").as_s - end - puts "deployment_name: #{deployment_name}" if check_verbose(args) - - if args.named.keys.includes? "helm_chart" - helm_chart = args.named["helm_chart"] - else - helm_chart = config.get("helm_chart").as_s - end - puts "helm_chart: #{helm_chart}" if check_verbose(args) - - - begin - - helm = "#{current_dir}/#{TOOLS_DIR}/helm/linux-amd64/helm" - puts helm if check_verbose(args) - # name must be dns compliant (no underscores) - helm_install = `#{helm} install bad-helm-coredns #{helm_chart}` - puts helm_install if check_verbose(args) - - - # Retrieve the helm chart source - FileUtils.mkdir_p("#{current_dir}/#{CNF_DIR}/bad_helm_coredns/helm_chart") - helm_pull = `#{helm} pull #{helm_chart}` - puts helm_pull if check_verbose(args) - core_mv = `mv coredns-*.tgz #{current_dir}/#{CNF_DIR}/bad_helm_coredns/helm_chart` - puts core_mv if check_verbose(args) - tar = `cd #{current_dir}/#{CNF_DIR}/bad_helm_coredns/helm_chart; tar -xvf #{current_dir}/#{CNF_DIR}/bad_helm_coredns/helm_chart/coredns-*.tgz` - puts tar if check_verbose(args) - - #sed command that changes helm chart to be bad - helm_sed = `sed -i s/"toYaml"/"sdfsdfsdf"/g #{current_dir}/#{CNF_DIR}/bad_helm_coredns/helm_chart/coredns/templates/deployment.yaml` - puts helm_sed if check_verbose(args) - - wait_for_install(deployment_name) - - if helm_install.to_s.size > 0 && helm_pull.to_s.size > 0 - puts "Successfully setup coredns".colorize(:green) - end - ensure - cd = `cd #{current_dir}` - puts cd if check_verbose(args) - end + puts "bad_helm_cnf_setup" if check_verbose(args) + sample_setup_args(sample_dir: "sample-cnfs/sample-bad_helm_coredns-cnf", deploy_with_chart: false, args: args, verbose: true, wait_count: 0 ) end task "sample_privileged_cnf_whitelisted_setup", ["helm_local_install"] do |_, args| - current_dir = FileUtils.pwd - puts current_dir if check_verbose(args) - - # Copy the chart into the cnfs directory and use the correct cnf-conformance.yml - chart_cp = `cp -r #{current_dir}/sample-cnfs/sample_privileged_cnf_setup_coredns #{current_dir}/#{CNF_DIR}/` - yml_mv = `mv #{current_dir}/#{CNF_DIR}/sample_privileged_cnf_setup_coredns/whitelisted-conformance.yml #{current_dir}/#{CNF_DIR}/sample_privileged_cnf_setup_coredns/cnf-conformance.yml` - puts chart_cp if check_verbose(args) - puts yml_mv if check_verbose(args) - - # Parse the cnf-conformance.yml - config = cnf_conformance_yml - - if args.named.keys.includes? "deployment_name" - deployment_name = args.named["deployment_name"] - else - deployment_name = config.get("deployment_name").as_s - end - puts "deployment_name: #{deployment_name}" if check_verbose(args) - - if args.named.keys.includes? "helm_chart" - helm_chart = args.named["helm_chart"] - else - helm_chart = config.get("helm_chart").as_s - end - puts "helm_chart: #{helm_chart}" if check_verbose(args) - - if args.named.keys.includes? "helm_directory" - helm_directory = args.named["helm_directory"] - else - helm_directory = config.get("helm_directory").as_s - end - puts "helm_directory: #{helm_directory}" if check_verbose(args) - - begin - - helm = "#{current_dir}/#{TOOLS_DIR}/helm/linux-amd64/helm" - puts helm if check_verbose(args) - helm_install = `#{helm} install privileged-coredns #{helm_directory}` - puts helm_install if check_verbose(args) - - wait_for_install(deployment_name) - if helm_install.to_s.size > 0 - puts "Successfully setup sample_privileged_cnf_whitelisted_setup".colorize(:green) - end - ensure - cd = `cd #{current_dir}` - puts cd if check_verbose(args) - end + puts "sample_privileged_cnf_whitelisted_setup" if check_verbose(args) + sample_setup_args(sample_dir: "sample-cnfs/sample_whitelisted_privileged_cnf", deploy_with_chart: false, args: args, verbose: true, wait_count: 0 ) end - task "sample_privileged_cnf_non_whitelisted_setup", ["helm_local_install"] do |_, args| - current_dir = FileUtils.pwd - puts current_dir if check_verbose(args) - - # Copy the chart into the cnfs directory and use the correct cnf-conformance.yml - chart_cp = `cp -r #{current_dir}/sample-cnfs/sample_privileged_cnf_setup_coredns #{current_dir}/#{CNF_DIR}/` - yml_mv = `mv #{current_dir}/#{CNF_DIR}/sample_privileged_cnf_setup_coredns/non-whitelisted-conformance.yml #{current_dir}/#{CNF_DIR}/sample_privileged_cnf_setup_coredns/cnf-conformance.yml` - puts chart_cp if check_verbose(args) - puts yml_mv if check_verbose(args) - - # Parse the cnf-conformance.yml - config = cnf_conformance_yml - - if args.named.keys.includes? "deployment_name" - deployment_name = args.named["deployment_name"] - else - deployment_name = config.get("deployment_name").as_s - end - puts "deployment_name: #{deployment_name}" if check_verbose(args) - - if args.named.keys.includes? "helm_chart" - helm_chart = args.named["helm_chart"] - else - helm_chart = config.get("helm_chart").as_s - end - puts "helm_chart: #{helm_chart}" if check_verbose(args) - - if args.named.keys.includes? "helm_directory" - helm_directory = args.named["helm_directory"] - else - helm_directory = config.get("helm_directory").as_s - end - puts "helm_directory: #{helm_directory}" if check_verbose(args) - - begin - - helm = "#{current_dir}/#{TOOLS_DIR}/helm/linux-amd64/helm" - puts helm if check_verbose(args) - helm_install = `#{helm} install privileged-coredns #{helm_directory}` - puts helm_install if check_verbose(args) - - wait_for_install(deployment_name) - if helm_install.to_s.size > 0 - puts "Successfully setup sample_privileged_cnf_non_whitelisted_setup".colorize(:green) - end - ensure - cd = `cd #{current_dir}` - puts cd if check_verbose(args) - end + puts "sample_privileged_cnf_non_whitelisted_setup" if check_verbose(args) + sample_setup_args(sample_dir: "sample-cnfs/sample_privileged_cnf", deploy_with_chart: false, args: args, verbose: true, wait_count: 0 ) end task "sample_coredns_bad_liveness", ["helm_local_install"] do |_, args| - current_dir = FileUtils.pwd - puts current_dir if check_verbose(args) - - # Copy the chart into the cnfs directory and use the correct cnf-conformance.yml - chart_cp = `cp -r #{current_dir}/sample-cnfs/sample_coredns_bad_liveness #{current_dir}/#{CNF_DIR}/` - puts chart_cp if check_verbose(args) - - # Parse the cnf-conformance.yml - config = cnf_conformance_yml - - if args.named.keys.includes? "deployment_name" - deployment_name = args.named["deployment_name"] - else - deployment_name = config.get("deployment_name").as_s - end - puts "deployment_name: #{deployment_name}" if check_verbose(args) - - if args.named.keys.includes? "helm_chart" - helm_chart = args.named["helm_chart"] - else - helm_chart = config.get("helm_chart").as_s - end - puts "helm_chart: #{helm_chart}" if check_verbose(args) - - if args.named.keys.includes? "helm_directory" - helm_directory = args.named["helm_directory"] - else - helm_directory = config.get("helm_directory").as_s - end - puts "helm_directory: #{helm_directory}" if check_verbose(args) - - begin - - helm = "#{current_dir}/#{TOOLS_DIR}/helm/linux-amd64/helm" - puts helm if check_verbose(args) - helm_install = `#{helm} install bad-liveness #{helm_directory}` - puts helm_install if check_verbose(args) - - wait_for_install(deployment_name) - if helm_install.to_s.size > 0 - puts "Successfully setup sample_coredns_bad_liveness".colorize(:green) - end - ensure - cd = `cd #{current_dir}` - puts cd if check_verbose(args) - end + puts "sample_coredns_bad_liveness" if check_verbose(args) + sample_setup_args(sample_dir: "sample-cnfs/sample_coredns_bad_liveness", deploy_with_chart: false, args: args, verbose: true, wait_count: 0 ) end - task "sample_coredns_cleanup" do |_, args| - current_dir = FileUtils.pwd - helm = "#{current_dir}/#{TOOLS_DIR}/helm/linux-amd64/helm" - puts helm if check_verbose(args) - helm_uninstall = `#{helm} uninstall coredns` - puts helm_uninstall if check_verbose(args) - rm = `rm -rf #{current_dir}/#{CNF_DIR}/coredns` - puts rm if check_verbose(args) + sample_cleanup(sample_dir: "sample-cnfs/sample-coredns-cnf", verbose: true) end - task "cleanup_sample_coredns" do |_, args| - current_dir = FileUtils.pwd - helm = "#{current_dir}/#{TOOLS_DIR}/helm/linux-amd64/helm" - puts helm if check_verbose(args) - helm_uninstall = `#{helm} uninstall coredns` - puts helm_uninstall if check_verbose(args) - rm = `rm -rf #{current_dir}/#{CNF_DIR}/sample_coredns` - puts rm if check_verbose(args) + sample_cleanup(sample_dir: "sample-cnfs/sample_coredns", verbose: true) end - task "bad_helm_cnf_cleanup" do |_, args| - current_dir = FileUtils.pwd - helm = "#{current_dir}/#{TOOLS_DIR}/helm/linux-amd64/helm" - puts helm if check_verbose(args) - helm_uninstall = `#{helm} uninstall bad-helm-coredns` - puts helm_uninstall if check_verbose(args) - rm = `rm -rf #{current_dir}/#{CNF_DIR}/bad_helm_coredns` - puts rm if check_verbose(args) + sample_cleanup(sample_dir: "sample-cnfs/sample-bad_helm_coredns-cnf", verbose: true) end task "sample_privileged_cnf_whitelisted_cleanup" do |_, args| - current_dir = FileUtils.pwd - helm = "#{current_dir}/#{TOOLS_DIR}/helm/linux-amd64/helm" - puts helm if check_verbose(args) - helm_uninstall = `#{helm} uninstall privileged-coredns` - puts helm_uninstall if check_verbose(args) - rm = `rm -rf #{current_dir}/#{CNF_DIR}/sample_privileged_cnf_setup_coredns` - puts rm if check_verbose(args) + sample_cleanup(sample_dir: "sample-cnfs/sample_whitelisted_privileged_cnf", verbose: true) end task "sample_privileged_cnf_non_whitelisted_cleanup" do |_, args| - current_dir = FileUtils.pwd - helm = "#{current_dir}/#{TOOLS_DIR}/helm/linux-amd64/helm" - puts helm if check_verbose(args) - helm_uninstall = `#{helm} uninstall privileged-coredns` - puts helm_uninstall if check_verbose(args) - rm = `rm -rf #{current_dir}/#{CNF_DIR}/sample_privileged_cnf_setup_coredns` - puts rm if check_verbose(args) + sample_cleanup(sample_dir: "sample-cnfs/sample_privileged_cnf", verbose: true) end task "sample_coredns_bad_liveness_cleanup" do |_, args| - current_dir = FileUtils.pwd - helm = "#{current_dir}/#{TOOLS_DIR}/helm/linux-amd64/helm" - puts helm if check_verbose(args) - helm_uninstall = `#{helm} uninstall bad-liveness` - puts helm_uninstall if check_verbose(args) - rm = `rm -rf #{current_dir}/#{CNF_DIR}/sample_coredns_bad_liveness` - puts rm if check_verbose(args) + sample_cleanup(sample_dir: "sample-cnfs/sample_coredns_bad_liveness", verbose: true) +end +task "sample_coredns_source_cleanup" do |_, args| + sample_cleanup(sample_dir: "sample-cnfs/sample-coredns-cnf-source", verbose: true) end diff --git a/src/tasks/sonobuoy_setup.cr b/src/tasks/sonobuoy_setup.cr index 1e17831f5..77720f181 100644 --- a/src/tasks/sonobuoy_setup.cr +++ b/src/tasks/sonobuoy_setup.cr @@ -3,15 +3,41 @@ require "file_utils" require "colorize" require "totem" require "./utils.cr" +require "http/client" desc "Sets up Sonobuoy in the K8s Cluster" task "install_sonobuoy" do |_, args| - response = String::Builder.new - Process.run("echo installing sonobuoy", shell: true) do |proc| - while line = proc.output.gets - response << line - puts "#{line}" if check_args(args) + #TODO: Fetch version dynamically + # k8s_version = HTTP::Client.get("https://storage.googleapis.com/kubernetes-release/release/stable.txt").body.chomp.split(".")[0..1].join(".").gsub("v", "") + k8s_version = "0.17.2" + puts k8s_version if check_verbose(args) + current_dir = FileUtils.pwd + puts current_dir if check_verbose(args) + unless Dir.exists?("#{current_dir}/#{TOOLS_DIR}/sonobuoy") + begin + puts "pwd? : #{current_dir}" if check_verbose(args) + puts "toolsdir : #{TOOLS_DIR}" if check_verbose(args) + puts "full path?: #{current_dir.to_s}/#{TOOLS_DIR}/sonobuoy" if check_verbose(args) + FileUtils.mkdir_p("#{current_dir}/#{TOOLS_DIR}/sonobuoy") + curl = `VERSION="#{k8s_version}" OS=linux ; curl -L "https://github.com/vmware-tanzu/sonobuoy/releases/download/v${VERSION}/sonobuoy_${VERSION}_${OS}_amd64.tar.gz" --output #{current_dir}/#{TOOLS_DIR}/sonobuoy/sonobuoy.tar.gz` + puts curl if check_verbose(args) + `tar -xzf #{current_dir}/#{TOOLS_DIR}/sonobuoy/sonobuoy.tar.gz -C #{current_dir}/#{TOOLS_DIR}/sonobuoy/ && \ + chmod +x #{current_dir}/#{TOOLS_DIR}/sonobuoy/sonobuoy && \ + rm #{current_dir}/#{TOOLS_DIR}/sonobuoy/sonobuoy.tar.gz` + sonobuoy = "#{current_dir}/#{TOOLS_DIR}/sonobuoy/sonobuoy" + puts sonobuoy if check_verbose(args) + puts `#{sonobuoy} version` if check_verbose(args) end end end +desc "Cleans up Sonobuoy" +task "sonobuoy_cleanup"do |_, args| + current_dir = FileUtils.pwd + sonobuoy = "#{current_dir}/#{TOOLS_DIR}/sonobuoy/sonobuoy" + delete = `#{sonobuoy} delete --wait` + puts delete if check_verbose(args) + rm = `rm -rf #{current_dir}/#{TOOLS_DIR}/sonobuoy` + puts rm if check_verbose(args) +end + diff --git a/src/tasks/utils.cr b/src/tasks/utils.cr index d01e1f8b7..26e388675 100644 --- a/src/tasks/utils.cr +++ b/src/tasks/utils.cr @@ -25,6 +25,14 @@ def cnf_conformance_yml Totem.from_file "./#{cnf_conformance}" end +def cnf_conformance_dir + cnf_conformance = `find cnfs/* -name "cnf-conformance.yml"`.split("\n")[0] + if cnf_conformance.empty? + raise "No cnf_conformance.yml found! Did you run the setup task?" + end + cnf_conformance.split("/")[-2] +end + def sample_conformance_yml(sample_dir) cnf_conformance = `find #{sample_dir}/* -name "cnf-conformance.yml"`.split("\n")[0] if cnf_conformance.empty? @@ -47,8 +55,9 @@ def wait_for_install(deployment_name, wait_count=180) second_count = second_count + 1 end end -def sample_setup_args(sample_dir, args, deploy_with_chart=true, verbose=false) - # # Parse the cnf-conformance.yml +def sample_setup_args(sample_dir, args, deploy_with_chart=true, verbose=false, wait_count=180) + puts "sample_setup_args" if verbose + config = sample_conformance_yml(sample_dir) if args.named.keys.includes? "release_name" @@ -82,21 +91,28 @@ def sample_setup_args(sample_dir, args, deploy_with_chart=true, verbose=false) if args.named.keys.includes? "git_clone_url" git_clone_url = "#{args.named["git_clone_url"]}" else - # TODO check type (any) before doing .as_s git_clone_url = "#{config.get("git_clone_url").as_s?}" end puts "git_clone_url: #{git_clone_url}" if verbose - sample_setup(sample_dir: sample_dir, release_name: release_name, deployment_name: deployment_name, helm_chart: helm_chart, helm_directory: helm_directory, git_clone_url: git_clone_url, deploy_with_chart: deploy_with_chart, verbose: verbose ) + sample_setup(sample_dir: sample_dir, release_name: release_name, deployment_name: deployment_name, helm_chart: helm_chart, helm_directory: helm_directory, git_clone_url: git_clone_url, deploy_with_chart: deploy_with_chart, verbose: verbose, wait_count: wait_count ) end -def sample_setup(sample_dir, release_name, deployment_name, helm_chart, helm_directory, git_clone_url="", deploy_with_chart=true, verbose=false) +def sample_destination_dir(sample_source_dir) + current_dir = FileUtils.pwd + "#{current_dir}/#{CNF_DIR}/#{short_sample_dir(sample_source_dir)}" +end + +def sample_setup(sample_dir, release_name, deployment_name, helm_chart, helm_directory, git_clone_url="", deploy_with_chart=true, verbose=false, wait_count=180) + puts "sample_setup" if verbose current_dir = FileUtils.pwd puts current_dir if verbose - destination_cnf_dir = "#{current_dir}/#{CNF_DIR}/#{short_sample_dir(sample_dir)}" + # destination_cnf_dir = "#{current_dir}/#{CNF_DIR}/#{short_sample_dir(sample_dir)}" + destination_cnf_dir = sample_destination_dir(sample_dir) + puts "destination_cnf_dir: #{destination_cnf_dir}" if verbose FileUtils.mkdir_p(destination_cnf_dir) # TODO enable recloning/fetching etc @@ -144,7 +160,7 @@ def sample_setup(sample_dir, release_name, deployment_name, helm_chart, helm_dir puts helm_install if verbose end - wait_for_install(deployment_name) + wait_for_install(deployment_name, wait_count) if helm_install.to_s.size > 0 # && helm_pull.to_s.size > 0 puts "Successfully setup #{release_name}".colorize(:green) end @@ -154,6 +170,11 @@ def sample_setup(sample_dir, release_name, deployment_name, helm_chart, helm_dir end end +def tools_helm + current_dir = FileUtils.pwd + helm = "#{current_dir}/#{TOOLS_DIR}/helm/linux-amd64/helm" +end + def sample_cleanup(sample_dir, verbose=true) config = sample_conformance_yml(sample_dir) release_name = config.get("release_name").as_s @@ -161,11 +182,13 @@ def sample_cleanup(sample_dir, verbose=true) current_dir = FileUtils.pwd helm = "#{current_dir}/#{TOOLS_DIR}/helm/linux-amd64/helm" puts helm if verbose - helm_uninstall = `#{helm} uninstall #{release_name}` - puts helm_uninstall if verbose destination_cnf_dir = "#{current_dir}/#{CNF_DIR}/#{short_sample_dir(sample_dir)}" rm = `rm -rf #{destination_cnf_dir}` puts rm if verbose + helm_uninstall = `#{helm} uninstall #{release_name}` + ret = $? + puts helm_uninstall if verbose + ret end def chart_name(helm_chart_repo)