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
cef744ec
Commit
cef744ec
authored
Apr 11, 2015
by
Xiang Li
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
pkg/kubelet: move the capabilities related code to util.go
parent
d577db99
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
31 deletions
+32
-31
kubelet.go
pkg/kubelet/kubelet.go
+1
-31
util.go
pkg/kubelet/util.go
+31
-0
No files found.
pkg/kubelet/kubelet.go
View file @
cef744ec
...
@@ -32,7 +32,6 @@ import (
...
@@ -32,7 +32,6 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/validation"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/validation"
"github.com/GoogleCloudPlatform/kubernetes/pkg/capabilities"
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
"github.com/GoogleCloudPlatform/kubernetes/pkg/client/cache"
"github.com/GoogleCloudPlatform/kubernetes/pkg/client/cache"
"github.com/GoogleCloudPlatform/kubernetes/pkg/client/record"
"github.com/GoogleCloudPlatform/kubernetes/pkg/client/record"
...
@@ -851,20 +850,6 @@ func (kl *Kubelet) killContainerByID(ID string) error {
...
@@ -851,20 +850,6 @@ func (kl *Kubelet) killContainerByID(ID string) error {
return
err
return
err
}
}
// Determined whether the specified pod is allowed to use host networking
func
allowHostNetwork
(
pod
*
api
.
Pod
)
(
bool
,
error
)
{
podSource
,
err
:=
getPodSource
(
pod
)
if
err
!=
nil
{
return
false
,
err
}
for
_
,
source
:=
range
capabilities
.
Get
()
.
HostNetworkSources
{
if
source
==
podSource
{
return
true
,
nil
}
}
return
false
,
nil
}
// createPodInfraContainer starts the pod infra container for a pod. Returns the docker container ID of the newly created container.
// createPodInfraContainer starts the pod infra container for a pod. Returns the docker container ID of the newly created container.
func
(
kl
*
Kubelet
)
createPodInfraContainer
(
pod
*
api
.
Pod
)
(
dockertools
.
DockerID
,
error
)
{
func
(
kl
*
Kubelet
)
createPodInfraContainer
(
pod
*
api
.
Pod
)
(
dockertools
.
DockerID
,
error
)
{
...
@@ -1209,21 +1194,6 @@ func (kl *Kubelet) computePodContainerChanges(pod *api.Pod, runningPod kubeconta
...
@@ -1209,21 +1194,6 @@ func (kl *Kubelet) computePodContainerChanges(pod *api.Pod, runningPod kubeconta
},
nil
},
nil
}
}
// Check whether we can run the specified pod.
func
(
kl
*
Kubelet
)
canRunPod
(
pod
*
api
.
Pod
)
error
{
if
pod
.
Spec
.
HostNetwork
{
allowed
,
err
:=
allowHostNetwork
(
pod
)
if
err
!=
nil
{
return
err
}
if
!
allowed
{
return
fmt
.
Errorf
(
"pod with UID %q specified host networking, but is disallowed"
,
pod
.
UID
)
}
}
// TODO(vmarmol): Check Privileged too.
return
nil
}
func
(
kl
*
Kubelet
)
syncPod
(
pod
*
api
.
Pod
,
mirrorPod
*
api
.
Pod
,
runningPod
kubecontainer
.
Pod
)
error
{
func
(
kl
*
Kubelet
)
syncPod
(
pod
*
api
.
Pod
,
mirrorPod
*
api
.
Pod
,
runningPod
kubecontainer
.
Pod
)
error
{
podFullName
:=
kubecontainer
.
GetPodFullName
(
pod
)
podFullName
:=
kubecontainer
.
GetPodFullName
(
pod
)
uid
:=
pod
.
UID
uid
:=
pod
.
UID
...
@@ -1248,7 +1218,7 @@ func (kl *Kubelet) syncPod(pod *api.Pod, mirrorPod *api.Pod, runningPod kubecont
...
@@ -1248,7 +1218,7 @@ func (kl *Kubelet) syncPod(pod *api.Pod, mirrorPod *api.Pod, runningPod kubecont
}()
}()
// Kill pods we can't run.
// Kill pods we can't run.
err
:=
kl
.
canRunPod
(
pod
)
err
:=
canRunPod
(
pod
)
if
err
!=
nil
{
if
err
!=
nil
{
kl
.
killPod
(
runningPod
)
kl
.
killPod
(
runningPod
)
return
err
return
err
...
...
pkg/kubelet/util.go
View file @
cef744ec
...
@@ -17,6 +17,8 @@ limitations under the License.
...
@@ -17,6 +17,8 @@ limitations under the License.
package
kubelet
package
kubelet
import
(
import
(
"fmt"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/resource"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/resource"
"github.com/GoogleCloudPlatform/kubernetes/pkg/capabilities"
"github.com/GoogleCloudPlatform/kubernetes/pkg/capabilities"
...
@@ -42,3 +44,32 @@ func CapacityFromMachineInfo(info *cadvisorApi.MachineInfo) api.ResourceList {
...
@@ -42,3 +44,32 @@ func CapacityFromMachineInfo(info *cadvisorApi.MachineInfo) api.ResourceList {
}
}
return
c
return
c
}
}
// Check whether we have the capabilities to run the specified pod.
func
canRunPod
(
pod
*
api
.
Pod
)
error
{
if
pod
.
Spec
.
HostNetwork
{
allowed
,
err
:=
allowHostNetwork
(
pod
)
if
err
!=
nil
{
return
err
}
if
!
allowed
{
return
fmt
.
Errorf
(
"pod with UID %q specified host networking, but is disallowed"
,
pod
.
UID
)
}
}
// TODO(vmarmol): Check Privileged too.
return
nil
}
// Determined whether the specified pod is allowed to use host networking
func
allowHostNetwork
(
pod
*
api
.
Pod
)
(
bool
,
error
)
{
podSource
,
err
:=
getPodSource
(
pod
)
if
err
!=
nil
{
return
false
,
err
}
for
_
,
source
:=
range
capabilities
.
Get
()
.
HostNetworkSources
{
if
source
==
podSource
{
return
true
,
nil
}
}
return
false
,
nil
}
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