Skip to content

Commit

Permalink
NAS-118930 / 23.10 / Improve/Refactor Common Library (truenas#917)
Browse files Browse the repository at this point in the history
* fix

* fix

* some more

* somefixs

* whops

* initial structure

* finish up configmap

* secret class

* runtest secret

* move files arround

* ignore

* make clear on call template that need root context

* imagePullSecret (minus targetSelector)

* move out of the way

* clean up comment

* deployment basic spec

* daemonset basic spec

* statefulset spec

* split file

* docs

* update values

* job spec

* job docs

* cronJob basic spec

* job in cron test

* add common version

* podsepc

* whoopsis

* selectorlabels and pod metadata

* job and cron pod metadata

* update docs

* consistent order

* get ready for pod

* first targetSelector

* remove todo

* update docs

* add hostnet and enableservicelinks

* update selector logic

* update docs

* add tests for restartpolicy

* schedulerName

* priorityclassname

* hostname

* termperiodsec

* nodeselector

* add fail case

* host aliases

* dns policy

* dns config

* tolerations

* serviceaccoutn class, spawner, saname selector

* add pod todo

* update some tests

* add runtimeclassname

* controllers -> workload and plurar to singular

* require at least 1 primary on enabled SAs

* fix script

* remove wrong comment

* update naming scheme

* update rbac values ref

* rbac docs

* rbac's

* append short name, for future use

* update comments

* initial service wireframe

* shorten line

* simplify labels and update tests

* service selectors

* simplify error messages

* finish clusterIP type

* loadbalancer

* noedport

* externalname

* external ip

* update service

* fix highlighting

* session affinity

* add comment

* update comments

* service ports

* fix indentation

* externalname can have no ports

* fixup externalIP

* add pvc class and spawner and tests

* add nfs and emptyDir vols

* example

* extend docs a bit

* not create pvc if existing claim is set

* helm... you are dumb really. how this fixes an unrelated test

* add configmap

* add secret vol

* add pvc vol

* add hostpath

* finish volumes

* initial podsec

* podsec context with some todo's to check

* automatic sysctls

* remove todo

* update doc struct

* split docs

* split service docs

* initial container plumbing

* fix tests

* fix test

* rename to class

* command and args

* termination

* add lifecycle

* int value from tpl

* another case

* fix service protocol tpl

* update readme

* ports

* update todo

* cleanup values a bit

* only add sysctl when port is bellow 1024

* whops, thats a different range

* update avlue

* move some old docs to the "to be deleted" dir

* externalinteface validation

* update an error message and apply externalinterface annotations to workloads

* external interfaces

* TZ - TIMEZONE

* update rdoc

* reduce code duple

* device vol type

* initial certificate plumbing

* update comments

* finish secret creation of certificate

* cert dosc

* volumeMounts

* scale certs

* doc

* add tests for volMounts

* values updates

* update todo

* add test case

* remove some todo

* update todos

* vct

* remove tdoo

* restore default

* rename function

* make selectorlabels a bit better

* trim

* some cleanup

* update some ci values

* update ci

* rollingup defaults

* rename dir

* fix nil pointers

* check the same strategy var

* whops

* fix tests

* typo

* not a good day for copy paste

* move check

* move another check

* fix some tests for upcoming probes

* one mroe

* split docs

* add default probes for `main` and docs

* add probes and some ci testruns

* whops

* fix an edge case

* add an error for edge case

* runtests

* runtest updaets

* update

* check if podvalues exist first

* force types

* force only one of the 2

* quote labels and annotaions values

* job/cron have auto gen selectors

* remove false test

* fix maxsureg

* fix end

* different fix

* fix some tests

* fix rollUp

* try to fix 3.9.4 helm

* move file to helpers

* use capital types in probes and lifecycle

* Revert "use capital types in probes and lifecycle"

This reverts commit 380ebd5.

* typo

* use lowercase for protocol everywhere

* rbac runtest

* prune old

* add resources

* add resources

* fix rbc

* fix sa naming in pod

* fix test

* 44 suppl group on gpu

* remove todo

* extract function in another file

* whops

* add securityContext implementation

* add fail cases

* add rest of the tests

* remove todo

* envFrom

* minify

* env list

* add env

* add envdupe check tests

* add fixed envs

* replace containers with callers

* add callers

* add initContainer

* add init run test

* reset default test val

* add  name tests

* add some more tests

* rename

* validate workload type only if enabled

* lint fix for 3.9.4

* add tpl on init enabled

* whops

* fix init

* echo

* echo

* args...

* list

* comment out disabled persistences

* fix some typos and improve resources `requests` requirement

* improve docs a bit

* require name,description,version,type

* add some wording regarding what Helm Template column means

* add title as requirement

* remove scheduler

* remove priority class name

* remove nfs + externalIP

* remove LB

* remove STS & VCT

* fix a test

* remove nodeselector

* remove DS

* remove pvc

* remove todo

* conditionally print the type, as we might want to use the template to select all objects inthe chart

* add some docs

* docs for notes

* add `tls.` in the certificate secret, according to k8s docs

* add some basic docs around the rest of the options

* clean values.yaml

* catch an edge case

* remove externalName

* set autmountSA on SA to false

* add note about the automountSA
  • Loading branch information
stavros-k authored Feb 20, 2023
1 parent fcf667f commit 5b1abdd
Show file tree
Hide file tree
Showing 258 changed files with 21,205 additions and 0 deletions.
39 changes: 39 additions & 0 deletions .github/ct-install-config/chart_schema.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: str(required=True)
title: str(required=True)
description: str(required=True)
version: str(required=True)
type: str(required=True)
kubeVersion: str()
apiVersion: str()
appVersion: any(str(), num())
upstream_version: any(str(), num(), required=False)
home: str()
icon: str()
sources: list(str(), required=False)
dependencies: list(include('dependency'), required=False)
deprecated: bool(required=False)
engine: str(required=False)
condition: str(required=False)
keywords: list(str(), required=False)
tags: str(required=False)
maintainers: list(include('maintainer'))
annotations: map(str(), str(), required=False)
---
maintainer:
name: str()
email: str(required=False)
url: str(required=True)
---
dependency:
name: str()
repository: str()
version: str()
condition: str(required=False)
tags: list(str(), required=False)
import-values: any(list(str()), list(include('import-value')), required=False)
enabled: bool(required=False)
alias: str(required=False)
---
import-value:
child: str()
parent: str()
8 changes: 8 additions & 0 deletions .github/ct-install-config/ct-install.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
remote: origin
target-branch: master
helm-extra-args: --timeout 600s --debug
chart-yaml-schema: .github/ct-install-config/chart_schema.yaml
chart-dirs:
- library
- charts
excluded-charts: []
7 changes: 7 additions & 0 deletions .github/ct-install-config/ct-lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
remote: origin
target-branch: master
helm-extra-args: --timeout 600s --debug
chart-yaml-schema: .github/ct-install-config/chart_schema.yaml
chart-dirs:
- library
excluded-charts: []
42 changes: 42 additions & 0 deletions .github/ct-install-config/lint-conf.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---
rules:
braces:
min-spaces-inside: 0
max-spaces-inside: 0
min-spaces-inside-empty: -1
max-spaces-inside-empty: -1
brackets:
min-spaces-inside: 0
max-spaces-inside: 0
min-spaces-inside-empty: -1
max-spaces-inside-empty: -1
colons:
max-spaces-before: 0
max-spaces-after: 1
commas:
max-spaces-before: 0
min-spaces-after: 1
max-spaces-after: 1
comments:
require-starting-space: true
min-spaces-from-content: 2
document-end: disable
document-start: disable # No --- to start a file
empty-lines:
max: 2
max-start: 0
max-end: 0
hyphens:
max-spaces-after: 1
indentation:
spaces: consistent
indent-sequences: whatever # - list indentation will handle both indentation and without
check-multi-line-strings: false
key-duplicates: enable
line-length: disable # Lines can be any length
new-line-at-end-of-file: enable
new-lines:
type: unix
trailing-spaces: enable
truthy:
level: warning
196 changes: 196 additions & 0 deletions .github/workflows/common_library_tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
name: Common Library Tests

on:
pull_request:
paths:
- library/**
- .github/workflows/common_library_tests.yaml

jobs:
lint:
name: Lint Common
runs-on: ubuntu-22.04
strategy:
fail-fast: false
matrix:
helm-version:
- v3.9.4
- v3.10.3
- v3.11.1
steps:
- name: Checkout
uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b # tag=v3
with:
fetch-depth: 1

- name: Install Helm
uses: azure/setup-helm@5119fcb9089d432beecbf79bb2c7915207344b78 # tag=v3
with:
version: ${{ matrix.helm-version }}

- uses: actions/setup-python@2c3dd9e7e29afd70cc0950079bde6c979d1f69f9 # tag=v4
with:
python-version: "3.10"

- name: Set up chart-testing
uses: helm/chart-testing-action@afea100a513515fbd68b0e72a7bb0ae34cb62aec # tag=v2.3.1

- name: Run chart-testing (lint)
id: lint
run: |
ct lint --config .github/ct-install-config/ct-lint.yaml \
--lint-conf .github/ct-install-config/lint-conf.yaml \
--charts library/common-test \
--debug
unittest:
needs:
- lint
name: Unit Tests
runs-on: ubuntu-22.04
env:
helmUnitVersion: 0.2.11
strategy:
fail-fast: false
matrix:
helm-version:
- v3.9.4
- v3.10.3
- v3.11.1
steps:
- name: Checkout
uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b # tag=v3
with:
fetch-depth: 1

- name: Install Helm
uses: azure/setup-helm@f382f75448129b3be48f8121b9857be18d815a82 # tag=v3
with:
version: ${{ matrix.helm-version }}

- name: Run Unit-tests
shell: bash
run: |
# Retry helm plugin install
helm plugin install https://github.com/quintush/helm-unittest --version v${helmUnitVersion} || \
helm plugin install https://github.com/quintush/helm-unittest --version v${helmUnitVersion} || \
helm plugin install https://github.com/quintush/helm-unittest --version v${helmUnitVersion} || \
helm plugin install https://github.com/quintush/helm-unittest --version v${helmUnitVersion}
# Run tests
cd library/common-test/
helm dependency update
helm unittest --helm3 -f "tests/*/*.yaml" .
install:
needs:
- lint
name: Install Charts
runs-on: ubuntu-22.04
strategy:
fail-fast: false
matrix:
# We run tests on k3s version of latest SCALE release, SCALE nightly and manually defined "latest"
k3s-version:
- v1.25.3+k3s1
# We run tests on Helm version of latest SCALE release, SCALE nightly and manually defined "latest"
helm-version:
- v3.11.1
values:
- basic-values.yaml
- configmap-values.yaml
- secrets-values.yaml
- imagePullSecret-values.yaml
- job-values.yaml
- cron-values.yaml
- persistence-values.yaml
- rbac-values.yaml
- init-values.yaml

steps:
- name: Checkout
uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b # tag=v3
with:
fetch-depth: 1

- name: Install Helm
uses: azure/setup-helm@f382f75448129b3be48f8121b9857be18d815a82 # tag=v3
with:
version: ${{ matrix.helm-version }}

- uses: actions/setup-python@2c3dd9e7e29afd70cc0950079bde6c979d1f69f9 # tag=v4
with:
python-version: "3.10"

- name: Set up chart-testing
uses: helm/chart-testing-action@afea100a513515fbd68b0e72a7bb0ae34cb62aec # tag=v2.3.1

- name: Create k3d cluster - Attempt 1/3
continue-on-error: true
id: createc1
uses: nolar/setup-k3d-k3s@293b8e5822a20bc0d5bcdd4826f1a665e72aba96 # tag=v1.0.9
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
version: ${{ matrix.k3s-version }}
# Flags found here https://github.com/k3d-io/k3d
k3d-args: --k3s-arg --disable=metrics-server@server:*

- name: Wait 10 second to retry
if: steps.createc1.outcome=='failure'
run: |
sleep 10
- name: Create k3d cluster - Attempt 2/3
continue-on-error: true
if: steps.createc1.outcome=='failure'
id: createc2
uses: nolar/setup-k3d-k3s@293b8e5822a20bc0d5bcdd4826f1a665e72aba96 # tag=v1.0.9
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
version: ${{ matrix.k3s-version }}
# Flags found here https://github.com/k3d-io/k3d
k3d-args: --k3s-arg --disable=metrics-server@server:*

- name: Wait 10 second to retry
if: steps.createc2.outcome=='failure'
run: |
sleep 10
- name: Create k3d cluster - Attempt 3/3
id: createc3
if: steps.createc2.outcome=='failure'
uses: nolar/setup-k3d-k3s@293b8e5822a20bc0d5bcdd4826f1a665e72aba96 # tag=v1.0.9
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
version: ${{ matrix.k3s-version }}
# Flags found here https://github.com/k3d-io/k3d
k3d-args: --k3s-arg --disable=metrics-server@server:*

# Install Kail to grab logs from tests, as there are cases ct-install fail to output logs
- name: Install Kail
run: |
export KAIL_VERSION=v0.16.1
wget https://github.com/boz/kail/releases/download/${KAIL_VERSION}/kail_${KAIL_VERSION}_linux_amd64.tar.gz
tar -xvzf kail_${KAIL_VERSION}_linux_amd64.tar.gz
chmod +x kail
- name: Run chart-testing (install)
run: |
# Move all ci values on a temp location (or skip if already moved from another matrix job)
mv library/common-test/ci library/common-test/runtests || echo "Nothing to move"
# Move one values.yaml to the correct location to run the test
mv -f library/common-test/runtests/${{ matrix.values }} library/common-test/values.yaml
# Stat kail on the background to grab logs from tests
./kail --ignore-ns kube-system >> /tmp/output.log &
# Actually run the test
ct install --config .github/ct-install-config/ct-install.yaml \
--charts library/common-test \
--debug || (echo -e "\n\n--===PODLOGS===--\n\n" && \
cat /tmp/output.log && \
rm -f /tmp/output.log && exit 1)
kill $!
echo -e "\n\n--===PODLOGS===--\n\n"
cat /tmp/output.log
rm -f /tmp/output.log
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,6 @@ npm-debug.log
tests/artifacts/
tests/test-report.txt
tests/test-report.xml
__snapshot__/
library/common-test/Chart.lock
library/common-test/charts
10 changes: 10 additions & 0 deletions .markdownlint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# https://github.com/DavidAnson/markdownlint/blob/main/doc/Rules.md#md033
# Do not warn for "Inline HTML"
MD033: false

# https://github.com/DavidAnson/markdownlint/blob/v0.26.2/doc/Rules.md#md024
# Multiple headings with the same content
MD024: false

MD013:
line_length: 300
33 changes: 33 additions & 0 deletions helm_template_common.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/bash

chart_path=library/common-test

if [ ! $1 == "template" ]; then
if [ $1 == "-f" ] && [ ! -z $2 ]; then
extra_args=("-f" "$chart_path/ci/$2")
fi
fi

function cleanup {
if [ -d "$chart_path/charts" ]; then
echo "🧹 Cleaning up charts..."
rm -r "$chart_path/charts"
rm "$chart_path/Chart.lock"
fi
}

cleanup

echo "Building common..."
helm dependency update "$chart_path"

if [ $1 == "template" ]; then
echo "🧪 Running <helm template ./$chart_path"
helm template -f "$chart_path/default-values.yaml" "./$chart_path" --debug
else
echo "🏁 Running <helm install --dry-run --debug common-test ${extra_args[@]} ./$chart_path"
helm install --dry-run --debug common-test "${extra_args[@]}" "./$chart_path"
fi
helm lint "./$chart_path"

cleanup
17 changes: 17 additions & 0 deletions library/common-test/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: common-test
title: Common Library Chart Testing
version: 1.0.0
apiVersion: v2
appVersion: v1.0.0
kubeVersion: '>=1.16.0-0'
description: A chart for the common library chart-testing
home: http://localhost
type: application
icon: https://localhost/icon
dependencies:
- name: common
repository: file://../common/1.0.0
version: ~1.0.0
maintainers:
- name: truenas
url: https://www.truenas.com/
Loading

0 comments on commit 5b1abdd

Please sign in to comment.