Skip to content

Commit e9edbf1

Browse files
committed
Clean unused code in pkg/securitycontext/util.go
1 parent a1cc48b commit e9edbf1

File tree

2 files changed

+0
-85
lines changed

2 files changed

+0
-85
lines changed

pkg/securitycontext/util.go

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@ limitations under the License.
1717
package securitycontext
1818

1919
import (
20-
"fmt"
21-
"strings"
22-
2320
"k8s.io/api/core/v1"
2421
)
2522

@@ -47,26 +44,6 @@ func HasCapabilitiesRequest(container *v1.Container) bool {
4744
return len(container.SecurityContext.Capabilities.Add) > 0 || len(container.SecurityContext.Capabilities.Drop) > 0
4845
}
4946

50-
const expectedSELinuxFields = 4
51-
52-
// ParseSELinuxOptions parses a string containing a full SELinux context
53-
// (user, role, type, and level) into an SELinuxOptions object. If the
54-
// context is malformed, an error is returned.
55-
func ParseSELinuxOptions(context string) (*v1.SELinuxOptions, error) {
56-
fields := strings.SplitN(context, ":", expectedSELinuxFields)
57-
58-
if len(fields) != expectedSELinuxFields {
59-
return nil, fmt.Errorf("expected %v fields in selinux; got %v (context: %v)", expectedSELinuxFields, len(fields), context)
60-
}
61-
62-
return &v1.SELinuxOptions{
63-
User: fields[0],
64-
Role: fields[1],
65-
Type: fields[2],
66-
Level: fields[3],
67-
}, nil
68-
}
69-
7047
func DetermineEffectiveSecurityContext(pod *v1.Pod, container *v1.Container) *v1.SecurityContext {
7148
effectiveSc := securityContextFromPodSecurityContext(pod)
7249
containerSc := container.SecurityContext

pkg/securitycontext/util_test.go

Lines changed: 0 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -23,68 +23,6 @@ import (
2323
"k8s.io/api/core/v1"
2424
)
2525

26-
func TestParseSELinuxOptions(t *testing.T) {
27-
cases := []struct {
28-
name string
29-
input string
30-
expected *v1.SELinuxOptions
31-
}{
32-
{
33-
name: "simple",
34-
input: "user_t:role_t:type_t:s0",
35-
expected: &v1.SELinuxOptions{
36-
User: "user_t",
37-
Role: "role_t",
38-
Type: "type_t",
39-
Level: "s0",
40-
},
41-
},
42-
{
43-
name: "simple + categories",
44-
input: "user_t:role_t:type_t:s0:c0",
45-
expected: &v1.SELinuxOptions{
46-
User: "user_t",
47-
Role: "role_t",
48-
Type: "type_t",
49-
Level: "s0:c0",
50-
},
51-
},
52-
{
53-
name: "not enough fields",
54-
input: "type_t:s0:c0",
55-
},
56-
}
57-
58-
for _, tc := range cases {
59-
result, err := ParseSELinuxOptions(tc.input)
60-
61-
if err != nil {
62-
if tc.expected == nil {
63-
continue
64-
} else {
65-
t.Errorf("%v: unexpected error: %v", tc.name, err)
66-
}
67-
}
68-
69-
compareContexts(tc.name, tc.expected, result, t)
70-
}
71-
}
72-
73-
func compareContexts(name string, ex, ac *v1.SELinuxOptions, t *testing.T) {
74-
if e, a := ex.User, ac.User; e != a {
75-
t.Errorf("%v: expected user: %v, got: %v", name, e, a)
76-
}
77-
if e, a := ex.Role, ac.Role; e != a {
78-
t.Errorf("%v: expected role: %v, got: %v", name, e, a)
79-
}
80-
if e, a := ex.Type, ac.Type; e != a {
81-
t.Errorf("%v: expected type: %v, got: %v", name, e, a)
82-
}
83-
if e, a := ex.Level, ac.Level; e != a {
84-
t.Errorf("%v: expected level: %v, got: %v", name, e, a)
85-
}
86-
}
87-
8826
func TestAddNoNewPrivileges(t *testing.T) {
8927
pfalse := false
9028
ptrue := true

0 commit comments

Comments
 (0)