Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kubeadm: add kubeadm phase addons command #51171

Merged
merged 1 commit into from
Sep 7, 2017

Conversation

andrewrynhard
Copy link
Contributor

@andrewrynhard andrewrynhard commented Aug 23, 2017

What this PR does / why we need it:
Adds the addons phase command to kubeadm

fixes: kubernetes/kubeadm#418

/cc @luxas

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Aug 23, 2017
@k8s-github-robot k8s-github-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. release-note-label-needed labels Aug 23, 2017
var kubeConfigFile string
cfg := &kubeadmapiext.MasterConfiguration{}
cmd := &cobra.Command{
Use: "addon",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can change to plural "addons" if we want to allow multiple addons to be installed with one command.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to allow multiple addons to be installed with one command?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See certs|kubeconfig|controlplane phases; they have an all command in addition

kubeadmutil.CheckErr(err)
addon := args[0]
switch addon {
case dnsaddon.KubeDNSServiceAccountName:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be hardcoded or should we stick to using the service account name?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@andrewrynhard
Copy link
Contributor Author

@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 {
Copy link
Contributor Author

@andrewrynhard andrewrynhard Aug 23, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please try to model this as we've done for the other phases to be consistent here; a struct { } slice should do

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Member

@luxas luxas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See certs|kubeconfig|controlplane phases; they have an all command in addition

kubeadmutil.CheckErr(err)
addon := args[0]
switch addon {
case dnsaddon.KubeDNSServiceAccountName:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should take --config as well and other relevant CLI args

Copy link
Member

@fabriziopandini fabriziopandini Aug 23, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add support as well for validate mixed argument logic if --config is combined with other flags. See e.g.

if err := validation.ValidateMixedArguments(cmd.Flags()); err != nil {

client, err := kubeconfigutil.ClientSetFromFile(kubeConfigFile)
kubeadmutil.CheckErr(err)
addon := args[0]
switch addon {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please try to model this as we've done for the other phases to be consistent here; a struct { } slice should do

@luxas luxas added release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed release-note-label-needed labels Aug 23, 2017
@luxas luxas added this to the v1.8 milestone Aug 23, 2017
@luxas luxas assigned luxas and unassigned justinsb Aug 23, 2017
@k8s-github-robot k8s-github-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Aug 23, 2017
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Aug 25, 2017
@k8s-github-robot k8s-github-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Aug 25, 2017
@andrewrynhard
Copy link
Contributor Author

@luxas PTAL, this is still a WIP but I believe it is a step in the direction you wanted.

@andrewrynhard andrewrynhard force-pushed the proxy-dns-phase branch 2 times, most recently from 0a7c6b2 to 5a56adf Compare August 25, 2017 04:38
return cmd
}

func EnsureAllAddons(cfg *kubeadmapi.MasterConfiguration, client clientset.Interface) error {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I will make that change and have it up in a bit.

@fabriziopandini
Copy link
Member

@andrewrynhard 👍 from my side :-)
Apart from the comment/question above, IMO the only step missing is to add necessary CLI flags
/cc @luxas

@k8s-ci-robot k8s-ci-robot requested a review from luxas August 25, 2017 06:40
Copy link
Member

@luxas luxas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple of change requests

)

// EnsureAllAddons install all addons to a Kubernetes cluster.
func EnsureAllAddons(cfg *kubeadmapi.MasterConfiguration, client clientset.Interface) error {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please move this function client-side to be consistent; i.e. in cmd/phases/addons.go

@@ -41,7 +41,12 @@ const (
)

// 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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Install the ...

},
{
use: "kube-proxy",
short: "Install kube-proxy addon to a Kubernetes cluster.",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Install the ...

api.Scheme.Convert(cfg, internalcfg, nil)
client, err := kubeconfigutil.ClientSetFromFile(kubeConfigFile)
kubeadmutil.CheckErr(err)
// internalcfg, err := configutil.ConfigFileAndDefaultsToInternalConfig(*cfgPath, cfg)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why commented out?
Also pass cfgPath to this func

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops. This was a mistake.

@andrewrynhard
Copy link
Contributor Author

@fabriziopandini @luxas I believe I have everything done now.

@fejta-bot
Copy link

/retest
This bot automatically retries jobs that failed/flaked on approved PRs (send feedback to @fejta).

Review the full test history for this PR.

2 similar comments
@fejta-bot
Copy link

/retest
This bot automatically retries jobs that failed/flaked on approved PRs (send feedback to @fejta).

Review the full test history for this PR.

@fejta-bot
Copy link

/retest
This bot automatically retries jobs that failed/flaked on approved PRs (send feedback to @fejta).

Review the full test history for this PR.

@andrewrynhard
Copy link
Contributor Author

/retest

@fejta-bot
Copy link

/retest
This bot automatically retries jobs that failed/flaked on approved PRs (send feedback to @fejta).

Review the full test history for this PR.

@luxas
Copy link
Member

luxas commented Sep 4, 2017

/retest

@luxas
Copy link
Member

luxas commented Sep 4, 2017

@andrewrynhard this needs a rebase

@fejta-bot
Copy link

/retest
This bot automatically retries jobs that failed/flaked on approved PRs (send feedback to @fejta).

Review the full test history for this PR.

3 similar comments
@fejta-bot
Copy link

/retest
This bot automatically retries jobs that failed/flaked on approved PRs (send feedback to @fejta).

Review the full test history for this PR.

@fejta-bot
Copy link

/retest
This bot automatically retries jobs that failed/flaked on approved PRs (send feedback to @fejta).

Review the full test history for this PR.

@fejta-bot
Copy link

/retest
This bot automatically retries jobs that failed/flaked on approved PRs (send feedback to @fejta).

Review the full test history for this PR.

@k8s-github-robot k8s-github-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Sep 4, 2017
@andrewrynhard
Copy link
Contributor Author

/retest

@andrewrynhard
Copy link
Contributor Author

/test pull-kubernetes-e2e-kops-aws

@andrewrynhard
Copy link
Contributor Author

/test pull-kubernetes-e2e-gce-etcd3

@andrewrynhard
Copy link
Contributor Author

/test pull-kubernetes-e2e-kops-aws

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Sep 7, 2017
Copy link
Member

@luxas luxas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

@k8s-github-robot
Copy link

[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.

Needs approval from an approver in each of these OWNERS Files:

You can indicate your approval by writing /approve in a comment
You can cancel your approval by writing /approve cancel in a comment

@k8s-github-robot
Copy link

/test all [submit-queue is verifying that this PR is safe to merge]

@k8s-github-robot
Copy link

Automatic merge from submit-queue

@k8s-github-robot k8s-github-robot merged commit ea01771 into kubernetes:master Sep 7, 2017
@andrewrynhard andrewrynhard deleted the proxy-dns-phase branch September 7, 2017 07:04
@k8s-ci-robot
Copy link
Contributor

@andrewrynhard: The following tests failed, say /retest to rerun them all:

Test name Commit Details Rerun command
pull-kubernetes-e2e-kops-aws d55cea6 link /test pull-kubernetes-e2e-kops-aws
pull-kubernetes-e2e-gce-bazel d55cea6 link /test pull-kubernetes-e2e-gce-bazel

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.

Instructions 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.

@fabriziopandini
Copy link
Member

👍

kubeadmutil.CheckErr(err)
}

var kubeConfigFile string
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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]

cc @luxas @andrewrynhard

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can have a fix soon. Thanks @r2d4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/cluster-lifecycle Categorizes an issue or PR as relevant to SIG Cluster Lifecycle. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make the addons phase invokable from the kubeadm phase CLI
9 participants