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
|
package kubeadm
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"time"
|
|
||||||
|
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -36,7 +34,7 @@ type MasterConfiguration struct {
|
||||||
AuthorizationModes []string
|
AuthorizationModes []string
|
||||||
|
|
||||||
Token string
|
Token string
|
||||||
TokenTTL time.Duration
|
TokenTTL metav1.Duration
|
||||||
|
|
||||||
APIServerExtraArgs map[string]string
|
APIServerExtraArgs map[string]string
|
||||||
ControllerManagerExtraArgs map[string]string
|
ControllerManagerExtraArgs map[string]string
|
||||||
|
|
|
@ -20,6 +20,7 @@ import (
|
||||||
"net/url"
|
"net/url"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/apimachinery/pkg/runtime"
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
"k8s.io/kubernetes/cmd/kubeadm/app/constants"
|
"k8s.io/kubernetes/cmd/kubeadm/app/constants"
|
||||||
)
|
)
|
||||||
|
@ -65,8 +66,10 @@ func SetDefaults_MasterConfiguration(obj *MasterConfiguration) {
|
||||||
obj.CertificatesDir = DefaultCertificatesDir
|
obj.CertificatesDir = DefaultCertificatesDir
|
||||||
}
|
}
|
||||||
|
|
||||||
if obj.TokenTTL == 0 {
|
if obj.TokenTTL.Duration == 0 {
|
||||||
obj.TokenTTL = constants.DefaultTokenDuration
|
obj.TokenTTL = metav1.Duration{
|
||||||
|
Duration: constants.DefaultTokenDuration,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if obj.ImageRepository == "" {
|
if obj.ImageRepository == "" {
|
||||||
|
|
|
@ -17,8 +17,6 @@ limitations under the License.
|
||||||
package v1alpha1
|
package v1alpha1
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"time"
|
|
||||||
|
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -33,17 +31,17 @@ type MasterConfiguration struct {
|
||||||
KubernetesVersion string `json:"kubernetesVersion"`
|
KubernetesVersion string `json:"kubernetesVersion"`
|
||||||
CloudProvider string `json:"cloudProvider"`
|
CloudProvider string `json:"cloudProvider"`
|
||||||
NodeName string `json:"nodeName"`
|
NodeName string `json:"nodeName"`
|
||||||
AuthorizationModes []string `json:"authorizationModes"`
|
AuthorizationModes []string `json:"authorizationModes,omitempty"`
|
||||||
|
|
||||||
Token string `json:"token"`
|
Token string `json:"token"`
|
||||||
TokenTTL time.Duration `json:"tokenTTL"`
|
TokenTTL metav1.Duration `json:"tokenTTL"`
|
||||||
|
|
||||||
APIServerExtraArgs map[string]string `json:"apiServerExtraArgs"`
|
APIServerExtraArgs map[string]string `json:"apiServerExtraArgs,omitempty"`
|
||||||
ControllerManagerExtraArgs map[string]string `json:"controllerManagerExtraArgs"`
|
ControllerManagerExtraArgs map[string]string `json:"controllerManagerExtraArgs,omitempty"`
|
||||||
SchedulerExtraArgs map[string]string `json:"schedulerExtraArgs"`
|
SchedulerExtraArgs map[string]string `json:"schedulerExtraArgs,omitempty"`
|
||||||
|
|
||||||
// APIServerCertSANs sets extra Subject Alternative Names for the API Server signing cert
|
// 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 specifies where to store or look for all required certificates
|
||||||
CertificatesDir string `json:"certificatesDir"`
|
CertificatesDir string `json:"certificatesDir"`
|
||||||
|
|
||||||
|
@ -53,7 +51,7 @@ type MasterConfiguration struct {
|
||||||
UnifiedControlPlaneImage string `json:"unifiedControlPlaneImage"`
|
UnifiedControlPlaneImage string `json:"unifiedControlPlaneImage"`
|
||||||
|
|
||||||
// FeatureGates enabled by the user
|
// FeatureGates enabled by the user
|
||||||
FeatureGates map[string]bool `json:"featureGates"`
|
FeatureGates map[string]bool `json:"featureGates,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type API struct {
|
type API struct {
|
||||||
|
@ -81,7 +79,7 @@ type Etcd struct {
|
||||||
CertFile string `json:"certFile"`
|
CertFile string `json:"certFile"`
|
||||||
KeyFile string `json:"keyFile"`
|
KeyFile string `json:"keyFile"`
|
||||||
DataDir string `json:"dataDir"`
|
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 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"`
|
Image string `json:"image"`
|
||||||
}
|
}
|
||||||
|
@ -94,7 +92,7 @@ type NodeConfiguration struct {
|
||||||
CACertPath string `json:"caCertPath"`
|
CACertPath string `json:"caCertPath"`
|
||||||
DiscoveryFile string `json:"discoveryFile"`
|
DiscoveryFile string `json:"discoveryFile"`
|
||||||
DiscoveryToken string `json:"discoveryToken"`
|
DiscoveryToken string `json:"discoveryToken"`
|
||||||
DiscoveryTokenAPIServers []string `json:"discoveryTokenAPIServers"`
|
DiscoveryTokenAPIServers []string `json:"discoveryTokenAPIServers,omitempty"`
|
||||||
NodeName string `json:"nodeName"`
|
NodeName string `json:"nodeName"`
|
||||||
TLSBootstrapToken string `json:"tlsBootstrapToken"`
|
TLSBootstrapToken string `json:"tlsBootstrapToken"`
|
||||||
Token string `json:"token"`
|
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
|
// 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:
|
// 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
|
// 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
|
// DiscoveryTokenUnsafeSkipCAVerification allows token-based discovery
|
||||||
// without CA verification via DiscoveryTokenCACertHashes. This can weaken
|
// without CA verification via DiscoveryTokenCACertHashes. This can weaken
|
||||||
|
|
|
@ -24,7 +24,6 @@ import (
|
||||||
conversion "k8s.io/apimachinery/pkg/conversion"
|
conversion "k8s.io/apimachinery/pkg/conversion"
|
||||||
runtime "k8s.io/apimachinery/pkg/runtime"
|
runtime "k8s.io/apimachinery/pkg/runtime"
|
||||||
kubeadm "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm"
|
kubeadm "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm"
|
||||||
time "time"
|
|
||||||
unsafe "unsafe"
|
unsafe "unsafe"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -120,7 +119,7 @@ func autoConvert_v1alpha1_MasterConfiguration_To_kubeadm_MasterConfiguration(in
|
||||||
out.NodeName = in.NodeName
|
out.NodeName = in.NodeName
|
||||||
out.AuthorizationModes = *(*[]string)(unsafe.Pointer(&in.AuthorizationModes))
|
out.AuthorizationModes = *(*[]string)(unsafe.Pointer(&in.AuthorizationModes))
|
||||||
out.Token = in.Token
|
out.Token = in.Token
|
||||||
out.TokenTTL = time.Duration(in.TokenTTL)
|
out.TokenTTL = in.TokenTTL
|
||||||
out.APIServerExtraArgs = *(*map[string]string)(unsafe.Pointer(&in.APIServerExtraArgs))
|
out.APIServerExtraArgs = *(*map[string]string)(unsafe.Pointer(&in.APIServerExtraArgs))
|
||||||
out.ControllerManagerExtraArgs = *(*map[string]string)(unsafe.Pointer(&in.ControllerManagerExtraArgs))
|
out.ControllerManagerExtraArgs = *(*map[string]string)(unsafe.Pointer(&in.ControllerManagerExtraArgs))
|
||||||
out.SchedulerExtraArgs = *(*map[string]string)(unsafe.Pointer(&in.SchedulerExtraArgs))
|
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.NodeName = in.NodeName
|
||||||
out.AuthorizationModes = *(*[]string)(unsafe.Pointer(&in.AuthorizationModes))
|
out.AuthorizationModes = *(*[]string)(unsafe.Pointer(&in.AuthorizationModes))
|
||||||
out.Token = in.Token
|
out.Token = in.Token
|
||||||
out.TokenTTL = time.Duration(in.TokenTTL)
|
out.TokenTTL = in.TokenTTL
|
||||||
out.APIServerExtraArgs = *(*map[string]string)(unsafe.Pointer(&in.APIServerExtraArgs))
|
out.APIServerExtraArgs = *(*map[string]string)(unsafe.Pointer(&in.APIServerExtraArgs))
|
||||||
out.ControllerManagerExtraArgs = *(*map[string]string)(unsafe.Pointer(&in.ControllerManagerExtraArgs))
|
out.ControllerManagerExtraArgs = *(*map[string]string)(unsafe.Pointer(&in.ControllerManagerExtraArgs))
|
||||||
out.SchedulerExtraArgs = *(*map[string]string)(unsafe.Pointer(&in.SchedulerExtraArgs))
|
out.SchedulerExtraArgs = *(*map[string]string)(unsafe.Pointer(&in.SchedulerExtraArgs))
|
||||||
|
|
|
@ -114,6 +114,7 @@ func (in *MasterConfiguration) DeepCopyInto(out *MasterConfiguration) {
|
||||||
*out = make([]string, len(*in))
|
*out = make([]string, len(*in))
|
||||||
copy(*out, *in)
|
copy(*out, *in)
|
||||||
}
|
}
|
||||||
|
out.TokenTTL = in.TokenTTL
|
||||||
if in.APIServerExtraArgs != nil {
|
if in.APIServerExtraArgs != nil {
|
||||||
in, out := &in.APIServerExtraArgs, &out.APIServerExtraArgs
|
in, out := &in.APIServerExtraArgs, &out.APIServerExtraArgs
|
||||||
*out = make(map[string]string, len(*in))
|
*out = make(map[string]string, len(*in))
|
||||||
|
|
|
@ -119,6 +119,7 @@ func (in *MasterConfiguration) DeepCopyInto(out *MasterConfiguration) {
|
||||||
*out = make([]string, len(*in))
|
*out = make([]string, len(*in))
|
||||||
copy(*out, *in)
|
copy(*out, *in)
|
||||||
}
|
}
|
||||||
|
out.TokenTTL = in.TokenTTL
|
||||||
if in.APIServerExtraArgs != nil {
|
if in.APIServerExtraArgs != nil {
|
||||||
in, out := &in.APIServerExtraArgs, &out.APIServerExtraArgs
|
in, out := &in.APIServerExtraArgs, &out.APIServerExtraArgs
|
||||||
*out = make(map[string]string, len(*in))
|
*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.",
|
"The token to use for establishing bidirectional trust between nodes and masters.",
|
||||||
)
|
)
|
||||||
flagSet.DurationVar(
|
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'.",
|
"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. "+
|
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
|
// Create the default node bootstrap token
|
||||||
tokenDescription := "The default bootstrap token generated by 'kubeadm init'."
|
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
|
return err
|
||||||
}
|
}
|
||||||
// Create RBAC rules that makes the bootstrap tokens able to post CSRs
|
// Create RBAC rules that makes the bootstrap tokens able to post CSRs
|
||||||
|
|
|
@ -41,21 +41,15 @@ func TestPrintConfiguration(t *testing.T) {
|
||||||
api:
|
api:
|
||||||
advertiseAddress: ""
|
advertiseAddress: ""
|
||||||
bindPort: 0
|
bindPort: 0
|
||||||
apiServerCertSANs: null
|
|
||||||
apiServerExtraArgs: null
|
|
||||||
authorizationModes: null
|
|
||||||
certificatesDir: ""
|
certificatesDir: ""
|
||||||
cloudProvider: ""
|
cloudProvider: ""
|
||||||
controllerManagerExtraArgs: null
|
|
||||||
etcd:
|
etcd:
|
||||||
caFile: ""
|
caFile: ""
|
||||||
certFile: ""
|
certFile: ""
|
||||||
dataDir: ""
|
dataDir: ""
|
||||||
endpoints: null
|
endpoints: null
|
||||||
extraArgs: null
|
|
||||||
image: ""
|
image: ""
|
||||||
keyFile: ""
|
keyFile: ""
|
||||||
featureGates: null
|
|
||||||
imageRepository: ""
|
imageRepository: ""
|
||||||
kubernetesVersion: v1.7.1
|
kubernetesVersion: v1.7.1
|
||||||
networking:
|
networking:
|
||||||
|
@ -63,9 +57,8 @@ func TestPrintConfiguration(t *testing.T) {
|
||||||
podSubnet: ""
|
podSubnet: ""
|
||||||
serviceSubnet: ""
|
serviceSubnet: ""
|
||||||
nodeName: ""
|
nodeName: ""
|
||||||
schedulerExtraArgs: null
|
|
||||||
token: ""
|
token: ""
|
||||||
tokenTTL: 0
|
tokenTTL: 0s
|
||||||
unifiedControlPlaneImage: ""
|
unifiedControlPlaneImage: ""
|
||||||
`),
|
`),
|
||||||
},
|
},
|
||||||
|
@ -80,21 +73,15 @@ func TestPrintConfiguration(t *testing.T) {
|
||||||
api:
|
api:
|
||||||
advertiseAddress: ""
|
advertiseAddress: ""
|
||||||
bindPort: 0
|
bindPort: 0
|
||||||
apiServerCertSANs: null
|
|
||||||
apiServerExtraArgs: null
|
|
||||||
authorizationModes: null
|
|
||||||
certificatesDir: ""
|
certificatesDir: ""
|
||||||
cloudProvider: ""
|
cloudProvider: ""
|
||||||
controllerManagerExtraArgs: null
|
|
||||||
etcd:
|
etcd:
|
||||||
caFile: ""
|
caFile: ""
|
||||||
certFile: ""
|
certFile: ""
|
||||||
dataDir: ""
|
dataDir: ""
|
||||||
endpoints: null
|
endpoints: null
|
||||||
extraArgs: null
|
|
||||||
image: ""
|
image: ""
|
||||||
keyFile: ""
|
keyFile: ""
|
||||||
featureGates: null
|
|
||||||
imageRepository: ""
|
imageRepository: ""
|
||||||
kubernetesVersion: v1.7.1
|
kubernetesVersion: v1.7.1
|
||||||
networking:
|
networking:
|
||||||
|
@ -102,9 +89,8 @@ func TestPrintConfiguration(t *testing.T) {
|
||||||
podSubnet: ""
|
podSubnet: ""
|
||||||
serviceSubnet: 10.96.0.1/12
|
serviceSubnet: 10.96.0.1/12
|
||||||
nodeName: ""
|
nodeName: ""
|
||||||
schedulerExtraArgs: null
|
|
||||||
token: ""
|
token: ""
|
||||||
tokenTTL: 0
|
tokenTTL: 0s
|
||||||
unifiedControlPlaneImage: ""
|
unifiedControlPlaneImage: ""
|
||||||
`),
|
`),
|
||||||
},
|
},
|
||||||
|
|
|
@ -69,7 +69,7 @@ networking:
|
||||||
nodeName: thegopher
|
nodeName: thegopher
|
||||||
schedulerExtraArgs: null
|
schedulerExtraArgs: null
|
||||||
token: ce3aa5.5ec8455bb76b379f
|
token: ce3aa5.5ec8455bb76b379f
|
||||||
tokenTTL: 86400000000000
|
tokenTTL: 24h
|
||||||
unifiedControlPlaneImage: ""
|
unifiedControlPlaneImage: ""
|
||||||
`
|
`
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue