Skip to content

Commit e88ef84

Browse files
committed
build: Consisent behaviour in addons update scripts
1 parent 2660571 commit e88ef84

14 files changed

+96
-61
lines changed

.pre-commit-config.yaml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,13 @@ repos:
2626
name: apis-sync
2727
entry: make apis.sync
2828
language: system
29-
files: "^(hack/third-party/|common/pkg/external/|make/apis.mk)"
29+
files: "^(hack/third-party/|common/pkg/external/|make/apis.mk$)"
30+
pass_filenames: false
31+
- id: addons-sync
32+
name: addons-sync
33+
entry: make addons.sync
34+
language: system
35+
files: "^(hack/addons/|charts/capi-runtime-extensions/templates/.+/manifests/|make/addons.mk$)"
3036
pass_filenames: false
3137
- repo: https://github.com/tekwizely/pre-commit-golang
3238
rev: v1.0.0-rc.1

charts/capi-runtime-extensions/templates/cni/calico/manifests/tigera-operator-configmap.yaml

Lines changed: 5 additions & 1 deletion
Large diffs are not rendered by default.

charts/capi-runtime-extensions/templates/nfd/manifests/node-feature-discovery-configmap.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ data:
1111
apiVersion: v1
1212
kind: Namespace
1313
metadata:
14+
labels:
15+
pod-security.kubernetes.io/enforce: privileged
16+
pod-security.kubernetes.io/enforce-version": latest
1417
name: node-feature-discovery
1518
---
1619
apiVersion: apiextensions.k8s.io/v1

hack/addons/kustomize/nfd/kustomization.yaml.tmpl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ resources:
1313
helmCharts:
1414
- name: node-feature-discovery
1515
includeCRDs: true
16-
valuesFile: node-feature-discovery-values.yaml
16+
valuesFile: helm-values.yaml
1717
valuesInline:
1818
image:
19-
tag: "v${NODE_FEATURE_VERSION}-minimal"
19+
tag: "v${NODE_FEATURE_DISCOVERY_VERSION}-minimal"
2020
releaseName: node-feature-discovery
21-
version: ${NODE_FEATURE_VERSION}
21+
version: ${NODE_FEATURE_DISCOVERY_VERSION}
2222
repo: https://kubernetes-sigs.github.io/node-feature-discovery/charts
2323

2424
namespace: node-feature-discovery

hack/addons/kustomize/nfd/namespace.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,6 @@ apiVersion: v1
55
kind: Namespace
66
metadata:
77
name: node-feature-discovery
8+
labels:
9+
pod-security.kubernetes.io/enforce: "privileged"
10+
pod-security.kubernetes.io/enforce-version": "latest"

hack/addons/kustomize/tigera-operator/ds-priorityClass.yaml

Lines changed: 0 additions & 11 deletions
This file was deleted.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Copyright 2023 D2iQ, Inc. All rights reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
---
5+
installation:
6+
enabled: false

hack/addons/kustomize/tigera-operator/kustomization.yaml

Lines changed: 0 additions & 17 deletions
This file was deleted.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Copyright 2023 D2iQ, Inc. All rights reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
apiVersion: kustomize.config.k8s.io/v1beta1
5+
kind: Kustomization
6+
7+
metadata:
8+
name: tigera-operator
9+
10+
sortOptions:
11+
order: fifo
12+
13+
resources:
14+
- namespace.yaml
15+
16+
helmCharts:
17+
- name: tigera-operator
18+
includeCRDs: true
19+
valuesFile: helm-values.yaml
20+
releaseName: tigera-operator
21+
version: ${CALICO_VERSION}
22+
repo: https://docs.tigera.io/calico/charts
23+
24+
namespace: tigera-operator
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Copyright 2023 D2iQ, Inc. All rights reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
apiVersion: v1
5+
kind: Namespace
6+
metadata:
7+
name: tigera-operator
8+
labels:
9+
pod-security.kubernetes.io/enforce: "privileged"
10+
pod-security.kubernetes.io/enforce-version": "latest"

