Skip to content

Commit

Permalink
Merge pull request #68449 from fabriziopandini/kubeadm-annotate-cri
Browse files Browse the repository at this point in the history
Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions here: https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md.

kubeadm: add mandatory phase "annotate-cri"

**What this PR does / why we need it**:
In v1.12, after the changing how kubeadm-config upload/fetch, AnnotateCRISocket is now a necessary step for getting a cluster that can be upgraded using phases. This PR adds a new subcommand for letting users to invoke AnnotateCRISocket as a phase

**Which issue(s) this PR fixes**:
Fixes # kubernetes/kubeadm#925

**Special notes for your reviewer**:
When testing this PR, I found that one of the tests on component config defaulting was broken (didn't have time to investigate why yet). This PR fixes this test as well  

**Release note**:
```release-note
kubeadm: added phase command "alpha phase kubelet config annotate-cri"
```
@kubernetes/sig-cluster-lifecycle-pr-reviews
/sig cluster-lifecycle
/area kubeadm
/assign @timothysc @neolit123 
/kind bug
  • Loading branch information
Kubernetes Submit Queue committed Sep 10, 2018
2 parents ba33abd + 44e49f0 commit d472a54
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 0 deletions.
1 change: 1 addition & 0 deletions cmd/kubeadm/app/cmd/phases/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
49 changes: 49 additions & 0 deletions cmd/kubeadm/app/cmd/phases/kubelet.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -177,6 +186,7 @@ func NewCmdKubeletConfig() *cobra.Command {
}

cmd.AddCommand(NewCmdKubeletConfigUpload())
cmd.AddCommand(NewCmdKubeletAnnotateCRI())
cmd.AddCommand(NewCmdKubeletConfigDownload())
cmd.AddCommand(NewCmdKubeletConfigWriteToDisk())
cmd.AddCommand(NewCmdKubeletConfigEnableDynamic())
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions docs/.generated_docs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions docs/admin/kubeadm_alpha_phase_kubelet_config_annotate-cri.md
Original file line number Diff line number Diff line change
@@ -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.
Original file line number Diff line number Diff line change
@@ -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.

0 comments on commit d472a54

Please sign in to comment.