-
Notifications
You must be signed in to change notification settings - Fork 39.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #65629 from luxas/kubeadm_add_v1alpha3
Automatic merge from submit-queue (batch tested with PRs 64593, 65117, 65629, 65827, 65686). 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: Add a `v1alpha3` API **What this PR does / why we need it**: Adds a (now duplicated) v1alpha3 API. Equal to `v1alpha2` now, but will be changed later. Hopefully we'll graduate this to `v1beta1` during the v1.12 cycle. **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 **Special notes for your reviewer**: These commits should be reviewed: - `Add a duplicated v1alpha3 API`: A pure directory copy of the `v1alpha2` folder, only changed the package name in the Go files - `Register the v1alpha3 API in the scheme, and update the roundtrip API tests`, started registering the new API and using it internally - `Automated bump from v1alpha2 references to v1alpha3`: Replaced all v1alpha2 references with v1alpha3 **Release note**: ```release-note kubeadm: Add a `v1alpha3` API. ``` @kubernetes/sig-cluster-lifecycle-pr-reviews
- Loading branch information
Showing
75 changed files
with
2,497 additions
and
201 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") | ||
|
||
go_library( | ||
name = "go_default_library", | ||
srcs = [ | ||
"bootstraptokenstring.go", | ||
"defaults.go", | ||
"defaults_unix.go", | ||
"defaults_windows.go", | ||
"doc.go", | ||
"register.go", | ||
"types.go", | ||
"zz_generated.conversion.go", | ||
"zz_generated.deepcopy.go", | ||
"zz_generated.defaults.go", | ||
], | ||
importpath = "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm/v1alpha3", | ||
visibility = ["//visibility:public"], | ||
deps = [ | ||
"//cmd/kubeadm/app/apis/kubeadm:go_default_library", | ||
"//cmd/kubeadm/app/constants:go_default_library", | ||
"//pkg/kubelet/apis/kubeletconfig/scheme:go_default_library", | ||
"//pkg/kubelet/apis/kubeletconfig/v1beta1:go_default_library", | ||
"//pkg/proxy/apis/kubeproxyconfig/scheme:go_default_library", | ||
"//pkg/proxy/apis/kubeproxyconfig/v1alpha1:go_default_library", | ||
"//pkg/util/pointer:go_default_library", | ||
"//staging/src/k8s.io/api/core/v1:go_default_library", | ||
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library", | ||
"//staging/src/k8s.io/apimachinery/pkg/conversion:go_default_library", | ||
"//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library", | ||
"//staging/src/k8s.io/apimachinery/pkg/runtime/schema:go_default_library", | ||
"//staging/src/k8s.io/client-go/tools/bootstrap/token/api:go_default_library", | ||
"//staging/src/k8s.io/client-go/tools/bootstrap/token/util:go_default_library", | ||
], | ||
) | ||
|
||
filegroup( | ||
name = "package-srcs", | ||
srcs = glob(["**"]), | ||
tags = ["automanaged"], | ||
visibility = ["//visibility:private"], | ||
) | ||
|
||
filegroup( | ||
name = "all-srcs", | ||
srcs = [":package-srcs"], | ||
tags = ["automanaged"], | ||
visibility = ["//visibility:public"], | ||
) | ||
|
||
go_test( | ||
name = "go_default_test", | ||
srcs = ["bootstraptokenstring_test.go"], | ||
embed = [":go_default_library"], | ||
) |
90 changes: 90 additions & 0 deletions
90
cmd/kubeadm/app/apis/kubeadm/v1alpha3/bootstraptokenstring.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/* | ||
Copyright 2018 The Kubernetes Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
// Package v1alpha2 holds the external kubeadm API types of version v1alpha2 | ||
// Note: This file should be kept in sync with the similar one for the internal API | ||
// TODO: The BootstrapTokenString object should move out to either k8s.io/client-go or k8s.io/api in the future | ||
// (probably as part of Bootstrap Tokens going GA). It should not be staged under the kubeadm API as it is now. | ||
package v1alpha3 | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
bootstrapapi "k8s.io/client-go/tools/bootstrap/token/api" | ||
bootstraputil "k8s.io/client-go/tools/bootstrap/token/util" | ||
) | ||
|
||
// BootstrapTokenString is a token of the format abcdef.abcdef0123456789 that is used | ||
// for both validation of the practically of the API server from a joining node's point | ||
// of view and as an authentication method for the node in the bootstrap phase of | ||
// "kubeadm join". This token is and should be short-lived | ||
type BootstrapTokenString struct { | ||
ID string | ||
Secret string | ||
} | ||
|
||
// MarshalJSON implements the json.Marshaler interface. | ||
func (bts BootstrapTokenString) MarshalJSON() ([]byte, error) { | ||
return []byte(fmt.Sprintf(`"%s"`, bts.String())), nil | ||
} | ||
|
||
// UnmarshalJSON implements the json.Unmarshaller interface. | ||
func (bts *BootstrapTokenString) UnmarshalJSON(b []byte) error { | ||
// If the token is represented as "", just return quickly without an error | ||
if len(b) == 0 { | ||
return nil | ||
} | ||
|
||
// Remove unnecessary " characters coming from the JSON parser | ||
token := strings.Replace(string(b), `"`, ``, -1) | ||
// Convert the string Token to a BootstrapTokenString object | ||
newbts, err := NewBootstrapTokenString(token) | ||
if err != nil { | ||
return err | ||
} | ||
bts.ID = newbts.ID | ||
bts.Secret = newbts.Secret | ||
return nil | ||
} | ||
|
||
// String returns the string representation of the BootstrapTokenString | ||
func (bts BootstrapTokenString) String() string { | ||
if len(bts.ID) > 0 && len(bts.Secret) > 0 { | ||
return bootstraputil.TokenFromIDAndSecret(bts.ID, bts.Secret) | ||
} | ||
return "" | ||
} | ||
|
||
// NewBootstrapTokenString converts the given Bootstrap Token as a string | ||
// to the BootstrapTokenString object used for serialization/deserialization | ||
// and internal usage. It also automatically validates that the given token | ||
// is of the right format | ||
func NewBootstrapTokenString(token string) (*BootstrapTokenString, error) { | ||
substrs := bootstraputil.BootstrapTokenRegexp.FindStringSubmatch(token) | ||
// TODO: Add a constant for the 3 value here, and explain better why it's needed (other than because how the regexp parsin works) | ||
if len(substrs) != 3 { | ||
return nil, fmt.Errorf("the bootstrap token %q was not of the form %q", token, bootstrapapi.BootstrapTokenPattern) | ||
} | ||
|
||
return &BootstrapTokenString{ID: substrs[1], Secret: substrs[2]}, nil | ||
} | ||
|
||
// NewBootstrapTokenStringFromIDAndSecret is a wrapper around NewBootstrapTokenString | ||
// that allows the caller to specify the ID and Secret separately | ||
func NewBootstrapTokenStringFromIDAndSecret(id, secret string) (*BootstrapTokenString, error) { | ||
return NewBootstrapTokenString(bootstraputil.TokenFromIDAndSecret(id, secret)) | ||
} |
Oops, something went wrong.