From 914fd40712c3e97c610024eaac07d025048a27e9 Mon Sep 17 00:00:00 2001 From: "Lubomir I. Ivanov" Date: Thu, 12 Sep 2024 11:49:56 +0300 Subject: [PATCH] kubeadm: add default paths to 'upgrade diff' After the flags to control manifest paths were removed, the variables in diff.go remained empty and the validation fails with "empty manifest path". Always populate the paths with the kubeadm defaults under /etc/kubernetes/manifest and remove the empty path validation. --- cmd/kubeadm/app/cmd/upgrade/diff.go | 10 +++++----- cmd/kubeadm/app/cmd/upgrade/diff_test.go | 7 ------- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/cmd/kubeadm/app/cmd/upgrade/diff.go b/cmd/kubeadm/app/cmd/upgrade/diff.go index 56940713b64..be62ed6509b 100644 --- a/cmd/kubeadm/app/cmd/upgrade/diff.go +++ b/cmd/kubeadm/app/cmd/upgrade/diff.go @@ -57,8 +57,11 @@ type diffFlags struct { // newCmdDiff returns the cobra command for `kubeadm upgrade diff` func newCmdDiff(out io.Writer) *cobra.Command { flags := &diffFlags{ - kubeConfigPath: constants.GetAdminKubeConfigPath(), - out: out, + kubeConfigPath: constants.GetAdminKubeConfigPath(), + out: out, + apiServerManifestPath: constants.GetStaticPodFilepath(constants.KubeAPIServer, constants.GetStaticPodDirectory()), + controllerManagerManifestPath: constants.GetStaticPodFilepath(constants.KubeControllerManager, constants.GetStaticPodDirectory()), + schedulerManifestPath: constants.GetStaticPodFilepath(constants.KubeScheduler, constants.GetStaticPodDirectory()), } cmd := &cobra.Command{ @@ -88,9 +91,6 @@ func newCmdDiff(out io.Writer) *cobra.Command { func validateManifestsPath(manifests ...string) (err error) { for _, manifestPath := range manifests { - if len(manifestPath) == 0 { - return errors.New("empty manifest path") - } s, err := os.Stat(manifestPath) if err != nil { if os.IsNotExist(err) { diff --git a/cmd/kubeadm/app/cmd/upgrade/diff_test.go b/cmd/kubeadm/app/cmd/upgrade/diff_test.go index 8d7d858a69b..65d4e6b5c2a 100644 --- a/cmd/kubeadm/app/cmd/upgrade/diff_test.go +++ b/cmd/kubeadm/app/cmd/upgrade/diff_test.go @@ -113,13 +113,6 @@ diff: cfgPath: "missing-path-to-a-config", expectedError: true, }, - { - name: "invalid: valid config but empty manifest path", - cfgPath: testUpgradeDiffConfig, - setManifestPath: true, - manifestPath: "", - expectedError: true, - }, { name: "invalid: valid config but bad manifest path", cfgPath: testUpgradeDiffConfig,