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
686b767f
Commit
686b767f
authored
Aug 21, 2015
by
Dr. Stefan Schimanski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove redundant kubelet dependency of executor
parent
6af86cba
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
57 deletions
+34
-57
executor.go
contrib/mesos/pkg/executor/executor.go
+11
-38
executor_test.go
contrib/mesos/pkg/executor/executor_test.go
+2
-9
service.go
contrib/mesos/pkg/executor/service/service.go
+21
-10
No files found.
contrib/mesos/pkg/executor/executor.go
View file @
686b767f
...
@@ -19,7 +19,6 @@ package executor
...
@@ -19,7 +19,6 @@ package executor
import
(
import
(
"encoding/json"
"encoding/json"
"fmt"
"fmt"
"net"
"strings"
"strings"
"sync"
"sync"
"sync/atomic"
"sync/atomic"
...
@@ -94,15 +93,9 @@ type kuberTask struct {
...
@@ -94,15 +93,9 @@ type kuberTask struct {
type
podStatusFunc
func
()
(
*
api
.
PodStatus
,
error
)
type
podStatusFunc
func
()
(
*
api
.
PodStatus
,
error
)
// KubeletInterface consists of the kubelet.Kubelet API's that we actually use
type
KubeletInterface
interface
{
GetHostIP
()
(
net
.
IP
,
error
)
}
// KubernetesExecutor is an mesos executor that runs pods
// KubernetesExecutor is an mesos executor that runs pods
// in a minion machine.
// in a minion machine.
type
KubernetesExecutor
struct
{
type
KubernetesExecutor
struct
{
kl
KubeletInterface
// the kubelet instance.
updateChan
chan
<-
interface
{}
// to send pod config updates to the kubelet
updateChan
chan
<-
interface
{}
// to send pod config updates to the kubelet
state
stateType
state
stateType
tasks
map
[
string
]
*
kuberTask
tasks
map
[
string
]
*
kuberTask
...
@@ -119,8 +112,7 @@ type KubernetesExecutor struct {
...
@@ -119,8 +112,7 @@ type KubernetesExecutor struct {
kubeletFinished
<-
chan
struct
{}
// signals that kubelet Run() died
kubeletFinished
<-
chan
struct
{}
// signals that kubelet Run() died
initialRegistration
sync
.
Once
initialRegistration
sync
.
Once
exitFunc
func
(
int
)
exitFunc
func
(
int
)
podStatusFunc
func
(
KubeletInterface
,
*
api
.
Pod
)
(
*
api
.
PodStatus
,
error
)
podStatusFunc
func
(
*
api
.
Pod
)
(
*
api
.
PodStatus
,
error
)
staticPodsConfig
[]
byte
staticPodsConfigPath
string
staticPodsConfigPath
string
initialRegComplete
chan
struct
{}
initialRegComplete
chan
struct
{}
podController
*
framework
.
Controller
podController
*
framework
.
Controller
...
@@ -128,7 +120,6 @@ type KubernetesExecutor struct {
...
@@ -128,7 +120,6 @@ type KubernetesExecutor struct {
}
}
type
Config
struct
{
type
Config
struct
{
Kubelet
KubeletInterface
Updates
chan
<-
interface
{}
// to send pod config updates to the kubelet
Updates
chan
<-
interface
{}
// to send pod config updates to the kubelet
SourceName
string
SourceName
string
APIClient
*
client
.
Client
APIClient
*
client
.
Client
...
@@ -137,7 +128,7 @@ type Config struct {
...
@@ -137,7 +128,7 @@ type Config struct {
SuicideTimeout
time
.
Duration
SuicideTimeout
time
.
Duration
KubeletFinished
<-
chan
struct
{}
// signals that kubelet Run() died
KubeletFinished
<-
chan
struct
{}
// signals that kubelet Run() died
ExitFunc
func
(
int
)
ExitFunc
func
(
int
)
PodStatusFunc
func
(
KubeletInterface
,
*
api
.
Pod
)
(
*
api
.
PodStatus
,
error
)
PodStatusFunc
func
(
*
api
.
Pod
)
(
*
api
.
PodStatus
,
error
)
StaticPodsConfigPath
string
StaticPodsConfigPath
string
PodLW
cache
.
ListerWatcher
// mandatory, otherwise initialiation will panic
PodLW
cache
.
ListerWatcher
// mandatory, otherwise initialiation will panic
LaunchGracePeriod
time
.
Duration
LaunchGracePeriod
time
.
Duration
...
@@ -150,7 +141,6 @@ func (k *KubernetesExecutor) isConnected() bool {
...
@@ -150,7 +141,6 @@ func (k *KubernetesExecutor) isConnected() bool {
// New creates a new kubernetes executor.
// New creates a new kubernetes executor.
func
New
(
config
Config
)
*
KubernetesExecutor
{
func
New
(
config
Config
)
*
KubernetesExecutor
{
k
:=
&
KubernetesExecutor
{
k
:=
&
KubernetesExecutor
{
kl
:
config
.
Kubelet
,
updateChan
:
config
.
Updates
,
updateChan
:
config
.
Updates
,
state
:
disconnectedState
,
state
:
disconnectedState
,
tasks
:
make
(
map
[
string
]
*
kuberTask
),
tasks
:
make
(
map
[
string
]
*
kuberTask
),
...
@@ -196,6 +186,10 @@ func New(config Config) *KubernetesExecutor {
...
@@ -196,6 +186,10 @@ func New(config Config) *KubernetesExecutor {
return
k
return
k
}
}
func
(
k
*
KubernetesExecutor
)
InitialRegComplete
()
<-
chan
struct
{}
{
return
k
.
initialRegComplete
}
func
(
k
*
KubernetesExecutor
)
Init
(
driver
bindings
.
ExecutorDriver
)
{
func
(
k
*
KubernetesExecutor
)
Init
(
driver
bindings
.
ExecutorDriver
)
{
k
.
killKubeletContainers
()
k
.
killKubeletContainers
()
k
.
resetSuicideWatch
(
driver
)
k
.
resetSuicideWatch
(
driver
)
...
@@ -231,7 +225,7 @@ func (k *KubernetesExecutor) Registered(driver bindings.ExecutorDriver,
...
@@ -231,7 +225,7 @@ func (k *KubernetesExecutor) Registered(driver bindings.ExecutorDriver,
}
}
if
executorInfo
!=
nil
&&
executorInfo
.
Data
!=
nil
{
if
executorInfo
!=
nil
&&
executorInfo
.
Data
!=
nil
{
k
.
staticPodsConfig
=
executorInfo
.
Data
k
.
initializeStaticPodsSource
(
executorInfo
.
Data
)
}
}
if
slaveInfo
!=
nil
{
if
slaveInfo
!=
nil
{
...
@@ -281,24 +275,14 @@ func (k *KubernetesExecutor) onInitialRegistration() {
...
@@ -281,24 +275,14 @@ func (k *KubernetesExecutor) onInitialRegistration() {
}
}
}
}
// InitializeStaticPodsSource blocks until initial regstration is complete and
// initializeStaticPodsSource unzips the data slice into the static-pods directory
// then creates a static pod source using the given factory func.
func
(
k
*
KubernetesExecutor
)
initializeStaticPodsSource
(
data
[]
byte
)
{
func
(
k
*
KubernetesExecutor
)
InitializeStaticPodsSource
(
sourceFactory
func
())
{
<-
k
.
initialRegComplete
if
k
.
staticPodsConfig
==
nil
{
return
}
log
.
V
(
2
)
.
Infof
(
"extracting static pods config to %s"
,
k
.
staticPodsConfigPath
)
log
.
V
(
2
)
.
Infof
(
"extracting static pods config to %s"
,
k
.
staticPodsConfigPath
)
err
:=
archive
.
UnzipDir
(
k
.
staticPodsConfig
,
k
.
staticPodsConfigPath
)
err
:=
archive
.
UnzipDir
(
data
,
k
.
staticPodsConfigPath
)
if
err
!=
nil
{
if
err
!=
nil
{
log
.
Errorf
(
"Failed to extract static pod config: %v"
,
err
)
log
.
Errorf
(
"Failed to extract static pod config: %v"
,
err
)
return
return
}
}
log
.
V
(
2
)
.
Infof
(
"initializing static pods source factory, configured at path %q"
,
k
.
staticPodsConfigPath
)
sourceFactory
()
}
}
// Disconnected is called when the executor is disconnected from the slave.
// Disconnected is called when the executor is disconnected from the slave.
...
@@ -597,18 +581,7 @@ func (k *KubernetesExecutor) launchTask(driver bindings.ExecutorDriver, taskId s
...
@@ -597,18 +581,7 @@ func (k *KubernetesExecutor) launchTask(driver bindings.ExecutorDriver, taskId s
// Delay reporting 'task running' until container is up.
// Delay reporting 'task running' until container is up.
psf
:=
podStatusFunc
(
func
()
(
*
api
.
PodStatus
,
error
)
{
psf
:=
podStatusFunc
(
func
()
(
*
api
.
PodStatus
,
error
)
{
status
,
err
:=
k
.
podStatusFunc
(
k
.
kl
,
pod
)
return
k
.
podStatusFunc
(
pod
)
if
err
!=
nil
{
return
nil
,
err
}
status
.
Phase
=
kubelet
.
GetPhase
(
&
pod
.
Spec
,
status
.
ContainerStatuses
)
hostIP
,
err
:=
k
.
kl
.
GetHostIP
()
if
err
!=
nil
{
log
.
Errorf
(
"Cannot get host IP: %v"
,
err
)
}
else
{
status
.
HostIP
=
hostIP
.
String
()
}
return
status
,
nil
})
})
go
k
.
_launchTask
(
driver
,
taskId
,
podFullName
,
psf
)
go
k
.
_launchTask
(
driver
,
taskId
,
podFullName
,
psf
)
...
...
contrib/mesos/pkg/executor/executor_test.go
View file @
686b767f
...
@@ -144,10 +144,6 @@ func TestExecutorLaunchAndKillTask(t *testing.T) {
...
@@ -144,10 +144,6 @@ func TestExecutorLaunchAndKillTask(t *testing.T) {
Host
:
testApiServer
.
server
.
URL
,
Host
:
testApiServer
.
server
.
URL
,
Version
:
testapi
.
Default
.
Version
(),
Version
:
testapi
.
Default
.
Version
(),
}),
}),
Kubelet
:
&
fakeKubelet
{
Kubelet
:
&
kubelet
.
Kubelet
{},
hostIP
:
net
.
IPv4
(
127
,
0
,
0
,
1
),
},
PodStatusFunc
:
func
(
kl
KubeletInterface
,
pod
*
api
.
Pod
)
(
*
api
.
PodStatus
,
error
)
{
PodStatusFunc
:
func
(
kl
KubeletInterface
,
pod
*
api
.
Pod
)
(
*
api
.
PodStatus
,
error
)
{
return
&
api
.
PodStatus
{
return
&
api
.
PodStatus
{
ContainerStatuses
:
[]
api
.
ContainerStatus
{
ContainerStatuses
:
[]
api
.
ContainerStatus
{
...
@@ -159,6 +155,7 @@ func TestExecutorLaunchAndKillTask(t *testing.T) {
...
@@ -159,6 +155,7 @@ func TestExecutorLaunchAndKillTask(t *testing.T) {
},
},
},
},
Phase
:
api
.
PodRunning
,
Phase
:
api
.
PodRunning
,
HostIP
:
"127.0.0.1"
,
},
nil
},
nil
},
},
PodLW
:
&
NewMockPodsListWatch
(
api
.
PodList
{})
.
ListWatch
,
PodLW
:
&
NewMockPodsListWatch
(
api
.
PodList
{})
.
ListWatch
,
...
@@ -311,7 +308,6 @@ func TestExecutorStaticPods(t *testing.T) {
...
@@ -311,7 +308,6 @@ func TestExecutorStaticPods(t *testing.T) {
Host
:
testApiServer
.
server
.
URL
,
Host
:
testApiServer
.
server
.
URL
,
Version
:
testapi
.
Default
.
Version
(),
Version
:
testapi
.
Default
.
Version
(),
}),
}),
Kubelet
:
&
kubelet
.
Kubelet
{},
PodStatusFunc
:
func
(
kl
KubeletInterface
,
pod
*
api
.
Pod
)
(
*
api
.
PodStatus
,
error
)
{
PodStatusFunc
:
func
(
kl
KubeletInterface
,
pod
*
api
.
Pod
)
(
*
api
.
PodStatus
,
error
)
{
return
&
api
.
PodStatus
{
return
&
api
.
PodStatus
{
ContainerStatuses
:
[]
api
.
ContainerStatus
{
ContainerStatuses
:
[]
api
.
ContainerStatus
{
...
@@ -393,10 +389,6 @@ func TestExecutorFrameworkMessage(t *testing.T) {
...
@@ -393,10 +389,6 @@ func TestExecutorFrameworkMessage(t *testing.T) {
Host
:
testApiServer
.
server
.
URL
,
Host
:
testApiServer
.
server
.
URL
,
Version
:
testapi
.
Default
.
Version
(),
Version
:
testapi
.
Default
.
Version
(),
}),
}),
Kubelet
:
&
fakeKubelet
{
Kubelet
:
&
kubelet
.
Kubelet
{},
hostIP
:
net
.
IPv4
(
127
,
0
,
0
,
1
),
},
PodStatusFunc
:
func
(
kl
KubeletInterface
,
pod
*
api
.
Pod
)
(
*
api
.
PodStatus
,
error
)
{
PodStatusFunc
:
func
(
kl
KubeletInterface
,
pod
*
api
.
Pod
)
(
*
api
.
PodStatus
,
error
)
{
return
&
api
.
PodStatus
{
return
&
api
.
PodStatus
{
ContainerStatuses
:
[]
api
.
ContainerStatus
{
ContainerStatuses
:
[]
api
.
ContainerStatus
{
...
@@ -408,6 +400,7 @@ func TestExecutorFrameworkMessage(t *testing.T) {
...
@@ -408,6 +400,7 @@ func TestExecutorFrameworkMessage(t *testing.T) {
},
},
},
},
Phase
:
api
.
PodRunning
,
Phase
:
api
.
PodRunning
,
HostIP
:
"127.0.0.1"
,
},
nil
},
nil
},
},
ShutdownAlert
:
func
()
{
ShutdownAlert
:
func
()
{
...
...
contrib/mesos/pkg/executor/service/service.go
View file @
686b767f
...
@@ -368,17 +368,28 @@ func (ks *KubeletExecutorServer) createAndInitKubelet(
...
@@ -368,17 +368,28 @@ func (ks *KubeletExecutorServer) createAndInitKubelet(
kubeletFinished
:=
make
(
chan
struct
{})
kubeletFinished
:=
make
(
chan
struct
{})
staticPodsConfigPath
:=
filepath
.
Join
(
kc
.
RootDirectory
,
"static-pods"
)
staticPodsConfigPath
:=
filepath
.
Join
(
kc
.
RootDirectory
,
"static-pods"
)
exec
:=
executor
.
New
(
executor
.
Config
{
exec
:=
executor
.
New
(
executor
.
Config
{
Kubelet
:
klet
,
Updates
:
updates
,
Updates
:
updates
,
SourceName
:
MESOS_CFG_SOURCE
,
SourceName
:
MESOS_CFG_SOURCE
,
APIClient
:
kc
.
KubeClient
,
APIClient
:
kc
.
KubeClient
,
Docker
:
kc
.
DockerClient
,
Docker
:
kc
.
DockerClient
,
SuicideTimeout
:
ks
.
SuicideTimeout
,
SuicideTimeout
:
ks
.
SuicideTimeout
,
LaunchGracePeriod
:
ks
.
LaunchGracePeriod
,
LaunchGracePeriod
:
ks
.
LaunchGracePeriod
,
KubeletFinished
:
kubeletFinished
,
KubeletFinished
:
kubeletFinished
,
ExitFunc
:
os
.
Exit
,
ExitFunc
:
os
.
Exit
,
PodStatusFunc
:
func
(
_
executor
.
KubeletInterface
,
pod
*
api
.
Pod
)
(
*
api
.
PodStatus
,
error
)
{
PodStatusFunc
:
func
(
pod
*
api
.
Pod
)
(
*
api
.
PodStatus
,
error
)
{
return
klet
.
GetRuntime
()
.
GetPodStatus
(
pod
)
status
,
err
:=
klet
.
GetRuntime
()
.
GetPodStatus
(
pod
)
if
err
!=
nil
{
return
nil
,
err
}
status
.
Phase
=
kubelet
.
GetPhase
(
&
pod
.
Spec
,
status
.
ContainerStatuses
)
hostIP
,
err
:=
klet
.
GetHostIP
()
if
err
!=
nil
{
log
.
Errorf
(
"Cannot get host IP: %v"
,
err
)
}
else
{
status
.
HostIP
=
hostIP
.
String
()
}
return
status
,
nil
},
},
StaticPodsConfigPath
:
staticPodsConfigPath
,
StaticPodsConfigPath
:
staticPodsConfigPath
,
PodLW
:
cache
.
NewListWatchFromClient
(
kc
.
KubeClient
,
"pods"
,
api
.
NamespaceAll
,
fields
.
OneTermEqualSelector
(
client
.
PodHost
,
kc
.
NodeName
)),
PodLW
:
cache
.
NewListWatchFromClient
(
kc
.
KubeClient
,
"pods"
,
api
.
NamespaceAll
,
fields
.
OneTermEqualSelector
(
client
.
PodHost
,
kc
.
NodeName
)),
...
...
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