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
b7b08226
Unverified
Commit
b7b08226
authored
Oct 19, 2016
by
Ilya Dmitrichenko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor `getComponentCommand()` for readability
parent
be1996ee
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
85 additions
and
73 deletions
+85
-73
addons.go
cmd/kubeadm/app/master/addons.go
+1
-1
manifests.go
cmd/kubeadm/app/master/manifests.go
+84
-72
No files found.
cmd/kubeadm/app/master/addons.go
View file @
b7b08226
...
@@ -43,7 +43,7 @@ func createKubeProxyPodSpec(cfg *kubeadmapi.MasterConfiguration, architecture st
...
@@ -43,7 +43,7 @@ func createKubeProxyPodSpec(cfg *kubeadmapi.MasterConfiguration, architecture st
Containers
:
[]
api
.
Container
{{
Containers
:
[]
api
.
Container
{{
Name
:
kubeProxy
,
Name
:
kubeProxy
,
Image
:
images
.
GetCoreImage
(
images
.
KubeProxyImage
,
cfg
,
envParams
[
"hyperkube_image"
]),
Image
:
images
.
GetCoreImage
(
images
.
KubeProxyImage
,
cfg
,
envParams
[
"hyperkube_image"
]),
Command
:
append
(
get
ComponentCommand
(
"proxy"
,
cfg
),
"--kubeconfig=/run/kubeconfig"
),
Command
:
append
(
get
ProxyCommand
(
cfg
),
"--kubeconfig=/run/kubeconfig"
),
SecurityContext
:
&
api
.
SecurityContext
{
Privileged
:
&
privilegedTrue
},
SecurityContext
:
&
api
.
SecurityContext
{
Privileged
:
&
privilegedTrue
},
VolumeMounts
:
[]
api
.
VolumeMount
{
VolumeMounts
:
[]
api
.
VolumeMount
{
{
{
...
...
cmd/kubeadm/app/master/manifests.go
View file @
b7b08226
...
@@ -60,7 +60,7 @@ func WriteStaticPodManifests(cfg *kubeadmapi.MasterConfiguration) error {
...
@@ -60,7 +60,7 @@ func WriteStaticPodManifests(cfg *kubeadmapi.MasterConfiguration) error {
kubeAPIServer
:
componentPod
(
api
.
Container
{
kubeAPIServer
:
componentPod
(
api
.
Container
{
Name
:
kubeAPIServer
,
Name
:
kubeAPIServer
,
Image
:
images
.
GetCoreImage
(
images
.
KubeAPIServerImage
,
cfg
,
envParams
[
"hyperkube_image"
]),
Image
:
images
.
GetCoreImage
(
images
.
KubeAPIServerImage
,
cfg
,
envParams
[
"hyperkube_image"
]),
Command
:
get
ComponentCommand
(
apiServer
,
cfg
),
Command
:
get
APIServerCommand
(
cfg
),
VolumeMounts
:
[]
api
.
VolumeMount
{
certsVolumeMount
(),
k8sVolumeMount
()},
VolumeMounts
:
[]
api
.
VolumeMount
{
certsVolumeMount
(),
k8sVolumeMount
()},
LivenessProbe
:
componentProbe
(
8080
,
"/healthz"
),
LivenessProbe
:
componentProbe
(
8080
,
"/healthz"
),
Resources
:
componentResources
(
"250m"
),
Resources
:
componentResources
(
"250m"
),
...
@@ -68,7 +68,7 @@ func WriteStaticPodManifests(cfg *kubeadmapi.MasterConfiguration) error {
...
@@ -68,7 +68,7 @@ func WriteStaticPodManifests(cfg *kubeadmapi.MasterConfiguration) error {
kubeControllerManager
:
componentPod
(
api
.
Container
{
kubeControllerManager
:
componentPod
(
api
.
Container
{
Name
:
kubeControllerManager
,
Name
:
kubeControllerManager
,
Image
:
images
.
GetCoreImage
(
images
.
KubeControllerManagerImage
,
cfg
,
envParams
[
"hyperkube_image"
]),
Image
:
images
.
GetCoreImage
(
images
.
KubeControllerManagerImage
,
cfg
,
envParams
[
"hyperkube_image"
]),
Command
:
getCo
mponentCommand
(
controllerManager
,
cfg
),
Command
:
getCo
ntrollerManagerCommand
(
cfg
),
VolumeMounts
:
[]
api
.
VolumeMount
{
certsVolumeMount
(),
k8sVolumeMount
()},
VolumeMounts
:
[]
api
.
VolumeMount
{
certsVolumeMount
(),
k8sVolumeMount
()},
LivenessProbe
:
componentProbe
(
10252
,
"/healthz"
),
LivenessProbe
:
componentProbe
(
10252
,
"/healthz"
),
Resources
:
componentResources
(
"200m"
),
Resources
:
componentResources
(
"200m"
),
...
@@ -76,7 +76,7 @@ func WriteStaticPodManifests(cfg *kubeadmapi.MasterConfiguration) error {
...
@@ -76,7 +76,7 @@ func WriteStaticPodManifests(cfg *kubeadmapi.MasterConfiguration) error {
kubeScheduler
:
componentPod
(
api
.
Container
{
kubeScheduler
:
componentPod
(
api
.
Container
{
Name
:
kubeScheduler
,
Name
:
kubeScheduler
,
Image
:
images
.
GetCoreImage
(
images
.
KubeSchedulerImage
,
cfg
,
envParams
[
"hyperkube_image"
]),
Image
:
images
.
GetCoreImage
(
images
.
KubeSchedulerImage
,
cfg
,
envParams
[
"hyperkube_image"
]),
Command
:
get
ComponentCommand
(
scheduler
,
cfg
),
Command
:
get
SchedulerCommand
(
cfg
),
LivenessProbe
:
componentProbe
(
10251
,
"/healthz"
),
LivenessProbe
:
componentProbe
(
10251
,
"/healthz"
),
Resources
:
componentResources
(
"100m"
),
Resources
:
componentResources
(
"100m"
),
}),
}),
...
@@ -221,88 +221,100 @@ func componentPod(container api.Container, volumes ...api.Volume) api.Pod {
...
@@ -221,88 +221,100 @@ func componentPod(container api.Container, volumes ...api.Volume) api.Pod {
}
}
}
}
func
getComponentCommand
(
component
string
,
cfg
*
kubeadmapi
.
MasterConfiguration
)
(
command
[]
string
)
{
func
getComponentBaseCommand
(
component
string
)
(
command
[]
string
)
{
baseFlags
:=
map
[
string
][]
string
{
apiServer
:
{
"--insecure-bind-address=127.0.0.1"
,
"--admission-control=NamespaceLifecycle,LimitRanger,ServiceAccount,PersistentVolumeLabel,DefaultStorageClass,ResourceQuota"
,
"--service-cluster-ip-range="
+
cfg
.
Networking
.
ServiceSubnet
,
"--service-account-key-file="
+
pkiDir
+
"/apiserver-key.pem"
,
"--client-ca-file="
+
pkiDir
+
"/ca.pem"
,
"--tls-cert-file="
+
pkiDir
+
"/apiserver.pem"
,
"--tls-private-key-file="
+
pkiDir
+
"/apiserver-key.pem"
,
"--token-auth-file="
+
pkiDir
+
"/tokens.csv"
,
fmt
.
Sprintf
(
"--secure-port=%d"
,
cfg
.
API
.
BindPort
),
"--allow-privileged"
,
},
controllerManager
:
{
"--address=127.0.0.1"
,
"--leader-elect"
,
"--master=127.0.0.1:8080"
,
"--cluster-name="
+
DefaultClusterName
,
"--root-ca-file="
+
pkiDir
+
"/ca.pem"
,
"--service-account-private-key-file="
+
pkiDir
+
"/apiserver-key.pem"
,
"--cluster-signing-cert-file="
+
pkiDir
+
"/ca.pem"
,
"--cluster-signing-key-file="
+
pkiDir
+
"/ca-key.pem"
,
"--insecure-experimental-approve-all-kubelet-csrs-for-group=system:kubelet-bootstrap"
,
},
scheduler
:
{
"--address=127.0.0.1"
,
"--leader-elect"
,
"--master=127.0.0.1:8080"
,
},
proxy
:
{},
}
envParams
:=
kubeadmapi
.
GetEnvParams
()
envParams
:=
kubeadmapi
.
GetEnvParams
()
if
envParams
[
"hyperkube_image"
]
!=
""
{
if
envParams
[
"hyperkube_image"
]
!=
""
{
command
=
[]
string
{
"/hyperkube"
,
component
}
command
=
[]
string
{
"/hyperkube"
,
component
}
}
else
{
}
else
{
command
=
[]
string
{
"
/usr/local/bin/
kube-"
+
component
}
command
=
[]
string
{
"kube-"
+
component
}
}
}
command
=
append
(
command
,
envParams
[
"component_loglevel"
])
command
=
append
(
command
,
envParams
[
"component_loglevel"
])
command
=
append
(
command
,
baseFlags
[
component
]
...
)
return
}
if
component
==
apiServer
{
func
getAPIServerCommand
(
cfg
*
kubeadmapi
.
MasterConfiguration
)
(
command
[]
string
)
{
// Use first address we are given
command
=
append
(
getComponentBaseCommand
(
apiServer
),
if
len
(
cfg
.
API
.
AdvertiseAddresses
)
>
0
{
"--insecure-bind-address=127.0.0.1"
,
command
=
append
(
command
,
fmt
.
Sprintf
(
"--advertise-address=%s"
,
cfg
.
API
.
AdvertiseAddresses
[
0
]))
"--admission-control=NamespaceLifecycle,LimitRanger,ServiceAccount,PersistentVolumeLabel,DefaultStorageClass,ResourceQuota"
,
}
"--service-cluster-ip-range="
+
cfg
.
Networking
.
ServiceSubnet
,
// Check if the user decided to use an external etcd cluster
"--service-account-key-file="
+
pkiDir
+
"/apiserver-key.pem"
,
if
len
(
cfg
.
Etcd
.
Endpoints
)
>
0
{
"--client-ca-file="
+
pkiDir
+
"/ca.pem"
,
command
=
append
(
command
,
fmt
.
Sprintf
(
"--etcd-servers=%s"
,
strings
.
Join
(
cfg
.
Etcd
.
Endpoints
,
","
)))
"--tls-cert-file="
+
pkiDir
+
"/apiserver.pem"
,
}
else
{
"--tls-private-key-file="
+
pkiDir
+
"/apiserver-key.pem"
,
command
=
append
(
command
,
"--etcd-servers=http://127.0.0.1:2379"
)
"--token-auth-file="
+
pkiDir
+
"/tokens.csv"
,
}
fmt
.
Sprintf
(
"--secure-port=%d"
,
cfg
.
API
.
BindPort
),
"--allow-privileged"
,
)
// Is etcd secured?
// Use first address we are given
if
cfg
.
Etcd
.
CAFile
!=
""
{
if
len
(
cfg
.
API
.
AdvertiseAddresses
)
>
0
{
command
=
append
(
command
,
fmt
.
Sprintf
(
"--etcd-cafile=%s"
,
cfg
.
Etcd
.
CAFile
))
command
=
append
(
command
,
fmt
.
Sprintf
(
"--advertise-address=%s"
,
cfg
.
API
.
AdvertiseAddresses
[
0
]))
}
if
cfg
.
Etcd
.
CertFile
!=
""
&&
cfg
.
Etcd
.
KeyFile
!=
""
{
etcdClientFileArg
:=
fmt
.
Sprintf
(
"--etcd-certfile=%s"
,
cfg
.
Etcd
.
CertFile
)
etcdKeyFileArg
:=
fmt
.
Sprintf
(
"--etcd-keyfile=%s"
,
cfg
.
Etcd
.
KeyFile
)
command
=
append
(
command
,
etcdClientFileArg
,
etcdKeyFileArg
)
}
}
}
if
component
==
controllerManager
{
// Check if the user decided to use an external etcd cluster
if
cfg
.
CloudProvider
!=
""
{
if
len
(
cfg
.
Etcd
.
Endpoints
)
>
0
{
command
=
append
(
command
,
"--cloud-provider="
+
cfg
.
CloudProvider
)
command
=
append
(
command
,
fmt
.
Sprintf
(
"--etcd-servers=%s"
,
strings
.
Join
(
cfg
.
Etcd
.
Endpoints
,
","
)))
}
else
{
command
=
append
(
command
,
"--etcd-servers=http://127.0.0.1:2379"
)
}
// Only append the --cloud-config option if there's a such file
// Is etcd secured?
// TODO(phase1+) this won't work unless it's in one of the few directories we bind-mount
if
cfg
.
Etcd
.
CAFile
!=
""
{
if
_
,
err
:=
os
.
Stat
(
DefaultCloudConfigPath
);
err
==
nil
{
command
=
append
(
command
,
fmt
.
Sprintf
(
"--etcd-cafile=%s"
,
cfg
.
Etcd
.
CAFile
))
command
=
append
(
command
,
"--cloud-config="
+
DefaultCloudConfigPath
)
}
}
if
cfg
.
Etcd
.
CertFile
!=
""
&&
cfg
.
Etcd
.
KeyFile
!=
""
{
}
etcdClientFileArg
:=
fmt
.
Sprintf
(
"--etcd-certfile=%s"
,
cfg
.
Etcd
.
CertFile
)
// Let the controller-manager allocate Node CIDRs for the Pod network.
etcdKeyFileArg
:=
fmt
.
Sprintf
(
"--etcd-keyfile=%s"
,
cfg
.
Etcd
.
KeyFile
)
// Each node will get a subspace of the address CIDR provided with --pod-network-cidr.
command
=
append
(
command
,
etcdClientFileArg
,
etcdKeyFileArg
)
if
cfg
.
Networking
.
PodSubnet
!=
""
{
}
command
=
append
(
command
,
"--allocate-node-cidrs=true"
,
"--cluster-cidr="
+
cfg
.
Networking
.
PodSubnet
)
return
}
func
getControllerManagerCommand
(
cfg
*
kubeadmapi
.
MasterConfiguration
)
(
command
[]
string
)
{
command
=
append
(
getComponentBaseCommand
(
controllerManager
),
"--address=127.0.0.1"
,
"--leader-elect"
,
"--master=127.0.0.1:8080"
,
"--cluster-name="
+
DefaultClusterName
,
"--root-ca-file="
+
pkiDir
+
"/ca.pem"
,
"--service-account-private-key-file="
+
pkiDir
+
"/apiserver-key.pem"
,
"--cluster-signing-cert-file="
+
pkiDir
+
"/ca.pem"
,
"--cluster-signing-key-file="
+
pkiDir
+
"/ca-key.pem"
,
"--insecure-experimental-approve-all-kubelet-csrs-for-group=system:kubelet-bootstrap"
,
)
if
cfg
.
CloudProvider
!=
""
{
command
=
append
(
command
,
"--cloud-provider="
+
cfg
.
CloudProvider
)
// Only append the --cloud-config option if there's a such file
// TODO(phase1+) this won't work unless it's in one of the few directories we bind-mount
if
_
,
err
:=
os
.
Stat
(
DefaultCloudConfigPath
);
err
==
nil
{
command
=
append
(
command
,
"--cloud-config="
+
DefaultCloudConfigPath
)
}
}
}
}
// Let the controller-manager allocate Node CIDRs for the Pod network.
// Each node will get a subspace of the address CIDR provided with --pod-network-cidr.
if
cfg
.
Networking
.
PodSubnet
!=
""
{
command
=
append
(
command
,
"--allocate-node-cidrs=true"
,
"--cluster-cidr="
+
cfg
.
Networking
.
PodSubnet
)
}
return
}
func
getSchedulerCommand
(
cfg
*
kubeadmapi
.
MasterConfiguration
)
(
command
[]
string
)
{
command
=
append
(
getComponentBaseCommand
(
scheduler
),
"--address=127.0.0.1"
,
"--leader-elect"
,
"--master=127.0.0.1:8080"
,
)
return
}
func
getProxyCommand
(
cfg
*
kubeadmapi
.
MasterConfiguration
)
(
command
[]
string
)
{
command
=
getComponentBaseCommand
(
proxy
)
return
return
}
}
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