mirror of https://github.com/k3s-io/k3s
Merge pull request #51336 from luxas/kubeadm_api_omitempty
Automatic merge from submit-queue kubeadm: Add omitempty tags to nullable values and use metav1.Duration **What this PR does / why we need it**: From @sttts review of https://github.com/kubernetes/kubernetes/pull/49959; we found some shortcomings of the current JSON tags in the kubeadm config file. **Which issue this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close that issue when PR gets merged)*: fixes # **Special notes for your reviewer**: Note that https://github.com/kubernetes/kubernetes/pull/49959 will not be merged for v1.8, but this at least improves the state in v1.8 without changing anything really. **Release note**: ```release-note NONE ``` @kubernetes/sig-api-machinery-pr-reviewspull/6/head
commit
d610b828ce
|
@ -17,8 +17,6 @@ limitations under the License.
|
|||
package kubeadm
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
)
|
||||
|
||||
|
@ -36,7 +34,7 @@ type MasterConfiguration struct {
|
|||
AuthorizationModes []string
|
||||
|
||||
Token string
|
||||
TokenTTL time.Duration
|
||||
TokenTTL metav1.Duration
|
||||
|
||||
APIServerExtraArgs map[string]string
|
||||
ControllerManagerExtraArgs map[string]string
|
||||
|
|
|
@ -20,6 +20,7 @@ import (
|
|||
"net/url"
|
||||
"strings"
|
||||
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"k8s.io/kubernetes/cmd/kubeadm/app/constants"
|
||||
)
|
||||
|
@ -65,8 +66,10 @@ func SetDefaults_MasterConfiguration(obj *MasterConfiguration) {
|
|||
obj.CertificatesDir = DefaultCertificatesDir
|
||||
}
|
||||
|
||||
if obj.TokenTTL == 0 {
|
||||
obj.TokenTTL = constants.DefaultTokenDuration
|
||||
if obj.TokenTTL.Duration == 0 {
|
||||
obj.TokenTTL = metav1.Duration{
|
||||
Duration: constants.DefaultTokenDuration,
|
||||
}
|
||||
}
|
||||
|
||||
if obj.ImageRepository == "" {
|
||||
|
|
|
@ -17,8 +17,6 @@ limitations under the License.
|
|||
package v1alpha1
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
)
|
||||
|
||||
|
@ -33,17 +31,17 @@ type MasterConfiguration struct {
|
|||
KubernetesVersion string `json:"kubernetesVersion"`
|
||||
CloudProvider string `json:"cloudProvider"`
|
||||
NodeName string `json:"nodeName"`
|
||||
AuthorizationModes []string `json:"authorizationModes"`
|
||||
AuthorizationModes []string `json:"authorizationModes,omitempty"`
|
||||
|
||||
Token string `json:"token"`
|
||||
TokenTTL time.Duration `json:"tokenTTL"`
|
||||
Token string `json:"token"`
|
||||
TokenTTL metav1.Duration `json:"tokenTTL"`
|
||||
|
||||
APIServerExtraArgs map[string]string `json:"apiServerExtraArgs"`
|
||||
ControllerManagerExtraArgs map[string]string `json:"controllerManagerExtraArgs"`
|
||||
SchedulerExtraArgs map[string]string `json:"schedulerExtraArgs"`
|
||||
APIServerExtraArgs map[string]string `json:"apiServerExtraArgs,omitempty"`
|
||||
ControllerManagerExtraArgs map[string]string `json:"controllerManagerExtraArgs,omitempty"`
|
||||
SchedulerExtraArgs map[string]string `json:"schedulerExtraArgs,omitempty"`
|
||||
|
||||
// APIServerCertSANs sets extra Subject Alternative Names for the API Server signing cert
|
||||
APIServerCertSANs []string `json:"apiServerCertSANs"`
|
||||
APIServerCertSANs []string `json:"apiServerCertSANs,omitempty"`
|
||||
// CertificatesDir specifies where to store or look for all required certificates
|
||||
CertificatesDir string `json:"certificatesDir"`
|
||||
|
||||
|
@ -53,7 +51,7 @@ type MasterConfiguration struct {
|
|||
UnifiedControlPlaneImage string `json:"unifiedControlPlaneImage"`
|
||||
|
||||
// FeatureGates enabled by the user
|
||||
FeatureGates map[string]bool `json:"featureGates"`
|
||||
FeatureGates map[string]bool `json:"featureGates,omitempty"`
|
||||
}
|
||||
|
||||
type API struct {
|
||||
|
@ -81,7 +79,7 @@ type Etcd struct {
|
|||
CertFile string `json:"certFile"`
|
||||
KeyFile string `json:"keyFile"`
|
||||
DataDir string `json:"dataDir"`
|
||||
ExtraArgs map[string]string `json:"extraArgs"`
|
||||
ExtraArgs map[string]string `json:"extraArgs,omitempty"`
|
||||
// Image specifies which container image to use for running etcd. If empty, automatically populated by kubeadm using the image repository and default etcd version
|
||||
Image string `json:"image"`
|
||||
}
|
||||
|
@ -94,7 +92,7 @@ type NodeConfiguration struct {
|
|||
CACertPath string `json:"caCertPath"`
|
||||
DiscoveryFile string `json:"discoveryFile"`
|
||||
DiscoveryToken string `json:"discoveryToken"`
|
||||
DiscoveryTokenAPIServers []string `json:"discoveryTokenAPIServers"`
|
||||
DiscoveryTokenAPIServers []string `json:"discoveryTokenAPIServers,omitempty"`
|
||||
NodeName string `json:"nodeName"`
|
||||
TLSBootstrapToken string `json:"tlsBootstrapToken"`
|
||||
Token string `json:"token"`
|
||||
|
@ -107,7 +105,7 @@ type NodeConfiguration struct {
|
|||
// SHA-256 hash of the Subject Public Key Info (SPKI) object in DER-encoded
|
||||
// ASN.1. These hashes can be calculated using, for example, OpenSSL:
|
||||
// openssl x509 -pubkey -in ca.crt openssl rsa -pubin -outform der 2>&/dev/null | openssl dgst -sha256 -hex
|
||||
DiscoveryTokenCACertHashes []string `json:"discoveryTokenCACertHashes"`
|
||||
DiscoveryTokenCACertHashes []string `json:"discoveryTokenCACertHashes,omitempty"`
|
||||
|
||||
// DiscoveryTokenUnsafeSkipCAVerification allows token-based discovery
|
||||
// without CA verification via DiscoveryTokenCACertHashes. This can weaken
|
||||
|
|
|
@ -24,7 +24,6 @@ import (
|
|||
conversion "k8s.io/apimachinery/pkg/conversion"
|
||||
runtime "k8s.io/apimachinery/pkg/runtime"
|
||||
kubeadm "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm"
|
||||
time "time"
|
||||
unsafe "unsafe"
|
||||
)
|
||||
|
||||
|
@ -120,7 +119,7 @@ func autoConvert_v1alpha1_MasterConfiguration_To_kubeadm_MasterConfiguration(in
|
|||
out.NodeName = in.NodeName
|
||||
out.AuthorizationModes = *(*[]string)(unsafe.Pointer(&in.AuthorizationModes))
|
||||
out.Token = in.Token
|
||||
out.TokenTTL = time.Duration(in.TokenTTL)
|
||||
out.TokenTTL = in.TokenTTL
|
||||
out.APIServerExtraArgs = *(*map[string]string)(unsafe.Pointer(&in.APIServerExtraArgs))
|
||||
out.ControllerManagerExtraArgs = *(*map[string]string)(unsafe.Pointer(&in.ControllerManagerExtraArgs))
|
||||
out.SchedulerExtraArgs = *(*map[string]string)(unsafe.Pointer(&in.SchedulerExtraArgs))
|
||||
|
@ -152,7 +151,7 @@ func autoConvert_kubeadm_MasterConfiguration_To_v1alpha1_MasterConfiguration(in
|
|||
out.NodeName = in.NodeName
|
||||
out.AuthorizationModes = *(*[]string)(unsafe.Pointer(&in.AuthorizationModes))
|
||||
out.Token = in.Token
|
||||
out.TokenTTL = time.Duration(in.TokenTTL)
|
||||
out.TokenTTL = in.TokenTTL
|
||||
out.APIServerExtraArgs = *(*map[string]string)(unsafe.Pointer(&in.APIServerExtraArgs))
|
||||
out.ControllerManagerExtraArgs = *(*map[string]string)(unsafe.Pointer(&in.ControllerManagerExtraArgs))
|
||||
out.SchedulerExtraArgs = *(*map[string]string)(unsafe.Pointer(&in.SchedulerExtraArgs))
|
||||
|
|
|
@ -114,6 +114,7 @@ func (in *MasterConfiguration) DeepCopyInto(out *MasterConfiguration) {
|
|||
*out = make([]string, len(*in))
|
||||
copy(*out, *in)
|
||||
}
|
||||
out.TokenTTL = in.TokenTTL
|
||||
if in.APIServerExtraArgs != nil {
|
||||
in, out := &in.APIServerExtraArgs, &out.APIServerExtraArgs
|
||||
*out = make(map[string]string, len(*in))
|
||||
|
|
|
@ -119,6 +119,7 @@ func (in *MasterConfiguration) DeepCopyInto(out *MasterConfiguration) {
|
|||
*out = make([]string, len(*in))
|
||||
copy(*out, *in)
|
||||
}
|
||||
out.TokenTTL = in.TokenTTL
|
||||
if in.APIServerExtraArgs != nil {
|
||||
in, out := &in.APIServerExtraArgs, &out.APIServerExtraArgs
|
||||
*out = make(map[string]string, len(*in))
|
||||
|
|
|
@ -169,7 +169,7 @@ func AddInitConfigFlags(flagSet *flag.FlagSet, cfg *kubeadmapiext.MasterConfigur
|
|||
"The token to use for establishing bidirectional trust between nodes and masters.",
|
||||
)
|
||||
flagSet.DurationVar(
|
||||
&cfg.TokenTTL, "token-ttl", cfg.TokenTTL,
|
||||
&cfg.TokenTTL.Duration, "token-ttl", cfg.TokenTTL.Duration,
|
||||
"The duration before the bootstrap token is automatically deleted. 0 means 'never expires'.",
|
||||
)
|
||||
flagSet.StringVar(featureGatesString, "feature-gates", *featureGatesString, "A set of key=value pairs that describe feature gates for various features. "+
|
||||
|
@ -352,7 +352,7 @@ func (i *Init) Run(out io.Writer) error {
|
|||
|
||||
// Create the default node bootstrap token
|
||||
tokenDescription := "The default bootstrap token generated by 'kubeadm init'."
|
||||
if err := nodebootstraptokenphase.UpdateOrCreateToken(client, i.cfg.Token, false, i.cfg.TokenTTL, kubeadmconstants.DefaultTokenUsages, []string{}, tokenDescription); err != nil {
|
||||
if err := nodebootstraptokenphase.UpdateOrCreateToken(client, i.cfg.Token, false, i.cfg.TokenTTL.Duration, kubeadmconstants.DefaultTokenUsages, []string{}, tokenDescription); err != nil {
|
||||
return err
|
||||
}
|
||||
// Create RBAC rules that makes the bootstrap tokens able to post CSRs
|
||||
|
|
|
@ -41,21 +41,15 @@ func TestPrintConfiguration(t *testing.T) {
|
|||
api:
|
||||
advertiseAddress: ""
|
||||
bindPort: 0
|
||||
apiServerCertSANs: null
|
||||
apiServerExtraArgs: null
|
||||
authorizationModes: null
|
||||
certificatesDir: ""
|
||||
cloudProvider: ""
|
||||
controllerManagerExtraArgs: null
|
||||
etcd:
|
||||
caFile: ""
|
||||
certFile: ""
|
||||
dataDir: ""
|
||||
endpoints: null
|
||||
extraArgs: null
|
||||
image: ""
|
||||
keyFile: ""
|
||||
featureGates: null
|
||||
imageRepository: ""
|
||||
kubernetesVersion: v1.7.1
|
||||
networking:
|
||||
|
@ -63,9 +57,8 @@ func TestPrintConfiguration(t *testing.T) {
|
|||
podSubnet: ""
|
||||
serviceSubnet: ""
|
||||
nodeName: ""
|
||||
schedulerExtraArgs: null
|
||||
token: ""
|
||||
tokenTTL: 0
|
||||
tokenTTL: 0s
|
||||
unifiedControlPlaneImage: ""
|
||||
`),
|
||||
},
|
||||
|
@ -80,21 +73,15 @@ func TestPrintConfiguration(t *testing.T) {
|
|||
api:
|
||||
advertiseAddress: ""
|
||||
bindPort: 0
|
||||
apiServerCertSANs: null
|
||||
apiServerExtraArgs: null
|
||||
authorizationModes: null
|
||||
certificatesDir: ""
|
||||
cloudProvider: ""
|
||||
controllerManagerExtraArgs: null
|
||||
etcd:
|
||||
caFile: ""
|
||||
certFile: ""
|
||||
dataDir: ""
|
||||
endpoints: null
|
||||
extraArgs: null
|
||||
image: ""
|
||||
keyFile: ""
|
||||
featureGates: null
|
||||
imageRepository: ""
|
||||
kubernetesVersion: v1.7.1
|
||||
networking:
|
||||
|
@ -102,9 +89,8 @@ func TestPrintConfiguration(t *testing.T) {
|
|||
podSubnet: ""
|
||||
serviceSubnet: 10.96.0.1/12
|
||||
nodeName: ""
|
||||
schedulerExtraArgs: null
|
||||
token: ""
|
||||
tokenTTL: 0
|
||||
tokenTTL: 0s
|
||||
unifiedControlPlaneImage: ""
|
||||
`),
|
||||
},
|
||||
|
|
|
@ -69,7 +69,7 @@ networking:
|
|||
nodeName: thegopher
|
||||
schedulerExtraArgs: null
|
||||
token: ce3aa5.5ec8455bb76b379f
|
||||
tokenTTL: 86400000000000
|
||||
tokenTTL: 24h
|
||||
unifiedControlPlaneImage: ""
|
||||
`
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue