Skip to content

Commit 4751e3c

Browse files
feat(api): Add kubernetes version to coredns version mapping (#939)
Added script and makefile target to update coredns version mapping. `make coredns.sync` will fetch the list of releases from upstream release branches and create a mapping of k8s versions to coredns versions.
1 parent adf8a6a commit 4751e3c

File tree

8 files changed

+556
-1
lines changed

8 files changed

+556
-1
lines changed

.pre-commit-config.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ repos:
6363
language: system
6464
files: "^devbox.(yaml|lock)$"
6565
pass_filenames: false
66+
- id: check-coredns-versions
67+
name: check-coredns-versions
68+
entry: make coredns.sync
69+
language: system
70+
files: "^api/versions/coredns.go$"
6671
- repo: https://github.com/tekwizely/pre-commit-golang
6772
rev: v1.0.0-rc.1
6873
hooks:

api/go.mod

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@ replace github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/c
1111

1212
require (
1313
github.com/aws/aws-sdk-go v1.55.5
14+
github.com/blang/semver/v4 v4.0.0
1415
github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common v0.7.0
1516
github.com/nutanix-cloud-native/prism-go-client v0.5.1
1617
github.com/onsi/gomega v1.34.2
18+
github.com/stretchr/testify v1.9.0
1719
k8s.io/api v0.30.5
1820
k8s.io/apiextensions-apiserver v0.30.5
1921
k8s.io/apimachinery v0.30.5
@@ -24,7 +26,6 @@ require (
2426

2527
require (
2628
github.com/beorn7/perks v1.0.1 // indirect
27-
github.com/blang/semver/v4 v4.0.0 // indirect
2829
github.com/cespare/xxhash/v2 v2.2.0 // indirect
2930
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
3031
github.com/emicklei/go-restful/v3 v3.12.1 // indirect
@@ -51,6 +52,7 @@ require (
5152
github.com/modern-go/reflect2 v1.0.2 // indirect
5253
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
5354
github.com/pkg/errors v0.9.1 // indirect
55+
github.com/pmezard/go-difflib v1.0.0 // indirect
5456
github.com/prometheus/client_golang v1.18.0 // indirect
5557
github.com/prometheus/client_model v0.6.0 // indirect
5658
github.com/prometheus/common v0.45.0 // indirect

api/versions/coredns.go

Lines changed: 77 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/versions/coredns_test.go

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// Copyright 2024 Nutanix. All rights reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package versions
5+
6+
import (
7+
"testing"
8+
9+
"github.com/stretchr/testify/assert"
10+
)
11+
12+
func TestReturnsCorrectCoreDNSVersionForValidKubernetesVersion(t *testing.T) {
13+
version, found := GetCoreDNSVersion("v1.27")
14+
assert.True(t, found)
15+
assert.Equal(t, "v1.10.1", version)
16+
}
17+
18+
func TestReturnsCorrectCoreDNSVersionForValidKubernetesVersionWithoutVPrefix(t *testing.T) {
19+
version, found := GetCoreDNSVersion("1.27")
20+
assert.True(t, found)
21+
assert.Equal(t, "v1.10.1", version)
22+
}
23+
24+
func TestReturnsFalseForInvalidKubernetesVersion(t *testing.T) {
25+
version, found := GetCoreDNSVersion("v2.99")
26+
assert.False(t, found)
27+
assert.Equal(t, "", version)
28+
}
29+
30+
func TestReturnsFalseForMalformedKubernetesVersion(t *testing.T) {
31+
version, found := GetCoreDNSVersion("invalid-version")
32+
assert.False(t, found)
33+
assert.Equal(t, "", version)
34+
}
35+
36+
func TestReturnsCorrectMappingForGetKubernetesToCoreDNSVersionMap(t *testing.T) {
37+
mapping := GetKubernetesToCoreDNSVersionMap()
38+
expected := map[string]string{
39+
"v1.22": "v1.8.4",
40+
"v1.23": "v1.8.6",
41+
"v1.24": "v1.8.6",
42+
"v1.25": "v1.9.3",
43+
"v1.26": "v1.9.3",
44+
"v1.27": "v1.10.1",
45+
"v1.28": "v1.10.1",
46+
"v1.29": "v1.11.1",
47+
"v1.30": "v1.11.3",
48+
"v1.31": "v1.11.3",
49+
}
50+
assert.Equal(t, expected, mapping)
51+
}

0 commit comments

Comments
 (0)