hack/addons/update-calico-manifests.sh

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,15 @@ if [ -z "${CALICO_VERSION:-}" ]; then
1313
exit 1
1414
fi
1515

16-
CALICO_CNI_ASSETS_DIR="$(mktemp -d -p "${TMPDIR:-/tmp}")"
17-
readonly CALICO_CNI_ASSETS_DIR
18-
trap 'rm -rf ${CALICO_CNI_ASSETS_DIR}' EXIT
16+
ASSETS_DIR="$(mktemp -d -p "${TMPDIR:-/tmp}")"
17+
readonly ASSETS_DIR
18+
trap 'rm -rf ${ASSETS_DIR}' EXIT
1919

20-
curl -fsSL "https://raw.githubusercontent.com/projectcalico/calico/${CALICO_VERSION}/manifests/tigera-operator.yaml" \
21-
-o "${CALICO_CNI_ASSETS_DIR}/tigera-operator.yaml"
20+
readonly FILE_NAME="tigera-operator.yaml"
2221

23-
readonly KUSTOMIZATION_DIR=${SCRIPT_DIR}/kustomize/tigera-operator
24-
cp -r "${KUSTOMIZATION_DIR}"/* "${CALICO_CNI_ASSETS_DIR}"
25-
kustomize --load-restrictor=LoadRestrictionsNone build "${CALICO_CNI_ASSETS_DIR}" \
26-
-o "${CALICO_CNI_ASSETS_DIR}/kustomized.yaml"
22+
readonly KUSTOMIZE_BASE_DIR=${SCRIPT_DIR}/kustomize/tigera-operator
23+
envsubst -no-unset <"${KUSTOMIZE_BASE_DIR}/kustomization.yaml.tmpl" >"${ASSETS_DIR}/kustomization.yaml"
24+
cp "${KUSTOMIZE_BASE_DIR}"/*.yaml "${ASSETS_DIR}"
2725

2826
# The operator manifest in YAML format is pretty big. It turns out that much of that is whitespace. Converting the
2927
# manifest to JSON without indentation allows us to remove most of the whitespace, reducing the size by more than half.
@@ -37,18 +35,25 @@ kustomize --load-restrictor=LoadRestrictionsNone build "${CALICO_CNI_ASSETS_DIR}
3735
# of the ClusterResourceSet controller to misbehave. We remove these null entries using a filter expression.
3836
# 3. If we indent the JSON document, it is nearly as large as the YAML document, at 1099093 bytes. We remove indentation
3937
# with the --indent=0 flag.
38+
kustomize build --enable-helm "${ASSETS_DIR}" >"${ASSETS_DIR}/${FILE_NAME}"
39+
4040
gojq --yaml-input \
4141
--slurp \
4242
--indent=0 \
43-
'[ .[] | select( . != null ) |
44-
(select( .kind=="Namespace").metadata.labels += {
45-
"pod-security.kubernetes.io/enforce": "privileged",
46-
"pod-security.kubernetes.io/enforce-version": "latest"
47-
})
48-
]' \
49-
<"${CALICO_CNI_ASSETS_DIR}/kustomized.yaml" \
50-
>"${CALICO_CNI_ASSETS_DIR}/tigera-operator.json"
43+
<"${ASSETS_DIR}/${FILE_NAME}" \
44+
>"${ASSETS_DIR}/tigera-operator.json"
5145

5246
kubectl create configmap "{{ .Values.hooks.CalicoCNI.defaultTigeraOperatorConfigMap.name }}" --dry-run=client --output yaml \
53-
--from-file "${CALICO_CNI_ASSETS_DIR}/tigera-operator.json" \
54-
>"${GIT_REPO_ROOT}/charts/capi-runtime-extensions/templates/cni/calico/manifests/tigera-operator-configmap.yaml"
47+
--from-file "${ASSETS_DIR}/tigera-operator.json" \
48+
>"${ASSETS_DIR}/tigera-operator-configmap.yaml"
49+
50+
# add warning not to edit file directly
51+
cat <<EOF >"${GIT_REPO_ROOT}/charts/capi-runtime-extensions/templates/cni/calico/manifests/tigera-operator-configmap.yaml"
52+
$(cat "${GIT_REPO_ROOT}/hack/license-header.yaml.txt")
53+
54+
#=================================================================
55+
# DO NOT EDIT THIS FILE
56+
# IT HAS BEEN GENERATED BY /hack/addons/update-calico-manifests.sh
57+
#=================================================================
58+
$(cat "${ASSETS_DIR}/tigera-operator-configmap.yaml")
59+
EOF

hack/addons/update-node-feature-discovery-manifests.sh

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ readonly SCRIPT_DIR
88
# shellcheck source=hack/common.sh
99
source "${SCRIPT_DIR}/../common.sh"
1010

11-
if [ -z "${NODE_FEATURE_VERSION:-}" ]; then
12-
echo "Missing environment variable: NODE_FEATURE_VERSION"
11+
if [ -z "${NODE_FEATURE_DISCOVERY_VERSION:-}" ]; then
12+
echo "Missing environment variable: NODE_FEATURE_DISCOVERY_VERSION"
1313
exit 1
1414
fi
1515

@@ -26,16 +26,15 @@ kustomize build --enable-helm "${ASSETS_DIR}" >"${ASSETS_DIR}/${FILE_NAME}"
2626

2727
kubectl create configmap node-feature-discovery --dry-run=client --output yaml \
2828
--from-file "${ASSETS_DIR}/${FILE_NAME}" \
29-
>"${GIT_REPO_ROOT}/charts/capi-runtime-extensions/templates/nfd/manifests/node-feature-discovery-configmap.yaml"
29+
>"${ASSETS_DIR}/node-feature-discovery-configmap.yaml"
3030

3131
# add warning not to edit file directly
32-
cat <<EOF >"${GIT_REPO_ROOT}/charts/capi-runtime-extensions/templates/nfd/manifests/node-feature-discovery-configmap-temp.yaml"
32+
cat <<EOF >"${GIT_REPO_ROOT}/charts/capi-runtime-extensions/templates/nfd/manifests/node-feature-discovery-configmap.yaml"
33+
$(cat "${GIT_REPO_ROOT}/hack/license-header.yaml.txt")
34+
3335
#=================================================================
3436
# DO NOT EDIT THIS FILE
3537
# IT HAS BEEN GENERATED BY /hack/addons/update-node-feature-discovery-manifests.sh
3638
#=================================================================
37-
$(cat "${GIT_REPO_ROOT}/charts/capi-runtime-extensions/templates/nfd/manifests/node-feature-discovery-configmap.yaml")
39+
$(cat "${ASSETS_DIR}/node-feature-discovery-configmap.yaml")
3840
EOF
39-
40-
mv "${GIT_REPO_ROOT}/charts/capi-runtime-extensions/templates/nfd/manifests/node-feature-discovery-configmap-temp.yaml" \
41-
"${GIT_REPO_ROOT}/charts/capi-runtime-extensions/templates/nfd/manifests/node-feature-discovery-configmap.yaml"

make/addons.mk

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
# SPDX-License-Identifier: Apache-2.0
33

44
export CALICO_VERSION := v3.26.1
5-
export NODE_FEATURE_VERSION := 0.14.1
5+
export NODE_FEATURE_DISCOVERY_VERSION := 0.14.1
6+
7+
.PHONY: addons.sync
8+
addons.sync: $(addprefix update-addon.,calico nfd)
69

710
.PHONY: update-addon.calico
811
update-addon.calico: ; $(info $(M) updating calico manifests)

0 commit comments

Comments
 (0)