Skip to content

Commit fb3c236

Browse files
committed
feat: adds previous versions to self hosted helm registry
1 parent 5aad02e commit fb3c236

File tree

4 files changed

+102
-41
lines changed

4 files changed

+102
-41
lines changed

hack/addons/generate-mindthegap-repofile.sh

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,15 @@ ASSETS_DIR="$(mktemp -d -p "${TMPDIR:-/tmp}")"
1212

1313
cp "${GIT_REPO_ROOT}/charts/cluster-api-runtime-extensions-nutanix/templates/helm-config.yaml" "${ASSETS_DIR}"
1414

15+
gh release download "${PREVIOUS_CAREN_CHARTS_VERSION}" \
16+
-p "runtime-extension-components.yaml" -D "${ASSETS_DIR}/" --clobber
17+
18+
cat "${ASSETS_DIR}/runtime-extension-components.yaml" | yq e '. | select(.metadata.name == "default-helm-addons-config")' >>"${ASSETS_DIR}/previous-charts.yaml"
19+
1520
# this sed line is needed because the go library is unable to parse yaml with a template string.
1621
sed -i s/"{{ .Values.helmAddonsConfigMap }}"/placeholder/g "${ASSETS_DIR}/helm-config.yaml"
17-
go run "${GIT_REPO_ROOT}/hack/tools/mindthegap-helm-reg/main.go" --input-configmap-file="${ASSETS_DIR}/helm-config.yaml" --output-file="${ASSETS_DIR}/repos.yaml"
22+
go run "${GIT_REPO_ROOT}/hack/tools/mindthegap-helm-reg/main.go" --input-configmap-file="${ASSETS_DIR}/helm-config.yaml" --output-file="${ASSETS_DIR}/repos.yaml" \
23+
--previous-configmap-file="${ASSETS_DIR}/previous-charts.yaml"
1824

1925
# add warning not to edit file directly
2026
cat <<EOF >"${GIT_REPO_ROOT}/hack/addons/mindthegap-helm-registry/repos.yaml"

hack/addons/mindthegap-helm-registry/repos.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,19 @@ repositories:
1616
charts:
1717
aws-ebs-csi-driver:
1818
- 2.35.1
19+
- 2.32.0
1920
cilium:
2021
repoURL: https://helm.cilium.io/
2122
charts:
2223
cilium:
2324
- 1.16.2
25+
- 1.15.6
2426
cluster-autoscaler:
2527
repoURL: https://kubernetes.github.io/autoscaler
2628
charts:
2729
cluster-autoscaler:
2830
- 9.40.0
31+
- 9.37.0
2932
local-path-provisioner:
3033
repoURL: https://charts.containeroo.ch
3134
charts:
@@ -36,11 +39,13 @@ repositories:
3639
charts:
3740
metallb:
3841
- 0.14.8
42+
- 0.14.5
3943
node-feature-discovery:
4044
repoURL: https://kubernetes-sigs.github.io/node-feature-discovery/charts
4145
charts:
4246
node-feature-discovery:
4347
- 0.16.4
48+
- 0.16.1
4449
nutanix-cloud-provider:
4550
repoURL: https://nutanix.github.io/helm/
4651
charts:
@@ -56,8 +61,10 @@ repositories:
5661
charts:
5762
snapshot-controller:
5863
- 3.0.6
64+
- 3.0.5
5965
tigera-operator:
6066
repoURL: https://docs.tigera.io/calico/charts
6167
charts:
6268
tigera-operator:
6369
- v3.28.2
70+
- v3.28.0

hack/tools/mindthegap-helm-reg/main.go

