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 support for reading multiple YAML documents #65631

Merged

Conversation

@luxas
Copy link
Member

commented Jun 29, 2018

What this PR does / why we need it:
In preparation for splitting the kubelet and kube-proxy componentconfigs out of the MasterConfiguration API struct, add support for reading multiple YAML documents

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
ref: kubernetes/kubeadm#911
Depends on:

Special notes for your reviewer:
Please only review the Refactor a bit of the config YAML loading code, and support loading multiple YAML documents commit

Release note:

NONE

@kubernetes/sig-cluster-lifecycle-pr-reviews

if apiObject == nodeConfig {
internalcfg, err := configutil.NodeConfigFileAndDefaultsToInternalConfig("", &kubeadmapiv1alpha3.NodeConfiguration{
case nodeConfig:
internalcfg, err = configutil.NodeConfigFileAndDefaultsToInternalConfig("", &kubeadmapiv1alpha3.NodeConfiguration{
Token: sillyToken.Token.String(),
DiscoveryTokenAPIServers: []string{"kube-apiserver:6443"},
DiscoveryTokenUnsafeSkipCAVerification: true,

This comment has been minimized.

Copy link
@fabriziopandini

fabriziopandini Jun 29, 2018

Contributor

We need this for passing validation, but afterwards we should set to false because it is the recommended value

This comment has been minimized.

Copy link
@luxas

luxas Jul 3, 2018

Author Member

added a TODO, please file an issue

return "", "", fmt.Errorf("any config file must have the apiVersion field set")
// SplitYAMLDocuments reads the YAML bytes per-document, unmarshals the TypeMeta information from each document
// and returns a map between the GroupVersionKind of the document and the document bytes
func SplitYAMLDocuments(yamlBytes []byte) (map[schema.GroupVersionKind][]byte, error) {

This comment has been minimized.

Copy link
@fabriziopandini

fabriziopandini Jun 29, 2018

Contributor

Please fail if there two objects of the same kind

This comment has been minimized.

Copy link
@luxas

luxas Jul 3, 2018

Author Member

fixed

if err := yaml.Unmarshal(b, &typeMetaInfo); err != nil {
return nil, err
}
// In earlier kubeadm versions TypeMeta wasn't set correctly when marshalling, so empty TypeMeta means the v1alpha1

This comment has been minimized.

Copy link
@fabriziopandini

fabriziopandini Jun 29, 2018

Contributor

We wont support untyped object, fail fast

This comment has been minimized.

Copy link
@luxas

luxas Jul 3, 2018

Author Member

fixed

@fabriziopandini
Copy link
Contributor

left a comment

Thanks for this PR.
Please fix comments; there is room for improving the read config but lets' this out of this PR and fix it in following one
/approve
@timothysc I let you give the final lgtm

@timothysc

This comment has been minimized.

Copy link
Member

commented Jul 3, 2018

repoke once rebases are done.

@luxas luxas force-pushed the luxas:kubeadm_support_yaml_documents branch from 63dc86e to 4e86e80 Jul 3, 2018

@luxas luxas force-pushed the luxas:kubeadm_support_yaml_documents branch from 4e86e80 to 7fa403b Jul 3, 2018

@neolit123 neolit123 referenced this pull request Jul 4, 2018

Closed

Tracking issue for "Config to v1beta1" #963

19 of 28 tasks complete

// YAMLDocumentSeparator is the separator for YAML documents
// TODO: Find a better place for this constant
YAMLDocumentSeparator = "---\n"

This comment has been minimized.

Copy link
@neolit123

neolit123 Jul 5, 2018

Member

@luxas a couple of notes:

key: value---

i think the above would trigger the separator, where --- could be intended as being part of value.

could be the safer way to do this.
YAMLDocumentSeparator = "\n---\n"

\n would only handle the Unix (POSIX), LF case.
does the file loading instrumentation in k8s convert e.g CRLF (\r\n) line endings to LF \n automatically?
things like ioutil.ReadFile() do not, which means that if the user created his config file with CRLF endings it would look like this:

\r\n---\r\n == 13 10 45 45 45 13 10

OSX sanely moved to LF a while ago, while some editors on Windows are still CRLF by default.

This comment has been minimized.

Copy link
@neolit123

neolit123 Jul 5, 2018

Member

^ so it seems the reader comes from api machinery, so 1) is handled by using \n---. not ideal but it's better than ---\n.
2) is not handled it seems.

the separator constant should be exported from here IMO:
https://github.com/kubernetes/kubernetes/blob/master/staging/src/k8s.io/apimachinery/pkg/util/yaml/decoder.go#L139

This comment has been minimized.

Copy link
@rosti

rosti Jul 5, 2018

Member

Practically all text editors on Windows (apart from Notepad) support Unix style line endings and UTF-8 these days, so I don't think that this is much of a problem here.

This comment has been minimized.

Copy link
@neolit123

neolit123 Jul 5, 2018

Member

that's true, but the parser has to be CRLF ready. otherwise - breakage.

This comment has been minimized.

Copy link
@luxas

luxas Jul 5, 2018

Author Member

This is only used for serialization, not deserialization. So I'm not sure these comments apply

This comment has been minimized.

Copy link
@neolit123

neolit123 Jul 5, 2018

Member

yeah, this is fine for now.
i'm going to test the api machinery code in terms of CRLF and things like that, soon.

This comment has been minimized.

Copy link
@luxas

luxas Jul 5, 2018

Author Member

great 👍

@luxas luxas force-pushed the luxas:kubeadm_support_yaml_documents branch from 7fa403b to 8b27e07 Jul 5, 2018

@k8s-ci-robot k8s-ci-robot added size/XL and removed size/XXL labels Jul 5, 2018

@luxas

This comment has been minimized.

Copy link
Member Author

commented Jul 5, 2018

/retest

)

// AnyConfigFileAndDefaultsToInternal reads either a MasterConfiguration or NodeConfiguration and unmarshals it
func AnyConfigFileAndDefaultsToInternal(cfgPath string) (runtime.Object, error) {

This comment has been minimized.

Copy link
@fabriziopandini

fabriziopandini Jul 5, 2018

Contributor

If the user is passing a file with both MasterConfiguration and NodeConfiguration this function will always return the first; however, as agreed in slack with @luxas this is going to be fixed in an upcoming PR

This comment has been minimized.

Copy link
@luxas

luxas Jul 5, 2018

Author Member

This is fixed in #65787 yes. Trying to do multiple PRs with limited scope in each

@fabriziopandini

This comment has been minimized.

Copy link
Contributor

commented Jul 5, 2018

Great work @luxas! Thanks
/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm label Jul 5, 2018

@k8s-ci-robot

This comment has been minimized.

Copy link
Contributor

commented Jul 5, 2018

[APPROVALNOTIFIER] This PR is APPROVED

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

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

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-github-robot

This comment has been minimized.

Copy link
Contributor

commented Jul 5, 2018

Automatic merge from submit-queue (batch tested with PRs 65822, 65834, 65859, 65631). If you want to cherry-pick this change to another branch, please follow the instructions here.

@k8s-github-robot k8s-github-robot merged commit d10ff1a into kubernetes:master Jul 5, 2018

17 checks passed

Submit Queue Queued to run github e2e tests a second time.
Details
cla/linuxfoundation luxas authorized
Details
pull-kubernetes-bazel-build Job succeeded.
Details
pull-kubernetes-bazel-test Job succeeded.
Details
pull-kubernetes-cross Skipped
pull-kubernetes-e2e-gce Job succeeded.
Details
pull-kubernetes-e2e-gce-100-performance Job succeeded.
Details
pull-kubernetes-e2e-gce-device-plugin-gpu Job succeeded.
Details
pull-kubernetes-e2e-gke Skipped
pull-kubernetes-e2e-kops-aws Job succeeded.
Details
pull-kubernetes-integration Job succeeded.
Details
pull-kubernetes-kubemark-e2e-gce-big Job succeeded.
Details
pull-kubernetes-local-e2e Skipped
pull-kubernetes-local-e2e-containerized Skipped
pull-kubernetes-node-e2e Job succeeded.
Details
pull-kubernetes-typecheck Job succeeded.
Details
pull-kubernetes-verify Job succeeded.
Details

luxas pushed a commit to luxas/kubernetes that referenced this pull request Jul 8, 2018

Kubernetes Submit Queue
Merge pull request kubernetes#65940 from luxas/kubeadm_internal_compo…
…nentconfigs

Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

kubeadm: Start using internal versions for ComponentConfigs in the internal API

**What this PR does / why we need it**:
This PR changes kubeadm to store the internal API versions of the ComponentConfig APIs, in order to in the future be able to read multiple external versions with conversion. It also moves all the ComponentConfigs to a common struct instead of splitting them out in many. This makes it possible to more easily host more ComponentConfigs in the future. In v1alpha3, the ComponentConfigs will later be removed from the external version of the API (see: kubernetes#65787), but for this PR no changes to the external API are made.

**Which issue(s) this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close the issue(s) when PR gets merged)*:
ref: kubernetes/kubeadm#911
Depends on:
 - [x] kubernetes#65776
 - [x] kubernetes#65628
 - [x] kubernetes#65629
 - [x] kubernetes#65631

**Special notes for your reviewer**:

**Release note**:

```release-note
NONE
```
@kubernetes/sig-cluster-lifecycle-pr-reviews

k8s-github-robot pushed a commit that referenced this pull request Jul 8, 2018

Kubernetes Submit Queue
Merge pull request #65787 from luxas/kubeadm_split_componentconfig_fr…
…om_api

Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

kubeadm: Use separate YAML docs for the kubelet and kube-proxy ComponentConfigs

**What this PR does / why we need it**:
This PR makes kubeadm load the ComponentConfig for the kubelet and kube-proxy from separate YAML documents in the `kubeadm init` config file. This is backwards-compatible with `v1alpha2`. The ComponentConfigs are stored internally in the internal kubeadm `MasterConfiguration` struct, but when marshalling the componentconfigs are written as separate YAML documents.

**Which issue(s) this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close the issue(s) when PR gets merged)*:
ref: kubernetes/kubeadm#911
Depends on:
 - [x] #65776
 - [x] #65628
 - [x] #65629
 - [x] #65631
 - [x] #65940

**Special notes for your reviewer**:
Only review the last five commits please. (The last commit is purely autogenerated, so can be skipped)

**Release note**:

```release-note
kubeadm: Use separate YAML documents for the kubelet and kube-proxy ComponentConfigs
```
@kubernetes/sig-cluster-lifecycle-pr-reviews 
/assign @timothysc

k8s-github-robot pushed a commit that referenced this pull request Jul 9, 2018

Kubernetes Submit Queue
Merge pull request #65945 from luxas/kubeadm_initconfig
Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

Rename `MasterConfiguration` to `InitConfiguration` in the kubeadm v1alpha3 Config API

**What this PR does / why we need it**:
In v1alpha3, we have made the design decision that `MasterConfiguration` will be renamed `InitConfiguration`. This PR implements that change.

**Which issue(s) this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close the issue(s) when PR gets merged)*:
ref: kubernetes/kubeadm#911
Depends on:
 - [x] #65776
 - [x] #65628
 - [x] #65629
 - [x] #65631
 - [x] #65940
 - [x] #65787

**Special notes for your reviewer**:
Most of the code is autogenerated, using just find and replace.
Please only review commits:
 - `Automated rename from MasterConfiguration to InitConfiguration`
 - `Rename MasterConfiguration to InitConfiguration in v1alpha3, but support both names for this release of kubeadm`

**Release note**:

```release-note
[action required] The `MasterConfiguration` kind in the kubeadm v1alpha2 API has been renamed `InitConfiguration` in v1alpha3
```
@kubernetes/sig-cluster-lifecycle-pr-reviews

cdkbot pushed a commit to juju-solutions/kubernetes that referenced this pull request Jul 14, 2018

Kubernetes Submit Queue
Merge pull request kubernetes#65951 from luxas/kubeadm_joinconfig
Automatic merge from submit-queue (batch tested with PRs 66138, 65951). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

Rename `NodeConfiguration` to `JoinConfiguration` in the kubeadm v1alpha3 Config API

**What this PR does / why we need it**:
In v1alpha3, we have made the design decision that `NodeConfiguration` will be renamed `JoinConfiguration`. This PR implements that change. 

**Which issue(s) this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close the issue(s) when PR gets merged)*:
ref: kubernetes/kubeadm#911
Depends on:
 - [x] kubernetes#65776
 - [x] kubernetes#65628
 - [x] kubernetes#65629
 - [x] kubernetes#65631
 - [x] kubernetes#65940
 - [x] kubernetes#65787
 - [ ] kubernetes#65945

**Special notes for your reviewer**:

Please only review the last three commits here.

**Release note**:

```release-note
[action required] The `NodeConfiguration` kind in the kubeadm v1alpha2 API has been renamed `JoinConfiguration` in v1alpha3
```
@kubernetes/sig-cluster-lifecycle-pr-reviews

k8s-github-robot pushed a commit that referenced this pull request Jul 17, 2018

Kubernetes Submit Queue
Merge pull request #65952 from luxas/kubeadm_init_join_exclusive
Automatic merge from submit-queue (batch tested with PRs 63877, 64559, 65952). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

kubeadm: Make the kubeadm config kinds mutually exclusive

**What this PR does / why we need it**:
Right now it would be possible to feed kubeadm with a YAML document with all the four different Config kinds kubeadm at HEAD supports, `MasterConfiguration`, `InitConfiguration`, `JoinConfiguration` and `NodeConfiguration`. This PR makes them mutually exclusive so that kubeadm can know how to handle the config file properly.

**Which issue(s) this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close the issue(s) when PR gets merged)*:
ref: kubernetes/kubeadm#911
Depends on:
 - [x] #65776
 - [x] #65628
 - [x] #65629
 - [x] #65631
 - [x] #65940
 - [x] #65787
 - [x] #65945
 - [x] #65951

