mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-22 11:21:47 +00:00
kubeadm: respect user specified image repository when using Kubernetes ci version
This commit is contained in:
parent
4569e646ef
commit
723cadf750
@ -364,6 +364,9 @@ const (
|
|||||||
// TODO: Find a better place for this constant
|
// TODO: Find a better place for this constant
|
||||||
YAMLDocumentSeparator = "---\n"
|
YAMLDocumentSeparator = "---\n"
|
||||||
|
|
||||||
|
// CIKubernetesVersionPrefix is the prefix for CI Kubernetes version
|
||||||
|
CIKubernetesVersionPrefix = "ci/"
|
||||||
|
|
||||||
// DefaultAPIServerBindAddress is the default bind address for the API Server
|
// DefaultAPIServerBindAddress is the default bind address for the API Server
|
||||||
DefaultAPIServerBindAddress = "0.0.0.0"
|
DefaultAPIServerBindAddress = "0.0.0.0"
|
||||||
|
|
||||||
|
@ -94,7 +94,7 @@ func NormalizeKubernetesVersion(cfg *kubeadmapi.ClusterConfiguration) error {
|
|||||||
isCIVersion := kubeadmutil.KubernetesIsCIVersion(cfg.KubernetesVersion)
|
isCIVersion := kubeadmutil.KubernetesIsCIVersion(cfg.KubernetesVersion)
|
||||||
|
|
||||||
// Requested version is automatic CI build, thus use KubernetesCI Image Repository for core images
|
// Requested version is automatic CI build, thus use KubernetesCI Image Repository for core images
|
||||||
if isCIVersion {
|
if isCIVersion && cfg.ImageRepository == kubeadmapiv1.DefaultImageRepository {
|
||||||
cfg.CIImageRepository = constants.DefaultCIImageRepository
|
cfg.CIImageRepository = constants.DefaultCIImageRepository
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -106,7 +106,7 @@ func NormalizeKubernetesVersion(cfg *kubeadmapi.ClusterConfiguration) error {
|
|||||||
|
|
||||||
// Requested version is automatic CI build, thus mark CIKubernetesVersion as `ci/<resolved-version>`
|
// Requested version is automatic CI build, thus mark CIKubernetesVersion as `ci/<resolved-version>`
|
||||||
if isCIVersion {
|
if isCIVersion {
|
||||||
cfg.CIKubernetesVersion = fmt.Sprintf("ci/%s", ver)
|
cfg.CIKubernetesVersion = fmt.Sprintf("%s%s", constants.CIKubernetesVersionPrefix, ver)
|
||||||
}
|
}
|
||||||
|
|
||||||
cfg.KubernetesVersion = ver
|
cfg.KubernetesVersion = ver
|
||||||
|
@ -18,6 +18,7 @@ package config
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/lithammer/dedent"
|
"github.com/lithammer/dedent"
|
||||||
@ -26,6 +27,7 @@ import (
|
|||||||
"k8s.io/apimachinery/pkg/util/version"
|
"k8s.io/apimachinery/pkg/util/version"
|
||||||
apimachineryversion "k8s.io/apimachinery/pkg/version"
|
apimachineryversion "k8s.io/apimachinery/pkg/version"
|
||||||
|
|
||||||
|
kubeadmapi "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm"
|
||||||
kubeadmapiv1old "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm/v1beta2"
|
kubeadmapiv1old "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm/v1beta2"
|
||||||
kubeadmapiv1 "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm/v1beta3"
|
kubeadmapiv1 "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm/v1beta3"
|
||||||
"k8s.io/kubernetes/cmd/kubeadm/app/constants"
|
"k8s.io/kubernetes/cmd/kubeadm/app/constants"
|
||||||
@ -452,3 +454,97 @@ func TestIsKubeadmPrereleaseVersion(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestNormalizeKubernetesVersion(t *testing.T) {
|
||||||
|
validVersion := fmt.Sprintf("v%v", constants.MinimumControlPlaneVersion)
|
||||||
|
validCIVersion := fmt.Sprintf("%s%s", constants.CIKubernetesVersionPrefix, validVersion)
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
cfg *kubeadmapi.ClusterConfiguration
|
||||||
|
expectedCfg *kubeadmapi.ClusterConfiguration
|
||||||
|
expectErr bool
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "normal version, default image repository",
|
||||||
|
cfg: &kubeadmapi.ClusterConfiguration{
|
||||||
|
KubernetesVersion: validVersion,
|
||||||
|
ImageRepository: kubeadmapiv1.DefaultImageRepository,
|
||||||
|
},
|
||||||
|
expectedCfg: &kubeadmapi.ClusterConfiguration{
|
||||||
|
KubernetesVersion: validVersion,
|
||||||
|
CIKubernetesVersion: "",
|
||||||
|
ImageRepository: kubeadmapiv1.DefaultImageRepository,
|
||||||
|
CIImageRepository: "",
|
||||||
|
},
|
||||||
|
expectErr: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "normal version, custom image repository",
|
||||||
|
cfg: &kubeadmapi.ClusterConfiguration{
|
||||||
|
KubernetesVersion: validVersion,
|
||||||
|
ImageRepository: "custom.repository",
|
||||||
|
},
|
||||||
|
expectedCfg: &kubeadmapi.ClusterConfiguration{
|
||||||
|
KubernetesVersion: validVersion,
|
||||||
|
CIKubernetesVersion: "",
|
||||||
|
ImageRepository: "custom.repository",
|
||||||
|
CIImageRepository: "",
|
||||||
|
},
|
||||||
|
expectErr: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "ci version, default image repository",
|
||||||
|
cfg: &kubeadmapi.ClusterConfiguration{
|
||||||
|
KubernetesVersion: validCIVersion,
|
||||||
|
ImageRepository: kubeadmapiv1.DefaultImageRepository,
|
||||||
|
},
|
||||||
|
expectedCfg: &kubeadmapi.ClusterConfiguration{
|
||||||
|
KubernetesVersion: validVersion,
|
||||||
|
CIKubernetesVersion: validCIVersion,
|
||||||
|
ImageRepository: kubeadmapiv1.DefaultImageRepository,
|
||||||
|
CIImageRepository: constants.DefaultCIImageRepository,
|
||||||
|
},
|
||||||
|
expectErr: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "ci version, custom image repository",
|
||||||
|
cfg: &kubeadmapi.ClusterConfiguration{
|
||||||
|
KubernetesVersion: validCIVersion,
|
||||||
|
ImageRepository: "custom.repository",
|
||||||
|
},
|
||||||
|
expectedCfg: &kubeadmapi.ClusterConfiguration{
|
||||||
|
KubernetesVersion: validVersion,
|
||||||
|
CIKubernetesVersion: validCIVersion,
|
||||||
|
ImageRepository: "custom.repository",
|
||||||
|
CIImageRepository: "",
|
||||||
|
},
|
||||||
|
expectErr: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "unsupported old version",
|
||||||
|
cfg: &kubeadmapi.ClusterConfiguration{
|
||||||
|
KubernetesVersion: "v0.0.0",
|
||||||
|
ImageRepository: kubeadmapiv1.DefaultImageRepository,
|
||||||
|
},
|
||||||
|
expectedCfg: &kubeadmapi.ClusterConfiguration{
|
||||||
|
KubernetesVersion: "v0.0.0",
|
||||||
|
CIKubernetesVersion: "",
|
||||||
|
ImageRepository: kubeadmapiv1.DefaultImageRepository,
|
||||||
|
CIImageRepository: "",
|
||||||
|
},
|
||||||
|
expectErr: true,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tc := range tests {
|
||||||
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
|
err := NormalizeKubernetesVersion(tc.cfg)
|
||||||
|
if !reflect.DeepEqual(tc.cfg, tc.expectedCfg) {
|
||||||
|
t.Errorf("expected ClusterConfiguration: %#v, got %#v", tc.expectedCfg, tc.cfg)
|
||||||
|
}
|
||||||
|
if !tc.expectErr && err != nil {
|
||||||
|
t.Errorf("unexpected failure: %v", err)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user