Skip to content

Conversation

@fabriziopandini
Copy link
Member

@fabriziopandini fabriziopandini commented Jul 21, 2017

What this PR does / why we need it:
This contains implementation of kubeconfig phases in kubeadm, which is part of the wider effort of implementing phases in kubeadm, previously in alpha stage.

The original proposal for this activity can be found here and related comments.

Kubeadm phase implementation checklist is defined here

Common implementation guidelines and principles for all phases are defined here

This PR implements:

  • kubeadm phase kubeconfig
    • kubeadm phase kubeconfig all
    • kubeadm phase kubeconfig admin
    • kubeadm phase kubeconfig kubelet
    • kubeadm phase kubeconfig scheduler
    • kubeadm phase kubeconfig controller-manager
    • kubeadm phase kubeconfig user

Which issue this PR fixes:
kubernetes/kubeadm#350

Special notes for your reviewer:

This PR implements the second phases of kubeadm init; implementation of this PR follow the same approach already used for #48196 (cert phases).

Please note that:

  • the API - phase\kubeconfig.go - is now totally free by any UX concerns, and implements only the core logic for kubeconfig generation.
  • the UX - cmd\phase\kubeconfig.go - now takes charge of UX commands and kubeadm own's rules for kubeconfig files in /etc/kubernetes folder (e.g. create only if not already exists)
  • The PR includes also a fix for a regression on a unit test for phase certs introduced by Add node-name flag to init phase #48594 and few minor code changes in phase certs introduced to avoid code duplication between the two phases.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Jul 21, 2017
@k8s-ci-robot
Copy link
Contributor

Hi @fabriziopandini. Thanks for your PR.

I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

I understand the commands that are listed here.

Details

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.

@k8s-ci-robot k8s-ci-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Jul 21, 2017
@k8s-github-robot k8s-github-robot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. release-note-label-needed labels Jul 21, 2017
@fabriziopandini
Copy link
Member Author

This PR will fix also kubernetes/kubeadm#350; edited command for easier reference

@luxas luxas assigned luxas and unassigned lukemarsden Jul 24, 2017
@luxas
Copy link
Member

luxas commented Jul 24, 2017

/ok-to-test
/release-note

@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. release-note-label-needed labels Jul 24, 2017
@timothysc timothysc added the sig/cluster-lifecycle Categorizes an issue or PR as relevant to SIG Cluster Lifecycle. label Jul 24, 2017
@timothysc timothysc added this to the v1.8 milestone Jul 24, 2017
@timothysc timothysc added the kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. label Jul 24, 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.

On a high level:

  • Please don't move useful pkg functions like writing a kubeconfig file if not exists. That's useful generally
  • Enhance the struct that describes the generation
  • Move over the map[string]buildStruct to cmd and call the generic fn from there

I'd like this PR to touch way less code. It can be done ;)

Copy link
Member

Choose a reason for hiding this comment

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

I think this will make the tempdir to be deleted immediately after this function exits, which is not what we want

Copy link
Member

Choose a reason for hiding this comment

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

In any case, I'd explicitely call defer os.RemoveAll after the createTmpDir call

Copy link
Member

Choose a reason for hiding this comment

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

what about getKubeConfigSubCommands?

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 a note: Please note that this should *only* be used for bootstrapping purposes. After your control plane is up, you should request all kubelet credentials from the CSR API

Copy link
Member

Choose a reason for hiding this comment

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

with an alias controller-manager possibly?

Copy link
Member

Choose a reason for hiding this comment

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

nit: the Controller Manager

Copy link
Member

Choose a reason for hiding this comment

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

Please make a ClientCertAuth struct with the unique fields there: Organization and CAKey

Copy link
Member

Choose a reason for hiding this comment

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

Use structs as pointers instead to detect auth method

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 propose to just move this map to cmd and consume it there.
Also keep most of the code as-is here in this pkg.
The only thing that has to change is that and the BuildConfigProperties struct organization

Copy link
Member

Choose a reason for hiding this comment

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

