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
53c20e36
Commit
53c20e36
authored
Jan 20, 2017
by
Pengfei Ni
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
kubelet/kuberuntime: update cri to protobuf v3
parent
d4bfcd1f
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
217 additions
and
203 deletions
+217
-203
helpers.go
pkg/kubelet/container/helpers.go
+3
-3
fake_kuberuntime_manager.go
pkg/kubelet/kuberuntime/fake_kuberuntime_manager.go
+1
-1
helpers.go
pkg/kubelet/kuberuntime/helpers.go
+25
-23
kuberuntime_container.go
pkg/kubelet/kuberuntime/kuberuntime_container.go
+57
-55
kuberuntime_container_test.go
pkg/kubelet/kuberuntime/kuberuntime_container_test.go
+2
-2
kuberuntime_gc.go
pkg/kubelet/kuberuntime/kuberuntime_gc.go
+9
-9
kuberuntime_gc_test.go
pkg/kubelet/kuberuntime/kuberuntime_gc_test.go
+2
-2
kuberuntime_image.go
pkg/kubelet/kuberuntime/kuberuntime_image.go
+13
-13
kuberuntime_manager.go
pkg/kubelet/kuberuntime/kuberuntime_manager.go
+21
-23
kuberuntime_manager_test.go
pkg/kubelet/kuberuntime/kuberuntime_manager_test.go
+22
-22
kuberuntime_sandbox.go
pkg/kubelet/kuberuntime/kuberuntime_sandbox.go
+38
-36
kuberuntime_sandbox_test.go
pkg/kubelet/kuberuntime/kuberuntime_sandbox_test.go
+1
-1
security_context.go
pkg/kubelet/kuberuntime/security_context.go
+23
-13
No files found.
pkg/kubelet/container/helpers.go
View file @
53c20e36
...
@@ -197,14 +197,14 @@ func ConvertPodStatusToRunningPod(runtimeName string, podStatus *PodStatus) Pod
...
@@ -197,14 +197,14 @@ func ConvertPodStatusToRunningPod(runtimeName string, podStatus *PodStatus) Pod
// Populate sandboxes in kubecontainer.Pod
// Populate sandboxes in kubecontainer.Pod
for
_
,
sandbox
:=
range
podStatus
.
SandboxStatuses
{
for
_
,
sandbox
:=
range
podStatus
.
SandboxStatuses
{
runningPod
.
Sandboxes
=
append
(
runningPod
.
Sandboxes
,
&
Container
{
runningPod
.
Sandboxes
=
append
(
runningPod
.
Sandboxes
,
&
Container
{
ID
:
ContainerID
{
Type
:
runtimeName
,
ID
:
*
sandbox
.
Id
},
ID
:
ContainerID
{
Type
:
runtimeName
,
ID
:
sandbox
.
Id
},
State
:
SandboxToContainerState
(
*
sandbox
.
State
),
State
:
SandboxToContainerState
(
sandbox
.
State
),
})
})
}
}
return
runningPod
return
runningPod
}
}
//
sandboxToContainerState converts runtimeA
pi.PodSandboxState to
//
SandboxToContainerState converts runtimea
pi.PodSandboxState to
// kubecontainer.ContainerState.
// kubecontainer.ContainerState.
// This is only needed because we need to return sandboxes as if they were
// This is only needed because we need to return sandboxes as if they were
// kubecontainer.Containers to avoid substantial changes to PLEG.
// kubecontainer.Containers to avoid substantial changes to PLEG.
...
...
pkg/kubelet/kuberuntime/fake_kuberuntime_manager.go
View file @
53c20e36
...
@@ -113,7 +113,7 @@ func NewFakeKubeRuntimeManager(runtimeService internalapi.RuntimeService, imageS
...
@@ -113,7 +113,7 @@ func NewFakeKubeRuntimeManager(runtimeService internalapi.RuntimeService, imageS
}
}
kubeRuntimeManager
.
containerGC
=
NewContainerGC
(
runtimeService
,
newFakePodGetter
(),
kubeRuntimeManager
)
kubeRuntimeManager
.
containerGC
=
NewContainerGC
(
runtimeService
,
newFakePodGetter
(),
kubeRuntimeManager
)
kubeRuntimeManager
.
runtimeName
=
typedVersion
.
GetRuntimeName
()
kubeRuntimeManager
.
runtimeName
=
typedVersion
.
RuntimeName
kubeRuntimeManager
.
imagePuller
=
images
.
NewImageManager
(
kubeRuntimeManager
.
imagePuller
=
images
.
NewImageManager
(
kubecontainer
.
FilterEventRecorder
(
recorder
),
kubecontainer
.
FilterEventRecorder
(
recorder
),
kubeRuntimeManager
,
kubeRuntimeManager
,
...
...
pkg/kubelet/kuberuntime/helpers.go
View file @
53c20e36
...
@@ -61,7 +61,7 @@ type podSandboxByCreated []*runtimeapi.PodSandbox
...
@@ -61,7 +61,7 @@ type podSandboxByCreated []*runtimeapi.PodSandbox
func
(
p
podSandboxByCreated
)
Len
()
int
{
return
len
(
p
)
}
func
(
p
podSandboxByCreated
)
Len
()
int
{
return
len
(
p
)
}
func
(
p
podSandboxByCreated
)
Swap
(
i
,
j
int
)
{
p
[
i
],
p
[
j
]
=
p
[
j
],
p
[
i
]
}
func
(
p
podSandboxByCreated
)
Swap
(
i
,
j
int
)
{
p
[
i
],
p
[
j
]
=
p
[
j
],
p
[
i
]
}
func
(
p
podSandboxByCreated
)
Less
(
i
,
j
int
)
bool
{
return
p
[
i
]
.
GetCreatedAt
()
>
p
[
j
]
.
GetCreatedAt
()
}
func
(
p
podSandboxByCreated
)
Less
(
i
,
j
int
)
bool
{
return
p
[
i
]
.
CreatedAt
>
p
[
j
]
.
CreatedAt
}
type
containerStatusByCreated
[]
*
kubecontainer
.
ContainerStatus
type
containerStatusByCreated
[]
*
kubecontainer
.
ContainerStatus
...
@@ -100,18 +100,18 @@ func toRuntimeProtocol(protocol v1.Protocol) runtimeapi.Protocol {
...
@@ -100,18 +100,18 @@ func toRuntimeProtocol(protocol v1.Protocol) runtimeapi.Protocol {
// toKubeContainer converts runtimeapi.Container to kubecontainer.Container.
// toKubeContainer converts runtimeapi.Container to kubecontainer.Container.
func
(
m
*
kubeGenericRuntimeManager
)
toKubeContainer
(
c
*
runtimeapi
.
Container
)
(
*
kubecontainer
.
Container
,
error
)
{
func
(
m
*
kubeGenericRuntimeManager
)
toKubeContainer
(
c
*
runtimeapi
.
Container
)
(
*
kubecontainer
.
Container
,
error
)
{
if
c
==
nil
||
c
.
Id
==
nil
||
c
.
Image
==
nil
||
c
.
Stat
e
==
nil
{
if
c
==
nil
||
c
.
Id
==
""
||
c
.
Imag
e
==
nil
{
return
nil
,
fmt
.
Errorf
(
"unable to convert a nil pointer to a runtime container"
)
return
nil
,
fmt
.
Errorf
(
"unable to convert a nil pointer to a runtime container"
)
}
}
labeledInfo
:=
getContainerInfoFromLabels
(
c
.
Labels
)
labeledInfo
:=
getContainerInfoFromLabels
(
c
.
Labels
)
annotatedInfo
:=
getContainerInfoFromAnnotations
(
c
.
Annotations
)
annotatedInfo
:=
getContainerInfoFromAnnotations
(
c
.
Annotations
)
return
&
kubecontainer
.
Container
{
return
&
kubecontainer
.
Container
{
ID
:
kubecontainer
.
ContainerID
{
Type
:
m
.
runtimeName
,
ID
:
c
.
GetId
()
},
ID
:
kubecontainer
.
ContainerID
{
Type
:
m
.
runtimeName
,
ID
:
c
.
Id
},
Name
:
labeledInfo
.
ContainerName
,
Name
:
labeledInfo
.
ContainerName
,
Image
:
c
.
Image
.
GetImage
()
,
Image
:
c
.
Image
.
Image
,
Hash
:
annotatedInfo
.
Hash
,
Hash
:
annotatedInfo
.
Hash
,
State
:
toKubeContainerState
(
c
.
GetState
()
),
State
:
toKubeContainerState
(
c
.
State
),
},
nil
},
nil
}
}
...
@@ -120,34 +120,36 @@ func (m *kubeGenericRuntimeManager) toKubeContainer(c *runtimeapi.Container) (*k
...
@@ -120,34 +120,36 @@ func (m *kubeGenericRuntimeManager) toKubeContainer(c *runtimeapi.Container) (*k
// kubecontainer.Containers to avoid substantial changes to PLEG.
// kubecontainer.Containers to avoid substantial changes to PLEG.
// TODO: Remove this once it becomes obsolete.
// TODO: Remove this once it becomes obsolete.
func
(
m
*
kubeGenericRuntimeManager
)
sandboxToKubeContainer
(
s
*
runtimeapi
.
PodSandbox
)
(
*
kubecontainer
.
Container
,
error
)
{
func
(
m
*
kubeGenericRuntimeManager
)
sandboxToKubeContainer
(
s
*
runtimeapi
.
PodSandbox
)
(
*
kubecontainer
.
Container
,
error
)
{
if
s
==
nil
||
s
.
Id
==
nil
||
s
.
State
==
nil
{
if
s
==
nil
||
s
.
Id
==
""
{
return
nil
,
fmt
.
Errorf
(
"unable to convert a nil pointer to a runtime container"
)
return
nil
,
fmt
.
Errorf
(
"unable to convert a nil pointer to a runtime container"
)
}
}
return
&
kubecontainer
.
Container
{
return
&
kubecontainer
.
Container
{
ID
:
kubecontainer
.
ContainerID
{
Type
:
m
.
runtimeName
,
ID
:
s
.
GetId
()
},
ID
:
kubecontainer
.
ContainerID
{
Type
:
m
.
runtimeName
,
ID
:
s
.
Id
},
State
:
kubecontainer
.
SandboxToContainerState
(
s
.
GetState
()
),
State
:
kubecontainer
.
SandboxToContainerState
(
s
.
State
),
},
nil
},
nil
}
}
// getImageUser gets uid or user name that will run the command(s) from image. The function
// getImageUser gets uid or user name that will run the command(s) from image. The function
// guarantees that only one of them is set.
// guarantees that only one of them is set.
func
(
m
*
kubeGenericRuntimeManager
)
getImageUser
(
image
string
)
(
*
int64
,
*
string
,
error
)
{
func
(
m
*
kubeGenericRuntimeManager
)
getImageUser
(
image
string
)
(
*
int64
,
string
,
error
)
{
imageStatus
,
err
:=
m
.
imageService
.
ImageStatus
(
&
runtimeapi
.
ImageSpec
{
Image
:
&
image
})
imageStatus
,
err
:=
m
.
imageService
.
ImageStatus
(
&
runtimeapi
.
ImageSpec
{
Image
:
image
})
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
nil
,
err
return
nil
,
""
,
err
}
}
if
imageStatus
!=
nil
&&
imageStatus
.
Uid
!=
nil
{
if
imageStatus
!=
nil
{
// If uid is set, return uid.
if
imageStatus
.
Uid
!=
nil
{
return
imageStatus
.
Uid
,
nil
,
nil
return
&
imageStatus
.
GetUid
()
.
Value
,
""
,
nil
}
}
if
imageStatus
!=
nil
&&
imageStatus
.
Username
!=
nil
{
// If uid is not set, but user name is set, return user name.
if
imageStatus
.
Username
!=
""
{
return
nil
,
imageStatus
.
Username
,
nil
return
nil
,
imageStatus
.
Username
,
nil
}
}
}
// If non of them is set, treat it as root.
// If non of them is set, treat it as root.
return
new
(
int64
),
nil
,
nil
return
new
(
int64
),
""
,
nil
}
}
// isContainerFailed returns true if container has exited and exitcode is not zero.
// isContainerFailed returns true if container has exited and exitcode is not zero.
...
@@ -226,10 +228,10 @@ func toKubeRuntimeStatus(status *runtimeapi.RuntimeStatus) *kubecontainer.Runtim
...
@@ -226,10 +228,10 @@ func toKubeRuntimeStatus(status *runtimeapi.RuntimeStatus) *kubecontainer.Runtim
conditions
:=
[]
kubecontainer
.
RuntimeCondition
{}
conditions
:=
[]
kubecontainer
.
RuntimeCondition
{}
for
_
,
c
:=
range
status
.
GetConditions
()
{
for
_
,
c
:=
range
status
.
GetConditions
()
{
conditions
=
append
(
conditions
,
kubecontainer
.
RuntimeCondition
{
conditions
=
append
(
conditions
,
kubecontainer
.
RuntimeCondition
{
Type
:
kubecontainer
.
RuntimeConditionType
(
c
.
GetType
()
),
Type
:
kubecontainer
.
RuntimeConditionType
(
c
.
Type
),
Status
:
c
.
GetStatus
()
,
Status
:
c
.
Status
,
Reason
:
c
.
GetReason
()
,
Reason
:
c
.
Reason
,
Message
:
c
.
GetMessage
()
,
Message
:
c
.
Message
,
})
})
}
}
return
&
kubecontainer
.
RuntimeStatus
{
Conditions
:
conditions
}
return
&
kubecontainer
.
RuntimeStatus
{
Conditions
:
conditions
}
...
...
pkg/kubelet/kuberuntime/kuberuntime_container.go
View file @
53c20e36
This diff is collapsed.
Click to expand it.
pkg/kubelet/kuberuntime/kuberuntime_container_test.go
View file @
53c20e36
...
@@ -51,7 +51,7 @@ func TestRemoveContainer(t *testing.T) {
...
@@ -51,7 +51,7 @@ func TestRemoveContainer(t *testing.T) {
_
,
fakeContainers
:=
makeAndSetFakePod
(
t
,
m
,
fakeRuntime
,
pod
)
_
,
fakeContainers
:=
makeAndSetFakePod
(
t
,
m
,
fakeRuntime
,
pod
)
assert
.
Equal
(
t
,
len
(
fakeContainers
),
1
)
assert
.
Equal
(
t
,
len
(
fakeContainers
),
1
)
containerId
:=
fakeContainers
[
0
]
.
GetId
()
containerId
:=
fakeContainers
[
0
]
.
Id
fakeOS
:=
m
.
osInterface
.
(
*
containertest
.
FakeOS
)
fakeOS
:=
m
.
osInterface
.
(
*
containertest
.
FakeOS
)
err
=
m
.
removeContainer
(
containerId
)
err
=
m
.
removeContainer
(
containerId
)
assert
.
NoError
(
t
,
err
)
assert
.
NoError
(
t
,
err
)
...
@@ -61,7 +61,7 @@ func TestRemoveContainer(t *testing.T) {
...
@@ -61,7 +61,7 @@ func TestRemoveContainer(t *testing.T) {
assert
.
Equal
(
t
,
fakeOS
.
Removes
,
[]
string
{
expectedContainerLogPath
,
expectedContainerLogSymlink
})
assert
.
Equal
(
t
,
fakeOS
.
Removes
,
[]
string
{
expectedContainerLogPath
,
expectedContainerLogSymlink
})
// Verify container is removed
// Verify container is removed
fakeRuntime
.
AssertCalls
([]
string
{
"RemoveContainer"
})
fakeRuntime
.
AssertCalls
([]
string
{
"RemoveContainer"
})
containers
,
err
:=
fakeRuntime
.
ListContainers
(
&
runtimeapi
.
ContainerFilter
{
Id
:
&
containerId
})
containers
,
err
:=
fakeRuntime
.
ListContainers
(
&
runtimeapi
.
ContainerFilter
{
Id
:
containerId
})
assert
.
NoError
(
t
,
err
)
assert
.
NoError
(
t
,
err
)
assert
.
Empty
(
t
,
containers
)
assert
.
Empty
(
t
,
containers
)
}
}
pkg/kubelet/kuberuntime/kuberuntime_gc.go
View file @
53c20e36
...
@@ -161,21 +161,21 @@ func (cgc *containerGC) evictableContainers(minAge time.Duration) (containersByE
...
@@ -161,21 +161,21 @@ func (cgc *containerGC) evictableContainers(minAge time.Duration) (containersByE
newestGCTime
:=
time
.
Now
()
.
Add
(
-
minAge
)
newestGCTime
:=
time
.
Now
()
.
Add
(
-
minAge
)
for
_
,
container
:=
range
containers
{
for
_
,
container
:=
range
containers
{
// Prune out running containers.
// Prune out running containers.
if
container
.
GetState
()
==
runtimeapi
.
ContainerState_CONTAINER_RUNNING
{
if
container
.
State
==
runtimeapi
.
ContainerState_CONTAINER_RUNNING
{
continue
continue
}
}
createdAt
:=
time
.
Unix
(
0
,
container
.
GetCreatedAt
()
)
createdAt
:=
time
.
Unix
(
0
,
container
.
CreatedAt
)
if
newestGCTime
.
Before
(
createdAt
)
{
if
newestGCTime
.
Before
(
createdAt
)
{
continue
continue
}
}
labeledInfo
:=
getContainerInfoFromLabels
(
container
.
Labels
)
labeledInfo
:=
getContainerInfoFromLabels
(
container
.
Labels
)
containerInfo
:=
containerGCInfo
{
containerInfo
:=
containerGCInfo
{
id
:
container
.
GetId
()
,
id
:
container
.
Id
,
name
:
container
.
Metadata
.
GetName
()
,
name
:
container
.
Metadata
.
Name
,
createTime
:
createdAt
,
createTime
:
createdAt
,
sandboxID
:
container
.
GetPodSandboxId
()
,
sandboxID
:
container
.
PodSandboxId
,
}
}
key
:=
evictUnit
{
key
:=
evictUnit
{
uid
:
labeledInfo
.
PodUID
,
uid
:
labeledInfo
.
PodUID
,
...
@@ -256,15 +256,15 @@ func (cgc *containerGC) evictSandboxes(minAge time.Duration) error {
...
@@ -256,15 +256,15 @@ func (cgc *containerGC) evictSandboxes(minAge time.Duration) error {
newestGCTime
:=
time
.
Now
()
.
Add
(
-
minAge
)
newestGCTime
:=
time
.
Now
()
.
Add
(
-
minAge
)
for
_
,
sandbox
:=
range
sandboxes
{
for
_
,
sandbox
:=
range
sandboxes
{
// Prune out ready sandboxes.
// Prune out ready sandboxes.
if
sandbox
.
GetState
()
==
runtimeapi
.
PodSandboxState_SANDBOX_READY
{
if
sandbox
.
State
==
runtimeapi
.
PodSandboxState_SANDBOX_READY
{
continue
continue
}
}
// Prune out sandboxes that still have containers.
// Prune out sandboxes that still have containers.
found
:=
false
found
:=
false
sandboxID
:=
sandbox
.
GetId
()
sandboxID
:=
sandbox
.
Id
for
_
,
container
:=
range
containers
{
for
_
,
container
:=
range
containers
{
if
container
.
GetPodSandboxId
()
==
sandboxID
{
if
container
.
PodSandboxId
==
sandboxID
{
found
=
true
found
=
true
break
break
}
}
...
@@ -274,7 +274,7 @@ func (cgc *containerGC) evictSandboxes(minAge time.Duration) error {
...
@@ -274,7 +274,7 @@ func (cgc *containerGC) evictSandboxes(minAge time.Duration) error {
}
}
// Only garbage collect sandboxes older than sandboxMinGCAge.
// Only garbage collect sandboxes older than sandboxMinGCAge.
createdAt
:=
time
.
Unix
(
0
,
sandbox
.
GetCreatedAt
()
)
createdAt
:=
time
.
Unix
(
0
,
sandbox
.
CreatedAt
)
if
createdAt
.
After
(
newestGCTime
)
{
if
createdAt
.
After
(
newestGCTime
)
{
continue
continue
}
}
...
...
pkg/kubelet/kuberuntime/kuberuntime_gc_test.go
View file @
53c20e36
...
@@ -115,7 +115,7 @@ func TestSandboxGC(t *testing.T) {
...
@@ -115,7 +115,7 @@ func TestSandboxGC(t *testing.T) {
assert
.
NoError
(
t
,
err
)
assert
.
NoError
(
t
,
err
)
assert
.
Len
(
t
,
realRemain
,
len
(
test
.
remain
))
assert
.
Len
(
t
,
realRemain
,
len
(
test
.
remain
))
for
_
,
remain
:=
range
test
.
remain
{
for
_
,
remain
:=
range
test
.
remain
{
status
,
err
:=
fakeRuntime
.
PodSandboxStatus
(
fakeSandboxes
[
remain
]
.
GetId
()
)
status
,
err
:=
fakeRuntime
.
PodSandboxStatus
(
fakeSandboxes
[
remain
]
.
Id
)
assert
.
NoError
(
t
,
err
)
assert
.
NoError
(
t
,
err
)
assert
.
Equal
(
t
,
&
fakeSandboxes
[
remain
]
.
PodSandboxStatus
,
status
)
assert
.
Equal
(
t
,
&
fakeSandboxes
[
remain
]
.
PodSandboxStatus
,
status
)
}
}
...
@@ -288,7 +288,7 @@ func TestContainerGC(t *testing.T) {
...
@@ -288,7 +288,7 @@ func TestContainerGC(t *testing.T) {
assert
.
NoError
(
t
,
err
)
assert
.
NoError
(
t
,
err
)
assert
.
Len
(
t
,
realRemain
,
len
(
test
.
remain
))
assert
.
Len
(
t
,
realRemain
,
len
(
test
.
remain
))
for
_
,
remain
:=
range
test
.
remain
{
for
_
,
remain
:=
range
test
.
remain
{
status
,
err
:=
fakeRuntime
.
ContainerStatus
(
fakeContainers
[
remain
]
.
GetId
()
)
status
,
err
:=
fakeRuntime
.
ContainerStatus
(
fakeContainers
[
remain
]
.
Id
)
assert
.
NoError
(
t
,
err
)
assert
.
NoError
(
t
,
err
)
assert
.
Equal
(
t
,
&
fakeContainers
[
remain
]
.
ContainerStatus
,
status
)
assert
.
Equal
(
t
,
&
fakeContainers
[
remain
]
.
ContainerStatus
,
status
)
}
}
...
...
pkg/kubelet/kuberuntime/kuberuntime_image.go
View file @
53c20e36
...
@@ -40,7 +40,7 @@ func (m *kubeGenericRuntimeManager) PullImage(image kubecontainer.ImageSpec, pul
...
@@ -40,7 +40,7 @@ func (m *kubeGenericRuntimeManager) PullImage(image kubecontainer.ImageSpec, pul
return
""
,
err
return
""
,
err
}
}
imgSpec
:=
&
runtimeapi
.
ImageSpec
{
Image
:
&
img
}
imgSpec
:=
&
runtimeapi
.
ImageSpec
{
Image
:
img
}
creds
,
withCredentials
:=
keyring
.
Lookup
(
repoToPull
)
creds
,
withCredentials
:=
keyring
.
Lookup
(
repoToPull
)
if
!
withCredentials
{
if
!
withCredentials
{
glog
.
V
(
3
)
.
Infof
(
"Pulling image %q without credentials"
,
img
)
glog
.
V
(
3
)
.
Infof
(
"Pulling image %q without credentials"
,
img
)
...
@@ -58,12 +58,12 @@ func (m *kubeGenericRuntimeManager) PullImage(image kubecontainer.ImageSpec, pul
...
@@ -58,12 +58,12 @@ func (m *kubeGenericRuntimeManager) PullImage(image kubecontainer.ImageSpec, pul
for
_
,
currentCreds
:=
range
creds
{
for
_
,
currentCreds
:=
range
creds
{
authConfig
:=
credentialprovider
.
LazyProvide
(
currentCreds
)
authConfig
:=
credentialprovider
.
LazyProvide
(
currentCreds
)
auth
:=
&
runtimeapi
.
AuthConfig
{
auth
:=
&
runtimeapi
.
AuthConfig
{
Username
:
&
authConfig
.
Username
,
Username
:
authConfig
.
Username
,
Password
:
&
authConfig
.
Password
,
Password
:
authConfig
.
Password
,
Auth
:
&
authConfig
.
Auth
,
Auth
:
authConfig
.
Auth
,
ServerAddress
:
&
authConfig
.
ServerAddress
,
ServerAddress
:
authConfig
.
ServerAddress
,
IdentityToken
:
&
authConfig
.
IdentityToken
,
IdentityToken
:
authConfig
.
IdentityToken
,
RegistryToken
:
&
authConfig
.
RegistryToken
,
RegistryToken
:
authConfig
.
RegistryToken
,
}
}
imageRef
,
err
:=
m
.
imageService
.
PullImage
(
imgSpec
,
auth
)
imageRef
,
err
:=
m
.
imageService
.
PullImage
(
imgSpec
,
auth
)
...
@@ -81,7 +81,7 @@ func (m *kubeGenericRuntimeManager) PullImage(image kubecontainer.ImageSpec, pul
...
@@ -81,7 +81,7 @@ func (m *kubeGenericRuntimeManager) PullImage(image kubecontainer.ImageSpec, pul
// GetImageRef gets the reference (digest or ID) of the image which has already been in
// GetImageRef gets the reference (digest or ID) of the image which has already been in
// the local storage. It returns ("", nil) if the image isn't in the local storage.
// the local storage. It returns ("", nil) if the image isn't in the local storage.
func
(
m
*
kubeGenericRuntimeManager
)
GetImageRef
(
image
kubecontainer
.
ImageSpec
)
(
string
,
error
)
{
func
(
m
*
kubeGenericRuntimeManager
)
GetImageRef
(
image
kubecontainer
.
ImageSpec
)
(
string
,
error
)
{
status
,
err
:=
m
.
imageService
.
ImageStatus
(
&
runtimeapi
.
ImageSpec
{
Image
:
&
image
.
Image
})
status
,
err
:=
m
.
imageService
.
ImageStatus
(
&
runtimeapi
.
ImageSpec
{
Image
:
image
.
Image
})
if
err
!=
nil
{
if
err
!=
nil
{
glog
.
Errorf
(
"ImageStatus for image %q failed: %v"
,
image
,
err
)
glog
.
Errorf
(
"ImageStatus for image %q failed: %v"
,
image
,
err
)
return
""
,
err
return
""
,
err
...
@@ -90,7 +90,7 @@ func (m *kubeGenericRuntimeManager) GetImageRef(image kubecontainer.ImageSpec) (
...
@@ -90,7 +90,7 @@ func (m *kubeGenericRuntimeManager) GetImageRef(image kubecontainer.ImageSpec) (
return
""
,
nil
return
""
,
nil
}
}
imageRef
:=
status
.
GetId
()
imageRef
:=
status
.
Id
if
len
(
status
.
RepoDigests
)
>
0
{
if
len
(
status
.
RepoDigests
)
>
0
{
imageRef
=
status
.
RepoDigests
[
0
]
imageRef
=
status
.
RepoDigests
[
0
]
}
}
...
@@ -109,8 +109,8 @@ func (m *kubeGenericRuntimeManager) ListImages() ([]kubecontainer.Image, error)
...
@@ -109,8 +109,8 @@ func (m *kubeGenericRuntimeManager) ListImages() ([]kubecontainer.Image, error)
for
_
,
img
:=
range
allImages
{
for
_
,
img
:=
range
allImages
{
images
=
append
(
images
,
kubecontainer
.
Image
{
images
=
append
(
images
,
kubecontainer
.
Image
{
ID
:
img
.
GetId
()
,
ID
:
img
.
Id
,
Size
:
int64
(
img
.
GetSize_
()
),
Size
:
int64
(
img
.
Size_
),
RepoTags
:
img
.
RepoTags
,
RepoTags
:
img
.
RepoTags
,
RepoDigests
:
img
.
RepoDigests
,
RepoDigests
:
img
.
RepoDigests
,
})
})
...
@@ -121,7 +121,7 @@ func (m *kubeGenericRuntimeManager) ListImages() ([]kubecontainer.Image, error)
...
@@ -121,7 +121,7 @@ func (m *kubeGenericRuntimeManager) ListImages() ([]kubecontainer.Image, error)
// RemoveImage removes the specified image.
// RemoveImage removes the specified image.
func
(
m
*
kubeGenericRuntimeManager
)
RemoveImage
(
image
kubecontainer
.
ImageSpec
)
error
{
func
(
m
*
kubeGenericRuntimeManager
)
RemoveImage
(
image
kubecontainer
.
ImageSpec
)
error
{
err
:=
m
.
imageService
.
RemoveImage
(
&
runtimeapi
.
ImageSpec
{
Image
:
&
image
.
Image
})
err
:=
m
.
imageService
.
RemoveImage
(
&
runtimeapi
.
ImageSpec
{
Image
:
image
.
Image
})
if
err
!=
nil
{
if
err
!=
nil
{
glog
.
Errorf
(
"Remove image %q failed: %v"
,
image
.
Image
,
err
)
glog
.
Errorf
(
"Remove image %q failed: %v"
,
image
.
Image
,
err
)
return
err
return
err
...
@@ -142,7 +142,7 @@ func (m *kubeGenericRuntimeManager) ImageStats() (*kubecontainer.ImageStats, err
...
@@ -142,7 +142,7 @@ func (m *kubeGenericRuntimeManager) ImageStats() (*kubecontainer.ImageStats, err
}
}
stats
:=
&
kubecontainer
.
ImageStats
{}
stats
:=
&
kubecontainer
.
ImageStats
{}
for
_
,
img
:=
range
allImages
{
for
_
,
img
:=
range
allImages
{
stats
.
TotalStorageBytes
+=
img
.
GetSize_
()
stats
.
TotalStorageBytes
+=
img
.
Size_
}
}
return
stats
,
nil
return
stats
,
nil
}
}
pkg/kubelet/kuberuntime/kuberuntime_manager.go
View file @
53c20e36
...
@@ -156,18 +156,18 @@ func NewKubeGenericRuntimeManager(
...
@@ -156,18 +156,18 @@ func NewKubeGenericRuntimeManager(
// Only matching kubeRuntimeAPIVersion is supported now
// Only matching kubeRuntimeAPIVersion is supported now
// TODO: Runtime API machinery is under discussion at https://github.com/kubernetes/kubernetes/issues/28642
// TODO: Runtime API machinery is under discussion at https://github.com/kubernetes/kubernetes/issues/28642
if
typedVersion
.
GetVersion
()
!=
kubeRuntimeAPIVersion
{
if
typedVersion
.
Version
!=
kubeRuntimeAPIVersion
{
glog
.
Errorf
(
"Runtime api version %s is not supported, only %s is supported now"
,
glog
.
Errorf
(
"Runtime api version %s is not supported, only %s is supported now"
,
typedVersion
.
GetVersion
()
,
typedVersion
.
Version
,
kubeRuntimeAPIVersion
)
kubeRuntimeAPIVersion
)
return
nil
,
ErrVersionNotSupported
return
nil
,
ErrVersionNotSupported
}
}
kubeRuntimeManager
.
runtimeName
=
typedVersion
.
GetRuntimeName
()
kubeRuntimeManager
.
runtimeName
=
typedVersion
.
RuntimeName
glog
.
Infof
(
"Container runtime %s initialized, version: %s, apiVersion: %s"
,
glog
.
Infof
(
"Container runtime %s initialized, version: %s, apiVersion: %s"
,
typedVersion
.
GetRuntimeName
()
,
typedVersion
.
RuntimeName
,
typedVersion
.
GetRuntimeVersion
()
,
typedVersion
.
RuntimeVersion
,
typedVersion
.
GetRuntimeApiVersion
()
)
typedVersion
.
RuntimeApiVersion
)
// If the container logs directory does not exist, create it.
// If the container logs directory does not exist, create it.
// TODO: create podLogsRootDirectory at kubelet.go when kubelet is refactored to
// TODO: create podLogsRootDirectory at kubelet.go when kubelet is refactored to
...
@@ -224,7 +224,7 @@ func (m *kubeGenericRuntimeManager) Version() (kubecontainer.Version, error) {
...
@@ -224,7 +224,7 @@ func (m *kubeGenericRuntimeManager) Version() (kubecontainer.Version, error) {
return
nil
,
err
return
nil
,
err
}
}
return
newRuntimeVersion
(
typedVersion
.
GetVersion
()
)
return
newRuntimeVersion
(
typedVersion
.
Version
)
}
}
// APIVersion returns the cached API version information of the container
// APIVersion returns the cached API version information of the container
...
@@ -237,7 +237,7 @@ func (m *kubeGenericRuntimeManager) APIVersion() (kubecontainer.Version, error)
...
@@ -237,7 +237,7 @@ func (m *kubeGenericRuntimeManager) APIVersion() (kubecontainer.Version, error)
}
}
typedVersion
:=
versionObject
.
(
*
runtimeapi
.
VersionResponse
)
typedVersion
:=
versionObject
.
(
*
runtimeapi
.
VersionResponse
)
return
newRuntimeVersion
(
typedVersion
.
GetRuntimeApiVersion
()
)
return
newRuntimeVersion
(
typedVersion
.
RuntimeApiVersion
)
}
}
// Status returns the status of the runtime. An error is returned if the Status
// Status returns the status of the runtime. An error is returned if the Status
...
@@ -265,12 +265,12 @@ func (m *kubeGenericRuntimeManager) GetPods(all bool) ([]*kubecontainer.Pod, err
...
@@ -265,12 +265,12 @@ func (m *kubeGenericRuntimeManager) GetPods(all bool) ([]*kubecontainer.Pod, err
glog
.
V
(
4
)
.
Infof
(
"Sandbox does not have metadata: %+v"
,
s
)
glog
.
V
(
4
)
.
Infof
(
"Sandbox does not have metadata: %+v"
,
s
)
continue
continue
}
}
podUID
:=
kubetypes
.
UID
(
s
.
Metadata
.
GetUid
()
)
podUID
:=
kubetypes
.
UID
(
s
.
Metadata
.
Uid
)
if
_
,
ok
:=
pods
[
podUID
];
!
ok
{
if
_
,
ok
:=
pods
[
podUID
];
!
ok
{
pods
[
podUID
]
=
&
kubecontainer
.
Pod
{
pods
[
podUID
]
=
&
kubecontainer
.
Pod
{
ID
:
podUID
,
ID
:
podUID
,
Name
:
s
.
Metadata
.
GetName
()
,
Name
:
s
.
Metadata
.
Name
,
Namespace
:
s
.
Metadata
.
GetNamespace
()
,
Namespace
:
s
.
Metadata
.
Namespace
,
}
}
}
}
p
:=
pods
[
podUID
]
p
:=
pods
[
podUID
]
...
@@ -372,26 +372,26 @@ func (m *kubeGenericRuntimeManager) podSandboxChanged(pod *v1.Pod, podStatus *ku
...
@@ -372,26 +372,26 @@ func (m *kubeGenericRuntimeManager) podSandboxChanged(pod *v1.Pod, podStatus *ku
readySandboxCount
:=
0
readySandboxCount
:=
0
for
_
,
s
:=
range
podStatus
.
SandboxStatuses
{
for
_
,
s
:=
range
podStatus
.
SandboxStatuses
{
if
s
.
GetState
()
==
runtimeapi
.
PodSandboxState_SANDBOX_READY
{
if
s
.
State
==
runtimeapi
.
PodSandboxState_SANDBOX_READY
{
readySandboxCount
++
readySandboxCount
++
}
}
}
}
// Needs to create a new sandbox when readySandboxCount > 1 or the ready sandbox is not the latest one.
// Needs to create a new sandbox when readySandboxCount > 1 or the ready sandbox is not the latest one.
sandboxStatus
:=
podStatus
.
SandboxStatuses
[
0
]
sandboxStatus
:=
podStatus
.
SandboxStatuses
[
0
]
if
readySandboxCount
>
1
||
sandboxStatus
.
GetState
()
!=
runtimeapi
.
PodSandboxState_SANDBOX_READY
{
if
readySandboxCount
>
1
||
sandboxStatus
.
State
!=
runtimeapi
.
PodSandboxState_SANDBOX_READY
{
glog
.
V
(
2
)
.
Infof
(
"No ready sandbox for pod %q can be found. Need to start a new one"
,
format
.
Pod
(
pod
))
glog
.
V
(
2
)
.
Infof
(
"No ready sandbox for pod %q can be found. Need to start a new one"
,
format
.
Pod
(
pod
))
return
true
,
sandboxStatus
.
Metadata
.
GetAttempt
()
+
1
,
sandboxStatus
.
GetId
()
return
true
,
sandboxStatus
.
Metadata
.
Attempt
+
1
,
sandboxStatus
.
Id
}
}
// Needs to create a new sandbox when network namespace changed.
// Needs to create a new sandbox when network namespace changed.
if
sandboxStatus
.
Linux
!=
nil
&&
sandboxStatus
.
Linux
.
Namespaces
.
Options
!=
nil
&&
if
sandboxStatus
.
Linux
!=
nil
&&
sandboxStatus
.
Linux
.
Namespaces
.
Options
!=
nil
&&
sandboxStatus
.
Linux
.
Namespaces
.
Options
.
GetHostNetwork
()
!=
kubecontainer
.
IsHostNetworkPod
(
pod
)
{
sandboxStatus
.
Linux
.
Namespaces
.
Options
.
HostNetwork
!=
kubecontainer
.
IsHostNetworkPod
(
pod
)
{
glog
.
V
(
2
)
.
Infof
(
"Sandbox for pod %q has changed. Need to start a new one"
,
format
.
Pod
(
pod
))
glog
.
V
(
2
)
.
Infof
(
"Sandbox for pod %q has changed. Need to start a new one"
,
format
.
Pod
(
pod
))
return
true
,
sandboxStatus
.
Metadata
.
GetAttempt
()
+
1
,
""
return
true
,
sandboxStatus
.
Metadata
.
Attempt
+
1
,
""
}
}
return
false
,
sandboxStatus
.
Metadata
.
GetAttempt
(),
sandboxStatus
.
GetId
()
return
false
,
sandboxStatus
.
Metadata
.
Attempt
,
sandboxStatus
.
Id
}
}
// checkAndKeepInitContainers keeps all successfully completed init containers. If there
// checkAndKeepInitContainers keeps all successfully completed init containers. If there
...
@@ -794,10 +794,8 @@ func (m *kubeGenericRuntimeManager) isHostNetwork(podSandBoxID string, pod *v1.P
...
@@ -794,10 +794,8 @@ func (m *kubeGenericRuntimeManager) isHostNetwork(podSandBoxID string, pod *v1.P
return
false
,
err
return
false
,
err
}
}
if
podStatus
.
Linux
!=
nil
&&
podStatus
.
Linux
.
Namespaces
!=
nil
&&
podStatus
.
Linux
.
Namespaces
.
Options
!=
nil
{
if
nsOpts
:=
podStatus
.
GetLinux
()
.
GetNamespaces
()
.
GetOptions
();
nsOpts
!=
nil
{
if
podStatus
.
Linux
.
Namespaces
.
Options
.
HostNetwork
!=
nil
{
return
nsOpts
.
HostNetwork
,
nil
return
podStatus
.
Linux
.
Namespaces
.
Options
.
GetHostNetwork
(),
nil
}
}
}
return
false
,
nil
return
false
,
nil
...
@@ -844,7 +842,7 @@ func (m *kubeGenericRuntimeManager) GetPodStatus(uid kubetypes.UID, name, namesp
...
@@ -844,7 +842,7 @@ func (m *kubeGenericRuntimeManager) GetPodStatus(uid kubetypes.UID, name, namesp
sandboxStatuses
[
idx
]
=
podSandboxStatus
sandboxStatuses
[
idx
]
=
podSandboxStatus
// Only get pod IP from latest sandbox
// Only get pod IP from latest sandbox
if
idx
==
0
&&
podSandboxStatus
.
GetState
()
==
runtimeapi
.
PodSandboxState_SANDBOX_READY
{
if
idx
==
0
&&
podSandboxStatus
.
State
==
runtimeapi
.
PodSandboxState_SANDBOX_READY
{
podIP
=
m
.
determinePodSandboxIP
(
namespace
,
name
,
podSandboxStatus
)
podIP
=
m
.
determinePodSandboxIP
(
namespace
,
name
,
podSandboxStatus
)
}
}
}
}
...
@@ -900,7 +898,7 @@ func (m *kubeGenericRuntimeManager) UpdatePodCIDR(podCIDR string) error {
...
@@ -900,7 +898,7 @@ func (m *kubeGenericRuntimeManager) UpdatePodCIDR(podCIDR string) error {
return
m
.
runtimeService
.
UpdateRuntimeConfig
(
return
m
.
runtimeService
.
UpdateRuntimeConfig
(
&
runtimeapi
.
RuntimeConfig
{
&
runtimeapi
.
RuntimeConfig
{
NetworkConfig
:
&
runtimeapi
.
NetworkConfig
{
NetworkConfig
:
&
runtimeapi
.
NetworkConfig
{
PodCidr
:
&
podCIDR
,
PodCidr
:
podCIDR
,
},
},
})
})
}
}
pkg/kubelet/kuberuntime/kuberuntime_manager_test.go
View file @
53c20e36
...
@@ -119,12 +119,12 @@ func makeFakePodSandbox(t *testing.T, m *kubeGenericRuntimeManager, template san
...
@@ -119,12 +119,12 @@ func makeFakePodSandbox(t *testing.T, m *kubeGenericRuntimeManager, template san
podSandboxID
:=
apitest
.
BuildSandboxName
(
config
.
Metadata
)
podSandboxID
:=
apitest
.
BuildSandboxName
(
config
.
Metadata
)
return
&
apitest
.
FakePodSandbox
{
return
&
apitest
.
FakePodSandbox
{
PodSandboxStatus
:
runtimeapi
.
PodSandboxStatus
{
PodSandboxStatus
:
runtimeapi
.
PodSandboxStatus
{
Id
:
&
podSandboxID
,
Id
:
podSandboxID
,
Metadata
:
config
.
Metadata
,
Metadata
:
config
.
Metadata
,
State
:
&
template
.
state
,
State
:
template
.
state
,
CreatedAt
:
&
template
.
createdAt
,
CreatedAt
:
template
.
createdAt
,
Network
:
&
runtimeapi
.
PodSandboxNetworkStatus
{
Network
:
&
runtimeapi
.
PodSandboxNetworkStatus
{
Ip
:
&
apitest
.
FakePodSandboxIP
,
Ip
:
apitest
.
FakePodSandboxIP
,
},
},
Labels
:
config
.
Labels
,
Labels
:
config
.
Labels
,
},
},
...
@@ -151,15 +151,15 @@ func makeFakeContainer(t *testing.T, m *kubeGenericRuntimeManager, template cont
...
@@ -151,15 +151,15 @@ func makeFakeContainer(t *testing.T, m *kubeGenericRuntimeManager, template cont
podSandboxID
:=
apitest
.
BuildSandboxName
(
sandboxConfig
.
Metadata
)
podSandboxID
:=
apitest
.
BuildSandboxName
(
sandboxConfig
.
Metadata
)
containerID
:=
apitest
.
BuildContainerName
(
containerConfig
.
Metadata
,
podSandboxID
)
containerID
:=
apitest
.
BuildContainerName
(
containerConfig
.
Metadata
,
podSandboxID
)
imageRef
:=
containerConfig
.
Image
.
GetImage
()
imageRef
:=
containerConfig
.
Image
.
Image
return
&
apitest
.
FakeContainer
{
return
&
apitest
.
FakeContainer
{
ContainerStatus
:
runtimeapi
.
ContainerStatus
{
ContainerStatus
:
runtimeapi
.
ContainerStatus
{
Id
:
&
containerID
,
Id
:
containerID
,
Metadata
:
containerConfig
.
Metadata
,
Metadata
:
containerConfig
.
Metadata
,
Image
:
containerConfig
.
Image
,
Image
:
containerConfig
.
Image
,
ImageRef
:
&
imageRef
,
ImageRef
:
imageRef
,
CreatedAt
:
&
template
.
createdAt
,
CreatedAt
:
template
.
createdAt
,
State
:
&
template
.
state
,
State
:
template
.
state
,
Labels
:
containerConfig
.
Labels
,
Labels
:
containerConfig
.
Labels
,
Annotations
:
containerConfig
.
Annotations
,
Annotations
:
containerConfig
.
Annotations
,
},
},
...
@@ -223,7 +223,7 @@ func verifyPods(a, b []*kubecontainer.Pod) bool {
...
@@ -223,7 +223,7 @@ func verifyPods(a, b []*kubecontainer.Pod) bool {
func
verifyFakeContainerList
(
fakeRuntime
*
apitest
.
FakeRuntimeService
,
expected
[]
string
)
([]
string
,
bool
)
{
func
verifyFakeContainerList
(
fakeRuntime
*
apitest
.
FakeRuntimeService
,
expected
[]
string
)
([]
string
,
bool
)
{
actual
:=
[]
string
{}
actual
:=
[]
string
{}
for
_
,
c
:=
range
fakeRuntime
.
Containers
{
for
_
,
c
:=
range
fakeRuntime
.
Containers
{
actual
=
append
(
actual
,
c
.
GetId
()
)
actual
=
append
(
actual
,
c
.
Id
)
}
}
sort
.
Sort
(
sort
.
StringSlice
(
actual
))
sort
.
Sort
(
sort
.
StringSlice
(
actual
))
sort
.
Sort
(
sort
.
StringSlice
(
expected
))
sort
.
Sort
(
sort
.
StringSlice
(
expected
))
...
@@ -411,7 +411,7 @@ func TestGetPodContainerID(t *testing.T) {
...
@@ -411,7 +411,7 @@ func TestGetPodContainerID(t *testing.T) {
Sandboxes
:
[]
*
kubecontainer
.
Container
{
sandbox
},
Sandboxes
:
[]
*
kubecontainer
.
Container
{
sandbox
},
}
}
actual
,
err
:=
m
.
GetPodContainerID
(
expectedPod
)
actual
,
err
:=
m
.
GetPodContainerID
(
expectedPod
)
assert
.
Equal
(
t
,
fakeSandbox
.
GetId
()
,
actual
.
ID
)
assert
.
Equal
(
t
,
fakeSandbox
.
Id
,
actual
.
ID
)
}
}
func
TestGetNetNS
(
t
*
testing
.
T
)
{
func
TestGetNetNS
(
t
*
testing
.
T
)
{
...
@@ -441,7 +441,7 @@ func TestGetNetNS(t *testing.T) {
...
@@ -441,7 +441,7 @@ func TestGetNetNS(t *testing.T) {
// Set fake sandbox and fake containers to fakeRuntime.
// Set fake sandbox and fake containers to fakeRuntime.
sandbox
,
_
:=
makeAndSetFakePod
(
t
,
m
,
fakeRuntime
,
pod
)
sandbox
,
_
:=
makeAndSetFakePod
(
t
,
m
,
fakeRuntime
,
pod
)
actual
,
err
:=
m
.
GetNetNS
(
kubecontainer
.
ContainerID
{
ID
:
sandbox
.
GetId
()
})
actual
,
err
:=
m
.
GetNetNS
(
kubecontainer
.
ContainerID
{
ID
:
sandbox
.
Id
})
assert
.
Equal
(
t
,
""
,
actual
)
assert
.
Equal
(
t
,
""
,
actual
)
assert
.
Equal
(
t
,
"not supported"
,
err
.
Error
())
assert
.
Equal
(
t
,
"not supported"
,
err
.
Error
())
}
}
...
@@ -498,7 +498,7 @@ func TestKillPod(t *testing.T) {
...
@@ -498,7 +498,7 @@ func TestKillPod(t *testing.T) {
Sandboxes
:
[]
*
kubecontainer
.
Container
{
Sandboxes
:
[]
*
kubecontainer
.
Container
{
{
{
ID
:
kubecontainer
.
ContainerID
{
ID
:
kubecontainer
.
ContainerID
{
ID
:
fakeSandbox
.
GetId
()
,
ID
:
fakeSandbox
.
Id
,
Type
:
apitest
.
FakeRuntimeName
,
Type
:
apitest
.
FakeRuntimeName
,
},
},
},
},
...
@@ -510,10 +510,10 @@ func TestKillPod(t *testing.T) {
...
@@ -510,10 +510,10 @@ func TestKillPod(t *testing.T) {
assert
.
Equal
(
t
,
2
,
len
(
fakeRuntime
.
Containers
))
assert
.
Equal
(
t
,
2
,
len
(
fakeRuntime
.
Containers
))
assert
.
Equal
(
t
,
1
,
len
(
fakeRuntime
.
Sandboxes
))
assert
.
Equal
(
t
,
1
,
len
(
fakeRuntime
.
Sandboxes
))
for
_
,
sandbox
:=
range
fakeRuntime
.
Sandboxes
{
for
_
,
sandbox
:=
range
fakeRuntime
.
Sandboxes
{
assert
.
Equal
(
t
,
runtimeapi
.
PodSandboxState_SANDBOX_NOTREADY
,
sandbox
.
GetState
()
)
assert
.
Equal
(
t
,
runtimeapi
.
PodSandboxState_SANDBOX_NOTREADY
,
sandbox
.
State
)
}
}
for
_
,
c
:=
range
fakeRuntime
.
Containers
{
for
_
,
c
:=
range
fakeRuntime
.
Containers
{
assert
.
Equal
(
t
,
runtimeapi
.
ContainerState_CONTAINER_EXITED
,
c
.
GetState
()
)
assert
.
Equal
(
t
,
runtimeapi
.
ContainerState_CONTAINER_EXITED
,
c
.
State
)
}
}
}
}
...
@@ -551,10 +551,10 @@ func TestSyncPod(t *testing.T) {
...
@@ -551,10 +551,10 @@ func TestSyncPod(t *testing.T) {
assert
.
Equal
(
t
,
2
,
len
(
fakeImage
.
Images
))
assert
.
Equal
(
t
,
2
,
len
(
fakeImage
.
Images
))
assert
.
Equal
(
t
,
1
,
len
(
fakeRuntime
.
Sandboxes
))
assert
.
Equal
(
t
,
1
,
len
(
fakeRuntime
.
Sandboxes
))
for
_
,
sandbox
:=
range
fakeRuntime
.
Sandboxes
{
for
_
,
sandbox
:=
range
fakeRuntime
.
Sandboxes
{
assert
.
Equal
(
t
,
runtimeapi
.
PodSandboxState_SANDBOX_READY
,
sandbox
.
GetState
()
)
assert
.
Equal
(
t
,
runtimeapi
.
PodSandboxState_SANDBOX_READY
,
sandbox
.
State
)
}
}
for
_
,
c
:=
range
fakeRuntime
.
Containers
{
for
_
,
c
:=
range
fakeRuntime
.
Containers
{
assert
.
Equal
(
t
,
runtimeapi
.
ContainerState_CONTAINER_RUNNING
,
c
.
GetState
()
)
assert
.
Equal
(
t
,
runtimeapi
.
ContainerState_CONTAINER_RUNNING
,
c
.
State
)
}
}
}
}
...
@@ -589,7 +589,7 @@ func TestPruneInitContainers(t *testing.T) {
...
@@ -589,7 +589,7 @@ func TestPruneInitContainers(t *testing.T) {
keep
:=
map
[
kubecontainer
.
ContainerID
]
int
{}
keep
:=
map
[
kubecontainer
.
ContainerID
]
int
{}
m
.
pruneInitContainersBeforeStart
(
pod
,
podStatus
,
keep
)
m
.
pruneInitContainersBeforeStart
(
pod
,
podStatus
,
keep
)
expectedContainers
:=
[]
string
{
fakes
[
0
]
.
GetId
(),
fakes
[
2
]
.
GetId
()
}
expectedContainers
:=
[]
string
{
fakes
[
0
]
.
Id
,
fakes
[
2
]
.
Id
}
if
actual
,
ok
:=
verifyFakeContainerList
(
fakeRuntime
,
expectedContainers
);
!
ok
{
if
actual
,
ok
:=
verifyFakeContainerList
(
fakeRuntime
,
expectedContainers
);
!
ok
{
t
.
Errorf
(
"expected %q, got %q"
,
expectedContainers
,
actual
)
t
.
Errorf
(
"expected %q, got %q"
,
expectedContainers
,
actual
)
}
}
...
@@ -635,11 +635,11 @@ func TestSyncPodWithInitContainers(t *testing.T) {
...
@@ -635,11 +635,11 @@ func TestSyncPodWithInitContainers(t *testing.T) {
buildContainerID
:=
func
(
pod
*
v1
.
Pod
,
container
v1
.
Container
)
string
{
buildContainerID
:=
func
(
pod
*
v1
.
Pod
,
container
v1
.
Container
)
string
{
uid
:=
string
(
pod
.
UID
)
uid
:=
string
(
pod
.
UID
)
sandboxID
:=
apitest
.
BuildSandboxName
(
&
runtimeapi
.
PodSandboxMetadata
{
sandboxID
:=
apitest
.
BuildSandboxName
(
&
runtimeapi
.
PodSandboxMetadata
{
Name
:
&
pod
.
Name
,
Name
:
pod
.
Name
,
Uid
:
&
uid
,
Uid
:
uid
,
Namespace
:
&
pod
.
Namespace
,
Namespace
:
pod
.
Namespace
,
})
})
return
apitest
.
BuildContainerName
(
&
runtimeapi
.
ContainerMetadata
{
Name
:
&
container
.
Name
},
sandboxID
)
return
apitest
.
BuildContainerName
(
&
runtimeapi
.
ContainerMetadata
{
Name
:
container
.
Name
},
sandboxID
)
}
}
backOff
:=
flowcontrol
.
NewBackOff
(
time
.
Second
,
time
.
Minute
)
backOff
:=
flowcontrol
.
NewBackOff
(
time
.
Second
,
time
.
Minute
)
...
...
pkg/kubelet/kuberuntime/kuberuntime_sandbox.go
View file @
53c20e36
...
@@ -41,7 +41,7 @@ func (m *kubeGenericRuntimeManager) createPodSandbox(pod *v1.Pod, attempt uint32
...
@@ -41,7 +41,7 @@ func (m *kubeGenericRuntimeManager) createPodSandbox(pod *v1.Pod, attempt uint32
}
}
// Create pod logs directory
// Create pod logs directory
err
=
m
.
osInterface
.
MkdirAll
(
podSandboxConfig
.
GetLogDirectory
()
,
0755
)
err
=
m
.
osInterface
.
MkdirAll
(
podSandboxConfig
.
LogDirectory
,
0755
)
if
err
!=
nil
{
if
err
!=
nil
{
message
:=
fmt
.
Sprintf
(
"Create pod log directory for pod %q failed: %v"
,
format
.
Pod
(
pod
),
err
)
message
:=
fmt
.
Sprintf
(
"Create pod log directory for pod %q failed: %v"
,
format
.
Pod
(
pod
),
err
)
glog
.
Errorf
(
message
)
glog
.
Errorf
(
message
)
...
@@ -65,10 +65,10 @@ func (m *kubeGenericRuntimeManager) generatePodSandboxConfig(pod *v1.Pod, attemp
...
@@ -65,10 +65,10 @@ func (m *kubeGenericRuntimeManager) generatePodSandboxConfig(pod *v1.Pod, attemp
podUID
:=
string
(
pod
.
UID
)
podUID
:=
string
(
pod
.
UID
)
podSandboxConfig
:=
&
runtimeapi
.
PodSandboxConfig
{
podSandboxConfig
:=
&
runtimeapi
.
PodSandboxConfig
{
Metadata
:
&
runtimeapi
.
PodSandboxMetadata
{
Metadata
:
&
runtimeapi
.
PodSandboxMetadata
{
Name
:
&
pod
.
Name
,
Name
:
pod
.
Name
,
Namespace
:
&
pod
.
Namespace
,
Namespace
:
pod
.
Namespace
,
Uid
:
&
podUID
,
Uid
:
podUID
,
Attempt
:
&
attempt
,
Attempt
:
attempt
,
},
},
Labels
:
newPodLabels
(
pod
),
Labels
:
newPodLabels
(
pod
),
Annotations
:
newPodAnnotations
(
pod
),
Annotations
:
newPodAnnotations
(
pod
),
...
@@ -89,11 +89,11 @@ func (m *kubeGenericRuntimeManager) generatePodSandboxConfig(pod *v1.Pod, attemp
...
@@ -89,11 +89,11 @@ func (m *kubeGenericRuntimeManager) generatePodSandboxConfig(pod *v1.Pod, attemp
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
podSandboxConfig
.
Hostname
=
&
hostname
podSandboxConfig
.
Hostname
=
hostname
}
}
logDir
:=
buildPodLogsDirectory
(
pod
.
UID
)
logDir
:=
buildPodLogsDirectory
(
pod
.
UID
)
podSandboxConfig
.
LogDirectory
=
&
logDir
podSandboxConfig
.
LogDirectory
=
logDir
cgroupParent
:=
""
cgroupParent
:=
""
portMappings
:=
[]
*
runtimeapi
.
PortMapping
{}
portMappings
:=
[]
*
runtimeapi
.
PortMapping
{}
...
@@ -110,10 +110,10 @@ func (m *kubeGenericRuntimeManager) generatePodSandboxConfig(pod *v1.Pod, attemp
...
@@ -110,10 +110,10 @@ func (m *kubeGenericRuntimeManager) generatePodSandboxConfig(pod *v1.Pod, attemp
containerPort
:=
int32
(
port
.
ContainerPort
)
containerPort
:=
int32
(
port
.
ContainerPort
)
protocol
:=
toRuntimeProtocol
(
port
.
Protocol
)
protocol
:=
toRuntimeProtocol
(
port
.
Protocol
)
portMappings
=
append
(
portMappings
,
&
runtimeapi
.
PortMapping
{
portMappings
=
append
(
portMappings
,
&
runtimeapi
.
PortMapping
{
HostIp
:
&
port
.
HostIP
,
HostIp
:
port
.
HostIP
,
HostPort
:
&
hostPort
,
HostPort
:
hostPort
,
ContainerPort
:
&
containerPort
,
ContainerPort
:
containerPort
,
Protocol
:
&
protocol
,
Protocol
:
protocol
,
})
})
}
}
...
@@ -131,20 +131,21 @@ func (m *kubeGenericRuntimeManager) generatePodSandboxConfig(pod *v1.Pod, attemp
...
@@ -131,20 +131,21 @@ func (m *kubeGenericRuntimeManager) generatePodSandboxConfig(pod *v1.Pod, attemp
// generatePodSandboxLinuxConfig generates LinuxPodSandboxConfig from v1.Pod.
// generatePodSandboxLinuxConfig generates LinuxPodSandboxConfig from v1.Pod.
func
(
m
*
kubeGenericRuntimeManager
)
generatePodSandboxLinuxConfig
(
pod
*
v1
.
Pod
,
cgroupParent
string
)
*
runtimeapi
.
LinuxPodSandboxConfig
{
func
(
m
*
kubeGenericRuntimeManager
)
generatePodSandboxLinuxConfig
(
pod
*
v1
.
Pod
,
cgroupParent
string
)
*
runtimeapi
.
LinuxPodSandboxConfig
{
lc
:=
&
runtimeapi
.
LinuxPodSandboxConfig
{
lc
:=
&
runtimeapi
.
LinuxPodSandboxConfig
{
SecurityContext
:
&
runtimeapi
.
LinuxSandboxSecurityContext
{},
CgroupParent
:
cgroupParent
,
}
SecurityContext
:
&
runtimeapi
.
LinuxSandboxSecurityContext
{
Privileged
:
kubecontainer
.
HasPrivilegedContainer
(
pod
),
if
cgroupParent
!=
""
{
},
lc
.
CgroupParent
=
&
cgroupParent
}
}
if
pod
.
Spec
.
SecurityContext
!=
nil
{
if
pod
.
Spec
.
SecurityContext
!=
nil
{
sc
:=
pod
.
Spec
.
SecurityContext
sc
:=
pod
.
Spec
.
SecurityContext
lc
.
SecurityContext
.
RunAsUser
=
sc
.
RunAsUser
if
sc
.
RunAsUser
!=
nil
{
lc
.
SecurityContext
.
RunAsUser
=
&
runtimeapi
.
Int64Value
{
Value
:
*
sc
.
RunAsUser
}
}
lc
.
SecurityContext
.
NamespaceOptions
=
&
runtimeapi
.
NamespaceOption
{
lc
.
SecurityContext
.
NamespaceOptions
=
&
runtimeapi
.
NamespaceOption
{
HostNetwork
:
&
pod
.
Spec
.
HostNetwork
,
HostNetwork
:
pod
.
Spec
.
HostNetwork
,
HostIpc
:
&
pod
.
Spec
.
HostIPC
,
HostIpc
:
pod
.
Spec
.
HostIPC
,
HostPid
:
&
pod
.
Spec
.
HostPID
,
HostPid
:
pod
.
Spec
.
HostPID
,
}
}
if
sc
.
FSGroup
!=
nil
{
if
sc
.
FSGroup
!=
nil
{
...
@@ -158,19 +159,14 @@ func (m *kubeGenericRuntimeManager) generatePodSandboxLinuxConfig(pod *v1.Pod, c
...
@@ -158,19 +159,14 @@ func (m *kubeGenericRuntimeManager) generatePodSandboxLinuxConfig(pod *v1.Pod, c
}
}
if
sc
.
SELinuxOptions
!=
nil
{
if
sc
.
SELinuxOptions
!=
nil
{
lc
.
SecurityContext
.
SelinuxOptions
=
&
runtimeapi
.
SELinuxOption
{
lc
.
SecurityContext
.
SelinuxOptions
=
&
runtimeapi
.
SELinuxOption
{
User
:
&
sc
.
SELinuxOptions
.
User
,
User
:
sc
.
SELinuxOptions
.
User
,
Role
:
&
sc
.
SELinuxOptions
.
Role
,
Role
:
sc
.
SELinuxOptions
.
Role
,
Type
:
&
sc
.
SELinuxOptions
.
Type
,
Type
:
sc
.
SELinuxOptions
.
Type
,
Level
:
&
sc
.
SELinuxOptions
.
Level
,
Level
:
sc
.
SELinuxOptions
.
Level
,
}
}
}
}
}
}
if
kubecontainer
.
HasPrivilegedContainer
(
pod
)
{
privileged
:=
true
lc
.
SecurityContext
.
Privileged
=
&
privileged
}
return
lc
return
lc
}
}
...
@@ -180,7 +176,9 @@ func (m *kubeGenericRuntimeManager) getKubeletSandboxes(all bool) ([]*runtimeapi
...
@@ -180,7 +176,9 @@ func (m *kubeGenericRuntimeManager) getKubeletSandboxes(all bool) ([]*runtimeapi
if
!
all
{
if
!
all
{
readyState
:=
runtimeapi
.
PodSandboxState_SANDBOX_READY
readyState
:=
runtimeapi
.
PodSandboxState_SANDBOX_READY
filter
=
&
runtimeapi
.
PodSandboxFilter
{
filter
=
&
runtimeapi
.
PodSandboxFilter
{
State
:
&
readyState
,
State
:
&
runtimeapi
.
PodSandboxStateValue
{
State
:
readyState
,
},
}
}
}
}
...
@@ -194,7 +192,7 @@ func (m *kubeGenericRuntimeManager) getKubeletSandboxes(all bool) ([]*runtimeapi
...
@@ -194,7 +192,7 @@ func (m *kubeGenericRuntimeManager) getKubeletSandboxes(all bool) ([]*runtimeapi
for
_
,
s
:=
range
resp
{
for
_
,
s
:=
range
resp
{
if
!
isManagedByKubelet
(
s
.
Labels
)
{
if
!
isManagedByKubelet
(
s
.
Labels
)
{
glog
.
V
(
5
)
.
Infof
(
"Sandbox %s is not managed by kubelet"
,
kubecontainer
.
BuildPodFullName
(
glog
.
V
(
5
)
.
Infof
(
"Sandbox %s is not managed by kubelet"
,
kubecontainer
.
BuildPodFullName
(
s
.
Metadata
.
GetName
(),
s
.
Metadata
.
GetNamespace
()
))
s
.
Metadata
.
Name
,
s
.
Metadata
.
Namespace
))
continue
continue
}
}
...
@@ -210,7 +208,7 @@ func (m *kubeGenericRuntimeManager) determinePodSandboxIP(podNamespace, podName
...
@@ -210,7 +208,7 @@ func (m *kubeGenericRuntimeManager) determinePodSandboxIP(podNamespace, podName
glog
.
Warningf
(
"Pod Sandbox status doesn't have network information, cannot report IP"
)
glog
.
Warningf
(
"Pod Sandbox status doesn't have network information, cannot report IP"
)
return
""
return
""
}
}
ip
:=
podSandbox
.
Network
.
GetIp
()
ip
:=
podSandbox
.
Network
.
Ip
if
net
.
ParseIP
(
ip
)
==
nil
{
if
net
.
ParseIP
(
ip
)
==
nil
{
glog
.
Warningf
(
"Pod Sandbox reported an unparseable IP %v"
,
ip
)
glog
.
Warningf
(
"Pod Sandbox reported an unparseable IP %v"
,
ip
)
return
""
return
""
...
@@ -222,9 +220,13 @@ func (m *kubeGenericRuntimeManager) determinePodSandboxIP(podNamespace, podName
...
@@ -222,9 +220,13 @@ func (m *kubeGenericRuntimeManager) determinePodSandboxIP(podNamespace, podName
// Param state could be nil in order to get all sandboxes belonging to same pod.
// Param state could be nil in order to get all sandboxes belonging to same pod.
func
(
m
*
kubeGenericRuntimeManager
)
getSandboxIDByPodUID
(
podUID
kubetypes
.
UID
,
state
*
runtimeapi
.
PodSandboxState
)
([]
string
,
error
)
{
func
(
m
*
kubeGenericRuntimeManager
)
getSandboxIDByPodUID
(
podUID
kubetypes
.
UID
,
state
*
runtimeapi
.
PodSandboxState
)
([]
string
,
error
)
{
filter
:=
&
runtimeapi
.
PodSandboxFilter
{
filter
:=
&
runtimeapi
.
PodSandboxFilter
{
State
:
state
,
LabelSelector
:
map
[
string
]
string
{
types
.
KubernetesPodUIDLabel
:
string
(
podUID
)},
LabelSelector
:
map
[
string
]
string
{
types
.
KubernetesPodUIDLabel
:
string
(
podUID
)},
}
}
if
state
!=
nil
{
filter
.
State
=
&
runtimeapi
.
PodSandboxStateValue
{
State
:
*
state
,
}
}
sandboxes
,
err
:=
m
.
runtimeService
.
ListPodSandbox
(
filter
)
sandboxes
,
err
:=
m
.
runtimeService
.
ListPodSandbox
(
filter
)
if
err
!=
nil
{
if
err
!=
nil
{
glog
.
Errorf
(
"ListPodSandbox with pod UID %q failed: %v"
,
podUID
,
err
)
glog
.
Errorf
(
"ListPodSandbox with pod UID %q failed: %v"
,
podUID
,
err
)
...
@@ -239,7 +241,7 @@ func (m *kubeGenericRuntimeManager) getSandboxIDByPodUID(podUID kubetypes.UID, s
...
@@ -239,7 +241,7 @@ func (m *kubeGenericRuntimeManager) getSandboxIDByPodUID(podUID kubetypes.UID, s
sandboxIDs
:=
make
([]
string
,
len
(
sandboxes
))
sandboxIDs
:=
make
([]
string
,
len
(
sandboxes
))
sort
.
Sort
(
podSandboxByCreated
(
sandboxes
))
sort
.
Sort
(
podSandboxByCreated
(
sandboxes
))
for
i
,
s
:=
range
sandboxes
{
for
i
,
s
:=
range
sandboxes
{
sandboxIDs
[
i
]
=
s
.
GetId
()
sandboxIDs
[
i
]
=
s
.
Id
}
}
return
sandboxIDs
,
nil
return
sandboxIDs
,
nil
...
@@ -256,11 +258,11 @@ func (m *kubeGenericRuntimeManager) GetPortForward(podName, podNamespace string,
...
@@ -256,11 +258,11 @@ func (m *kubeGenericRuntimeManager) GetPortForward(podName, podNamespace string,
}
}
// TODO: Port is unused for now, but we may need it in the future.
// TODO: Port is unused for now, but we may need it in the future.
req
:=
&
runtimeapi
.
PortForwardRequest
{
req
:=
&
runtimeapi
.
PortForwardRequest
{
PodSandboxId
:
&
sandboxIDs
[
0
],
PodSandboxId
:
sandboxIDs
[
0
],
}
}
resp
,
err
:=
m
.
runtimeService
.
PortForward
(
req
)
resp
,
err
:=
m
.
runtimeService
.
PortForward
(
req
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
return
url
.
Parse
(
resp
.
GetUrl
()
)
return
url
.
Parse
(
resp
.
Url
)
}
}
pkg/kubelet/kuberuntime/kuberuntime_sandbox_test.go
View file @
53c20e36
...
@@ -58,7 +58,7 @@ func TestCreatePodSandbox(t *testing.T) {
...
@@ -58,7 +58,7 @@ func TestCreatePodSandbox(t *testing.T) {
id
,
_
,
err
:=
m
.
createPodSandbox
(
pod
,
1
)
id
,
_
,
err
:=
m
.
createPodSandbox
(
pod
,
1
)
assert
.
NoError
(
t
,
err
)
assert
.
NoError
(
t
,
err
)
fakeRuntime
.
AssertCalls
([]
string
{
"RunPodSandbox"
})
fakeRuntime
.
AssertCalls
([]
string
{
"RunPodSandbox"
})
sandboxes
,
err
:=
fakeRuntime
.
ListPodSandbox
(
&
runtimeapi
.
PodSandboxFilter
{
Id
:
&
id
})
sandboxes
,
err
:=
fakeRuntime
.
ListPodSandbox
(
&
runtimeapi
.
PodSandboxFilter
{
Id
:
id
})
assert
.
NoError
(
t
,
err
)
assert
.
NoError
(
t
,
err
)
assert
.
Equal
(
t
,
len
(
sandboxes
),
1
)
assert
.
Equal
(
t
,
len
(
sandboxes
),
1
)
// TODO Check pod sandbox configuration
// TODO Check pod sandbox configuration
...
...
pkg/kubelet/kuberuntime/security_context.go
View file @
53c20e36
...
@@ -25,7 +25,7 @@ import (
...
@@ -25,7 +25,7 @@ import (
)
)
// determineEffectiveSecurityContext gets container's security context from v1.Pod and v1.Container.
// determineEffectiveSecurityContext gets container's security context from v1.Pod and v1.Container.
func
(
m
*
kubeGenericRuntimeManager
)
determineEffectiveSecurityContext
(
pod
*
v1
.
Pod
,
container
*
v1
.
Container
,
uid
*
int64
,
username
*
string
)
*
runtimeapi
.
LinuxContainerSecurityContext
{
func
(
m
*
kubeGenericRuntimeManager
)
determineEffectiveSecurityContext
(
pod
*
v1
.
Pod
,
container
*
v1
.
Container
,
uid
*
int64
,
username
string
)
*
runtimeapi
.
LinuxContainerSecurityContext
{
effectiveSc
:=
securitycontext
.
DetermineEffectiveSecurityContext
(
pod
,
container
)
effectiveSc
:=
securitycontext
.
DetermineEffectiveSecurityContext
(
pod
,
container
)
synthesized
:=
convertToRuntimeSecurityContext
(
effectiveSc
)
synthesized
:=
convertToRuntimeSecurityContext
(
effectiveSc
)
if
synthesized
==
nil
{
if
synthesized
==
nil
{
...
@@ -34,7 +34,9 @@ func (m *kubeGenericRuntimeManager) determineEffectiveSecurityContext(pod *v1.Po
...
@@ -34,7 +34,9 @@ func (m *kubeGenericRuntimeManager) determineEffectiveSecurityContext(pod *v1.Po
// set RunAsUser.
// set RunAsUser.
if
synthesized
.
RunAsUser
==
nil
{
if
synthesized
.
RunAsUser
==
nil
{
synthesized
.
RunAsUser
=
uid
if
uid
!=
nil
{
synthesized
.
RunAsUser
=
&
runtimeapi
.
Int64Value
{
Value
:
*
uid
}
}
synthesized
.
RunAsUsername
=
username
synthesized
.
RunAsUsername
=
username
}
}
...
@@ -44,9 +46,9 @@ func (m *kubeGenericRuntimeManager) determineEffectiveSecurityContext(pod *v1.Po
...
@@ -44,9 +46,9 @@ func (m *kubeGenericRuntimeManager) determineEffectiveSecurityContext(pod *v1.Po
return
synthesized
return
synthesized
}
}
synthesized
.
NamespaceOptions
=
&
runtimeapi
.
NamespaceOption
{
synthesized
.
NamespaceOptions
=
&
runtimeapi
.
NamespaceOption
{
HostNetwork
:
&
pod
.
Spec
.
HostNetwork
,
HostNetwork
:
pod
.
Spec
.
HostNetwork
,
HostIpc
:
&
pod
.
Spec
.
HostIPC
,
HostIpc
:
pod
.
Spec
.
HostIPC
,
HostPid
:
&
pod
.
Spec
.
HostPID
,
HostPid
:
pod
.
Spec
.
HostPID
,
}
}
if
podSc
.
FSGroup
!=
nil
{
if
podSc
.
FSGroup
!=
nil
{
synthesized
.
SupplementalGroups
=
append
(
synthesized
.
SupplementalGroups
,
*
podSc
.
FSGroup
)
synthesized
.
SupplementalGroups
=
append
(
synthesized
.
SupplementalGroups
,
*
podSc
.
FSGroup
)
...
@@ -88,13 +90,21 @@ func convertToRuntimeSecurityContext(securityContext *v1.SecurityContext) *runti
...
@@ -88,13 +90,21 @@ func convertToRuntimeSecurityContext(securityContext *v1.SecurityContext) *runti
return
nil
return
nil
}
}
return
&
runtimeapi
.
LinuxContainerSecurityContext
{
sc
:=
&
runtimeapi
.
LinuxContainerSecurityContext
{
RunAsUser
:
securityContext
.
RunAsUser
,
Privileged
:
securityContext
.
Privileged
,
ReadonlyRootfs
:
securityContext
.
ReadOnlyRootFilesystem
,
Capabilities
:
convertToRuntimeCapabilities
(
securityContext
.
Capabilities
),
Capabilities
:
convertToRuntimeCapabilities
(
securityContext
.
Capabilities
),
SelinuxOptions
:
convertToRuntimeSELinuxOption
(
securityContext
.
SELinuxOptions
),
SelinuxOptions
:
convertToRuntimeSELinuxOption
(
securityContext
.
SELinuxOptions
),
}
}
if
securityContext
.
RunAsUser
!=
nil
{
sc
.
RunAsUser
=
&
runtimeapi
.
Int64Value
{
Value
:
*
securityContext
.
RunAsUser
}
}
if
securityContext
.
Privileged
!=
nil
{
sc
.
Privileged
=
*
securityContext
.
Privileged
}
if
securityContext
.
ReadOnlyRootFilesystem
!=
nil
{
sc
.
ReadonlyRootfs
=
*
securityContext
.
ReadOnlyRootFilesystem
}
return
sc
}
}
// convertToRuntimeSELinuxOption converts v1.SELinuxOptions to runtimeapi.SELinuxOption.
// convertToRuntimeSELinuxOption converts v1.SELinuxOptions to runtimeapi.SELinuxOption.
...
@@ -104,10 +114,10 @@ func convertToRuntimeSELinuxOption(opts *v1.SELinuxOptions) *runtimeapi.SELinuxO
...
@@ -104,10 +114,10 @@ func convertToRuntimeSELinuxOption(opts *v1.SELinuxOptions) *runtimeapi.SELinuxO
}
}
return
&
runtimeapi
.
SELinuxOption
{
return
&
runtimeapi
.
SELinuxOption
{
User
:
&
opts
.
User
,
User
:
opts
.
User
,
Role
:
&
opts
.
Role
,
Role
:
opts
.
Role
,
Type
:
&
opts
.
Type
,
Type
:
opts
.
Type
,
Level
:
&
opts
.
Level
,
Level
:
opts
.
Level
,
}
}
}
}
...
...
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