mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-25 20:53:33 +00:00
kubeadm: Add omitempty tags to nullable values and use metav1.Duration
This commit is contained in:
parent
75e111ad87
commit
b0a17d11e4
@ -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
|
||||||
|
@ -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
Block a user