I think making a new function for all special cases is not necessary. We have the pattern, let's express what we want with a struct instead and pass it to a generic function GetKubeConfigBytesFromSpec or similar
Then just move the default generation profiles into cmd

Copy link
Member

Choose a reason for hiding this comment

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

Can you make this a wrapped function so that you can set this as cmdFunc: createDefaultKubeConfigFiles("all|api-server|etc.")?

@k8s-github-robot k8s-github-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jul 30, 2017
@fabriziopandini fabriziopandini force-pushed the kubeadm-phase-kubeconfig2 branch from cf0bbdb to f9f91bf Compare August 5, 2017 14:45
@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 5, 2017
@fabriziopandini
Copy link
Member Author

@luxas, this version includes all your comments - including also what we agreed during the follow up call - except the one about ipv6, because #48288 is not merged yet.
Looking forward for a new round of feedbacks! 😄

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.

Thank you a bunch @fabriziopandini!
I left a couple of nits here, but none of them block this PR
It's better to merge this now and reiterate on small one-line changes than to hold this and its dependencies up for such trivial things.

I downloaded this and tested it out manually and it works well. Thank you for improving our test coverage as part of this btw ;)

/lgtm

MakeClientCerts bool
// clientCertAuth struct holds info required to build a client certificate to provide authentication info in a kubeconfig object
type clientCertAuth struct {
CaKey *rsa.PrivateKey
Copy link
Member

Choose a reason for hiding this comment

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

nit: CAKey

// /etc/kubernetes/{admin,kubelet}.conf exist but not certs => certs will be generated and conflict with the kubeconfig files => error
// kubeConfigSpec struct holds info required to build a KubeConfig object
type kubeConfigSpec struct {
CaCert *x509.Certificate
Copy link
Member

Choose a reason for hiding this comment

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

nit: CACert

kubeConfigFilePath := filepath.Join(outDir, filename)
err = writeKubeconfigToDiskIfNotExists(kubeConfigFilePath, kubeconfig)
// writes the KubeConfig to disk if it not exists
err = createKubeConfigFileIfNotExists(outDir, kubeConfigFileName, config)
Copy link
Member

Choose a reason for hiding this comment

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

nit: inline this in the if clause: if err := foo(); err != nil {. Reduces scope, which is good

kubeadmconstants.KubeletKubeConfigFileName: {
CaCert: caCert,
APIServer: cfg.GetMasterEndpoint(),
ClientName: fmt.Sprintf("system:node:%s", cfg.NodeName),
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 love to find a helper func in an auth pkg for this some day.

}
return kubeconfigutil.CreateWithCerts(
config.APIServer,
// If this kubeconfing should use token
Copy link
Member

Choose a reason for hiding this comment

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

nit: kubeconfig

}
cmd.Flags().StringVar(&cfg.CertificatesDir, "cert-dir", cfg.CertificatesDir, "The path where to save and store the certificates")
cmd.Flags().StringVar(&cfg.API.AdvertiseAddress, "apiserver-advertise-address", cfg.API.AdvertiseAddress, "The IP address the API Server will advertise it's listening on. 0.0.0.0 means the default network interface's address.")
cmd.Flags().Int32Var(&cfg.API.BindPort, "apiserver-bind-port", cfg.API.BindPort, "Port for the API Server to bind to")
Copy link
Member

Choose a reason for hiding this comment

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

nit: apiserver-port
nit: The port the API server is accessible on

cmd.Flags().StringVar(&cfg.API.AdvertiseAddress, "apiserver-advertise-address", cfg.API.AdvertiseAddress, "The IP address the API Server will advertise it's listening on. 0.0.0.0 means the default network interface's address.")
cmd.Flags().Int32Var(&cfg.API.BindPort, "apiserver-bind-port", cfg.API.BindPort, "Port for the API Server to bind to")
if properties.use == "all" || properties.use == "kubelet" {
cmd.Flags().StringVar(&cfg.NodeName, "node-name", cfg.NodeName, `Specify the node name`)
Copy link
Member

Choose a reason for hiding this comment

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

nit: The node name that the kubelet client cert should use

cmd.Flags().StringVar(&cfg.NodeName, "node-name", cfg.NodeName, `Specify the node name`)
}
if properties.use == "user" {
cmd.Flags().StringVar(&token, "token", token, "The path to the directory where the certificates are.")
Copy link
Member

Choose a reason for hiding this comment

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

nit: The token that should be used as the authentication mechanism for this kubeconfig

}
if properties.use == "user" {
cmd.Flags().StringVar(&token, "token", token, "The path to the directory where the certificates are.")
cmd.Flags().StringVar(&clientName, "client-name", clientName, "The name of the client for which the KubeConfig file will be generated.")
Copy link
Member

Choose a reason for hiding this comment

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

nit: The name of the KubeConfig user that will be created. Will also be used as the CN if client certs are created.

kubeconfigtestutil "k8s.io/kubernetes/cmd/kubeadm/test/kubeconfig"
)

func TestKubeConfigCSubCommandsHasFlags(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

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

nit: TestKubeConfigSubCommandsHasFlags?

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

luxas commented Aug 5, 2017

/retest

@k8s-github-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: fabriziopandini, luxas

Associated issue: 267

The full list of commands accepted by this bot can be found here.

Details 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 k8s-github-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Aug 5, 2017
@luxas
Copy link
Member

luxas commented Aug 5, 2017

/retest

@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 48415c0 into kubernetes:master Aug 5, 2017
@fabriziopandini
Copy link
Member Author

Thanks @luxas! 🎉 As agreed I move to phase "controlplane" and then I will come back on this comments and on refactoring phase cert!

@fabriziopandini fabriziopandini deleted the kubeadm-phase-kubeconfig2 branch August 6, 2017 20:17
k8s-github-robot pushed a commit that referenced this pull request Aug 15, 2017
…plane2

Automatic merge from submit-queue

kubeadm: Implementing the controlplane phase

**What this PR does / why we need it:**
This contains implementation of controlplane phases in kubeadm, which is part of the wider effort of implementing phases in kubeadm, previously in alpha stage.

The original proposal for this activity can be found [here](https://github.com/kubernetes/kubeadm/pull/156/files) and related comments.

Kubeadm phase implementation checklist is defined [here](kubernetes/kubeadm#267)

Common implementation guidelines and principles for all phases are defined [here](https://docs.google.com/document/d/1VQMyFIVMfRGQPP3oCUpfjiWtOr3pLxp4g7cP-hXQFXc/edit?usp=sharing)

This PR implements:

- [x] kubeadm phase controlplane: wip by @fabriziopandini
  - [x] kubeadm phase controlplane all
  - [x] kubeadm phase controlplane etcd
  - [x] kubeadm phase controlplane apiserver
  - [x] kubeadm phase controlplane scheduler
  - [x] kubeadm phase controlplane controller-manager

**Which issue this PR fixes:**
kubernetes/kubeadm#349

**Special notes for your reviewer:**
This PR implements the same approach of #49419, thus minimising rework/impacts on existing codebase.
k8s-github-robot pushed a commit that referenced this pull request Aug 16, 2017
…leanups

Automatic merge from submit-queue (batch tested with PRs 50692, 50727)

kubeadm: Small cleanups from the phases refactoring

**What this PR does / why we need it**:
Small cleanups on kubeadm phases

**Which issue this PR fixes**: 
fixes pending comments in [#49419](#49419)
fixes [#376](kubernetes/kubeadm#376)

**Special notes for your reviewer**:
cc @luxas
k8s-github-robot pushed a commit that referenced this pull request Aug 18, 2017
Automatic merge from submit-queue (batch tested with PRs 50904, 50691)

Make Kubeadm phase certs codebase consistent with other phases

**What this PR does / why we need it:**
This PR is a refactoring of [#48196](#48196), that makes this part of kubeadm more consistent with other parts of kubeadm recently changed, e.g. [controlplane & etcd phase #50302](#50302) and [kubeconfig phase #49419](#49419)

**Which issue this PR fixes:**
none

**Special notes for your reviewer:**
cc @luxas
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. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. 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/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants