Skip to content

Commit ae2f3e9

Browse files
jehoMaurice Faber
jeho
and
Maurice Faber
authored
feat: downgrade knative-serving (#257)
* feat: automated schema fetching and packing, added k8s v1.19 * fix: validate-templates now correct exit code, bash tests robust * fix: docker secret auth with username prefix * fix: now alphasorting arrays before toJson to avoid diff [ci skip] Co-authored-by: Maurice Faber <[email protected]>
1 parent a11cacf commit ae2f3e9

23 files changed

+81
-38
lines changed

.demo/env/clusters.yaml

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ clouds:
66
enabled: false
77
apiName: eks_otomi-cloud_eu-central-1_otomi-eks-demo
88
apiServer: 1.1.1.1
9-
k8sVersion: '1.16'
9+
k8sVersion: '1.17'
1010
otomiVersion: 'master'
1111
region: eu-central-1
1212
google:
@@ -16,7 +16,7 @@ clouds:
1616
enabled: true
1717
apiName: gke_otomi-cloud_europe-west4_otomi-gke-demo
1818
apiServer: 1.1.1.1
19-
k8sVersion: '1.17'
19+
k8sVersion: '1.18'
2020
otomiVersion: 'master'
2121
region: europe-west4
2222
azure:
@@ -26,7 +26,7 @@ clouds:
2626
enabled: false
2727
apiName: aks_otomi-cloud_westeurope_otomi-aks-demo
2828
apiServer: 1.1.1.1
29-
k8sVersion: '1.17'
29+
k8sVersion: '1.18'
3030
otomiVersion: 'master'
3131
region: westeurope
3232
onprem:
@@ -37,7 +37,7 @@ clouds:
3737
dnsProvider: google
3838
apiName: onprem_otomi-cloud
3939
apiServer: 1.1.1.1
40-
k8sVersion: '1.18'
40+
k8sVersion: '1.19'
4141
otomiVersion: 'master'
4242
region: local
4343
entrypoint: 1.1.1.1

bin/gen-schemas.sh

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/bin/bash -xe
2+
3+
# This script uses openapi2jsonschema to generate a set of JSON schemas for
4+
# the specified Kubernetes versions in different flavours:
5+
#
6+
# X.Y.Z - URL referenced based on the specified GitHub repository
7+
# X.Y.Z-standalone - de-referenced schemas, more useful as standalone documents
8+
# X.Y.Z-standalone-strict - de-referenced schemas, more useful as standalone documents, additionalProperties disallowed
9+
# X.Y.Z-local - relative references, useful to avoid the network dependency
10+
11+
declare -a arr=(
12+
# v1.19.6
13+
# v1.18.14
14+
v1.17.16
15+
)
16+
17+
readonly tmp_path=$(mktemp -d)
18+
readonly schemas_path=$PWD/schemas
19+
20+
cd $tmp_path
21+
for version in "${arr[@]}"; do
22+
schema=https://raw.githubusercontent.com/kubernetes/kubernetes/${version}/api/openapi-spec/swagger.json
23+
prefix=https://kubernetesjsonschema.dev/${version}/_definitions.JSON
24+
out_version=${version%.*}
25+
26+
# openapi2jsonschema -o "${out_version}-standalone-strict" --expanded --kubernetes --stand-alone --strict "${schema}"
27+
openapi2jsonschema -o "${out_version}-standalone" --expanded --kubernetes --stand-alone "${schema}"
28+
# openapi2jsonschema -o "${out_version}-local" --expanded --kubernetes "${schema}"
29+
# openapi2jsonschema -o "${out_version}" --expanded --kubernetes --prefix "${prefix}" "${schema}"
30+
# openapi2jsonschema -o "${out_version}-standalone-strict" --kubernetes --stand-alone --strict "${schema}"
31+
openapi2jsonschema -o "${out_version}-standalone" --kubernetes --stand-alone "${schema}"
32+
# openapi2jsonschema -o "${out_version}-local" --kubernetes "${schema}"
33+
# openapi2jsonschema -o "${out_version}" --kubernetes --prefix "${prefix}" "${schema}"
34+
35+
tar -zcvf ${out_version}-standalone.tar.gz ${out_version}-standalone
36+
mv *.tar.gz $schemas_path/
37+
rm -rf ${out_version}*
38+
done
39+
cd -

bin/hooks/pre-commit

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#!/bin/sh
22

33
echo "Don't commit directly via git. Use 'otomi commit'."
4-
exit 1
4+
exit 1

bin/otomi

+4-4
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ set +e
4848
customer=$(customer_name || $CUSTOMER || "unknown")
4949
set -e
5050
cmd_image=''
51-
docker_terminal_params='-ti'
51+
docker_terminal_params='-t'
5252
helm_config=''
5353
readme_url='https://github.com/redkubes/otomi-core'
5454

@@ -283,7 +283,7 @@ function execute() {
283283
check_sops_file
284284
check_kube_context=0
285285
evaluate_secrets
286-
if [ "$@" != '' ]; then
286+
if [[ "$@" != '' ]]; then
287287
for f in $@; do
288288
echo "Decrypting $f"
289289
drun helm secrets dec ./env/$f >/dev/null
@@ -306,7 +306,7 @@ function execute() {
306306
check_sops_file
307307
check_kube_context=0
308308
evaluate_secrets
309-
if [ "$@" != '' ]; then
309+
if [[ "$@" != '' ]]; then
310310
for f in $@; do
311311
echo "Encrypting $f"
312312
drun helm secrets enc ./env/$f >/dev/null
@@ -349,7 +349,7 @@ function execute() {
349349
drun bin/test.sh
350350
;;
351351
validate-templates)
352-
if [ "$@" != '' ]; then
352+
if [[ "$@" != '' ]]; then
353353
validate_cluster_env
354354
fi
355355
check_kube_context=0

bin/validate-templates.sh

+18-16
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,32 @@
33
[ "$CI" != "" ] && set -e
44
set -uo pipefail
55

6-
schemaOutputPath="/tmp/otomi/kubernetes-json-schema/master"
6+
schemaOutputPath="/tmp/otomi/kubernetes-json-schema"
77
outputPath="/tmp/otomi/generated-crd-schemas"
88
schemasBundleFile="$outputPath/all.json"
99
k8sResourcesPath="/tmp/otomi/kubeval-fixtures"
1010
extractCrdSchemaJQFile=$(mktemp -u)
11-
exitcode=1
11+
exitcode=0
1212

1313
. bin/common.sh
1414

15+
readonly k8s_version="v$(get_k8s_version)"
16+
1517
cleanup() {
1618
[ $exitcode -eq 0 ] && echo "Validation Success" || echo "Validation Failed"
1719
rm -rf $extractCrdSchemaJQFile
18-
rm -rf $k8sResourcesPath $outputPath $schemaOutputPath
20+
rm -rf $k8sResourcesPath -rf $outputPath $schemaOutputPath
1921
exit $exitcode
2022
}
2123
trap cleanup EXIT ERR
2224

2325
run_setup() {
24-
exitcode=1
25-
local version="v$(get_k8s_version).0"
2626
rm -rf $k8sResourcesPath $outputPath $schemaOutputPath
2727
mkdir -p $k8sResourcesPath $outputPath $schemaOutputPath
2828
echo "" >$schemasBundleFile
2929
# use standalone schemas
30-
tar -xzf "schemas/${version}-standalone.tar.gz" -C $schemaOutputPath
31-
tar -xzf "schemas/generated-crd-schemas.tar.gz" -C "$schemaOutputPath/$version-standalone"
30+
tar -xzf "schemas/$k8s_version-standalone.tar.gz" -C "$schemaOutputPath/"
31+
tar -xzf "schemas/generated-crd-schemas.tar.gz" -C "$schemaOutputPath/$k8s_version-standalone"
3232

3333
# loop over .spec.versions[] and generate one file for each version
3434
cat <<'EOF' >$extractCrdSchemaJQFile
@@ -66,11 +66,10 @@ process_crd() {
6666
}
6767

6868
validate_templates() {
69-
local version="v$(get_k8s_version).0"
7069

7170
run_setup
7271
# generate_manifests
73-
echo "Generating Kubernetes ${version} Manifests for ${CLOUD}-${CLUSTER}."
72+
echo "Generating Kubernetes $k8s_version Manifests for ${CLOUD}-${CLUSTER}."
7473

7574
hf -f helmfile.tpl/helmfile-init.yaml template --skip-deps --output-dir="$k8sResourcesPath" >/dev/null
7675
hf template --skip-deps --output-dir="$k8sResourcesPath" >/dev/null
@@ -88,19 +87,22 @@ validate_templates() {
8887
done
8988
# create schema in canonical format for each extracted file
9089
for json in $(jq -s -r '.[] | .filename' $schemasBundleFile); do
91-
jq "select(.filename==\"$json\")" $schemasBundleFile | jq '.schema' >"$schemaOutputPath/$version-standalone/$json"
90+
jq "select(.filename==\"$json\")" $schemasBundleFile | jq '.schema' >"$schemaOutputPath/$k8s_version-standalone/$json"
9291
done
9392

9493
# validate_resources
95-
echo "Validating resources against Kubernetes version: $version"
94+
echo "Validating resources against Kubernetes version: $k8s_version"
9695
local kubevalSchemaLocation="file://${schemaOutputPath}"
9796
local skipKinds="CustomResourceDefinition"
9897
local skipFilenames="crd,knative-services"
99-
{
100-
set +o pipefail
101-
kubeval --quiet --skip-kinds $skipKinds --ignored-filename-patterns $skipFilenames --force-color -d $k8sResourcesPath --schema-location $kubevalSchemaLocation --kubernetes-version $(echo $version | sed 's/v//') | grep -Ev 'PASS\b'
102-
set -o pipefail
103-
} && exitcode=0
98+
local tmp_out=$(mktemp -u)
99+
set +o pipefail
100+
kubeval --quiet --skip-kinds $skipKinds --ignored-filename-patterns $skipFilenames \
101+
--force-color -d $k8sResourcesPath --schema-location $kubevalSchemaLocation \
102+
--kubernetes-version $(echo $k8s_version | sed 's/v//') | tee $tmp_out | grep -Ev 'PASS\b'
103+
set -o pipefail
104+
grep -q "ERROR" $tmp_out && exitcode=1
105+
rm $tmp_out
104106
}
105107

106108
if [ "${1-}" != "" ]; then

charts/keycloak/templates/statefulset.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ spec:
6767
- sh
6868
- -c
6969
- |
70-
until printf "." && nc -z -w 2 {{ include "keycloak.postgresql.fullname" . }} {{ .Values.postgresql.service.port }}; do
70+
until printf "." && nc -z -w 2 {{ include "keycloak.postgresql.fullname" . }}.{{ .Release.Namespace }} {{ .Values.postgresql.service.port }}; do
7171
sleep 2;
7272
done;
7373

charts/raw/ci/resources-values.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
resources:
2-
- apiVersion: scheduling.k8s.io/v1beta1
2+
- apiVersion: scheduling.k8s.io/v1
33
kind: PriorityClass
44
metadata:
55
name: common-critical

charts/team-ns/templates/_helpers.tpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ helm.sh/chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
2424
{{- end -}}
2525

2626
{{- define "dockercfg" -}}
27-
{"auths":{"{{ .server }}":{"username":"{{ .username }}","password":"{{ .password | replace "\"" "\\\"" }}","email":"[email protected]","auth":"{{ .password | b64enc}}"}}}
27+
{"auths":{"{{ .server }}":{"username":"{{ .username }}","password":"{{ .password | replace "\"" "\\\"" }}","email":"[email protected]","auth":"{{ print .username ":" .password | b64enc}}"}}}
2828
{{- end -}}
2929

3030
{{- define "itemsByName" -}}

helmfile.d/helmfile-20.ingress.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ releases:
3232
namespace: ingress
3333
labels:
3434
tag: ingress
35+
pkg: ingress-azure
3536
<<: *default
3637
- name: ingress-merge
3738
installed: {{ and (eq $v.cluster.provider "aws") $v.otomi.hasCloudLB }}

helmfile.d/helmfile-99.post.yaml

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ bases:
77

88
releases:
99
- name: jobs-ingress-azure
10-
installed: {{ eq $v.cluster.provider "azure" }}
10+
installed: {{ and (eq $v.cluster.provider "azure") $v.otomi.hasCloudLB }}
1111
<<: *jobs
12+
labels:
13+
pkg: ingress-azure
1214
- name: jobs-harbor
1315
installed: {{ $c | get "harbor.enabled" false }}
1416
labels:

helmfile.d/snippets/domains.gotmpl

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
{{- $domains := list }}
66
{{- $domainNames := list }}
77
{{- $teams := set $tc.teams "admin" dict }}
8-
# {{ $tc.teams | toJson }}
98
{{- range $teamId, $team := $tc.teams }}
109
{{- $baseDomain := printf "%s%s" (eq $teamId "admin" | ternary "" (printf "team-%s." $teamId)) $v.cluster.domain }}
1110
{{- $services := (eq $teamId "admin" | ternary $coreAdminServices (concat $coreTeamServices ($team | get "services" list))) }}

schemas/v1.16.0-standalone.tar.gz

-5.12 MB
Binary file not shown.

schemas/v1.17-standalone.tar.gz

5.26 MB
Binary file not shown.

schemas/v1.17.0-standalone.tar.gz

-5.26 MB
Binary file not shown.

schemas/v1.18-standalone.tar.gz

4.08 MB
Binary file not shown.

schemas/v1.18.0-standalone.tar.gz

-4.08 MB
Binary file not shown.

schemas/v1.19-standalone.tar.gz

4.57 MB
Binary file not shown.

values-schema.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -211,9 +211,9 @@ definitions:
211211
default: '1.18'
212212
description: The cluster k8s version. Otomi supports 2 minor versions backwards compatibility from the suggested default.
213213
enum:
214-
- '1.16'
215214
- '1.17'
216215
- '1.18'
216+
- '1.19'
217217
type: string
218218
labels:
219219
$ref: '#/definitions/labelsAnnotations'

values/jobs/harbor.gotmpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ tasks:
3838
OIDC_CLIENT_SECRET: {{ $hasKeycloak | ternary $k.idp.clientSecret $o.clientSecret }}
3939
env:
4040
HARBOR_BASE_URL: "http://harbor-harbor-core.harbor/api/v2.0"
41-
TEAM_NAMES: '{{ $teamNames | toJson }}'
41+
TEAM_NAMES: '{{ $teamNames | sortAlpha | toJson }}'
4242
OIDC_ENDPOINT: '{{ $hasKeycloak | ternary $keycloakIssuer $o.issuer }}'
4343
OIDC_GROUPS_CLAIM: 'groups'
4444
OIDC_NAME: 'keycloak'

values/jobs/keycloak.gotmpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ tasks:
4949
IDP_ALIAS: {{ $k.idp.alias }}
5050
IDP_GROUP_OTOMI_ADMIN: {{ $v.oidc.adminGroupID }}
5151
IDP_GROUP_TEAM_ADMIN: {{ $v.oidc.teamAdminGroupID }}
52-
IDP_GROUP_MAPPINGS_TEAMS: '{{ $teamsMapping | toJson }}'
52+
IDP_GROUP_MAPPINGS_TEAMS: '{{ $teamsMapping | sortAlpha | toJson }}'
5353
IDP_OIDC_URL: {{ $v.oidc.issuer }}
5454
REDIRECT_URIS: '[
5555
"https://otomi.{{ $v.cluster.domain }}",

values/k8s/k8s-raw.gotmpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ resources:
9595
- name: gcr-json-key
9696
{{- end }}
9797
{{- end }}
98-
- apiVersion: scheduling.k8s.io/v1beta1
98+
- apiVersion: scheduling.k8s.io/v1
9999
kind: PriorityClass
100100
metadata:
101101
name: otomi-critical

values/knative/knative-serving-raw.gotmpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ resources:
66
name: knative-serving
77
namespace: knative-serving
88
spec:
9-
version: 0.19.0
9+
version: 0.18.0
1010
config:
1111
defaults:
1212
revision-timeout-seconds: "300" # 5 minutes

values/otomi-console/otomi-console.gotmpl

+3-3
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ env:
4040
CONTEXT_PATH: ''
4141
CONSOLE_MODE: {{ and (ne ($v.otomi | get "pullSecret" "") "") (ne ($v.otomi | get "mode" "ee") "ce") | ternary "ee" "ce" }}
4242
CLUSTER_ID: '{{ printf "%s/%s" $c.provider $c.name }}'
43-
CLUSTERS: '{{ $clusters | toJson }}'
44-
CORE: '{"services":{{ $v.services | toJson }},"teamConfig":{"services":{{ $v.teamConfig.services | toJson }}}}'
43+
CLUSTERS: '{{ $clusters | sortAlpha | toJson }}'
44+
CORE: '{"services":{{ $v.services | sortAlpha | toJson }},"teamConfig":{"services":{{ $v.teamConfig.services | sortAlpha | toJson }}}}'
4545
CORE_VERSION: '{{ $version }}'
46-
TEAMS: '{{ keys $v.teamConfig.teams | toJson }}'
46+
TEAMS: '{{ keys $v.teamConfig.teams | sortAlpha | toJson }}'

0 commit comments

Comments
 (0)