From 08e4138c16f8f042f72024ba8b0b75ffebe8c7c5 Mon Sep 17 00:00:00 2001 From: MatthieuFin Date: Tue, 31 Aug 2021 17:43:09 +0200 Subject: [PATCH] Fix lint issue and test failed Signed-off-by: MatthieuFin --- pkg/restore/restic_restore_action.go | 9 ++--- pkg/restore/restic_restore_action_test.go | 2 +- pkg/util/kube/security_context_test.go | 42 +++++++++++------------ 3 files changed, 27 insertions(+), 26 deletions(-) diff --git a/pkg/restore/restic_restore_action.go b/pkg/restore/restic_restore_action.go index f72923efe..91b4a6761 100644 --- a/pkg/restore/restic_restore_action.go +++ b/pkg/restore/restic_restore_action.go @@ -245,6 +245,7 @@ func getResourceLimits(log logrus.FieldLogger, config *corev1.ConfigMap) (string return config.Data["cpuLimit"], config.Data["memLimit"] } + // getSecurityContext extracts securityContext runAsUser, runAsGroup, allowPrivilegeEscalation, and securityContext from a ConfigMap. func getSecurityContext(log logrus.FieldLogger, config *corev1.ConfigMap) (string, string, string, string) { if config == nil { @@ -252,10 +253,10 @@ func getSecurityContext(log logrus.FieldLogger, config *corev1.ConfigMap) (strin return "", "", "", "" } - return config.Data["secCtxRunAsUser"], - config.Data["secCtxRunAsGroup"], - config.Data["secCtxAllowPrivilegeEscalation"], - config.Data["secCtx"] + return config.Data["secCtxRunAsUser"], + config.Data["secCtxRunAsGroup"], + config.Data["secCtxAllowPrivilegeEscalation"], + config.Data["secCtx"] } // TODO eventually this can move to pkg/plugin/framework since it'll be used across multiple diff --git a/pkg/restore/restic_restore_action_test.go b/pkg/restore/restic_restore_action_test.go index 10148db68..b218f4b88 100644 --- a/pkg/restore/restic_restore_action_test.go +++ b/pkg/restore/restic_restore_action_test.go @@ -117,7 +117,7 @@ func TestResticRestoreActionExecute(t *testing.T) { defaultCPURequestLimit, defaultMemRequestLimit, // limits ) - securityContext, _ := kube.ParseSecurityContext("", "", "") + securityContext, _ := kube.ParseSecurityContext("", "", "", "") var ( restoreName = "my-restore" diff --git a/pkg/util/kube/security_context_test.go b/pkg/util/kube/security_context_test.go index 8ad72e49c..f4b9ccb7c 100644 --- a/pkg/util/kube/security_context_test.go +++ b/pkg/util/kube/security_context_test.go @@ -60,7 +60,7 @@ func TestParseSecurityContext(t *testing.T) { }, { "valid securityContext with comments only secCtx key", - args{"", "", "",` + args{"", "", "", ` capabilities: drop: - ALL @@ -81,16 +81,16 @@ readOnlyRootFilesystem: true allowPrivilegeEscalation: false`}, false, &corev1.SecurityContext{ - RunAsUser: pointInt64(3333), - RunAsGroup: pointInt64(3333), - Capabilities: &corev1.Capabilities{ + RunAsUser: pointInt64(3333), + RunAsGroup: pointInt64(3333), + Capabilities: &corev1.Capabilities{ Drop: []corev1.Capability{"ALL"}, - Add: []corev1.Capability{"cap1", "cap2"}, + Add: []corev1.Capability{"cap1", "cap2"}, }, - SELinuxOptions: &corev1.SELinuxOptions{ - User: "userLabel", - Role: "roleLabel", - Type: "typeLabel", + SELinuxOptions: &corev1.SELinuxOptions{ + User: "userLabel", + Role: "roleLabel", + Type: "typeLabel", Level: "levelLabel", }, RunAsNonRoot: boolptr.True(), @@ -100,7 +100,7 @@ allowPrivilegeEscalation: false`}, }, { "valid securityContext with secCtx key override runAsUser runAsGroup and allowPrivilegeEscalation", - args{"1001", "999", "true",` + args{"1001", "999", "true", ` capabilities: drop: - ALL @@ -121,16 +121,16 @@ readOnlyRootFilesystem: true allowPrivilegeEscalation: false`}, false, &corev1.SecurityContext{ - RunAsUser: pointInt64(3333), - RunAsGroup: pointInt64(3333), - Capabilities: &corev1.Capabilities{ + RunAsUser: pointInt64(3333), + RunAsGroup: pointInt64(3333), + Capabilities: &corev1.Capabilities{ Drop: []corev1.Capability{"ALL"}, - Add: []corev1.Capability{"cap1", "cap2"}, + Add: []corev1.Capability{"cap1", "cap2"}, }, - SELinuxOptions: &corev1.SELinuxOptions{ - User: "userLabel", - Role: "roleLabel", - Type: "typeLabel", + SELinuxOptions: &corev1.SELinuxOptions{ + User: "userLabel", + Role: "roleLabel", + Type: "typeLabel", Level: "levelLabel", }, RunAsNonRoot: boolptr.True(), @@ -157,7 +157,7 @@ allowPrivilegeEscalation: false`}, {"empty context without runAsUser", args{"", "", "", ""}, false, &corev1.SecurityContext{}}, { "invalid securityContext secCtx unknown key", - args{"", "", "",` + args{"", "", "", ` capabilitiesUnknownkey: drop: - ALL @@ -175,7 +175,7 @@ allowPrivilegeEscalation: false`}, }, { "invalid securityContext secCtx wrong value type string instead of bool", - args{"", "", "",` + args{"", "", "", ` capabilitiesUnknownkey: drop: - ALL @@ -193,7 +193,7 @@ allowPrivilegeEscalation: false`}, }, { "invalid securityContext secCtx wrong value type string instead of int", - args{"", "", "",` + args{"", "", "", ` capabilitiesUnknownkey: drop: - ALL