Skip to content

Commit e6fb22f

Browse files
committed
feat: Create default configmaps via charts to make configurable
1 parent 2a0269a commit e6fb22f

File tree

16 files changed

+319
-141
lines changed

16 files changed

+319
-141
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ openapi_violations.report
1919
.idea/
2020

2121
#ignore report files generated by unittest
22-
*/pkg/**/junit_node*.xml
22+
**/pkg/**/junit_node*.xml
2323

2424
dist/
2525
.local/

.go-tools

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
github.com/oligot/[email protected]
2-
sigs.k8s.io/controller-runtime/tools/[email protected]20230611165747-7edfc04cacbd
2+
sigs.k8s.io/controller-runtime/tools/[email protected]20230817155522-304027bcbe4b

charts/capi-runtime-extensions/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@ A Helm chart for capi-runtime-extensions
3131
| controllers.enableLeaderElection | bool | `false` | |
3232
| deployment.replicas | int | `1` | |
3333
| env | object | `{}` | |
34+
| handlers.CalicoCNI.defaultInstallationConfigMaps.DockerCluster.configMap.content | string | `nil` | |
35+
| handlers.CalicoCNI.defaultInstallationConfigMaps.DockerCluster.configMap.name | string | `"calico-cni-installation-dockercluster"` | |
36+
| handlers.CalicoCNI.defaultInstallationConfigMaps.DockerCluster.create | bool | `true` | |
37+
| handlers.CalicoCNI.defaultPodSubnet | string | `"192.168.0.0/16"` | |
38+
| handlers.CalicoCNI.defaultTigeraOperatorConfigMap.name | string | `"tigera-operator"` | |
39+
| handlers.CalicoCNI.enabled | bool | `true` | |
40+
| handlers.ServiceLoadBalancerGC.enabled | bool | `true` | |
3441
| image.pullPolicy | string | `"IfNotPresent"` | |
3542
| image.repository | string | `"ghcr.io/d2iq-labs/capi-runtime-extensions"` | |
3643
| image.tag | string | `""` | |
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Copyright 2023 D2iQ, Inc. All rights reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
{{- if and .Values.handlers.CalicoCNI.enabled .Values.handlers.CalicoCNI.defaultInstallationConfigMaps.DockerCluster.create }}
5+
apiVersion: v1
6+
kind: ConfigMap
7+
metadata:
8+
name: '{{ .Values.handlers.CalicoCNI.defaultInstallationConfigMaps.DockerCluster.configMap.name }}'
9+
data:
10+
calico-installation: |
11+
{{- if .Values.handlers.CalicoCNI.defaultInstallationConfigMaps.DockerCluster.configMap.content -}}
12+
{{ .Values.handlers.CalicoCNI.defaultInstallationConfigMaps.DockerCluster.configMap.content | nindent 4}}
13+
{{- else -}}
14+
# This section includes base Calico installation configuration.
15+
# For more information, see: https://docs.projectcalico.org/reference/installation/api
16+
apiVersion: operator.tigera.io/v1
17+
kind: Installation
18+
metadata:
19+
name: default
20+
spec:
21+
cni:
22+
type: Calico
23+
# Configures Calico networking.
24+
calicoNetwork:
25+
# Note: The ipPools section cannot be modified post-install.
26+
ipPools:
27+
- blockSize: 26
28+
cidr: {{ .Values.handlers.CalicoCNI.defaultPodSubnet }}
29+
encapsulation: VXLANCrossSubnet
30+
natOutgoing: Enabled
31+
nodeSelector: all()
32+
nodeMetricsPort: 9091
33+
typhaMetricsPort: 9093
34+
{{- end -}}
35+
{{- end -}}

pkg/handlers/cni/calico/manifests/tigera-operator-configmap.yaml renamed to charts/capi-runtime-extensions/templates/cni/calico/manifests/tigera-operator-configmap.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ data:
88
kind: ConfigMap
99
metadata:
1010
creationTimestamp: null
11-
name: tigera-operator
11+
name: '{{ .Values.handlers.CalicoCNI.defaultTigeraOperatorConfigMap.name }}'

