From d3f81d5c4a186878ad12c0b53a54c5c237090526 Mon Sep 17 00:00:00 2001 From: okozachenko Date: Sat, 18 Jul 2020 00:31:46 +0300 Subject: [PATCH] Add node-labeler helm chart Change-Id: I286c283272a86eff81b479a9dad29eb2d958fecc --- charts/node-labeler/Chart.yaml | 11 +++++ charts/node-labeler/templates/_helpers.tpl | 41 +++++++++++++++++++ .../node-labeler/templates/clusterrole.yaml | 15 +++++++ .../templates/clusterrolebinding.yaml | 15 +++++++ charts/node-labeler/templates/daemonset.yaml | 41 +++++++++++++++++++ .../templates/serviceaccount.yaml | 8 ++++ charts/node-labeler/values.yaml | 1 + playbooks/node-labeler/pre.yaml | 22 ++++++++++ playbooks/node-labeler/run.yaml | 40 ++++++++++++++++++ zuul.d/project.yaml | 18 ++++++++ 10 files changed, 212 insertions(+) create mode 100755 charts/node-labeler/Chart.yaml create mode 100755 charts/node-labeler/templates/_helpers.tpl create mode 100755 charts/node-labeler/templates/clusterrole.yaml create mode 100755 charts/node-labeler/templates/clusterrolebinding.yaml create mode 100755 charts/node-labeler/templates/daemonset.yaml create mode 100755 charts/node-labeler/templates/serviceaccount.yaml create mode 100755 charts/node-labeler/values.yaml create mode 100755 playbooks/node-labeler/pre.yaml create mode 100755 playbooks/node-labeler/run.yaml create mode 100755 zuul.d/project.yaml diff --git a/charts/node-labeler/Chart.yaml b/charts/node-labeler/Chart.yaml new file mode 100755 index 0000000..6e3a4e4 --- /dev/null +++ b/charts/node-labeler/Chart.yaml @@ -0,0 +1,11 @@ +--- +apiVersion: v1 +name: node-labeler +version: 0.5.3 +description: Node labeler for Kubernetes +home: https://github.com/vexxhost/node-labeler +maintainers: +- name: Mohammed Naser + email: mnaser@vexxhost.com + url: https://github.com/mnaser +appVersion: v0.1.1 diff --git a/charts/node-labeler/templates/_helpers.tpl b/charts/node-labeler/templates/_helpers.tpl new file mode 100755 index 0000000..16111eb --- /dev/null +++ b/charts/node-labeler/templates/_helpers.tpl @@ -0,0 +1,41 @@ +{{/* vim: set filetype=mustache: */}} +{{/* +Expand the name of the chart. +*/}} +{{- define "node-labeler.name" -}} +{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}} +{{- end -}} + +{{/* +Create a default fully qualified app name. +We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). +If release name contains chart name it will be used as a full name. +*/}} +{{- define "node-labeler.fullname" -}} +{{- if .Values.fullnameOverride -}} +{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}} +{{- else -}} +{{- $name := default .Chart.Name .Values.nameOverride -}} +{{- if contains $name .Release.Name -}} +{{- .Release.Name | trunc 63 | trimSuffix "-" -}} +{{- else -}} +{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}} +{{- end -}} +{{- end -}} +{{- end -}} + +{{/* +Generate basic labels +*/}} +{{- define "node-labeler.labels" }} +app.kubernetes.io/name: {{ include "node-labeler.fullname" . }} +app.kubernetes.io/instance: {{ include "node-labeler.chart" . }} +app.kubernetes.io/version: {{ .Chart.Version }} +{{- end }} + +{{/* +Create chart name and version as used by the chart label. +*/}} +{{- define "node-labeler.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}} +{{- end -}} \ No newline at end of file diff --git a/charts/node-labeler/templates/clusterrole.yaml b/charts/node-labeler/templates/clusterrole.yaml new file mode 100755 index 0000000..f7bb104 --- /dev/null +++ b/charts/node-labeler/templates/clusterrole.yaml @@ -0,0 +1,15 @@ +--- +kind: ClusterRole +apiVersion: rbac.authorization.k8s.io/v1beta1 +metadata: + name: {{ include "node-labeler.fullname" . }} + labels: +{{ include "node-labeler.labels" . | indent 4 }} +rules: +- apiGroups: + - "" + resources: + - nodes + verbs: + - get + - patch \ No newline at end of file diff --git a/charts/node-labeler/templates/clusterrolebinding.yaml b/charts/node-labeler/templates/clusterrolebinding.yaml new file mode 100755 index 0000000..3c1f08f --- /dev/null +++ b/charts/node-labeler/templates/clusterrolebinding.yaml @@ -0,0 +1,15 @@ +--- +kind: ClusterRoleBinding +apiVersion: rbac.authorization.k8s.io/v1beta1 +metadata: + name: {{ include "node-labeler.fullname" . }} + labels: +{{ include "node-labeler.labels" . | indent 4 }} +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: ClusterRole + name: {{ include "node-labeler.fullname" . }} +subjects: +- kind: ServiceAccount + name: {{ include "node-labeler.fullname" . }} + namespace: {{ .Release.Namespace }} \ No newline at end of file diff --git a/charts/node-labeler/templates/daemonset.yaml b/charts/node-labeler/templates/daemonset.yaml new file mode 100755 index 0000000..f9d8369 --- /dev/null +++ b/charts/node-labeler/templates/daemonset.yaml @@ -0,0 +1,41 @@ +--- +apiVersion: apps/v1 +kind: DaemonSet +metadata: + name: {{ include "node-labeler.fullname" . }} + namespace: {{ .Release.Namespace }} + labels: +{{ include "node-labeler.labels" . | indent 4 }} +spec: + selector: + matchLabels: +{{ include "node-labeler.labels" . | indent 6 }} + template: + metadata: + labels: +{{ include "node-labeler.labels" . | indent 8 }} + spec: + tolerations: + - operator: Exists + effect: NoSchedule + serviceAccountName: {{ include "node-labeler.fullname" . }} + containers: + - name: node-labeler + image: vexxhost/node-labeler:latest + resources: + requests: + cpu: "100m" + memory: "50Mi" + limits: + cpu: "100m" + memory: "50Mi" + env: + - name: NODE + valueFrom: + fieldRef: + fieldPath: spec.nodeName + nodeSelector: + kubernetes.io/arch: amd64 + updateStrategy: + rollingUpdate: + maxUnavailable: 10% \ No newline at end of file diff --git a/charts/node-labeler/templates/serviceaccount.yaml b/charts/node-labeler/templates/serviceaccount.yaml new file mode 100755 index 0000000..c7fbb46 --- /dev/null +++ b/charts/node-labeler/templates/serviceaccount.yaml @@ -0,0 +1,8 @@ +--- +apiVersion: v1 +kind: ServiceAccount +metadata: + name: {{ include "node-labeler.fullname" . }} + namespace: {{ .Release.Namespace }} + labels: +{{ include "node-labeler.labels" . | indent 4 }} \ No newline at end of file diff --git a/charts/node-labeler/values.yaml b/charts/node-labeler/values.yaml new file mode 100755 index 0000000..ed97d53 --- /dev/null +++ b/charts/node-labeler/values.yaml @@ -0,0 +1 @@ +--- diff --git a/playbooks/node-labeler/pre.yaml b/playbooks/node-labeler/pre.yaml new file mode 100755 index 0000000..5b2d6a9 --- /dev/null +++ b/playbooks/node-labeler/pre.yaml @@ -0,0 +1,22 @@ +--- +# Copyright (c) 2020 VEXXHOST, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +# implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +- hosts: all + roles: + - name: helm-template + helm_release_name: node-labeler + helm_chart: ./charts/node-labeler + helm_values_file: ./charts/node-labeler/values.yaml \ No newline at end of file diff --git a/playbooks/node-labeler/run.yaml b/playbooks/node-labeler/run.yaml new file mode 100755 index 0000000..c8d2633 --- /dev/null +++ b/playbooks/node-labeler/run.yaml @@ -0,0 +1,40 @@ +--- +# Copyright (c) 2020 VEXXHOST, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +# implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +- hosts: all + tasks: + - name: Get node name + shell: kubectl get nodes -o=name | head -1 + register: _node_name + until: _node_name is success + retries: 60 + delay: 5 + failed_when: | + {{ _node_name.stdout_lines | length == 0 }} + + - name: Get the node labels + shell: kubectl label {{ _node_name.stdout }} --list + register: _node_labels + + - name: Check the label node.vexxhost.com/vendor is set + fail: + msg: node.vexxhost.com/vendor label is missing. + when: (_node_labels.stdout is search('node.vexxhost.com/vendor'))==False + + - name: Check the label node.vexxhost.com/product is set + fail: + msg: node.vexxhost.com/product label is missing. + when: (_node_labels.stdout is search('node.vexxhost.com/product'))==False diff --git a/zuul.d/project.yaml b/zuul.d/project.yaml new file mode 100755 index 0000000..ad62971 --- /dev/null +++ b/zuul.d/project.yaml @@ -0,0 +1,18 @@ +- job: + name: helm-charts:node-labeler + parent: apply-helm-charts + pre-run: playbooks/node-labeler/pre.yaml + run: playbooks/node-labeler/run.yaml + vars: + minikube_dns_resolvers: [1.1.1.1, 8.8.8.8] + collect_kubernetes_logs_namespace: kube-system + +- project: + check: + jobs: + - chart-testing-lint + - helm-charts:node-labeler + gate: + jobs: + - chart-testing-lint + - helm-charts:node-labeler