Lines changed: 86 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import (
99
"fmt"
1010
"os"
1111
"path"
12+
"path/filepath"
13+
"slices"
1214

1315
"gopkg.in/yaml.v2"
1416
corev1 "k8s.io/api/core/v1"
@@ -36,57 +38,46 @@ var log = ctrl.LoggerFrom(context.Background())
3638
func main() {
3739
args := os.Args
3840
var (
39-
outputFile string
40-
inputConfigMapFile string
41+
outputFile string
42+
inputConfigMapFile string
43+
previousConfigMapFile string
4144
)
4245
flagSet := flag.NewFlagSet("mindthegap-helm-registry", flag.ExitOnError)
43-
flagSet.StringVar(&outputFile, "output-file", "",
44-
"output file name to write config map to.")
45-
flagSet.StringVar(&inputConfigMapFile, "input-configmap-file", "",
46-
"input configmap file to create the mindthegap repo file from")
46+
flagSet.StringVar(
47+
&outputFile,
48+
"output-file",
49+
"",
50+
"output file name to write config map to.",
51+
)
52+
flagSet.StringVar(
53+
&inputConfigMapFile,
54+
"input-configmap-file",
55+
"",
56+
"input configmap file to create the mindthegap repo file from",
57+
)
58+
flagSet.StringVar(
59+
&previousConfigMapFile,
60+
"previous-configmap-file",
61+
"",
62+
"input configmap file to create the mindthegap repo file from",
63+
)
4764
err := flagSet.Parse(args[1:])
4865
if err != nil {
4966
log.Error(err, "failed to parse args")
5067
}
51-
fullPath := inputConfigMapFile
52-
if !path.IsAbs(fullPath) {
53-
wd, err := os.Getwd()
54-
if err != nil {
55-
log.Error(err, "failed to get wd")
56-
return
57-
}
58-
fullPath = path.Join(wd, inputConfigMapFile)
59-
}
60-
f, err := os.Open(fullPath)
61-
if err != nil {
62-
log.Error(err, "failed to open file")
63-
return
64-
}
65-
defer f.Close()
66-
cm := &corev1.ConfigMap{}
67-
err = yamlDecode.NewYAMLOrJSONDecoder(f, 1024).Decode(cm)
68+
inputCm, err := getConfigMapFromFile(inputConfigMapFile)
6869
if err != nil {
69-
log.Error(err, fmt.Sprintf("failed to unmarshal file %s", fullPath))
70+
log.Error(err, fmt.Sprintf("failed to get configmap from file %s %w", inputConfigMapFile, err))
7071
}
7172
out := HelmChartsConfig{
7273
map[string]Repository{},
7374
}
74-
for _, info := range cm.Data {
75-
var settings HelmChartFromConfigMap
76-
err = yaml.Unmarshal([]byte(info), &settings)
77-
if err != nil {
78-
log.Error(err, "failed unmarshl settings")
79-
return
80-
}
81-
out.Repositories[settings.Name] = Repository{
82-
RepoURL: settings.Repository,
83-
Charts: map[string][]string{
84-
settings.Name: {
85-
settings.Version,
86-
},
87-
},
88-
}
75+
ConfigMapToHelmChartConfig(&out, inputCm)
76+
previousCm, err := getConfigMapFromFile(previousConfigMapFile)
77+
if err != nil {
78+
log.Error(err, fmt.Sprintf("failed to get configmap from file %s %w", inputConfigMapFile, err))
8979
}
80+
ConfigMapToHelmChartConfig(&out, previousCm)
9081
b, err := yaml.Marshal(out)
9182
if err != nil {
9283
log.Error(err, fmt.Sprintf("failed to marshal obj %v", out))
@@ -99,7 +90,7 @@ func main() {
9990
}
10091
fullOutputfilePath = path.Join(wd, outputFile)
10192
}
102-
f, err = os.OpenFile(fullOutputfilePath, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0o666)
93+
f, err := os.OpenFile(fullOutputfilePath, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0o666)
10394
if err != nil {
10495
log.Error(err, "failed to create file")
10596
}
@@ -109,3 +100,58 @@ func main() {
109100
log.Error(err, "failed to write to file")
110101
}
111102
}
103+
104+
func ConfigMapToHelmChartConfig(out *HelmChartsConfig, cm *corev1.ConfigMap) {
105+
for _, info := range cm.Data {
106+
var settings HelmChartFromConfigMap
107+
err := yaml.Unmarshal([]byte(info), &settings)
108+
if err != nil {
109+
log.Error(err, "failed unmarshl settings")
110+
return
111+
}
112+
repo, ok := out.Repositories[settings.Name]
113+
// if this is the first time we saw this add a new entry
114+
if !ok {
115+
out.Repositories[settings.Name] = Repository{
116+
RepoURL: settings.Repository,
117+
Charts: map[string][]string{
118+
settings.Name: {
119+
settings.Version,
120+
},
121+
},
122+
}
123+
continue
124+
}
125+
// we've seen it already only add a new chart if the versions are different
126+
if !slices.Contains(repo.Charts[settings.Name], settings.Version) {
127+
repo.Charts[settings.Name] = append(repo.Charts[settings.Name], settings.Version)
128+
}
129+
}
130+
}
131+
132+
func getConfigMapFromFile(configMapFile string) (*corev1.ConfigMap, error) {
133+
fullPath, err := EnsureFullPath(configMapFile)
134+
if err != nil {
135+
return nil, err
136+
}
137+
f, err := os.Open(fullPath)
138+
if err != nil {
139+
return nil, err
140+
}
141+
defer f.Close()
142+
cm := &corev1.ConfigMap{}
143+
err = yamlDecode.NewYAMLOrJSONDecoder(f, 1024).Decode(cm)
144+
return cm, err
145+
}
146+
147+
func EnsureFullPath(filename string) (string, error) {
148+
fullPath, err := filepath.Abs(filename)
149+
if err != nil {
150+
return "", err
151+
}
152+
_, err = os.Stat(fullPath)
153+
if err != nil {
154+
return "", err
155+
}
156+
return fullPath, nil
157+
}

make/addons.mk

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ export KUBE_VIP_VERSION := v0.8.3
2525

2626
export METALLB_CHART_VERSION := 0.14.8
2727

28+
export PREVIOUS_CAREN_CHARTS_VERSION := v0.14.6
29+
2830
.PHONY: addons.sync
2931
addons.sync: $(addprefix update-addon.,calico cilium nfd cluster-autoscaler snapshot-controller local-path-provisioner-csi aws-ebs-csi kube-vip)
3032
addons.sync: $(addprefix update-addon.aws-ccm.,127 128 129 130 131)

0 commit comments

Comments
 (0)