mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-25 20:53:33 +00:00
kubeadm: support fetching configuration from the original cluster for 'upgrade diff'
This commit is contained in:
parent
a5eedcde61
commit
a49f62f786
@ -26,12 +26,15 @@ import (
|
|||||||
corev1 "k8s.io/api/core/v1"
|
corev1 "k8s.io/api/core/v1"
|
||||||
"k8s.io/apimachinery/pkg/util/version"
|
"k8s.io/apimachinery/pkg/util/version"
|
||||||
"k8s.io/klog"
|
"k8s.io/klog"
|
||||||
|
kubeadmapi "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm"
|
||||||
"k8s.io/kubernetes/cmd/kubeadm/app/cmd/options"
|
"k8s.io/kubernetes/cmd/kubeadm/app/cmd/options"
|
||||||
cmdutil "k8s.io/kubernetes/cmd/kubeadm/app/cmd/util"
|
cmdutil "k8s.io/kubernetes/cmd/kubeadm/app/cmd/util"
|
||||||
"k8s.io/kubernetes/cmd/kubeadm/app/constants"
|
"k8s.io/kubernetes/cmd/kubeadm/app/constants"
|
||||||
|
kubeadmconstants "k8s.io/kubernetes/cmd/kubeadm/app/constants"
|
||||||
"k8s.io/kubernetes/cmd/kubeadm/app/phases/controlplane"
|
"k8s.io/kubernetes/cmd/kubeadm/app/phases/controlplane"
|
||||||
kubeadmutil "k8s.io/kubernetes/cmd/kubeadm/app/util"
|
kubeadmutil "k8s.io/kubernetes/cmd/kubeadm/app/util"
|
||||||
configutil "k8s.io/kubernetes/cmd/kubeadm/app/util/config"
|
configutil "k8s.io/kubernetes/cmd/kubeadm/app/util/config"
|
||||||
|
kubeconfigutil "k8s.io/kubernetes/cmd/kubeadm/app/util/kubeconfig"
|
||||||
)
|
)
|
||||||
|
|
||||||
type diffFlags struct {
|
type diffFlags struct {
|
||||||
@ -40,6 +43,7 @@ type diffFlags struct {
|
|||||||
schedulerManifestPath string
|
schedulerManifestPath string
|
||||||
newK8sVersionStr string
|
newK8sVersionStr string
|
||||||
contextLines int
|
contextLines int
|
||||||
|
kubeConfigPath string
|
||||||
cfgPath string
|
cfgPath string
|
||||||
out io.Writer
|
out io.Writer
|
||||||
}
|
}
|
||||||
@ -53,7 +57,8 @@ var (
|
|||||||
// NewCmdDiff returns the cobra command for `kubeadm upgrade diff`
|
// NewCmdDiff returns the cobra command for `kubeadm upgrade diff`
|
||||||
func NewCmdDiff(out io.Writer) *cobra.Command {
|
func NewCmdDiff(out io.Writer) *cobra.Command {
|
||||||
flags := &diffFlags{
|
flags := &diffFlags{
|
||||||
out: out,
|
kubeConfigPath: kubeadmconstants.GetAdminKubeConfigPath(),
|
||||||
|
out: out,
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd := &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
@ -65,6 +70,7 @@ func NewCmdDiff(out io.Writer) *cobra.Command {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
options.AddKubeConfigFlag(cmd.Flags(), &flags.kubeConfigPath)
|
||||||
options.AddConfigFlag(cmd.Flags(), &flags.cfgPath)
|
options.AddConfigFlag(cmd.Flags(), &flags.cfgPath)
|
||||||
cmd.Flags().StringVar(&flags.apiServerManifestPath, "api-server-manifest", defaultAPIServerManifestPath, "path to API server manifest")
|
cmd.Flags().StringVar(&flags.apiServerManifestPath, "api-server-manifest", defaultAPIServerManifestPath, "path to API server manifest")
|
||||||
cmd.Flags().StringVar(&flags.controllerManagerManifestPath, "controller-manager-manifest", defaultControllerManagerManifestPath, "path to controller manifest")
|
cmd.Flags().StringVar(&flags.controllerManagerManifestPath, "controller-manager-manifest", defaultControllerManagerManifestPath, "path to controller manifest")
|
||||||
@ -75,13 +81,22 @@ func NewCmdDiff(out io.Writer) *cobra.Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func runDiff(flags *diffFlags, args []string) error {
|
func runDiff(flags *diffFlags, args []string) error {
|
||||||
|
var err error
|
||||||
// If the version is specified in config file, pick up that value.
|
var cfg *kubeadmapi.InitConfiguration
|
||||||
cfg, err := configutil.LoadInitConfigurationFromFile(flags.cfgPath)
|
if flags.cfgPath != "" {
|
||||||
|
cfg, err = configutil.LoadInitConfigurationFromFile(flags.cfgPath)
|
||||||
|
} else {
|
||||||
|
client, err := kubeconfigutil.ClientSetFromFile(flags.kubeConfigPath)
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrapf(err, "couldn't create a Kubernetes client from file %q", flags.kubeConfigPath)
|
||||||
|
}
|
||||||
|
cfg, err = configutil.FetchInitConfigurationFromCluster(client, flags.out, "upgrade/diff", false)
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If the version is specified in config file, pick up that value.
|
||||||
if cfg.KubernetesVersion != "" {
|
if cfg.KubernetesVersion != "" {
|
||||||
flags.newK8sVersionStr = cfg.KubernetesVersion
|
flags.newK8sVersionStr = cfg.KubernetesVersion
|
||||||
}
|
}
|
||||||
|
@ -32,6 +32,7 @@ func TestRunDiff(t *testing.T) {
|
|||||||
out: ioutil.Discard,
|
out: ioutil.Discard,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Add test cases for empty cfgPath, it should automatically fetch cfg from cluster
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
name string
|
name string
|
||||||
args []string
|
args []string
|
||||||
|
Loading…
Reference in New Issue
Block a user