Skip to content

Commit 81d32eb

Browse files
committed
Use IsAppArmorEnabled of Kubernetes instead of local one
The function is now available so we can use this one instead of our own implementation. Signed-off-by: Sascha Grunert <[email protected]>
1 parent cd664e8 commit 81d32eb

File tree

1 file changed

+2
-16
lines changed

1 file changed

+2
-16
lines changed

pkg/validate/apparmor.go

+2-16
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
"github.com/kubernetes-sigs/cri-tools/pkg/framework"
2828
internalapi "k8s.io/cri-api/pkg/apis"
2929
runtimeapi "k8s.io/cri-api/pkg/apis/runtime/v1alpha2"
30+
"k8s.io/kubernetes/pkg/security/apparmor"
3031

3132
"github.com/golang/glog"
3233
. "github.com/onsi/ginkgo"
@@ -58,7 +59,7 @@ var _ = framework.KubeDescribe("AppArmor", func() {
5859
var rc internalapi.RuntimeService
5960
var ic internalapi.ImageManagerService
6061

61-
if isAppArmorEnabled() {
62+
if apparmor.IsAppArmorEnabled() {
6263
BeforeEach(func() {
6364
rc = f.CRIClient.CRIRuntimeClient
6465
ic = f.CRIClient.CRIImageClient
@@ -177,18 +178,3 @@ func loadTestProfiles() error {
177178
glog.V(2).Infof("Loaded profiles: %v", out)
178179
return nil
179180
}
180-
181-
// isAppArmorEnabled returns true if apparmor is enabled for the host.
182-
// This function is forked from
183-
// https://github.com/opencontainers/runc/blob/1a81e9ab1f138c091fe5c86d0883f87716088527/libcontainer/apparmor/apparmor.go
184-
// to avoid the libapparmor dependency.
185-
// TODO: replace with k8s.io/kubernetes/pkg/security/apparmor when vendor is possible.
186-
func isAppArmorEnabled() bool {
187-
if _, err := os.Stat("/sys/kernel/security/apparmor"); err == nil && os.Getenv("container") == "" {
188-
if _, err = os.Stat("/sbin/apparmor_parser"); err == nil {
189-
buf, err := ioutil.ReadFile("/sys/module/apparmor/parameters/enabled")
190-
return err == nil && len(buf) > 1 && buf[0] == 'Y'
191-
}
192-
}
193-
return false
194-
}

0 commit comments

Comments
 (0)