From 44e49f00bceee81b3b9d38b1f277994aafa0d918 Mon Sep 17 00:00:00 2001 From: fabriziopandini Date: Mon, 10 Sep 2018 10:23:46 +0200 Subject: [PATCH] kubeadm-annotate-cri --- cmd/kubeadm/app/cmd/phases/BUILD | 1 + cmd/kubeadm/app/cmd/phases/kubelet.go | 49 +++++++++++++++++++ docs/.generated_docs | 2 + ...alpha_phase_kubelet_config_annotate-cri.md | 3 ++ ...-alpha-phase-kubelet-config-annotate-cri.1 | 3 ++ 5 files changed, 58 insertions(+) create mode 100644 docs/admin/kubeadm_alpha_phase_kubelet_config_annotate-cri.md create mode 100644 docs/man/man1/kubeadm-alpha-phase-kubelet-config-annotate-cri.1 diff --git a/cmd/kubeadm/app/cmd/phases/BUILD b/cmd/kubeadm/app/cmd/phases/BUILD index 636aeef99f0..c9750d5ec00 100644 --- a/cmd/kubeadm/app/cmd/phases/BUILD +++ b/cmd/kubeadm/app/cmd/phases/BUILD @@ -38,6 +38,7 @@ go_library( "//cmd/kubeadm/app/phases/kubeconfig:go_default_library", "//cmd/kubeadm/app/phases/kubelet:go_default_library", "//cmd/kubeadm/app/phases/markmaster:go_default_library", + "//cmd/kubeadm/app/phases/patchnode:go_default_library", "//cmd/kubeadm/app/phases/selfhosting:go_default_library", "//cmd/kubeadm/app/phases/upgrade:go_default_library", "//cmd/kubeadm/app/phases/uploadconfig:go_default_library", diff --git a/cmd/kubeadm/app/cmd/phases/kubelet.go b/cmd/kubeadm/app/cmd/phases/kubelet.go index 927121b4b0f..2c14dd7563a 100644 --- a/cmd/kubeadm/app/cmd/phases/kubelet.go +++ b/cmd/kubeadm/app/cmd/phases/kubelet.go @@ -27,6 +27,7 @@ import ( cmdutil "k8s.io/kubernetes/cmd/kubeadm/app/cmd/util" "k8s.io/kubernetes/cmd/kubeadm/app/constants" kubeletphase "k8s.io/kubernetes/cmd/kubeadm/app/phases/kubelet" + patchnodephase "k8s.io/kubernetes/cmd/kubeadm/app/phases/patchnode" "k8s.io/kubernetes/cmd/kubeadm/app/preflight" kubeadmutil "k8s.io/kubernetes/cmd/kubeadm/app/util" configutil "k8s.io/kubernetes/cmd/kubeadm/app/util/config" @@ -61,6 +62,14 @@ var ( kubeadm alpha phase kubelet config upload --config kubeadm.yaml `) + kubeletConfigAnnotateCRILongDesc = normalizer.LongDesc(` + Adds an annotation to the current node with the CRI socket specified in the kubeadm InitConfiguration object. + ` + cmdutil.AlphaDisclaimer) + + kubeletConfigAnnotateCRIExample = normalizer.Examples(` + kubeadm alpha phase kubelet config annotate-cri --config kubeadm.yaml + `) + kubeletConfigDownloadLongDesc = normalizer.LongDesc(` Downloads the kubelet configuration from a ConfigMap of the form "kubelet-config-1.X" in the cluster, where X is the minor version of the kubelet. Either kubeadm autodetects the kubelet version by exec-ing @@ -177,6 +186,7 @@ func NewCmdKubeletConfig() *cobra.Command { } cmd.AddCommand(NewCmdKubeletConfigUpload()) + cmd.AddCommand(NewCmdKubeletAnnotateCRI()) cmd.AddCommand(NewCmdKubeletConfigDownload()) cmd.AddCommand(NewCmdKubeletConfigWriteToDisk()) cmd.AddCommand(NewCmdKubeletConfigEnableDynamic()) @@ -222,6 +232,45 @@ func NewCmdKubeletConfigUpload() *cobra.Command { return cmd } +// NewCmdKubeletAnnotateCRI calls cobra.Command for annotating the node with the given crisocket +func NewCmdKubeletAnnotateCRI() *cobra.Command { + cfg := &kubeadmapiv1alpha3.InitConfiguration{} + var cfgPath string + kubeConfigFile := constants.GetAdminKubeConfigPath() + + cmd := &cobra.Command{ + Use: "annotate-cri", + Short: "annotates the node with the given crisocket", + Long: kubeletConfigAnnotateCRILongDesc, + Example: kubeletConfigAnnotateCRIExample, + Run: func(cmd *cobra.Command, args []string) { + if len(cfgPath) == 0 { + kubeadmutil.CheckErr(fmt.Errorf("The --config argument is required")) + } + + // KubernetesVersion is not used, but we set it explicitly to avoid the lookup + // of the version from the internet when executing ConfigFileAndDefaultsToInternalConfig + err := SetKubernetesVersion(nil, cfg) + kubeadmutil.CheckErr(err) + + // This call returns the ready-to-use configuration based on the configuration file + internalcfg, err := configutil.ConfigFileAndDefaultsToInternalConfig(cfgPath, cfg) + kubeadmutil.CheckErr(err) + + kubeConfigFile = cmdutil.FindExistingKubeConfig(kubeConfigFile) + client, err := kubeconfigutil.ClientSetFromFile(kubeConfigFile) + kubeadmutil.CheckErr(err) + + err = patchnodephase.AnnotateCRISocket(client, internalcfg.NodeRegistration.Name, internalcfg.NodeRegistration.CRISocket) + kubeadmutil.CheckErr(err) + }, + } + + options.AddKubeConfigFlag(cmd.Flags(), &kubeConfigFile) + options.AddConfigFlag(cmd.Flags(), &cfgPath) + return cmd +} + // NewCmdKubeletConfigDownload calls cobra.Command for downloading the kubelet configuration from the kubelet-config-1.X ConfigMap in the cluster func NewCmdKubeletConfigDownload() *cobra.Command { var kubeletVersionStr string diff --git a/docs/.generated_docs b/docs/.generated_docs index 37f48f72adf..d6662f5c58f 100644 --- a/docs/.generated_docs +++ b/docs/.generated_docs @@ -47,6 +47,7 @@ docs/admin/kubeadm_alpha_phase_kubeconfig_scheduler.md docs/admin/kubeadm_alpha_phase_kubeconfig_user.md docs/admin/kubeadm_alpha_phase_kubelet.md docs/admin/kubeadm_alpha_phase_kubelet_config.md +docs/admin/kubeadm_alpha_phase_kubelet_config_annotate-cri.md docs/admin/kubeadm_alpha_phase_kubelet_config_download.md docs/admin/kubeadm_alpha_phase_kubelet_config_enable-dynamic.md docs/admin/kubeadm_alpha_phase_kubelet_config_upload.md @@ -130,6 +131,7 @@ docs/man/man1/kubeadm-alpha-phase-kubeconfig-kubelet.1 docs/man/man1/kubeadm-alpha-phase-kubeconfig-scheduler.1 docs/man/man1/kubeadm-alpha-phase-kubeconfig-user.1 docs/man/man1/kubeadm-alpha-phase-kubeconfig.1 +docs/man/man1/kubeadm-alpha-phase-kubelet-config-annotate-cri.1 docs/man/man1/kubeadm-alpha-phase-kubelet-config-download.1 docs/man/man1/kubeadm-alpha-phase-kubelet-config-enable-dynamic.1 docs/man/man1/kubeadm-alpha-phase-kubelet-config-upload.1 diff --git a/docs/admin/kubeadm_alpha_phase_kubelet_config_annotate-cri.md b/docs/admin/kubeadm_alpha_phase_kubelet_config_annotate-cri.md new file mode 100644 index 00000000000..b6fd7a0f989 --- /dev/null +++ b/docs/admin/kubeadm_alpha_phase_kubelet_config_annotate-cri.md @@ -0,0 +1,3 @@ +This file is autogenerated, but we've stopped checking such files into the +repository to reduce the need for rebases. Please run hack/generate-docs.sh to +populate this file. diff --git a/docs/man/man1/kubeadm-alpha-phase-kubelet-config-annotate-cri.1 b/docs/man/man1/kubeadm-alpha-phase-kubelet-config-annotate-cri.1 new file mode 100644 index 00000000000..b6fd7a0f989 --- /dev/null +++ b/docs/man/man1/kubeadm-alpha-phase-kubelet-config-annotate-cri.1 @@ -0,0 +1,3 @@ +This file is autogenerated, but we've stopped checking such files into the +repository to reduce the need for rebases. Please run hack/generate-docs.sh to +populate this file.