Skip to content

Commit 2716aa7

Browse files
committed
update cmd/runtimetest to 0.3.0
Signed-off-by: liangchenye <[email protected]>
1 parent df0afd1 commit 2716aa7

File tree

1 file changed

+13
-25
lines changed

1 file changed

+13
-25
lines changed

cmd/runtimetest/main.go

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -15,37 +15,25 @@ import (
1515
"github.com/syndtr/gocapability/capability"
1616
)
1717

18-
type validation func(*specs.LinuxSpec, *specs.LinuxRuntimeSpec) error
18+
type validation func(*specs.LinuxSpec) error
1919

20-
func loadSpecConfig() (spec *specs.LinuxSpec, rspec *specs.LinuxRuntimeSpec, err error) {
20+
func loadSpecConfig() (spec *specs.LinuxSpec, err error) {
2121
cPath := "config.json"
2222
cf, err := os.Open(cPath)
2323
if err != nil {
2424
if os.IsNotExist(err) {
25-
return nil, nil, fmt.Errorf("config.json not found")
25+
return nil, fmt.Errorf("config.json not found")
2626
}
2727
}
2828
defer cf.Close()
2929

30-
rPath := "runtime.json"
31-
rf, err := os.Open(rPath)
32-
if err != nil {
33-
if os.IsNotExist(err) {
34-
return nil, nil, fmt.Errorf("runtime.json not found")
35-
}
36-
}
37-
defer rf.Close()
38-
3930
if err = json.NewDecoder(cf).Decode(&spec); err != nil {
4031
return
4132
}
42-
if err = json.NewDecoder(rf).Decode(&rspec); err != nil {
43-
return
44-
}
45-
return spec, rspec, nil
33+
return spec, nil
4634
}
4735

48-
func validateProcess(spec *specs.LinuxSpec, rspec *specs.LinuxRuntimeSpec) error {
36+
func validateProcess(spec *specs.LinuxSpec) error {
4937
fmt.Println("validating container process")
5038
uid := os.Getuid()
5139
if uint32(uid) != spec.Process.User.UID {
@@ -110,7 +98,7 @@ func validateProcess(spec *specs.LinuxSpec, rspec *specs.LinuxRuntimeSpec) error
11098
return nil
11199
}
112100

113-
func validateCapabilities(spec *specs.LinuxSpec, rspec *specs.LinuxRuntimeSpec) error {
101+
func validateCapabilities(spec *specs.LinuxSpec) error {
114102
fmt.Println("validating capabilities")
115103
capabilityMap := make(map[string]capability.Cap)
116104
expectedCaps := make(map[capability.Cap]bool)
@@ -152,7 +140,7 @@ func validateCapabilities(spec *specs.LinuxSpec, rspec *specs.LinuxRuntimeSpec)
152140
return nil
153141
}
154142

155-
func validateHostname(spec *specs.LinuxSpec, rspec *specs.LinuxRuntimeSpec) error {
143+
func validateHostname(spec *specs.LinuxSpec) error {
156144
fmt.Println("validating hostname")
157145
hostname, err := os.Hostname()
158146
if err != nil {
@@ -164,9 +152,9 @@ func validateHostname(spec *specs.LinuxSpec, rspec *specs.LinuxRuntimeSpec) erro
164152
return nil
165153
}
166154

167-
func validateRlimits(spec *specs.LinuxSpec, rspec *specs.LinuxRuntimeSpec) error {
155+
func validateRlimits(spec *specs.LinuxSpec) error {
168156
fmt.Println("validating rlimits")
169-
for _, r := range rspec.Linux.Rlimits {
157+
for _, r := range spec.Linux.Rlimits {
170158
rl, err := strToRlimit(r.Type)
171159
if err != nil {
172160
return err
@@ -187,9 +175,9 @@ func validateRlimits(spec *specs.LinuxSpec, rspec *specs.LinuxRuntimeSpec) error
187175
return nil
188176
}
189177

190-
func validateSysctls(spec *specs.LinuxSpec, rspec *specs.LinuxRuntimeSpec) error {
178+
func validateSysctls(spec *specs.LinuxSpec) error {
191179
fmt.Println("validating sysctls")
192-
for k, v := range rspec.Linux.Sysctl {
180+
for k, v := range spec.Linux.Sysctl {
193181
keyPath := filepath.Join("/proc/sys", strings.Replace(k, ".", "/", -1))
194182
vBytes, err := ioutil.ReadFile(keyPath)
195183
if err != nil {
@@ -204,7 +192,7 @@ func validateSysctls(spec *specs.LinuxSpec, rspec *specs.LinuxRuntimeSpec) error
204192
}
205193

206194
func main() {
207-
spec, rspec, err := loadSpecConfig()
195+
spec, err := loadSpecConfig()
208196
if err != nil {
209197
logrus.Fatalf("Failed to load configuration: %q", err)
210198
}
@@ -218,7 +206,7 @@ func main() {
218206
}
219207

220208
for _, v := range validations {
221-
if err := v(spec, rspec); err != nil {
209+
if err := v(spec); err != nil {
222210
logrus.Fatalf("Validation failed: %q", err)
223211
}
224212
}

0 commit comments

Comments
 (0)