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
0faa96e7
Commit
0faa96e7
authored
Nov 09, 2017
by
xiangpengzhao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use volumeutil.LoadPodFromFile for pod spec
parent
3e315aa0
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
10 additions
and
25 deletions
+10
-25
BUILD
cmd/kubeadm/app/phases/selfhosting/BUILD
+2
-2
selfhosting.go
cmd/kubeadm/app/phases/selfhosting/selfhosting.go
+4
-21
selfhosting_test.go
cmd/kubeadm/app/phases/selfhosting/selfhosting_test.go
+4
-2
No files found.
cmd/kubeadm/app/phases/selfhosting/BUILD
View file @
0faa96e7
...
...
@@ -18,6 +18,7 @@ go_test(
deps = [
"//cmd/kubeadm/app/constants:go_default_library",
"//cmd/kubeadm/app/util:go_default_library",
"//pkg/volume/util:go_default_library",
"//vendor/k8s.io/api/apps/v1beta2:go_default_library",
"//vendor/k8s.io/api/core/v1:go_default_library",
],
...
...
@@ -37,11 +38,10 @@ go_library(
"//cmd/kubeadm/app/features:go_default_library",
"//cmd/kubeadm/app/util:go_default_library",
"//cmd/kubeadm/app/util/apiclient:go_default_library",
"//pkg/
api/legacyscheme
:go_default_library",
"//pkg/
volume/util
:go_default_library",
"//vendor/k8s.io/api/apps/v1beta2:go_default_library",
"//vendor/k8s.io/api/core/v1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//vendor/k8s.io/client-go/kubernetes:go_default_library",
],
)
...
...
cmd/kubeadm/app/phases/selfhosting/selfhosting.go
View file @
0faa96e7
...
...
@@ -18,20 +18,18 @@ package selfhosting
import
(
"fmt"
"io/ioutil"
"os"
"time"
apps
"k8s.io/api/apps/v1beta2"
"k8s.io/api/core/v1"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
kuberuntime
"k8s.io/apimachinery/pkg/runtime"
clientset
"k8s.io/client-go/kubernetes"
kubeadmapi
"k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm"
kubeadmconstants
"k8s.io/kubernetes/cmd/kubeadm/app/constants"
"k8s.io/kubernetes/cmd/kubeadm/app/features"
"k8s.io/kubernetes/cmd/kubeadm/app/util/apiclient"
"k8s.io/kubernetes/pkg/api/legacyscheme
"
volumeutil
"k8s.io/kubernetes/pkg/volume/util
"
)
const
(
...
...
@@ -59,7 +57,7 @@ func CreateSelfHostedControlPlane(manifestsDir, kubeConfigDir string, cfg *kubea
// Adjust the timeout slightly to something self-hosting specific
waiter
.
SetTimeout
(
selfHostingWaitTimeout
)
// Here the map of different mutators to use for the control plane's
pods
pec is stored
// Here the map of different mutators to use for the control plane's
PodS
pec is stored
mutators
:=
GetMutatorsFromFeatureGates
(
cfg
.
FeatureGates
)
// Some extra work to be done if we should store the control plane certificates in Secrets
...
...
@@ -85,10 +83,11 @@ func CreateSelfHostedControlPlane(manifestsDir, kubeConfigDir string, cfg *kubea
}
// Load the Static Pod file in order to be able to create a self-hosted variant of that file
pod
Spec
,
err
:=
loadPodSpec
FromFile
(
manifestPath
)
pod
,
err
:=
volumeutil
.
LoadPod
FromFile
(
manifestPath
)
if
err
!=
nil
{
return
err
}
podSpec
:=
&
pod
.
Spec
// Build a DaemonSet object from the loaded PodSpec
ds
:=
BuildDaemonSet
(
componentName
,
podSpec
,
mutators
)
...
...
@@ -156,22 +155,6 @@ func BuildDaemonSet(name string, podSpec *v1.PodSpec, mutators map[string][]PodS
}
}
// loadPodSpecFromFile reads and decodes a file containing a specification of a Pod
// TODO: Consider using "k8s.io/kubernetes/pkg/volume/util".LoadPodFromFile(filename string) in the future instead.
func
loadPodSpecFromFile
(
manifestPath
string
)
(
*
v1
.
PodSpec
,
error
)
{
podBytes
,
err
:=
ioutil
.
ReadFile
(
manifestPath
)
if
err
!=
nil
{
return
nil
,
err
}
staticPod
:=
&
v1
.
Pod
{}
if
err
:=
kuberuntime
.
DecodeInto
(
legacyscheme
.
Codecs
.
UniversalDecoder
(),
podBytes
,
staticPod
);
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"unable to decode static pod %v"
,
err
)
}
return
&
staticPod
.
Spec
,
nil
}
// BuildSelfhostedComponentLabels returns the labels for a self-hosted component
func
BuildSelfhostedComponentLabels
(
component
string
)
map
[
string
]
string
{
return
map
[
string
]
string
{
...
...
cmd/kubeadm/app/phases/selfhosting/selfhosting_test.go
View file @
0faa96e7
...
...
@@ -26,6 +26,7 @@ import (
apps
"k8s.io/api/apps/v1beta2"
"k8s.io/kubernetes/cmd/kubeadm/app/constants"
"k8s.io/kubernetes/cmd/kubeadm/app/util"
volumeutil
"k8s.io/kubernetes/pkg/volume/util"
)
const
(
...
...
@@ -479,10 +480,11 @@ func TestBuildDaemonSet(t *testing.T) {
}
defer
os
.
Remove
(
tempFile
)
pod
Spec
,
err
:=
loadPodSpec
FromFile
(
tempFile
)
pod
,
err
:=
volumeutil
.
LoadPod
FromFile
(
tempFile
)
if
err
!=
nil
{
t
.
Fatalf
(
"couldn't load the specified Pod"
)
}
podSpec
:=
&
pod
.
Spec
ds
:=
BuildDaemonSet
(
rt
.
component
,
podSpec
,
GetDefaultMutators
())
dsBytes
,
err
:=
util
.
MarshalToYaml
(
ds
,
apps
.
SchemeGroupVersion
)
...
...
@@ -554,7 +556,7 @@ spec:
}
defer
os
.
Remove
(
tempFile
)
_
,
err
=
loadPodSpec
FromFile
(
tempFile
)
_
,
err
=
volumeutil
.
LoadPod
FromFile
(
tempFile
)
if
(
err
!=
nil
)
!=
rt
.
expectError
{
t
.
Errorf
(
"failed TestLoadPodSpecFromFile:
\n
expected error:
\n
%t
\n
saw:
\n
%v"
,
rt
.
expectError
,
err
)
}
...
...
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