charts/capi-runtime-extensions/templates/deployment.yaml

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,28 @@ spec:
2727
- name: webhook
2828
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default $.Chart.AppVersion }}"
2929
imagePullPolicy: "{{ .Values.image.pullPolicy }}"
30-
{{- if .Values.env }}
31-
env:
32-
{{- range $key, $value := .Values.env }}
33-
- name: "{{ $key }}"
34-
value: "{{ $value }}"
35-
{{- end }}
36-
{{- end }}
3730
args:
3831
- --controllermanager.cert-dir=/controllers-certs/
3932
- --controllermanager.leader-elect={{ if gt (.Values.deployment.replicas | int) 1 }}true{{ else }}{{ .Values.controllers.enableLeaderElection }}{{ end }}
4033
- --runtimehooks.cert-dir=/runtimehooks-certs/
34+
{{- range $key, $value := .Values.handlers }}{{ if $value.enabled }}
35+
- --runtimehooks.enabled-handlers={{ $key }}
36+
{{ end }}{{- end }}
37+
- --runtimehooks.calicocni.defaultsNamespace=$(POD_NAMESPACE)
4138
{{- range $key, $value := .Values.extraArgs }}
4239
- --{{ $key }}={{ $value }}
4340
{{- end }}
41+
env:
42+
- name: POD_NAMESPACE
43+
valueFrom:
44+
fieldRef:
45+
fieldPath: metadata.namespace
46+
{{- if .Values.env }}
47+
{{- range $key, $value := .Values.env }}
48+
- name: "{{ $key }}"
49+
value: "{{ $value }}"
50+
{{- end }}
51+
{{- end }}
4452
ports:
4553
- containerPort: 8443
4654
name: controllers

