mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 11:50:44 +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"
|
||||
"k8s.io/apimachinery/pkg/util/version"
|
||||
"k8s.io/klog"
|
||||
kubeadmapi "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm"
|
||||
"k8s.io/kubernetes/cmd/kubeadm/app/cmd/options"
|
||||
cmdutil "k8s.io/kubernetes/cmd/kubeadm/app/cmd/util"
|
||||
"k8s.io/kubernetes/cmd/kubeadm/app/constants"
|
||||
kubeadmconstants "k8s.io/kubernetes/cmd/kubeadm/app/constants"
|
||||
"k8s.io/kubernetes/cmd/kubeadm/app/phases/controlplane"
|
||||
kubeadmutil "k8s.io/kubernetes/cmd/kubeadm/app/util"
|
||||
configutil "k8s.io/kubernetes/cmd/kubeadm/app/util/config"
|
||||
kubeconfigutil "k8s.io/kubernetes/cmd/kubeadm/app/util/kubeconfig"
|
||||
)
|
||||
|
||||
type diffFlags struct {
|
||||
@ -40,6 +43,7 @@ type diffFlags struct {
|
||||
schedulerManifestPath string
|
||||
newK8sVersionStr string
|
||||
contextLines int
|
||||
kubeConfigPath string
|
||||
cfgPath string
|
||||
out io.Writer
|
||||
}
|
||||
@ -53,7 +57,8 @@ var (
|
||||
// NewCmdDiff returns the cobra command for `kubeadm upgrade diff`
|
||||
func NewCmdDiff(out io.Writer) *cobra.Command {
|
||||
flags := &diffFlags{
|
||||
out: out,
|
||||
kubeConfigPath: kubeadmconstants.GetAdminKubeConfigPath(),
|
||||
out: out,
|
||||
}
|
||||
|
||||
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)
|
||||
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")
|
||||
@ -75,13 +81,22 @@ func NewCmdDiff(out io.Writer) *cobra.Command {
|
||||
}
|
||||
|
||||
func runDiff(flags *diffFlags, args []string) error {
|
||||
|
||||
// If the version is specified in config file, pick up that value.
|
||||
cfg, err := configutil.LoadInitConfigurationFromFile(flags.cfgPath)
|
||||
var err error
|
||||
var cfg *kubeadmapi.InitConfiguration
|
||||
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 {
|
||||
return err
|
||||
}
|
||||
|
||||
// If the version is specified in config file, pick up that value.
|
||||
if cfg.KubernetesVersion != "" {
|
||||
flags.newK8sVersionStr = cfg.KubernetesVersion
|
||||
}
|
||||
|
@ -32,6 +32,7 @@ func TestRunDiff(t *testing.T) {
|
||||
out: ioutil.Discard,
|
||||
}
|
||||
|
||||
// TODO: Add test cases for empty cfgPath, it should automatically fetch cfg from cluster
|
||||
testCases := []struct {
|
||||
name string
|
||||
args []string
|
||||
|
Loading…
Reference in New Issue
Block a user