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
41a7f579
Commit
41a7f579
authored
Oct 12, 2015
by
Marek Grabowski
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #15462 from gmarek/kubemark-refactor
HollowNode refactoring
parents
e3c67509
fb56afe4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
125 additions
and
67 deletions
+125
-67
integration.go
cmd/integration/integration.go
+4
-3
hollow-node.go
cmd/kubemark/hollow-node.go
+25
-64
hollow-kubelet.go
pkg/kubemark/hollow-kubelet.go
+80
-0
utils.go
test/integration/utils.go
+16
-0
No files found.
cmd/integration/integration.go
View file @
41a7f579
...
...
@@ -64,6 +64,7 @@ import (
_
"k8s.io/kubernetes/plugin/pkg/scheduler/algorithmprovider"
"k8s.io/kubernetes/plugin/pkg/scheduler/factory"
"k8s.io/kubernetes/test/e2e"
"k8s.io/kubernetes/test/integration"
"github.com/coreos/go-etcd/etcd"
"github.com/golang/glog"
...
...
@@ -211,8 +212,8 @@ func startComponents(firstManifestURL, secondManifestURL string) (string, string
cadvisorInterface
:=
new
(
cadvisor
.
Fake
)
// Kubelet (localhost)
testRootDir
:=
m
akeTempDirOrDie
(
"kubelet_integ_1."
,
""
)
configFilePath
:=
m
akeTempDirOrDie
(
"config"
,
testRootDir
)
testRootDir
:=
integration
.
M
akeTempDirOrDie
(
"kubelet_integ_1."
,
""
)
configFilePath
:=
integration
.
M
akeTempDirOrDie
(
"config"
,
testRootDir
)
glog
.
Infof
(
"Using %s as root dir for kubelet #1"
,
testRootDir
)
fakeDocker1
.
VersionInfo
=
docker
.
Env
{
"ApiVersion=1.15"
}
...
...
@@ -243,7 +244,7 @@ func startComponents(firstManifestURL, secondManifestURL string) (string, string
// Kubelet (machine)
// Create a second kubelet so that the guestbook example's two redis slaves both
// have a place they can schedule.
testRootDir
=
m
akeTempDirOrDie
(
"kubelet_integ_2."
,
""
)
testRootDir
=
integration
.
M
akeTempDirOrDie
(
"kubelet_integ_2."
,
""
)
glog
.
Infof
(
"Using %s as root dir for kubelet #2"
,
testRootDir
)
fakeDocker2
.
VersionInfo
=
docker
.
Env
{
"ApiVersion=1.15"
}
...
...
cmd/kubemark/hollow-node.go
View file @
41a7f579
...
...
@@ -18,58 +18,35 @@ package main
import
(
"fmt"
"io/ioutil"
"os"
"runtime"
"time"
docker
"github.com/fsouza/go-dockerclient"
kubeletapp
"k8s.io/kubernetes/cmd/kubelet/app"
"k8s.io/kubernetes/pkg/api"
client
"k8s.io/kubernetes/pkg/client/unversioned"
"k8s.io/kubernetes/pkg/client/unversioned/clientcmd"
"k8s.io/kubernetes/pkg/kubelet/cadvisor"
kubecontainer
"k8s.io/kubernetes/pkg/kubelet/container"
"k8s.io/kubernetes/pkg/kubelet/dockertools"
"k8s.io/kubernetes/pkg/kubemark"
"k8s.io/kubernetes/pkg/util"
"k8s.io/kubernetes/pkg/volume/empty_dir"
"github.com/golang/glog"
"github.com/spf13/pflag"
)
var
(
fakeDockerClient
dockertools
.
FakeDockerClient
apiServer
string
kubeconfigPath
string
kubeletPort
int
kubeletReadOnlyPort
int
nodeName
string
serverPort
int
)
func
addFlags
(
fs
*
pflag
.
FlagSet
)
{
fs
.
StringVar
(
&
apiServer
,
"server"
,
""
,
"API server IP."
)
fs
.
StringVar
(
&
kubeconfigPath
,
"kubeconfig"
,
"/kubeconfig/kubeconfig"
,
"Path to kubeconfig file."
)
fs
.
IntVar
(
&
kubeletPort
,
"kubelet-port"
,
10250
,
"Port on which HollowKubelet should be listening."
)
fs
.
IntVar
(
&
kubeletReadOnlyPort
,
"kubelet-read-only-port"
,
10255
,
"Read-only port on which Kubelet is listening."
)
fs
.
StringVar
(
&
nodeName
,
"name"
,
"fake-node"
,
"Name of this Hollow Node."
)
fs
.
IntVar
(
&
serverPort
,
"api-server-port"
,
443
,
"Port on which API server is listening."
)
type
HollowNodeConfig
struct
{
KubeconfigPath
string
KubeletPort
int
KubeletReadOnlyPort
int
NodeName
string
ServerPort
int
}
func
makeTempDirOrDie
(
prefix
string
,
baseDir
string
)
string
{
if
baseDir
==
""
{
baseDir
=
"/tmp"
}
tempDir
,
err
:=
ioutil
.
TempDir
(
baseDir
,
prefix
)
if
err
!=
nil
{
glog
.
Fatalf
(
"Can't make a temp rootdir: %v"
,
err
)
}
if
err
=
os
.
MkdirAll
(
tempDir
,
0750
);
err
!=
nil
{
glog
.
Fatalf
(
"Can't mkdir(%q): %v"
,
tempDir
,
err
)
}
return
tempDir
func
(
c
*
HollowNodeConfig
)
addFlags
(
fs
*
pflag
.
FlagSet
)
{
fs
.
StringVar
(
&
c
.
KubeconfigPath
,
"kubeconfig"
,
"/kubeconfig/kubeconfig"
,
"Path to kubeconfig file."
)
fs
.
IntVar
(
&
c
.
KubeletPort
,
"kubelet-port"
,
10250
,
"Port on which HollowKubelet should be listening."
)
fs
.
IntVar
(
&
c
.
KubeletReadOnlyPort
,
"kubelet-read-only-port"
,
10255
,
"Read-only port on which Kubelet is listening."
)
fs
.
StringVar
(
&
c
.
NodeName
,
"name"
,
"fake-node"
,
"Name of this Hollow Node."
)
fs
.
IntVar
(
&
c
.
ServerPort
,
"api-server-port"
,
443
,
"Port on which API server is listening."
)
}
func
createClientFromFile
(
path
string
)
(
*
client
.
Client
,
error
)
{
...
...
@@ -93,46 +70,30 @@ func createClientFromFile(path string) (*client.Client, error) {
func
main
()
{
runtime
.
GOMAXPROCS
(
runtime
.
NumCPU
())
addFlags
(
pflag
.
CommandLine
)
config
:=
HollowNodeConfig
{}
config
.
addFlags
(
pflag
.
CommandLine
)
util
.
InitFlags
()
// create a client for Kubelet to communicate with API server.
cl
,
err
:=
createClientFromFile
(
k
ubeconfigPath
)
cl
,
err
:=
createClientFromFile
(
config
.
K
ubeconfigPath
)
if
err
!=
nil
{
glog
.
Fatal
(
"Failed to create a Client. Exiting."
)
}
cadvisorInterface
:=
new
(
cadvisor
.
Fake
)
testRootDir
:=
makeTempDirOrDie
(
"hollow-kubelet."
,
""
)
configFilePath
:=
makeTempDirOrDie
(
"config"
,
testRootDir
)
glog
.
Infof
(
"Using %s as root dir for hollow-kubelet"
,
testRootDir
)
fakeDockerClient
:=
&
dockertools
.
FakeDockerClient
{}
fakeDockerClient
.
VersionInfo
=
docker
.
Env
{
"ApiVersion=1.18"
}
fakeDockerClient
.
ContainerMap
=
make
(
map
[
string
]
*
docker
.
Container
)
fakeDockerClient
.
EnableSleep
=
true
kcfg
:=
kubeletapp
.
SimpleKubelet
(
hollowKubelet
:=
kubemark
.
NewHollowKubelet
(
config
.
NodeName
,
cl
,
&
fakeDockerClient
,
nodeName
,
testRootDir
,
""
,
/* manifest-url */
"0.0.0.0"
,
/* bind address */
uint
(
kubeletPort
),
uint
(
kubeletReadOnlyPort
),
api
.
NamespaceDefault
,
empty_dir
.
ProbeVolumePlugins
(),
nil
,
/* tls-options */
cadvisorInterface
,
configFilePath
,
nil
,
/* cloud-provider */
kubecontainer
.
FakeOS
{},
/* os-interface */
20
*
time
.
Second
,
/* FileCheckFrequency */
20
*
time
.
Second
,
/* HTTPCheckFrequency */
1
*
time
.
Minute
,
/* MinimumGCAge */
10
*
time
.
Second
,
/* NodeStatusUpdateFrequency */
10
*
time
.
Second
,
/* SyncFrequency */
40
,
/* MaxPods */
fakeDockerClient
,
config
.
KubeletPort
,
config
.
KubeletReadOnlyPort
,
)
kubeletapp
.
RunKubelet
(
kcfg
)
select
{}
hollowKubelet
.
Run
()
}
pkg/kubemark/hollow-kubelet.go
0 → 100644
View file @
41a7f579
/*
Copyright 2015 The Kubernetes Authors All rights reserved.
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
kubemark
import
(
"time"
kubeletapp
"k8s.io/kubernetes/cmd/kubelet/app"
"k8s.io/kubernetes/pkg/api"
client
"k8s.io/kubernetes/pkg/client/unversioned"
"k8s.io/kubernetes/pkg/kubelet/cadvisor"
kubecontainer
"k8s.io/kubernetes/pkg/kubelet/container"
"k8s.io/kubernetes/pkg/kubelet/dockertools"
"k8s.io/kubernetes/pkg/volume/empty_dir"
"k8s.io/kubernetes/test/integration"
"github.com/golang/glog"
)
type
HollowKubelet
struct
{
KubeletConfig
*
kubeletapp
.
KubeletConfig
}
func
NewHollowKubelet
(
nodeName
string
,
client
*
client
.
Client
,
cadvisorInterface
cadvisor
.
Interface
,
dockerClient
dockertools
.
DockerInterface
,
kubeletPort
,
kubeletReadOnlyPort
int
,
)
*
HollowKubelet
{
testRootDir
:=
integration
.
MakeTempDirOrDie
(
"hollow-kubelet."
,
""
)
manifestFilePath
:=
integration
.
MakeTempDirOrDie
(
"manifest"
,
testRootDir
)
glog
.
Infof
(
"Using %s as root dir for hollow-kubelet"
,
testRootDir
)
return
&
HollowKubelet
{
KubeletConfig
:
kubeletapp
.
SimpleKubelet
(
client
,
dockerClient
,
nodeName
,
testRootDir
,
""
,
/* manifest-url */
"0.0.0.0"
,
/* bind address */
uint
(
kubeletPort
),
uint
(
kubeletReadOnlyPort
),
api
.
NamespaceDefault
,
empty_dir
.
ProbeVolumePlugins
(),
nil
,
/* tls-options */
cadvisorInterface
,
manifestFilePath
,
nil
,
/* cloud-provider */
kubecontainer
.
FakeOS
{},
/* os-interface */
20
*
time
.
Second
,
/* FileCheckFrequency */
20
*
time
.
Second
,
/* HTTPCheckFrequency */
1
*
time
.
Minute
,
/* MinimumGCAge */
10
*
time
.
Second
,
/* NodeStatusUpdateFrequency */
10
*
time
.
Second
,
/* SyncFrequency */
40
,
/* MaxPods */
),
}
}
// Starts this HollowKubelet and blocks.
func
(
hk
*
HollowKubelet
)
Run
()
{
kubeletapp
.
RunKubelet
(
hk
.
KubeletConfig
)
select
{}
}
test/integration/utils.go
View file @
41a7f579
...
...
@@ -18,9 +18,11 @@ package integration
import
(
"fmt"
"io/ioutil"
"math/rand"
"net/http"
"net/http/httptest"
"os"
"testing"
"k8s.io/kubernetes/pkg/api/latest"
...
...
@@ -92,3 +94,17 @@ func runAMaster(t *testing.T) (*master.Master, *httptest.Server) {
return
m
,
s
}
func
MakeTempDirOrDie
(
prefix
string
,
baseDir
string
)
string
{
if
baseDir
==
""
{
baseDir
=
"/tmp"
}
tempDir
,
err
:=
ioutil
.
TempDir
(
baseDir
,
prefix
)
if
err
!=
nil
{
glog
.
Fatalf
(
"Can't make a temp rootdir: %v"
,
err
)
}
if
err
=
os
.
MkdirAll
(
tempDir
,
0750
);
err
!=
nil
{
glog
.
Fatalf
(
"Can't mkdir(%q): %v"
,
tempDir
,
err
)
}
return
tempDir
}
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