charts/capi-runtime-extensions/values.schema.json

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,68 @@
4545
"type": "object",
4646
"additionalProperties": { "type": "string" }
4747
},
48+
"handlers": {
49+
"type": "object",
50+
"properties": {
51+
"CalicoCNI": {
52+
"type": "object",
53+
"properties": {
54+
"defaultInstallationConfigMaps": {
55+
"type": "object",
56+
"properties": {
57+
"DockerCluster": {
58+
"type": "object",
59+
"properties": {
60+
"configMap": {
61+
"type": "object",
62+
"properties": {
63+
"content": {
64+
"type": "string"
65+
},
66+
"name": {
67+
"type": "string"
68+
}
69+
},
70+
"required": ["name"]
71+
},
72+
"create": {
73+
"type": "boolean",
74+
"default": true
75+
}
76+
}
77+
}
78+
}
79+
},
80+
"defaultPodSubnet": {
81+
"type": "string",
82+
"default": "192.168.0.0/16"
83+
},
84+
"defaultTigeraOperatorConfigMap": {
85+
"type": "object",
86+
"properties": {
87+
"name": {
88+
"type": "string"
89+
}
90+
},
91+
"required": ["name"]
92+
},
93+
"enabled": {
94+
"type": "boolean",
95+
"default": true
96+
}
97+
}
98+
},
99+
"ServiceLoadBalancerGC": {
100+
"type": "object",
101+
"properties": {
102+
"enabled": {
103+
"type": "boolean",
104+
"default": true
105+
}
106+
}
107+
}
108+
}
109+
},
48110
"image": {
49111
"type": "object",
50112
"properties": {

charts/capi-runtime-extensions/values.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,21 @@
11
# Copyright 2023 D2iQ, Inc. All rights reserved.
22
# SPDX-License-Identifier: Apache-2.0
33

4+
handlers:
5+
CalicoCNI:
6+
enabled: true
7+
defaultPodSubnet: 192.168.0.0/16
8+
defaultTigeraOperatorConfigMap:
9+
name: tigera-operator
10+
defaultInstallationConfigMaps:
11+
DockerCluster:
12+
create: true
13+
configMap:
14+
name: calico-cni-installation-dockercluster
15+
content:
16+
ServiceLoadBalancerGC:
17+
enabled: true
18+
419
deployment:
520
replicas: 1
621

devbox.lock

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,16 @@
1414
"version": "3.8.0"
1515
},
1616
"clusterctl@latest": {
17-
"last_modified": "2023-07-23T03:35:12Z",
18-
"resolved": "github:NixOS/nixpkgs/af8cd5ded7735ca1df1a1174864daab75feeb64a#clusterctl",
17+
"last_modified": "2023-08-08T03:07:33Z",
18+
"resolved": "github:NixOS/nixpkgs/844ffa82bbe2a2779c86ab3a72ff1b4176cec467#clusterctl",
1919
"source": "devbox-search",
20-
"version": "1.4.4"
20+
"version": "1.5.0"
2121
},
2222
"crane@latest": {
23-
"last_modified": "2023-06-30T04:44:22Z",
24-
"resolved": "github:NixOS/nixpkgs/3c614fbc76fc152f3e1bc4b2263da6d90adf80fb#crane",
23+
"last_modified": "2023-08-08T03:07:33Z",
24+
"resolved": "github:NixOS/nixpkgs/844ffa82bbe2a2779c86ab3a72ff1b4176cec467#crane",
2525
"source": "devbox-search",
26-
"version": "0.15.2"
26+
"version": "0.16.1"
2727
},
2828
"envsubst@latest": {
2929
"last_modified": "2023-06-30T04:44:22Z",
@@ -140,10 +140,10 @@
140140
"version": "3.11.1"
141141
},
142142
"kubectl@latest": {
143-
"last_modified": "2023-06-30T04:44:22Z",
144-
"resolved": "github:NixOS/nixpkgs/3c614fbc76fc152f3e1bc4b2263da6d90adf80fb#kubectl",
143+
"last_modified": "2023-08-08T03:07:33Z",
144+
"resolved": "github:NixOS/nixpkgs/844ffa82bbe2a2779c86ab3a72ff1b4176cec467#kubectl",
145145
"source": "devbox-search",
146-
"version": "1.27.3"
146+
"version": "1.27.4"
147147
},
148148
"kubernetes-controller-tools@latest": {
149149
"last_modified": "2023-07-23T03:35:12Z",
@@ -170,8 +170,8 @@
170170
"version": "3.3.3"
171171
},
172172
"shfmt@latest": {
173-
"last_modified": "2023-06-30T04:44:22Z",
174-
"resolved": "github:NixOS/nixpkgs/3c614fbc76fc152f3e1bc4b2263da6d90adf80fb#shfmt",
173+
"last_modified": "2023-08-08T03:07:33Z",
174+
"resolved": "github:NixOS/nixpkgs/844ffa82bbe2a2779c86ab3a72ff1b4176cec467#shfmt",
175175
"source": "devbox-search",
176176
"version": "3.7.0"
177177
},

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ require (
1515
k8s.io/client-go v0.28.0
1616
k8s.io/component-base v0.28.0
1717
k8s.io/klog/v2 v2.100.1
18+
k8s.io/utils v0.0.0-20230406110748-d93618cff8a2
1819
sigs.k8s.io/cluster-api v1.5.0
1920
sigs.k8s.io/controller-runtime v0.15.1
2021
)
@@ -72,7 +73,6 @@ require (
7273
k8s.io/apiextensions-apiserver v0.27.2 // indirect
7374
k8s.io/cluster-bootstrap v0.27.2 // indirect
7475
k8s.io/kube-openapi v0.0.0-20230717233707-2695361300d9 // indirect
75-
k8s.io/utils v0.0.0-20230406110748-d93618cff8a2 // indirect
7676
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
7777
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
7878
sigs.k8s.io/yaml v1.3.0 // indirect

hack/addons/update-calico-manifests.sh

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,21 @@ curl -fsSL "https://raw.githubusercontent.com/projectcalico/calico/${CALICO_VERS
2222

2323
readonly KUSTOMIZATION_DIR=${SCRIPT_DIR}/kustomize/tigera-operator
2424
cp -r "${KUSTOMIZATION_DIR}"/* "${CALICO_CNI_ASSETS_DIR}"
25-
kustomize --load-restrictor=LoadRestrictionsNone build "${CALICO_CNI_ASSETS_DIR}" -o "${CALICO_CNI_ASSETS_DIR}/kustomized.yaml"
25+
kustomize --load-restrictor=LoadRestrictionsNone build "${CALICO_CNI_ASSETS_DIR}" \
26+
-o "${CALICO_CNI_ASSETS_DIR}/kustomized.yaml"
2627

2728
# The operator manifest in YAML format is pretty big. It turns out that much of that is whitespace. Converting the
2829
# manifest to JSON without indentation allows us to remove most of the whitespace, reducing the size by more than half.
2930
#
3031
# Some important notes:
31-
# 1. The YAML manifest includes many documents, and the documents must become elements in a JSON array in order for the ClusterResourceController to [parse them](https://github.com/mesosphere/cluster-api//blob/65586de0080a960d085031de87ec627b2d606a6b/exp/addons/internal/controllers/clusterresourceset_helpers.go#L59). We create a JSON array with the --slurp flag.
32-
# 2. The YAML manifest has some whitespace between YAML document markers (`---`), and these become `null` entries in the JSON array. This causes the ["SortForCreate" subroutine](https://github.com/mesosphere/cluster-api//blob/65586de0080a960d085031de87ec627b2d606a6b/exp/addons/internal/controllers/clusterresourceset_helpers.go#L84) of the ClusterResourceSet controller to misbehave. We remove these null entries using a filter expression.
33-
# 3. If we indent the JSON document, it is nearly as large as the YAML document, at 1099093 bytes. We remove indentation with the --indent=0 flag.
32+
# 1. The YAML manifest includes many documents, and the documents must become elements in a JSON array in order for the
33+
# ClusterResourceController to [parse them](https://github.com/mesosphere/cluster-api//blob/65586de0080a960d085031de87ec627b2d606a6b/exp/addons/internal/controllers/clusterresourceset_helpers.go#L59).
34+
# We create a JSON array with the --slurp flag.
35+
# 2. The YAML manifest has some whitespace between YAML document markers (`---`), and these become `null` entries in the
36+
# JSON array. This causes the ["SortForCreate" subroutine](https://github.com/mesosphere/cluster-api//blob/65586de0080a960d085031de87ec627b2d606a6b/exp/addons/internal/controllers/clusterresourceset_helpers.go#L84)
37+
# of the ClusterResourceSet controller to misbehave. We remove these null entries using a filter expression.
38+
# 3. If we indent the JSON document, it is nearly as large as the YAML document, at 1099093 bytes. We remove indentation
39+
# with the --indent=0 flag.
3440
gojq --yaml-input \
3541
--slurp \
3642
--indent=0 \
@@ -43,6 +49,6 @@ gojq --yaml-input \
4349
<"${CALICO_CNI_ASSETS_DIR}/kustomized.yaml" \
4450
>"${CALICO_CNI_ASSETS_DIR}/tigera-operator.json"
4551

46-
kubectl create configmap tigera-operator --dry-run=client --output yaml \
52+
kubectl create configmap "{{ .Values.handlers.CalicoCNI.defaultTigeraOperatorConfigMap.name }}" --dry-run=client --output yaml \
4753
--from-file "${CALICO_CNI_ASSETS_DIR}/tigera-operator.json" \
48-
>"${GIT_REPO_ROOT}/pkg/handlers/cni/calico/manifests/tigera-operator-configmap.yaml"
54+
>"${GIT_REPO_ROOT}/charts/capi-runtime-extensions/templates/cni/calico/manifests/tigera-operator-configmap.yaml"

0 commit comments

Comments
 (0)