Add build tags and Improve the test case of selinux
- Add build tags - Fixes a bug because of my negligence - Improve the test case of selinux Signed-off-by: Yanqiang Miao <miao.yanqiang@zte.com.cn> test
This commit is contained in:
parent
3647ff5976
commit
7096027d21
10
Makefile
10
Makefile
@ -24,7 +24,10 @@ VERSION := $(shell git describe --tags --dirty)
|
|||||||
# strip the first char of the tag if it's a `v`
|
# strip the first char of the tag if it's a `v`
|
||||||
VERSION := $(VERSION:v%=%)
|
VERSION := $(VERSION:v%=%)
|
||||||
TARBALL ?= cri-containerd-$(VERSION).tar.gz
|
TARBALL ?= cri-containerd-$(VERSION).tar.gz
|
||||||
BUILD_TAGS:= -ldflags '-X $(PROJECT)/pkg/version.criContainerdVersion=$(VERSION)'
|
ifdef BUILD_TAGS
|
||||||
|
BUILD_TAGS := -tags $(BUILD_TAGS)
|
||||||
|
endif
|
||||||
|
GO_LDFLAGS := -ldflags '-X $(PROJECT)/pkg/version.criContainerdVersion=$(VERSION)'
|
||||||
SOURCES := $(shell find . -name '*.go')
|
SOURCES := $(shell find . -name '*.go')
|
||||||
|
|
||||||
all: binaries
|
all: binaries
|
||||||
@ -68,8 +71,7 @@ boiler:
|
|||||||
|
|
||||||
$(BUILD_DIR)/cri-containerd: $(SOURCES)
|
$(BUILD_DIR)/cri-containerd: $(SOURCES)
|
||||||
$(GO) build -o $@ \
|
$(GO) build -o $@ \
|
||||||
$(BUILD_TAGS) \
|
$(BUILD_TAGS) $(GO_LDFLAGS) $(GO_GCFLAGS) \
|
||||||
$(GO_LDFLAGS) $(GO_GCFLAGS) \
|
|
||||||
$(PROJECT)/cmd/cri-containerd
|
$(PROJECT)/cmd/cri-containerd
|
||||||
|
|
||||||
test:
|
test:
|
||||||
@ -86,7 +88,7 @@ clean:
|
|||||||
|
|
||||||
binaries: $(BUILD_DIR)/cri-containerd
|
binaries: $(BUILD_DIR)/cri-containerd
|
||||||
|
|
||||||
static-binaries: GO_LDFLAGS=--ldflags '-extldflags "-fno-PIC -static"'
|
static-binaries: GO_LDFLAGS += --ldflags '-extldflags "-fno-PIC -static"'
|
||||||
static-binaries: $(BUILD_DIR)/cri-containerd
|
static-binaries: $(BUILD_DIR)/cri-containerd
|
||||||
|
|
||||||
install: binaries
|
install: binaries
|
||||||
|
@ -368,11 +368,19 @@ func initSelinuxOpts(selinuxOpt *runtime.SELinuxOption) (string, string, error)
|
|||||||
return "", "", nil
|
return "", "", nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Should ignored selinuxOpts if they are incomplete.
|
||||||
|
if selinuxOpt.GetUser() == "" ||
|
||||||
|
selinuxOpt.GetRole() == "" ||
|
||||||
|
selinuxOpt.GetType() == "" ||
|
||||||
|
selinuxOpt.GetLevel() == "" {
|
||||||
|
return "", "", nil
|
||||||
|
}
|
||||||
|
|
||||||
labelOpts := fmt.Sprintf("%s:%s:%s:%s",
|
labelOpts := fmt.Sprintf("%s:%s:%s:%s",
|
||||||
selinuxOpt.GetUser(),
|
selinuxOpt.GetUser(),
|
||||||
selinuxOpt.GetRole(),
|
selinuxOpt.GetRole(),
|
||||||
selinuxOpt.GetRole(),
|
selinuxOpt.GetType(),
|
||||||
selinuxOpt.GetType())
|
selinuxOpt.GetLevel())
|
||||||
return label.InitLabels(selinux.DupSecOpt(labelOpts))
|
return label.InitLabels(selinux.DupSecOpt(labelOpts))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,22 +36,22 @@ func TestInitSelinuxOpts(t *testing.T) {
|
|||||||
processLabel string
|
processLabel string
|
||||||
mountLabels []string
|
mountLabels []string
|
||||||
}{
|
}{
|
||||||
"testNullValue": {
|
"Should return empty strings for processLabel and mountLabel when selinuxOpt is nil": {
|
||||||
selinuxOpt: nil,
|
selinuxOpt: nil,
|
||||||
processLabel: "",
|
processLabel: "",
|
||||||
mountLabels: []string{"", ""},
|
mountLabels: []string{"", ""},
|
||||||
},
|
},
|
||||||
"testEmptyString": {
|
"Should return empty strings for processLabel and mountLabel when selinuxOpt has been initialized partially": {
|
||||||
selinuxOpt: &runtime.SELinuxOption{
|
selinuxOpt: &runtime.SELinuxOption{
|
||||||
User: "",
|
User: "",
|
||||||
Role: "",
|
Role: "user_r",
|
||||||
Type: "",
|
Type: "",
|
||||||
Level: "",
|
Level: "s0:c1,c2",
|
||||||
},
|
},
|
||||||
processLabel: ":::",
|
processLabel: "",
|
||||||
mountLabels: []string{":object_r:container_file_t:", ":object_r:svirt_sandbox_file_t:"},
|
mountLabels: []string{"", ""},
|
||||||
},
|
},
|
||||||
"testUser": {
|
"Should be resolved correctly when selinuxOpt has been initialized completely": {
|
||||||
selinuxOpt: &runtime.SELinuxOption{
|
selinuxOpt: &runtime.SELinuxOption{
|
||||||
User: "user_u",
|
User: "user_u",
|
||||||
Role: "user_r",
|
Role: "user_r",
|
||||||
|
Loading…
Reference in New Issue
Block a user