**Special notes for your reviewer**:
Please only review the last commit

**Release note**:

```release-note
NONE
```
@kubernetes/sig-cluster-lifecycle-pr-reviews

k8s-github-robot pushed a commit that referenced this pull request Aug 22, 2018

Kubernetes Submit Queue
Merge pull request #67441 from rosti/kubeadm_clusterconfig
Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

[reissue] kubeadm: Split out ClusterConfiguration from InitConfiguration

As @luxas is not able to take care of #66219, I am reissuing the same change here. There are a few minor things added by me:

- The original PR is rebased on latest master.
- Some broken tests were fixed.
- Some TODOs were added.
- Run update-bazel and update-gofmt

Below is the text of the original PR by Lucas.

-----

**What this PR does / why we need it:**

Splits MasterConfiguration to InitConfiguration and ClusterConfiguration as outlined in the kubeadm Config KEP. InitConfiguration holds init-only information, and ClusterConfiguration holds cluster-wide information. In the internal representation InitConfiguration wraps ClusterConfiguration as a field, but in serialized format they're different YAML documents.

**Which issue(s) this PR fixes** (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
ref: kubernetes/kubeadm#911
Depends on:

- [X] #65776
- [X] #65628
- [X] #65629
- [X] #65631
- [X] #65940
- [X] #65787
- [X] #65945
- [X] #65951
- [X] #65952

**Special notes for your reviewer:**

**Release note**:
```release-note
kubeadm: InitConfiguration now consists of two structs: InitConfiguration and ClusterConfiguration
```

@kubernetes/sig-cluster-lifecycle-pr-reviews
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.