kubeadm: add kubeadm phase addons command#51171
Conversation
| var kubeConfigFile string | ||
| cfg := &kubeadmapiext.MasterConfiguration{} | ||
| cmd := &cobra.Command{ | ||
| Use: "addon", |
There was a problem hiding this comment.
I can change to plural "addons" if we want to allow multiple addons to be installed with one command.
There was a problem hiding this comment.
I'd let this be addon but have an addons alias
| Aliases: []string{}, | ||
| Short: "Install an addon to a Kubernetes cluster.", | ||
| RunE: func(cmd *cobra.Command, args []string) error { | ||
| if len(args) != 1 { |
There was a problem hiding this comment.
Do we want to allow multiple addons to be installed with one command?
There was a problem hiding this comment.
See certs|kubeconfig|controlplane phases; they have an all command in addition
| kubeadmutil.CheckErr(err) | ||
| addon := args[0] | ||
| switch addon { | ||
| case dnsaddon.KubeDNSServiceAccountName: |
There was a problem hiding this comment.
Should this be hardcoded or should we stick to using the service account name?
There was a problem hiding this comment.
It might be that the ServiceAccountName constants are moved into the respective addon package eventually; so I'd hard-code kube-proxy|kube-dns here
|
@luxas I left a few comments. I can push updates based on your review. |
| client, err := kubeconfigutil.ClientSetFromFile(kubeConfigFile) | ||
| kubeadmutil.CheckErr(err) | ||
| addon := args[0] | ||
| switch addon { |
There was a problem hiding this comment.
If we are not happy with a switch statement, I can create a map[string]func(cfg, client), but that would depend on us sticking with the EnsureXXXAddon(cfg, client) convention.
There was a problem hiding this comment.
Please try to model this as we've done for the other phases to be consistent here; a struct { } slice should do
There was a problem hiding this comment.
Please provide users a way to inspect which addons could be managed with kubeadm addons; other phases are doing this by leveraging on cobra native support for --help and subcommands
luxas
left a comment
There was a problem hiding this comment.
Thanks @andrewrynhard
I'd like it to be a little bit more like the certs, kubeconfig and controlplane phases if that's okay with you.
Please make it possible to configure the addon creation with CLI flags.
/assign @fabriziopandini
| var kubeConfigFile string | ||
| cfg := &kubeadmapiext.MasterConfiguration{} | ||
| cmd := &cobra.Command{ | ||
| Use: "addon", |
There was a problem hiding this comment.
I'd let this be addon but have an addons alias
| Aliases: []string{}, | ||
| Short: "Install an addon to a Kubernetes cluster.", | ||
| RunE: func(cmd *cobra.Command, args []string) error { | ||
| if len(args) != 1 { |
There was a problem hiding this comment.
See certs|kubeconfig|controlplane phases; they have an all command in addition
| kubeadmutil.CheckErr(err) | ||
| addon := args[0] | ||
| switch addon { | ||
| case dnsaddon.KubeDNSServiceAccountName: |
There was a problem hiding this comment.
It might be that the ServiceAccountName constants are moved into the respective addon package eventually; so I'd hard-code kube-proxy|kube-dns here
| } | ||
|
|
||
| cmd.Flags().StringVar(&kubeConfigFile, "kubeconfig", "/etc/kubernetes/admin.conf", "The KubeConfig file to use for talking to the cluster") | ||
| return cmd |
There was a problem hiding this comment.
this should take --config as well and other relevant CLI args
There was a problem hiding this comment.
Please add support as well for validate mixed argument logic if --config is combined with other flags. See e.g.
| client, err := kubeconfigutil.ClientSetFromFile(kubeConfigFile) | ||
| kubeadmutil.CheckErr(err) | ||
| addon := args[0] | ||
| switch addon { |
There was a problem hiding this comment.
Please try to model this as we've done for the other phases to be consistent here; a struct { } slice should do
46b22b8 to
989d9d9
Compare
|
@luxas PTAL, this is still a WIP but I believe it is a step in the direction you wanted. |
0a7c6b2 to
5a56adf
Compare
| return cmd | ||
| } | ||
|
|
||
| func EnsureAllAddons(cfg *kubeadmapi.MasterConfiguration, client clientset.Interface) error { |
There was a problem hiding this comment.
Is this function going to be replaced with https://github.com/kubernetes/kubernetes/pull/51171/files#diff-eadad99fe8edbb21ce1c0f32a362240a?
There was a problem hiding this comment.
Yes, I will make that change and have it up in a bit.
|
@andrewrynhard 👍 from my side :-) |
| ) | ||
|
|
||
| // EnsureAllAddons install all addons to a Kubernetes cluster. | ||
| func EnsureAllAddons(cfg *kubeadmapi.MasterConfiguration, client clientset.Interface) error { |
There was a problem hiding this comment.
please move this function client-side to be consistent; i.e. in cmd/phases/addons.go
| // EnsureDNSAddon creates the kube-dns addon | ||
| func EnsureDNSAddon(cfg *kubeadmapi.MasterConfiguration, client clientset.Interface, k8sVersion *version.Version) error { | ||
| func EnsureDNSAddon(cfg *kubeadmapi.MasterConfiguration, client clientset.Interface) error { | ||
| k8sVersion, err := version.ParseSemantic(cfg.KubernetesVersion) |
There was a problem hiding this comment.
I'd prefer to pass k8sVersion still and do the parsing client-side in cmd/phases
Luckily, I expect to soon get rid of this in the v1.9 cycle by moving this into the internal variant of cfg or something so we can stop passing and parsing this all the time.
There was a problem hiding this comment.
The only issue I had with this was that I needed all the EnsureXXXAddon functions have the same signature. Look at the EnsureAllAddons and runAddonsCmdFunc functions. I'm happy to do something different if we still prefer to pass k8sVersion in.
There was a problem hiding this comment.
ok with this for now; will fix it for real later
|
|
||
| // Add flags to the command | ||
| cmd.Flags().StringVar(&kubeConfigFile, "kubeconfig", "/etc/kubernetes/admin.conf", "The KubeConfig file to use for talking to the cluster") | ||
| cmd.Flags().StringVar(&cfgPath, "config", cfgPath, "Path to kubeadm config file (WARNING: Usage of a configuration file is experimental)") |
There was a problem hiding this comment.
Please add flags for these fields:
common:
- KubernetesVersion
- ImageRepository
proxy:
- AdvertiseAddress
- BindPort
- PodSubnet
dns:
- DNSDomain
| }, | ||
| { | ||
| use: "kube-dns", | ||
| short: "Install kube-dns addon to a Kubernetes cluster.", |
| }, | ||
| { | ||
| use: "kube-proxy", | ||
| short: "Install kube-proxy addon to a Kubernetes cluster.", |
| api.Scheme.Convert(cfg, internalcfg, nil) | ||
| client, err := kubeconfigutil.ClientSetFromFile(kubeConfigFile) | ||
| kubeadmutil.CheckErr(err) | ||
| // internalcfg, err := configutil.ConfigFileAndDefaultsToInternalConfig(*cfgPath, cfg) |
There was a problem hiding this comment.
why commented out?
Also pass cfgPath to this func
There was a problem hiding this comment.
Whoops. This was a mistake.
5a56adf to
48c8423
Compare
|
@fabriziopandini @luxas I believe I have everything done now. |
|
/retest Review the full test history for this PR. |
2 similar comments
|
/retest Review the full test history for this PR. |
|
/retest Review the full test history for this PR. |
|
/retest |
|
/retest Review the full test history for this PR. |
|
/retest |
|
@andrewrynhard this needs a rebase |
|
/retest Review the full test history for this PR. |
3 similar comments
|
/retest Review the full test history for this PR. |
|
/retest Review the full test history for this PR. |
|
/retest Review the full test history for this PR. |
13b9955 to
cf05141
Compare
|
/retest |
cf05141 to
d55cea6
Compare
|
/test pull-kubernetes-e2e-kops-aws |
|
/test pull-kubernetes-e2e-gce-etcd3 |
|
/test pull-kubernetes-e2e-kops-aws |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: andrewrynhard, luxas Associated issue: 418 The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these OWNERS Files:
You can indicate your approval by writing |
|
/test all [submit-queue is verifying that this PR is safe to merge] |
|
Automatic merge from submit-queue |
|
@andrewrynhard: The following tests failed, say
Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here. |
|
👍 |
| kubeadmutil.CheckErr(err) | ||
| } | ||
|
|
||
| var kubeConfigFile string |
There was a problem hiding this comment.
I'm not able to actually get any of these commands working. Because of this closure, the kubeconfig value from the flag won't ever get used.
$ _output/bin/kubeadm alpha phase addon all --kubeconfig test
failed to load admin kubeconfig [open : no such file or directory]
What this PR does / why we need it:
Adds the
addonsphase command tokubeadmfixes: kubernetes/kubeadm#418
/cc @luxas