Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
8ae5179a
Commit
8ae5179a
authored
Oct 04, 2018
by
fabriziopandini
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add a duplicated v1beta1 API
parent
7136a3e4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
799 additions
and
2 deletions
+799
-2
scheme.go
cmd/kubeadm/app/apis/kubeadm/scheme/scheme.go
+3
-1
bootstraptokenstring.go
cmd/kubeadm/app/apis/kubeadm/v1beta1/bootstraptokenstring.go
+86
-0
bootstraptokenstring_test.go
...adm/app/apis/kubeadm/v1beta1/bootstraptokenstring_test.go
+236
-0
defaults.go
cmd/kubeadm/app/apis/kubeadm/v1beta1/defaults.go
+202
-0
defaults_unix.go
cmd/kubeadm/app/apis/kubeadm/v1beta1/defaults_unix.go
+28
-0
defaults_windows.go
cmd/kubeadm/app/apis/kubeadm/v1beta1/defaults_windows.go
+28
-0
doc.go
cmd/kubeadm/app/apis/kubeadm/v1beta1/doc.go
+145
-0
register.go
cmd/kubeadm/app/apis/kubeadm/v1beta1/register.go
+68
-0
types.go
cmd/kubeadm/app/apis/kubeadm/v1beta1/types.go
+0
-0
config.go
cmd/kubeadm/app/cmd/config.go
+3
-1
No files found.
cmd/kubeadm/app/apis/kubeadm/scheme/scheme.go
View file @
8ae5179a
...
@@ -24,6 +24,7 @@ import (
...
@@ -24,6 +24,7 @@ import (
utilruntime
"k8s.io/apimachinery/pkg/util/runtime"
utilruntime
"k8s.io/apimachinery/pkg/util/runtime"
"k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm"
"k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm"
"k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm/v1alpha3"
"k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm/v1alpha3"
"k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm/v1beta1"
)
)
// Scheme is the runtime.Scheme to which all kubeadm api types are registered.
// Scheme is the runtime.Scheme to which all kubeadm api types are registered.
...
@@ -41,5 +42,6 @@ func init() {
...
@@ -41,5 +42,6 @@ func init() {
func
AddToScheme
(
scheme
*
runtime
.
Scheme
)
{
func
AddToScheme
(
scheme
*
runtime
.
Scheme
)
{
utilruntime
.
Must
(
kubeadm
.
AddToScheme
(
scheme
))
utilruntime
.
Must
(
kubeadm
.
AddToScheme
(
scheme
))
utilruntime
.
Must
(
v1alpha3
.
AddToScheme
(
scheme
))
utilruntime
.
Must
(
v1alpha3
.
AddToScheme
(
scheme
))
utilruntime
.
Must
(
scheme
.
SetVersionPriority
(
v1alpha3
.
SchemeGroupVersion
))
utilruntime
.
Must
(
v1beta1
.
AddToScheme
(
scheme
))
utilruntime
.
Must
(
scheme
.
SetVersionPriority
(
v1beta1
.
SchemeGroupVersion
))
}
}
cmd/kubeadm/app/apis/kubeadm/v1beta1/bootstraptokenstring.go
0 → 100644
View file @
8ae5179a
/*
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
v1beta1
import
(
"fmt"
"strings"
bootstrapapi
"k8s.io/cluster-bootstrap/token/api"
bootstraputil
"k8s.io/cluster-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
))
}
cmd/kubeadm/app/apis/kubeadm/v1beta1/bootstraptokenstring_test.go
0 → 100644
View file @
8ae5179a
/*
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
v1beta1
import
(
"encoding/json"
"fmt"
"reflect"
"testing"
)
func
TestMarshalJSON
(
t
*
testing
.
T
)
{
var
tests
=
[]
struct
{
bts
BootstrapTokenString
expected
string
}{
{
BootstrapTokenString
{
ID
:
"abcdef"
,
Secret
:
"abcdef0123456789"
},
`"abcdef.abcdef0123456789"`
},
{
BootstrapTokenString
{
ID
:
"foo"
,
Secret
:
"bar"
},
`"foo.bar"`
},
{
BootstrapTokenString
{
ID
:
"h"
,
Secret
:
"b"
},
`"h.b"`
},
}
for
_
,
rt
:=
range
tests
{
b
,
err
:=
json
.
Marshal
(
rt
.
bts
)
if
err
!=
nil
{
t
.
Fatalf
(
"json.Marshal returned an unexpected error: %v"
,
err
)
}
if
string
(
b
)
!=
rt
.
expected
{
t
.
Errorf
(
"failed BootstrapTokenString.MarshalJSON:
\n\t
expected: %s
\n\t
actual: %s"
,
rt
.
expected
,
string
(
b
),
)
}
}
}
func
TestUnmarshalJSON
(
t
*
testing
.
T
)
{
var
tests
=
[]
struct
{
input
string
bts
*
BootstrapTokenString
expectedError
bool
}{
{
`"f.s"`
,
&
BootstrapTokenString
{},
true
},
{
`"abcdef."`
,
&
BootstrapTokenString
{},
true
},
{
`"abcdef:abcdef0123456789"`
,
&
BootstrapTokenString
{},
true
},
{
`abcdef.abcdef0123456789`
,
&
BootstrapTokenString
{},
true
},
{
`"abcdef.abcdef0123456789`
,
&
BootstrapTokenString
{},
true
},
{
`"abcdef.ABCDEF0123456789"`
,
&
BootstrapTokenString
{},
true
},
{
`"abcdef.abcdef0123456789"`
,
&
BootstrapTokenString
{
ID
:
"abcdef"
,
Secret
:
"abcdef0123456789"
},
false
},
{
`"123456.aabbccddeeffgghh"`
,
&
BootstrapTokenString
{
ID
:
"123456"
,
Secret
:
"aabbccddeeffgghh"
},
false
},
}
for
_
,
rt
:=
range
tests
{
newbts
:=
&
BootstrapTokenString
{}
err
:=
json
.
Unmarshal
([]
byte
(
rt
.
input
),
newbts
)
if
(
err
!=
nil
)
!=
rt
.
expectedError
{
t
.
Errorf
(
"failed BootstrapTokenString.UnmarshalJSON:
\n\t
expected error: %t
\n\t
actual error: %v"
,
rt
.
expectedError
,
err
)
}
else
if
!
reflect
.
DeepEqual
(
rt
.
bts
,
newbts
)
{
t
.
Errorf
(
"failed BootstrapTokenString.UnmarshalJSON:
\n\t
expected: %v
\n\t
actual: %v"
,
rt
.
bts
,
newbts
,
)
}
}
}
func
TestJSONRoundtrip
(
t
*
testing
.
T
)
{
var
tests
=
[]
struct
{
input
string
bts
*
BootstrapTokenString
}{
{
`"abcdef.abcdef0123456789"`
,
nil
},
{
""
,
&
BootstrapTokenString
{
ID
:
"abcdef"
,
Secret
:
"abcdef0123456789"
}},
}
for
_
,
rt
:=
range
tests
{
if
err
:=
roundtrip
(
rt
.
input
,
rt
.
bts
);
err
!=
nil
{
t
.
Errorf
(
"failed BootstrapTokenString JSON roundtrip with error: %v"
,
err
)
}
}
}
func
roundtrip
(
input
string
,
bts
*
BootstrapTokenString
)
error
{
var
b
[]
byte
var
err
error
newbts
:=
&
BootstrapTokenString
{}
// If string input was specified, roundtrip like this: string -> (unmarshal) -> object -> (marshal) -> string
if
len
(
input
)
>
0
{
if
err
:=
json
.
Unmarshal
([]
byte
(
input
),
newbts
);
err
!=
nil
{
return
fmt
.
Errorf
(
"expected no unmarshal error, got error: %v"
,
err
)
}
if
b
,
err
=
json
.
Marshal
(
newbts
);
err
!=
nil
{
return
fmt
.
Errorf
(
"expected no marshal error, got error: %v"
,
err
)
}
if
input
!=
string
(
b
)
{
return
fmt
.
Errorf
(
"expected token: %s
\n\t
actual: %s"
,
input
,
string
(
b
),
)
}
}
else
{
// Otherwise, roundtrip like this: object -> (marshal) -> string -> (unmarshal) -> object
if
b
,
err
=
json
.
Marshal
(
bts
);
err
!=
nil
{
return
fmt
.
Errorf
(
"expected no marshal error, got error: %v"
,
err
)
}
if
err
:=
json
.
Unmarshal
(
b
,
newbts
);
err
!=
nil
{
return
fmt
.
Errorf
(
"expected no unmarshal error, got error: %v"
,
err
)
}
if
!
reflect
.
DeepEqual
(
bts
,
newbts
)
{
return
fmt
.
Errorf
(
"expected object: %v
\n\t
actual: %v"
,
bts
,
newbts
,
)
}
}
return
nil
}
func
TestTokenFromIDAndSecret
(
t
*
testing
.
T
)
{
var
tests
=
[]
struct
{
bts
BootstrapTokenString
expected
string
}{
{
BootstrapTokenString
{
ID
:
"foo"
,
Secret
:
"bar"
},
"foo.bar"
},
{
BootstrapTokenString
{
ID
:
"abcdef"
,
Secret
:
"abcdef0123456789"
},
"abcdef.abcdef0123456789"
},
{
BootstrapTokenString
{
ID
:
"h"
,
Secret
:
"b"
},
"h.b"
},
}
for
_
,
rt
:=
range
tests
{
actual
:=
rt
.
bts
.
String
()
if
actual
!=
rt
.
expected
{
t
.
Errorf
(
"failed BootstrapTokenString.String():
\n\t
expected: %s
\n\t
actual: %s"
,
rt
.
expected
,
actual
,
)
}
}
}
func
TestNewBootstrapTokenString
(
t
*
testing
.
T
)
{
var
tests
=
[]
struct
{
token
string
expectedError
bool
bts
*
BootstrapTokenString
}{
{
token
:
""
,
expectedError
:
true
,
bts
:
nil
},
{
token
:
"."
,
expectedError
:
true
,
bts
:
nil
},
{
token
:
"1234567890123456789012"
,
expectedError
:
true
,
bts
:
nil
},
// invalid parcel size
{
token
:
"12345.1234567890123456"
,
expectedError
:
true
,
bts
:
nil
},
// invalid parcel size
{
token
:
".1234567890123456"
,
expectedError
:
true
,
bts
:
nil
},
// invalid parcel size
{
token
:
"123456."
,
expectedError
:
true
,
bts
:
nil
},
// invalid parcel size
{
token
:
"123456:1234567890.123456"
,
expectedError
:
true
,
bts
:
nil
},
// invalid separation
{
token
:
"abcdef:1234567890123456"
,
expectedError
:
true
,
bts
:
nil
},
// invalid separation
{
token
:
"Abcdef.1234567890123456"
,
expectedError
:
true
,
bts
:
nil
},
// invalid token id
{
token
:
"123456.AABBCCDDEEFFGGHH"
,
expectedError
:
true
,
bts
:
nil
},
// invalid token secret
{
token
:
"123456.AABBCCD-EEFFGGHH"
,
expectedError
:
true
,
bts
:
nil
},
// invalid character
{
token
:
"abc*ef.1234567890123456"
,
expectedError
:
true
,
bts
:
nil
},
// invalid character
{
token
:
"abcdef.1234567890123456"
,
expectedError
:
false
,
bts
:
&
BootstrapTokenString
{
ID
:
"abcdef"
,
Secret
:
"1234567890123456"
}},
{
token
:
"123456.aabbccddeeffgghh"
,
expectedError
:
false
,
bts
:
&
BootstrapTokenString
{
ID
:
"123456"
,
Secret
:
"aabbccddeeffgghh"
}},
{
token
:
"abcdef.abcdef0123456789"
,
expectedError
:
false
,
bts
:
&
BootstrapTokenString
{
ID
:
"abcdef"
,
Secret
:
"abcdef0123456789"
}},
{
token
:
"123456.1234560123456789"
,
expectedError
:
false
,
bts
:
&
BootstrapTokenString
{
ID
:
"123456"
,
Secret
:
"1234560123456789"
}},
}
for
_
,
rt
:=
range
tests
{
actual
,
err
:=
NewBootstrapTokenString
(
rt
.
token
)
if
(
err
!=
nil
)
!=
rt
.
expectedError
{
t
.
Errorf
(
"failed NewBootstrapTokenString for the token %q
\n\t
expected error: %t
\n\t
actual error: %v"
,
rt
.
token
,
rt
.
expectedError
,
err
,
)
}
else
if
!
reflect
.
DeepEqual
(
actual
,
rt
.
bts
)
{
t
.
Errorf
(
"failed NewBootstrapTokenString for the token %q
\n\t
expected: %v
\n\t
actual: %v"
,
rt
.
token
,
rt
.
bts
,
actual
,
)
}
}
}
func
TestNewBootstrapTokenStringFromIDAndSecret
(
t
*
testing
.
T
)
{
var
tests
=
[]
struct
{
id
,
secret
string
expectedError
bool
bts
*
BootstrapTokenString
}{
{
id
:
""
,
secret
:
""
,
expectedError
:
true
,
bts
:
nil
},
{
id
:
"1234567890123456789012"
,
secret
:
""
,
expectedError
:
true
,
bts
:
nil
},
// invalid parcel size
{
id
:
"12345"
,
secret
:
"1234567890123456"
,
expectedError
:
true
,
bts
:
nil
},
// invalid parcel size
{
id
:
""
,
secret
:
"1234567890123456"
,
expectedError
:
true
,
bts
:
nil
},
// invalid parcel size
{
id
:
"123456"
,
secret
:
""
,
expectedError
:
true
,
bts
:
nil
},
// invalid parcel size
{
id
:
"Abcdef"
,
secret
:
"1234567890123456"
,
expectedError
:
true
,
bts
:
nil
},
// invalid token id
{
id
:
"123456"
,
secret
:
"AABBCCDDEEFFGGHH"
,
expectedError
:
true
,
bts
:
nil
},
// invalid token secret
{
id
:
"123456"
,
secret
:
"AABBCCD-EEFFGGHH"
,
expectedError
:
true
,
bts
:
nil
},
// invalid character
{
id
:
"abc*ef"
,
secret
:
"1234567890123456"
,
expectedError
:
true
,
bts
:
nil
},
// invalid character
{
id
:
"abcdef"
,
secret
:
"1234567890123456"
,
expectedError
:
false
,
bts
:
&
BootstrapTokenString
{
ID
:
"abcdef"
,
Secret
:
"1234567890123456"
}},
{
id
:
"123456"
,
secret
:
"aabbccddeeffgghh"
,
expectedError
:
false
,
bts
:
&
BootstrapTokenString
{
ID
:
"123456"
,
Secret
:
"aabbccddeeffgghh"
}},
{
id
:
"abcdef"
,
secret
:
"abcdef0123456789"
,
expectedError
:
false
,
bts
:
&
BootstrapTokenString
{
ID
:
"abcdef"
,
Secret
:
"abcdef0123456789"
}},
{
id
:
"123456"
,
secret
:
"1234560123456789"
,
expectedError
:
false
,
bts
:
&
BootstrapTokenString
{
ID
:
"123456"
,
Secret
:
"1234560123456789"
}},
}
for
_
,
rt
:=
range
tests
{
actual
,
err
:=
NewBootstrapTokenStringFromIDAndSecret
(
rt
.
id
,
rt
.
secret
)
if
(
err
!=
nil
)
!=
rt
.
expectedError
{
t
.
Errorf
(
"failed NewBootstrapTokenStringFromIDAndSecret for the token with id %q and secret %q
\n\t
expected error: %t
\n\t
actual error: %v"
,
rt
.
id
,
rt
.
secret
,
rt
.
expectedError
,
err
,
)
}
else
if
!
reflect
.
DeepEqual
(
actual
,
rt
.
bts
)
{
t
.
Errorf
(
"failed NewBootstrapTokenStringFromIDAndSecret for the token with id %q and secret %q
\n\t
expected: %v
\n\t
actual: %v"
,
rt
.
id
,
rt
.
secret
,
rt
.
bts
,
actual
,
)
}
}
}
cmd/kubeadm/app/apis/kubeadm/v1beta1/defaults.go
0 → 100644
View file @
8ae5179a
/*
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
v1beta1
import
(
"net/url"
"time"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/kubernetes/cmd/kubeadm/app/constants"
)
const
(
// DefaultServiceDNSDomain defines default cluster-internal domain name for Services and Pods
DefaultServiceDNSDomain
=
"cluster.local"
// DefaultServicesSubnet defines default service subnet range
DefaultServicesSubnet
=
"10.96.0.0/12"
// DefaultClusterDNSIP defines default DNS IP
DefaultClusterDNSIP
=
"10.96.0.10"
// DefaultKubernetesVersion defines default kubernetes version
DefaultKubernetesVersion
=
"stable-1"
// DefaultAPIBindPort defines default API port
DefaultAPIBindPort
=
6443
// DefaultCertificatesDir defines default certificate directory
DefaultCertificatesDir
=
"/etc/kubernetes/pki"
// DefaultImageRepository defines default image registry
DefaultImageRepository
=
"k8s.gcr.io"
// DefaultManifestsDir defines default manifests directory
DefaultManifestsDir
=
"/etc/kubernetes/manifests"
// DefaultClusterName defines the default cluster name
DefaultClusterName
=
"kubernetes"
// DefaultEtcdDataDir defines default location of etcd where static pods will save data to
DefaultEtcdDataDir
=
"/var/lib/etcd"
// DefaultProxyBindAddressv4 is the default bind address when the advertise address is v4
DefaultProxyBindAddressv4
=
"0.0.0.0"
// DefaultProxyBindAddressv6 is the default bind address when the advertise address is v6
DefaultProxyBindAddressv6
=
"::"
// DefaultDiscoveryTimeout specifies the default discovery timeout for kubeadm (used unless one is specified in the JoinConfiguration)
DefaultDiscoveryTimeout
=
5
*
time
.
Minute
)
var
(
// DefaultAuditPolicyLogMaxAge is defined as a var so its address can be taken
// It is the number of days to store audit logs
DefaultAuditPolicyLogMaxAge
=
int32
(
2
)
)
func
addDefaultingFuncs
(
scheme
*
runtime
.
Scheme
)
error
{
return
RegisterDefaults
(
scheme
)
}
// SetDefaults_InitConfiguration assigns default values for the InitConfiguration
func
SetDefaults_InitConfiguration
(
obj
*
InitConfiguration
)
{
SetDefaults_ClusterConfiguration
(
&
obj
.
ClusterConfiguration
)
SetDefaults_NodeRegistrationOptions
(
&
obj
.
NodeRegistration
)
SetDefaults_BootstrapTokens
(
obj
)
SetDefaults_APIEndpoint
(
&
obj
.
APIEndpoint
)
}
// SetDefaults_ClusterConfiguration assigns default values for the ClusterConfiguration
func
SetDefaults_ClusterConfiguration
(
obj
*
ClusterConfiguration
)
{
if
obj
.
KubernetesVersion
==
""
{
obj
.
KubernetesVersion
=
DefaultKubernetesVersion
}
if
obj
.
Networking
.
ServiceSubnet
==
""
{
obj
.
Networking
.
ServiceSubnet
=
DefaultServicesSubnet
}
if
obj
.
Networking
.
DNSDomain
==
""
{
obj
.
Networking
.
DNSDomain
=
DefaultServiceDNSDomain
}
if
obj
.
CertificatesDir
==
""
{
obj
.
CertificatesDir
=
DefaultCertificatesDir
}
if
obj
.
ImageRepository
==
""
{
obj
.
ImageRepository
=
DefaultImageRepository
}
if
obj
.
ClusterName
==
""
{
obj
.
ClusterName
=
DefaultClusterName
}
SetDefaults_Etcd
(
obj
)
SetDefaults_AuditPolicyConfiguration
(
obj
)
}
// SetDefaults_Etcd assigns default values for the Proxy
func
SetDefaults_Etcd
(
obj
*
ClusterConfiguration
)
{
if
obj
.
Etcd
.
External
==
nil
&&
obj
.
Etcd
.
Local
==
nil
{
obj
.
Etcd
.
Local
=
&
LocalEtcd
{}
}
if
obj
.
Etcd
.
Local
!=
nil
{
if
obj
.
Etcd
.
Local
.
DataDir
==
""
{
obj
.
Etcd
.
Local
.
DataDir
=
DefaultEtcdDataDir
}
}
}
// SetDefaults_JoinConfiguration assigns default values to a regular node
func
SetDefaults_JoinConfiguration
(
obj
*
JoinConfiguration
)
{
if
obj
.
CACertPath
==
""
{
obj
.
CACertPath
=
DefaultCACertPath
}
if
len
(
obj
.
TLSBootstrapToken
)
==
0
{
obj
.
TLSBootstrapToken
=
obj
.
Token
}
if
len
(
obj
.
DiscoveryToken
)
==
0
&&
len
(
obj
.
DiscoveryFile
)
==
0
{
obj
.
DiscoveryToken
=
obj
.
Token
}
// Make sure file URLs become paths
if
len
(
obj
.
DiscoveryFile
)
!=
0
{
u
,
err
:=
url
.
Parse
(
obj
.
DiscoveryFile
)
if
err
==
nil
&&
u
.
Scheme
==
"file"
{
obj
.
DiscoveryFile
=
u
.
Path
}
}
if
obj
.
DiscoveryTimeout
==
nil
{
obj
.
DiscoveryTimeout
=
&
metav1
.
Duration
{
Duration
:
DefaultDiscoveryTimeout
,
}
}
if
obj
.
ClusterName
==
""
{
obj
.
ClusterName
=
DefaultClusterName
}
SetDefaults_NodeRegistrationOptions
(
&
obj
.
NodeRegistration
)
SetDefaults_APIEndpoint
(
&
obj
.
APIEndpoint
)
}
func
SetDefaults_NodeRegistrationOptions
(
obj
*
NodeRegistrationOptions
)
{
if
obj
.
CRISocket
==
""
{
obj
.
CRISocket
=
DefaultCRISocket
}
}
// SetDefaults_AuditPolicyConfiguration sets default values for the AuditPolicyConfiguration
func
SetDefaults_AuditPolicyConfiguration
(
obj
*
ClusterConfiguration
)
{
if
obj
.
AuditPolicyConfiguration
.
LogDir
==
""
{
obj
.
AuditPolicyConfiguration
.
LogDir
=
constants
.
StaticPodAuditPolicyLogDir
}
if
obj
.
AuditPolicyConfiguration
.
LogMaxAge
==
nil
{
obj
.
AuditPolicyConfiguration
.
LogMaxAge
=
&
DefaultAuditPolicyLogMaxAge
}
}
// SetDefaults_BootstrapTokens sets the defaults for the .BootstrapTokens field
// If the slice is empty, it's defaulted with one token. Otherwise it just loops
// through the slice and sets the defaults for the omitempty fields that are TTL,
// Usages and Groups. Token is NOT defaulted with a random one in the API defaulting
// layer, but set to a random value later at runtime if not set before.
func
SetDefaults_BootstrapTokens
(
obj
*
InitConfiguration
)
{
if
obj
.
BootstrapTokens
==
nil
||
len
(
obj
.
BootstrapTokens
)
==
0
{
obj
.
BootstrapTokens
=
[]
BootstrapToken
{{}}
}
for
i
:=
range
obj
.
BootstrapTokens
{
SetDefaults_BootstrapToken
(
&
obj
.
BootstrapTokens
[
i
])
}
}
// SetDefaults_BootstrapToken sets the defaults for an individual Bootstrap Token
func
SetDefaults_BootstrapToken
(
bt
*
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
}
}
// SetDefaults_APIEndpoint sets the defaults for the API server instance deployed on a node.
func
SetDefaults_APIEndpoint
(
obj
*
APIEndpoint
)
{
if
obj
.
BindPort
==
0
{
obj
.
BindPort
=
DefaultAPIBindPort
}
}
cmd/kubeadm/app/apis/kubeadm/v1beta1/defaults_unix.go
0 → 100644
View file @
8ae5179a
// +build !windows
/*
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
v1beta1
const
(
// DefaultCACertPath defines default location of CA certificate on Linux
DefaultCACertPath
=
"/etc/kubernetes/pki/ca.crt"
// DefaultSocketUrlScheme defines default socket url prefix
DefaultUrlScheme
=
"unix"
// DefaultCRISocket defines the default cri socket
DefaultCRISocket
=
"/var/run/dockershim.sock"
)
cmd/kubeadm/app/apis/kubeadm/v1beta1/defaults_windows.go
0 → 100644
View file @
8ae5179a
// +build windows
/*
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
v1beta1
const
(
// DefaultCACertPath defines default location of CA certificate on Windows
DefaultCACertPath
=
"C:/etc/kubernetes/pki/ca.crt"
// DefaultSocketUrlScheme defines default socket url prefix
DefaultUrlScheme
=
"tcp"
// DefaultCRISocket defines the default cri socket
DefaultCRISocket
=
"tcp://localhost:2375"
)
cmd/kubeadm/app/apis/kubeadm/v1beta1/doc.go
0 → 100644
View file @
8ae5179a
/*
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.
*/
// +k8s:defaulter-gen=TypeMeta
// +groupName=kubeadm.k8s.io
// +k8s:deepcopy-gen=package
// +k8s:conversion-gen=k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm
// Package v1beta1 is the API (config file) for driving the kubeadm binary.
// Some of these options are also available as command line flags, but
// the preferred way to configure kubeadm is to pass a single YAML file with
// multiple configuration types in with the --config option.
// The configuration types should be separated by a line with `---`.
//
// kubeadm uses several API types:
// * InitConfiguration
// https://godoc.org/k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm/v1beta1#InitConfiguration
// * JoinConfiguration
// https://godoc.org/k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm/v1beta1#JoinConfiguration
// * ClusterConfiguration
// https://godoc.org/k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm/v1beta1#ClusterConfiguration
// * KubeProxyConfiguration
// https://godoc.org/k8s.io/kube-proxy/config/v1alpha1#KubeProxyConfiguration
// * KubeletConfiguration
// https://godoc.org/k8s.io/kubelet/config/v1beta1#KubeletConfiguration
//
// For `kubeadm init` you can include the following types:
// InitConfiguration, ClusterConfiguration, KubeProxyConfiguration, KubeletConfiguration
//
// For `kubeadm join` you can include the following types:
// JoinConfiguration, KubeProxyConfiguration, KubeletConfiguration
//
// To print the default values for certain API type you can use:
// kubeadm config print-default --api-objects=<type1>,<type2>
//
// Here is a fully populated example of a single YAML file containing multiple
// configuration types to be used during a `kubeadm init` run.
//
// apiVersion: kubeadm.k8s.io/v1beta1
// kind: InitConfiguration
// bootstrapTokens:
// - token: "9a08jv.c0izixklcxtmnze7"
// description: "kubeadm bootstrap token"
// ttl: "24h"
// - token: "783bde.3f89s0fje9f38fhf"
// description: "another bootstrap token"
// usages:
// - signing
// groups:
// - system:anonymous
// nodeRegistration:
// name: "ec2-10-100-0-1"
// criSocket: "/var/run/dockershim.sock"
// taints:
// - key: "kubeadmNode"
// value: "master"
// effect: "NoSchedule"
// kubeletExtraArgs:
// cgroupDriver: "cgroupfs"
// apiEndpoint:
// advertiseAddress: "10.100.0.1"
// bindPort: 6443
// ---
// apiVersion: kubeadm.k8s.io/v1beta1
// kind: ClusterConfiguration
// etcd:
// # one of local or external
// local:
// image: "k8s.gcr.io/etcd-amd64:3.2.18"
// dataDir: "/var/lib/etcd"
// extraArgs:
// listen-client-urls: "http://10.100.0.1:2379"
// serverCertSANs:
// - "ec2-10-100-0-1.compute-1.amazonaws.com"
// peerCertSANs:
// - "10.100.0.1"
// external:
// endpoints:
// - "10.100.0.1:2379"
// - "10.100.0.2:2379"
// caFile: "/etcd/kubernetes/pki/etcd/etcd-ca.crt"
// certFile: "/etcd/kubernetes/pki/etcd/etcd.crt"
// certKey: "/etcd/kubernetes/pki/etcd/etcd.key"
// networking:
// serviceSubnet: "10.96.0.0/12"
// podSubnet: "10.100.0.1/24"
// dnsDomain: "cluster.local"
// kubernetesVersion: "v1.12.0"
// controlPlaneEndpoint: "10.100.0.1:6443"
// apiServerExtraArgs:
// authorization-mode: "Node,RBAC"
// controlManagerExtraArgs:
// node-cidr-mask-size: 20
// schedulerExtraArgs:
// address: "10.100.0.1"
// apiServerExtraVolumes:
// - name: "some-volume"
// hostPath: "/etc/some-path"
// mountPath: "/etc/some-pod-path"
// writable: true
// pathType: File
// controllerManagerExtraVolumes:
// - name: "some-volume"
// hostPath: "/etc/some-path"
// mountPath: "/etc/some-pod-path"
// writable: true
// pathType: File
// schedulerExtraVolumes:
// - name: "some-volume"
// hostPath: "/etc/some-path"
// mountPath: "/etc/some-pod-path"
// writable: true
// pathType: File
// apiServerCertSANs:
// - "10.100.1.1"
// - "ec2-10-100-0-1.compute-1.amazonaws.com"
// certificatesDir: "/etc/kubernetes/pki"
// imageRepository: "k8s.gcr.io"
// unifiedControlPlaneImage: "k8s.gcr.io/controlplane:v1.12.0"
// auditPolicy:
// # https://kubernetes.io/docs/tasks/debug-application-cluster/audit/#audit-policy
// path: "/var/log/audit/audit.json"
// logDir: "/var/log/audit"
// logMaxAge: 7 # in days
// featureGates:
// selfhosting: false
// clusterName: "example-cluster"
//
// 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
v1beta1
// import "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm/v1beta1"
cmd/kubeadm/app/apis/kubeadm/v1beta1/register.go
0 → 100644
View file @
8ae5179a
/*
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
v1beta1
import
(
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
)
// GroupName is the group name use in this package
const
GroupName
=
"kubeadm.k8s.io"
// SchemeGroupVersion is group version used to register these objects
var
SchemeGroupVersion
=
schema
.
GroupVersion
{
Group
:
GroupName
,
Version
:
"v1beta1"
}
var
(
// TODO: move SchemeBuilder with zz_generated.deepcopy.go to k8s.io/api.
// localSchemeBuilder and AddToScheme will stay in k8s.io/kubernetes.
// SchemeBuilder points to a list of functions added to Scheme.
SchemeBuilder
runtime
.
SchemeBuilder
localSchemeBuilder
=
&
SchemeBuilder
// AddToScheme applies all the stored functions to the scheme.
AddToScheme
=
localSchemeBuilder
.
AddToScheme
)
func
init
()
{
// We only register manually written functions here. The registration of the
// generated functions takes place in the generated files. The separation
// makes the code compile even when the generated files are missing.
localSchemeBuilder
.
Register
(
addKnownTypes
,
addDefaultingFuncs
)
}
// Kind takes an unqualified kind and returns a Group qualified GroupKind
func
Kind
(
kind
string
)
schema
.
GroupKind
{
return
SchemeGroupVersion
.
WithKind
(
kind
)
.
GroupKind
()
}
// Resource takes an unqualified resource and returns a Group qualified GroupResource
func
Resource
(
resource
string
)
schema
.
GroupResource
{
return
SchemeGroupVersion
.
WithResource
(
resource
)
.
GroupResource
()
}
func
addKnownTypes
(
scheme
*
runtime
.
Scheme
)
error
{
scheme
.
AddKnownTypes
(
SchemeGroupVersion
,
&
InitConfiguration
{},
&
ClusterConfiguration
{},
&
ClusterStatus
{},
&
JoinConfiguration
{},
)
metav1
.
AddToGroupVersion
(
scheme
,
SchemeGroupVersion
)
return
nil
}
cmd/kubeadm/app/apis/kubeadm/v1beta1/types.go
0 → 100644
View file @
8ae5179a
This diff is collapsed.
Click to expand it.
cmd/kubeadm/app/cmd/config.go
View file @
8ae5179a
...
@@ -33,6 +33,7 @@ import (
...
@@ -33,6 +33,7 @@ import (
kubeadmapi
"k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm"
kubeadmapi
"k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm"
kubeadmscheme
"k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm/scheme"
kubeadmscheme
"k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm/scheme"
kubeadmapiv1alpha3
"k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm/v1alpha3"
kubeadmapiv1alpha3
"k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm/v1alpha3"
kubeadmapiv1beta1
"k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm/v1beta1"
"k8s.io/kubernetes/cmd/kubeadm/app/cmd/options"
"k8s.io/kubernetes/cmd/kubeadm/app/cmd/options"
phaseutil
"k8s.io/kubernetes/cmd/kubeadm/app/cmd/phases"
phaseutil
"k8s.io/kubernetes/cmd/kubeadm/app/cmd/phases"
cmdutil
"k8s.io/kubernetes/cmd/kubeadm/app/cmd/util"
cmdutil
"k8s.io/kubernetes/cmd/kubeadm/app/cmd/util"
...
@@ -230,6 +231,7 @@ func NewCmdConfigMigrate(out io.Writer) *cobra.Command {
...
@@ -230,6 +231,7 @@ func NewCmdConfigMigrate(out io.Writer) *cobra.Command {
locally in the CLI tool without ever touching anything in the cluster.
locally in the CLI tool without ever touching anything in the cluster.
In this version of kubeadm, the following API versions are supported:
In this version of kubeadm, the following API versions are supported:
- %s
- %s
- %s
Further, kubeadm can only write out config of version %q, but read both types.
Further, kubeadm can only write out config of version %q, but read both types.
So regardless of what version you pass to the --old-config parameter here, the API object will be
So regardless of what version you pass to the --old-config parameter here, the API object will be
...
@@ -238,7 +240,7 @@ func NewCmdConfigMigrate(out io.Writer) *cobra.Command {
...
@@ -238,7 +240,7 @@ func NewCmdConfigMigrate(out io.Writer) *cobra.Command {
In other words, the output of this command is what kubeadm actually would read internally if you
In other words, the output of this command is what kubeadm actually would read internally if you
submitted this file to "kubeadm init"
submitted this file to "kubeadm init"
`
),
kubeadmapiv1alpha3
.
SchemeGroupVersion
.
String
(),
kubeadmapiv1
alpha3
.
SchemeGroupVersion
.
String
()),
`
),
kubeadmapiv1alpha3
.
SchemeGroupVersion
.
String
(),
kubeadmapiv1
beta1
.
SchemeGroupVersion
.
String
(),
kubeadmapiv1beta1
.
SchemeGroupVersion
.
String
()),
Run
:
func
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
Run
:
func
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
if
len
(
oldCfgPath
)
==
0
{
if
len
(
oldCfgPath
)
==
0
{
kubeadmutil
.
CheckErr
(
fmt
.
Errorf
(
"The --old-config flag is mandatory"
))
kubeadmutil
.
CheckErr
(
fmt
.
Errorf
(
"The --old-config flag is mandatory"
))
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment