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
2a2a8756
Commit
2a2a8756
authored
Nov 22, 2017
by
Pengfei Ni
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix incorrect localhost seccomp profile path
parent
6b97376a
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
106 additions
and
1 deletion
+106
-1
fake_kuberuntime_manager.go
pkg/kubelet/kuberuntime/fake_kuberuntime_manager.go
+5
-0
helpers.go
pkg/kubelet/kuberuntime/helpers.go
+1
-1
helpers_test.go
pkg/kubelet/kuberuntime/helpers_test.go
+100
-0
No files found.
pkg/kubelet/kuberuntime/fake_kuberuntime_manager.go
View file @
2a2a8756
...
@@ -33,6 +33,10 @@ import (
...
@@ -33,6 +33,10 @@ import (
proberesults
"k8s.io/kubernetes/pkg/kubelet/prober/results"
proberesults
"k8s.io/kubernetes/pkg/kubelet/prober/results"
)
)
const
(
fakeSeccompProfileRoot
=
"/fakeSeccompProfileRoot"
)
type
fakeHTTP
struct
{
type
fakeHTTP
struct
{
url
string
url
string
err
error
err
error
...
@@ -78,6 +82,7 @@ func NewFakeKubeRuntimeManager(runtimeService internalapi.RuntimeService, imageS
...
@@ -78,6 +82,7 @@ func NewFakeKubeRuntimeManager(runtimeService internalapi.RuntimeService, imageS
runtimeService
:
runtimeService
,
runtimeService
:
runtimeService
,
imageService
:
imageService
,
imageService
:
imageService
,
keyring
:
keyring
,
keyring
:
keyring
,
seccompProfileRoot
:
fakeSeccompProfileRoot
,
internalLifecycle
:
cm
.
NewFakeInternalContainerLifecycle
(),
internalLifecycle
:
cm
.
NewFakeInternalContainerLifecycle
(),
}
}
...
...
pkg/kubelet/kuberuntime/helpers.go
View file @
2a2a8756
...
@@ -273,7 +273,7 @@ func (m *kubeGenericRuntimeManager) getSeccompProfileFromAnnotations(annotations
...
@@ -273,7 +273,7 @@ func (m *kubeGenericRuntimeManager) getSeccompProfileFromAnnotations(annotations
if
strings
.
HasPrefix
(
profile
,
"localhost/"
)
{
if
strings
.
HasPrefix
(
profile
,
"localhost/"
)
{
name
:=
strings
.
TrimPrefix
(
profile
,
"localhost/"
)
name
:=
strings
.
TrimPrefix
(
profile
,
"localhost/"
)
fname
:=
filepath
.
Join
(
m
.
seccompProfileRoot
,
filepath
.
FromSlash
(
name
))
fname
:=
filepath
.
Join
(
m
.
seccompProfileRoot
,
filepath
.
FromSlash
(
name
))
return
fname
return
"localhost/"
+
fname
}
}
return
profile
return
profile
...
...
pkg/kubelet/kuberuntime/helpers_test.go
View file @
2a2a8756
...
@@ -17,9 +17,12 @@ limitations under the License.
...
@@ -17,9 +17,12 @@ limitations under the License.
package
kuberuntime
package
kuberuntime
import
(
import
(
"path/filepath"
"testing"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"k8s.io/api/core/v1"
"k8s.io/api/core/v1"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
runtimetesting
"k8s.io/kubernetes/pkg/kubelet/apis/cri/testing"
runtimetesting
"k8s.io/kubernetes/pkg/kubelet/apis/cri/testing"
...
@@ -205,3 +208,100 @@ func TestGetImageUser(t *testing.T) {
...
@@ -205,3 +208,100 @@ func TestGetImageUser(t *testing.T) {
assert
.
Equal
(
t
,
test
.
expectedImageUserValues
.
username
,
username
,
"TestCase[%d]"
,
j
)
assert
.
Equal
(
t
,
test
.
expectedImageUserValues
.
username
,
username
,
"TestCase[%d]"
,
j
)
}
}
}
}
func
TestGetSeccompProfileFromAnnotations
(
t
*
testing
.
T
)
{
_
,
_
,
m
,
err
:=
createTestRuntimeManager
()
require
.
NoError
(
t
,
err
)
tests
:=
[]
struct
{
description
string
annotation
map
[
string
]
string
containerName
string
expectedProfile
string
}{
{
description
:
"no seccomp should return empty string"
,
expectedProfile
:
""
,
},
{
description
:
"no seccomp with containerName should return exmpty string"
,
containerName
:
"container1"
,
expectedProfile
:
""
,
},
{
description
:
"pod docker/default seccomp profile should return docker/default"
,
annotation
:
map
[
string
]
string
{
v1
.
SeccompPodAnnotationKey
:
"docker/default"
,
},
expectedProfile
:
"docker/default"
,
},
{
description
:
"pod docker/default seccomp profile with containerName should return docker/default"
,
annotation
:
map
[
string
]
string
{
v1
.
SeccompPodAnnotationKey
:
"docker/default"
,
},
containerName
:
"container1"
,
expectedProfile
:
"docker/default"
,
},
{
description
:
"pod unconfined seccomp profile should return unconfined"
,
annotation
:
map
[
string
]
string
{
v1
.
SeccompPodAnnotationKey
:
"unconfined"
,
},
expectedProfile
:
"unconfined"
,
},
{
description
:
"pod unconfined seccomp profile with containerName should return unconfined"
,
annotation
:
map
[
string
]
string
{
v1
.
SeccompPodAnnotationKey
:
"unconfined"
,
},
containerName
:
"container1"
,
expectedProfile
:
"unconfined"
,
},
{
description
:
"pod localhost seccomp profile should return local profile path"
,
annotation
:
map
[
string
]
string
{
v1
.
SeccompPodAnnotationKey
:
"localhost/chmod.json"
,
},
expectedProfile
:
"localhost/"
+
filepath
.
Join
(
fakeSeccompProfileRoot
,
"chmod.json"
),
},
{
description
:
"pod localhost seccomp profile with containerName should return local profile path"
,
annotation
:
map
[
string
]
string
{
v1
.
SeccompPodAnnotationKey
:
"localhost/chmod.json"
,
},
containerName
:
"container1"
,
expectedProfile
:
"localhost/"
+
filepath
.
Join
(
fakeSeccompProfileRoot
,
"chmod.json"
),
},
{
description
:
"container localhost seccomp profile with containerName should return local profile path"
,
annotation
:
map
[
string
]
string
{
v1
.
SeccompContainerAnnotationKeyPrefix
+
"container1"
:
"localhost/chmod.json"
,
},
containerName
:
"container1"
,
expectedProfile
:
"localhost/"
+
filepath
.
Join
(
fakeSeccompProfileRoot
,
"chmod.json"
),
},
{
description
:
"container localhost seccomp profile should override pod profile"
,
annotation
:
map
[
string
]
string
{
v1
.
SeccompPodAnnotationKey
:
"unconfined"
,
v1
.
SeccompContainerAnnotationKeyPrefix
+
"container1"
:
"localhost/chmod.json"
,
},
containerName
:
"container1"
,
expectedProfile
:
"localhost/"
+
filepath
.
Join
(
fakeSeccompProfileRoot
,
"chmod.json"
),
},
{
description
:
"container localhost seccomp profile with unmatched containerName should return empty string"
,
annotation
:
map
[
string
]
string
{
v1
.
SeccompContainerAnnotationKeyPrefix
+
"container1"
:
"localhost/chmod.json"
,
},
containerName
:
"container2"
,
expectedProfile
:
""
,
},
}
for
i
,
test
:=
range
tests
{
seccompProfile
:=
m
.
getSeccompProfileFromAnnotations
(
test
.
annotation
,
test
.
containerName
)
assert
.
Equal
(
t
,
test
.
expectedProfile
,
seccompProfile
,
"TestCase[%d]"
,
i
)
}
}
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