Skip to content

Commit b23772d

Browse files
committed
kubeadm: cleanup unnecessary k8sVer parameter for GetStaticPodSpecs
1 parent aaad86c commit b23772d

File tree

4 files changed

+11
-23
lines changed

4 files changed

+11
-23
lines changed

cmd/kubeadm/app/cmd/upgrade/diff.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,14 @@ func runDiff(flags *diffFlags, args []string) error {
9898
flags.newK8sVersionStr = args[0]
9999
}
100100

101-
k8sVer, err := version.ParseSemantic(flags.newK8sVersionStr)
101+
_, err = version.ParseSemantic(flags.newK8sVersionStr)
102102
if err != nil {
103103
return err
104104
}
105105

106-
specs := controlplane.GetStaticPodSpecs(&cfg.ClusterConfiguration, &cfg.LocalAPIEndpoint, k8sVer)
106+
cfg.ClusterConfiguration.KubernetesVersion = flags.newK8sVersionStr
107+
108+
specs := controlplane.GetStaticPodSpecs(&cfg.ClusterConfiguration, &cfg.LocalAPIEndpoint)
107109
for spec, pod := range specs {
108110
var path string
109111
switch spec {

cmd/kubeadm/app/phases/controlplane/BUILD

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ go_test(
2121
"//pkg/kubeapiserver/authorizer/modes:go_default_library",
2222
"//staging/src/k8s.io/api/core/v1:go_default_library",
2323
"//staging/src/k8s.io/apimachinery/pkg/util/sets:go_default_library",
24-
"//staging/src/k8s.io/apimachinery/pkg/util/version:go_default_library",
2524
],
2625
)
2726

@@ -43,7 +42,6 @@ go_library(
4342
"//staging/src/k8s.io/api/core/v1:go_default_library",
4443
"//staging/src/k8s.io/apimachinery/pkg/util/intstr:go_default_library",
4544
"//staging/src/k8s.io/apimachinery/pkg/util/sets:go_default_library",
46-
"//staging/src/k8s.io/apimachinery/pkg/util/version:go_default_library",
4745
"//vendor/github.com/pkg/errors:go_default_library",
4846
"//vendor/k8s.io/klog:go_default_library",
4947
"//vendor/k8s.io/utils/net:go_default_library",

cmd/kubeadm/app/phases/controlplane/manifests.go

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import (
2727
"github.com/pkg/errors"
2828
"k8s.io/api/core/v1"
2929
"k8s.io/apimachinery/pkg/util/intstr"
30-
"k8s.io/apimachinery/pkg/util/version"
3130
"k8s.io/klog"
3231
kubeadmapi "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm"
3332
kubeadmconstants "k8s.io/kubernetes/cmd/kubeadm/app/constants"
@@ -47,7 +46,7 @@ func CreateInitStaticPodManifestFiles(manifestDir string, cfg *kubeadmapi.InitCo
4746

4847
// GetStaticPodSpecs returns all staticPodSpecs actualized to the context of the current configuration
4948
// NB. this methods holds the information about how kubeadm creates static pod manifests.
50-
func GetStaticPodSpecs(cfg *kubeadmapi.ClusterConfiguration, endpoint *kubeadmapi.APIEndpoint, k8sVersion *version.Version) map[string]v1.Pod {
49+
func GetStaticPodSpecs(cfg *kubeadmapi.ClusterConfiguration, endpoint *kubeadmapi.APIEndpoint) map[string]v1.Pod {
5150
// Get the required hostpath mounts
5251
mounts := getHostPathVolumesForTheControlPlane(cfg)
5352

@@ -67,7 +66,7 @@ func GetStaticPodSpecs(cfg *kubeadmapi.ClusterConfiguration, endpoint *kubeadmap
6766
Name: kubeadmconstants.KubeControllerManager,
6867
Image: images.GetKubernetesImage(kubeadmconstants.KubeControllerManager, cfg),
6968
ImagePullPolicy: v1.PullIfNotPresent,
70-
Command: getControllerManagerCommand(cfg, k8sVersion),
69+
Command: getControllerManagerCommand(cfg),
7170
VolumeMounts: staticpodutil.VolumeMountMapToSlice(mounts.GetVolumeMounts(kubeadmconstants.KubeControllerManager)),
7271
LivenessProbe: livenessProbe(staticpodutil.GetControllerManagerProbeAddress(cfg), kubeadmconstants.InsecureKubeControllerManagerPort, v1.URISchemeHTTP),
7372
Resources: staticpodutil.ComponentResources("200m"),
@@ -105,15 +104,9 @@ func livenessProbe(host string, port int, scheme v1.URIScheme) *v1.Probe {
105104

106105
// CreateStaticPodFiles creates all the requested static pod files.
107106
func CreateStaticPodFiles(manifestDir string, cfg *kubeadmapi.ClusterConfiguration, endpoint *kubeadmapi.APIEndpoint, componentNames ...string) error {
108-
// TODO: Move the "pkg/util/version".Version object into the internal API instead of always parsing the string
109-
k8sVersion, err := version.ParseSemantic(cfg.KubernetesVersion)
110-
if err != nil {
111-
return err
112-
}
113-
114107
// gets the StaticPodSpecs, actualized for the current ClusterConfiguration
115108
klog.V(1).Infoln("[control-plane] getting StaticPodSpecs")
116-
specs := GetStaticPodSpecs(cfg, endpoint, k8sVersion)
109+
specs := GetStaticPodSpecs(cfg, endpoint)
117110

118111
// creates required static pod specs
119112
for _, componentName := range componentNames {
@@ -262,7 +255,7 @@ func calcNodeCidrSize(podSubnet string) string {
262255
}
263256

264257
// getControllerManagerCommand builds the right controller manager command from the given config object and version
265-
func getControllerManagerCommand(cfg *kubeadmapi.ClusterConfiguration, k8sVersion *version.Version) []string {
258+
func getControllerManagerCommand(cfg *kubeadmapi.ClusterConfiguration) []string {
266259

267260
kubeconfigFile := filepath.Join(kubeadmconstants.KubernetesDir, kubeadmconstants.ControllerManagerKubeConfigFileName)
268261
caFile := filepath.Join(cfg.CertificatesDir, kubeadmconstants.CACertName)

cmd/kubeadm/app/phases/controlplane/manifests_test.go

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import (
2626
"testing"
2727

2828
"k8s.io/apimachinery/pkg/util/sets"
29-
"k8s.io/apimachinery/pkg/util/version"
3029
kubeadmapi "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm"
3130
kubeadmconstants "k8s.io/kubernetes/cmd/kubeadm/app/constants"
3231
"k8s.io/kubernetes/cmd/kubeadm/app/phases/certs"
@@ -49,11 +48,7 @@ func TestGetStaticPodSpecs(t *testing.T) {
4948
}
5049

5150
// Executes GetStaticPodSpecs
52-
53-
// TODO: Move the "pkg/util/version".Version object into the internal API instead of always parsing the string
54-
k8sVersion, _ := version.ParseSemantic(cfg.KubernetesVersion)
55-
56-
specs := GetStaticPodSpecs(cfg, &kubeadmapi.APIEndpoint{}, k8sVersion)
51+
specs := GetStaticPodSpecs(cfg, &kubeadmapi.APIEndpoint{})
5752

5853
var tests = []struct {
5954
name string
@@ -672,7 +667,7 @@ func TestGetControllerManagerCommand(t *testing.T) {
672667

673668
for _, rt := range tests {
674669
t.Run(rt.name, func(t *testing.T) {
675-
actual := getControllerManagerCommand(rt.cfg, version.MustParseSemantic(rt.cfg.KubernetesVersion))
670+
actual := getControllerManagerCommand(rt.cfg)
676671
sort.Strings(actual)
677672
sort.Strings(rt.expected)
678673
if !reflect.DeepEqual(actual, rt.expected) {
@@ -848,7 +843,7 @@ func TestGetControllerManagerCommandExternalCA(t *testing.T) {
848843
}
849844
}
850845

851-
actual := getControllerManagerCommand(&test.cfg.ClusterConfiguration, version.MustParseSemantic(test.cfg.KubernetesVersion))
846+
actual := getControllerManagerCommand(&test.cfg.ClusterConfiguration)
852847
expected := test.expectedArgFunc(tmpdir)
853848
sort.Strings(actual)
854849
sort.Strings(expected)

0 commit comments

Comments
 (0)