Skip to content

Commit

Permalink
feat(api): Add kubernetes version to coredns version mapping (#939)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
thunderboltsid authored Oct 10, 2024
1 parent adf8a6a commit 4751e3c
Show file tree
Hide file tree
Showing 8 changed files with 556 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ repos:
language: system
files: "^devbox.(yaml|lock)$"
pass_filenames: false
- id: check-coredns-versions
name: check-coredns-versions
entry: make coredns.sync
language: system
files: "^api/versions/coredns.go$"
- repo: https://github.com/tekwizely/pre-commit-golang
rev: v1.0.0-rc.1
hooks:
Expand Down
4 changes: 3 additions & 1 deletion api/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ replace github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/c

require (
github.com/aws/aws-sdk-go v1.55.5
github.com/blang/semver/v4 v4.0.0
github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common v0.7.0
github.com/nutanix-cloud-native/prism-go-client v0.5.1
github.com/onsi/gomega v1.34.2
github.com/stretchr/testify v1.9.0
k8s.io/api v0.30.5
k8s.io/apiextensions-apiserver v0.30.5
k8s.io/apimachinery v0.30.5
Expand All @@ -24,7 +26,6 @@ require (

require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/blang/semver/v4 v4.0.0 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/emicklei/go-restful/v3 v3.12.1 // indirect
Expand All @@ -51,6 +52,7 @@ require (
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_golang v1.18.0 // indirect
github.com/prometheus/client_model v0.6.0 // indirect
github.com/prometheus/common v0.45.0 // indirect
Expand Down
77 changes: 77 additions & 0 deletions api/versions/coredns.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

51 changes: 51 additions & 0 deletions api/versions/coredns_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Copyright 2024 Nutanix. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

package versions

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestReturnsCorrectCoreDNSVersionForValidKubernetesVersion(t *testing.T) {
version, found := GetCoreDNSVersion("v1.27")
assert.True(t, found)
assert.Equal(t, "v1.10.1", version)
}

func TestReturnsCorrectCoreDNSVersionForValidKubernetesVersionWithoutVPrefix(t *testing.T) {
version, found := GetCoreDNSVersion("1.27")
assert.True(t, found)
assert.Equal(t, "v1.10.1", version)
}

func TestReturnsFalseForInvalidKubernetesVersion(t *testing.T) {
version, found := GetCoreDNSVersion("v2.99")
assert.False(t, found)
assert.Equal(t, "", version)
}

func TestReturnsFalseForMalformedKubernetesVersion(t *testing.T) {
version, found := GetCoreDNSVersion("invalid-version")
assert.False(t, found)
assert.Equal(t, "", version)
}

func TestReturnsCorrectMappingForGetKubernetesToCoreDNSVersionMap(t *testing.T) {
mapping := GetKubernetesToCoreDNSVersionMap()
expected := map[string]string{
"v1.22": "v1.8.4",
"v1.23": "v1.8.6",
"v1.24": "v1.8.6",
"v1.25": "v1.9.3",
"v1.26": "v1.9.3",
"v1.27": "v1.10.1",
"v1.28": "v1.10.1",
"v1.29": "v1.11.1",
"v1.30": "v1.11.3",
"v1.31": "v1.11.3",
}
assert.Equal(t, expected, mapping)
}
Loading

0 comments on commit 4751e3c

Please sign in to comment.