mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-10 12:32:03 +00:00
kubeadm: move token defaulting and related constants to token package
Move the defaulting of the BootstrapToken type inside the bootstraptoken/v1 package. This prevents an error where codegen complains that a defaulter for the type exists in both the kubeadm v1beta3 and v1beta4. Adapt kubeadm code to use the defaulter function and constants that were moved to bootstraptoken/v1. NOTE: technically this is a breaking change for direct users of v1beta3/SetDefaults_BootstrapToken().
This commit is contained in:
parent
eecac05871
commit
edb59e9bc7
54
cmd/kubeadm/app/apis/bootstraptoken/v1/defaults.go
Normal file
54
cmd/kubeadm/app/apis/bootstraptoken/v1/defaults.go
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2023 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 v1
|
||||||
|
|
||||||
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
|
bootstrapapi "k8s.io/cluster-bootstrap/token/api"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
// DefaultTokenDuration specifies the default amount of time that a bootstrap token will be valid
|
||||||
|
// Default behaviour is 24 hours
|
||||||
|
DefaultTokenDuration = 24 * time.Hour
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
// DefaultTokenUsages specifies the default functions a token will get
|
||||||
|
DefaultTokenUsages = bootstrapapi.KnownTokenUsages
|
||||||
|
|
||||||
|
// DefaultTokenGroups specifies the default groups that this token will authenticate as when used for authentication
|
||||||
|
DefaultTokenGroups = []string{"system:bootstrappers:kubeadm:default-node-token"}
|
||||||
|
)
|
||||||
|
|
||||||
|
// SetDefaults_BootstrapToken sets the defaults for an individual Bootstrap Token
|
||||||
|
func SetDefaults_BootstrapToken(bt *BootstrapToken) {
|
||||||
|
if bt.TTL == nil {
|
||||||
|
bt.TTL = &metav1.Duration{
|
||||||
|
Duration: DefaultTokenDuration,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if len(bt.Usages) == 0 {
|
||||||
|
bt.Usages = DefaultTokenUsages
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(bt.Groups) == 0 {
|
||||||
|
bt.Groups = DefaultTokenGroups
|
||||||
|
}
|
||||||
|
}
|
@ -181,23 +181,7 @@ func SetDefaults_BootstrapTokens(obj *InitConfiguration) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for i := range obj.BootstrapTokens {
|
for i := range obj.BootstrapTokens {
|
||||||
SetDefaults_BootstrapToken(&obj.BootstrapTokens[i])
|
bootstraptokenv1.SetDefaults_BootstrapToken(&obj.BootstrapTokens[i])
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetDefaults_BootstrapToken sets the defaults for an individual Bootstrap Token
|
|
||||||
func SetDefaults_BootstrapToken(bt *bootstraptokenv1.BootstrapToken) {
|
|
||||||
if bt.TTL == nil {
|
|
||||||
bt.TTL = &metav1.Duration{
|
|
||||||
Duration: constants.DefaultTokenDuration,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if len(bt.Usages) == 0 {
|
|
||||||
bt.Usages = constants.DefaultTokenUsages
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(bt.Groups) == 0 {
|
|
||||||
bt.Groups = constants.DefaultTokenGroups
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,10 +42,6 @@ func SetObjectDefaults_ClusterConfiguration(in *ClusterConfiguration) {
|
|||||||
|
|
||||||
func SetObjectDefaults_InitConfiguration(in *InitConfiguration) {
|
func SetObjectDefaults_InitConfiguration(in *InitConfiguration) {
|
||||||
SetDefaults_InitConfiguration(in)
|
SetDefaults_InitConfiguration(in)
|
||||||
for i := range in.BootstrapTokens {
|
|
||||||
a := &in.BootstrapTokens[i]
|
|
||||||
SetDefaults_BootstrapToken(a)
|
|
||||||
}
|
|
||||||
SetDefaults_APIEndpoint(&in.LocalAPIEndpoint)
|
SetDefaults_APIEndpoint(&in.LocalAPIEndpoint)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -181,23 +181,7 @@ func SetDefaults_BootstrapTokens(obj *InitConfiguration) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for i := range obj.BootstrapTokens {
|
for i := range obj.BootstrapTokens {
|
||||||
SetDefaults_BootstrapToken(&obj.BootstrapTokens[i])
|
bootstraptokenv1.SetDefaults_BootstrapToken(&obj.BootstrapTokens[i])
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetDefaults_BootstrapToken sets the defaults for an individual Bootstrap Token
|
|
||||||
func SetDefaults_BootstrapToken(bt *bootstraptokenv1.BootstrapToken) {
|
|
||||||
if bt.TTL == nil {
|
|
||||||
bt.TTL = &metav1.Duration{
|
|
||||||
Duration: constants.DefaultTokenDuration,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if len(bt.Usages) == 0 {
|
|
||||||
bt.Usages = constants.DefaultTokenUsages
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(bt.Groups) == 0 {
|
|
||||||
bt.Groups = constants.DefaultTokenGroups
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,10 +42,6 @@ func SetObjectDefaults_ClusterConfiguration(in *ClusterConfiguration) {
|
|||||||
|
|
||||||
func SetObjectDefaults_InitConfiguration(in *InitConfiguration) {
|
func SetObjectDefaults_InitConfiguration(in *InitConfiguration) {
|
||||||
SetDefaults_InitConfiguration(in)
|
SetDefaults_InitConfiguration(in)
|
||||||
for i := range in.BootstrapTokens {
|
|
||||||
a := &in.BootstrapTokens[i]
|
|
||||||
SetDefaults_BootstrapToken(a)
|
|
||||||
}
|
|
||||||
SetDefaults_APIEndpoint(&in.LocalAPIEndpoint)
|
SetDefaults_APIEndpoint(&in.LocalAPIEndpoint)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@ import (
|
|||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/apimachinery/pkg/util/sets"
|
"k8s.io/apimachinery/pkg/util/sets"
|
||||||
|
|
||||||
v1 "k8s.io/kubernetes/cmd/kubeadm/app/apis/bootstraptoken/v1"
|
bootstraptokenv1 "k8s.io/kubernetes/cmd/kubeadm/app/apis/bootstraptoken/v1"
|
||||||
kubeadmapi "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm"
|
kubeadmapi "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm"
|
||||||
kubeadmapiv1 "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm/v1beta3"
|
kubeadmapiv1 "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm/v1beta3"
|
||||||
"k8s.io/kubernetes/cmd/kubeadm/app/cmd/options"
|
"k8s.io/kubernetes/cmd/kubeadm/app/cmd/options"
|
||||||
@ -121,12 +121,12 @@ func TestNewInitData(t *testing.T) {
|
|||||||
AdvertiseAddress: "1.2.3.4",
|
AdvertiseAddress: "1.2.3.4",
|
||||||
BindPort: 6443,
|
BindPort: 6443,
|
||||||
},
|
},
|
||||||
BootstrapTokens: []v1.BootstrapToken{
|
BootstrapTokens: []bootstraptokenv1.BootstrapToken{
|
||||||
{
|
{
|
||||||
Token: &v1.BootstrapTokenString{ID: "abcdef", Secret: "0123456789abcdef"},
|
Token: &bootstraptokenv1.BootstrapTokenString{ID: "abcdef", Secret: "0123456789abcdef"},
|
||||||
Usages: []string{"signing", "authentication"},
|
Usages: []string{"signing", "authentication"},
|
||||||
TTL: &metav1.Duration{
|
TTL: &metav1.Duration{
|
||||||
Duration: constants.DefaultTokenDuration,
|
Duration: bootstraptokenv1.DefaultTokenDuration,
|
||||||
},
|
},
|
||||||
Groups: []string{"system:bootstrappers:kubeadm:default-node-token"},
|
Groups: []string{"system:bootstrappers:kubeadm:default-node-token"},
|
||||||
},
|
},
|
||||||
|
@ -26,13 +26,12 @@ import (
|
|||||||
|
|
||||||
bootstraptokenv1 "k8s.io/kubernetes/cmd/kubeadm/app/apis/bootstraptoken/v1"
|
bootstraptokenv1 "k8s.io/kubernetes/cmd/kubeadm/app/apis/bootstraptoken/v1"
|
||||||
kubeadmapiv1 "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm/v1beta3"
|
kubeadmapiv1 "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm/v1beta3"
|
||||||
kubeadmconstants "k8s.io/kubernetes/cmd/kubeadm/app/constants"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewBootstrapTokenOptions creates a new BootstrapTokenOptions object with the default values
|
// NewBootstrapTokenOptions creates a new BootstrapTokenOptions object with the default values
|
||||||
func NewBootstrapTokenOptions() *BootstrapTokenOptions {
|
func NewBootstrapTokenOptions() *BootstrapTokenOptions {
|
||||||
bto := &BootstrapTokenOptions{&bootstraptokenv1.BootstrapToken{}, ""}
|
bto := &BootstrapTokenOptions{&bootstraptokenv1.BootstrapToken{}, ""}
|
||||||
kubeadmapiv1.SetDefaults_BootstrapToken(bto.BootstrapToken)
|
bootstraptokenv1.SetDefaults_BootstrapToken(bto.BootstrapToken)
|
||||||
return bto
|
return bto
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -69,7 +68,7 @@ func (bto *BootstrapTokenOptions) AddTTLFlagWithName(fs *pflag.FlagSet, flagName
|
|||||||
func (bto *BootstrapTokenOptions) AddUsagesFlag(fs *pflag.FlagSet) {
|
func (bto *BootstrapTokenOptions) AddUsagesFlag(fs *pflag.FlagSet) {
|
||||||
fs.StringSliceVar(
|
fs.StringSliceVar(
|
||||||
&bto.Usages, TokenUsages, bto.Usages,
|
&bto.Usages, TokenUsages, bto.Usages,
|
||||||
fmt.Sprintf("Describes the ways in which this token can be used. You can pass --usages multiple times or provide a comma separated list of options. Valid options: [%s]", strings.Join(kubeadmconstants.DefaultTokenUsages, ",")),
|
fmt.Sprintf("Describes the ways in which this token can be used. You can pass --usages multiple times or provide a comma separated list of options. Valid options: [%s]", strings.Join(bootstraptokenv1.DefaultTokenUsages, ",")),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,7 +31,6 @@ import (
|
|||||||
"k8s.io/apimachinery/pkg/util/version"
|
"k8s.io/apimachinery/pkg/util/version"
|
||||||
"k8s.io/apimachinery/pkg/util/wait"
|
"k8s.io/apimachinery/pkg/util/wait"
|
||||||
apimachineryversion "k8s.io/apimachinery/pkg/version"
|
apimachineryversion "k8s.io/apimachinery/pkg/version"
|
||||||
bootstrapapi "k8s.io/cluster-bootstrap/token/api"
|
|
||||||
componentversion "k8s.io/component-base/version"
|
componentversion "k8s.io/component-base/version"
|
||||||
netutils "k8s.io/utils/net"
|
netutils "k8s.io/utils/net"
|
||||||
)
|
)
|
||||||
@ -243,10 +242,6 @@ const (
|
|||||||
// The node subnet mask size must be no more than the pod subnet mask size + 16
|
// The node subnet mask size must be no more than the pod subnet mask size + 16
|
||||||
PodSubnetNodeMaskMaxDiff = 16
|
PodSubnetNodeMaskMaxDiff = 16
|
||||||
|
|
||||||
// DefaultTokenDuration specifies the default amount of time that a bootstrap token will be valid
|
|
||||||
// Default behaviour is 24 hours
|
|
||||||
DefaultTokenDuration = 24 * time.Hour
|
|
||||||
|
|
||||||
// DefaultCertTokenDuration specifies the default amount of time that the token used by upload certs will be valid
|
// DefaultCertTokenDuration specifies the default amount of time that the token used by upload certs will be valid
|
||||||
// Default behaviour is 2 hours
|
// Default behaviour is 2 hours
|
||||||
DefaultCertTokenDuration = 2 * time.Hour
|
DefaultCertTokenDuration = 2 * time.Hour
|
||||||
@ -447,12 +442,6 @@ var (
|
|||||||
Effect: v1.TaintEffectNoSchedule,
|
Effect: v1.TaintEffectNoSchedule,
|
||||||
}
|
}
|
||||||
|
|
||||||
// DefaultTokenUsages specifies the default functions a token will get
|
|
||||||
DefaultTokenUsages = bootstrapapi.KnownTokenUsages
|
|
||||||
|
|
||||||
// DefaultTokenGroups specifies the default groups that this token will authenticate as when used for authentication
|
|
||||||
DefaultTokenGroups = []string{NodeBootstrapTokenAuthGroup}
|
|
||||||
|
|
||||||
// ControlPlaneComponents defines the control-plane component names
|
// ControlPlaneComponents defines the control-plane component names
|
||||||
ControlPlaneComponents = []string{KubeAPIServer, KubeControllerManager, KubeScheduler}
|
ControlPlaneComponents = []string{KubeAPIServer, KubeControllerManager, KubeScheduler}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user