From 358dec9f3d85264883cc39b20d175b40ee6a0490 Mon Sep 17 00:00:00 2001 From: clarklee92 Date: Tue, 29 Oct 2019 17:32:42 +0800 Subject: [PATCH] Use log functions of core framework on test/e2e/freamwork/psp.go Signed-off-by: clarklee92 --- test/e2e/auth/BUILD | 1 - test/e2e/auth/pod_security_policy.go | 3 +-- test/e2e/framework/BUILD | 7 ++++-- test/e2e/framework/framework.go | 3 +-- test/e2e/framework/{psp => }/psp.go | 18 +++----------- test/e2e/framework/psp/BUILD | 37 ---------------------------- 6 files changed, 11 insertions(+), 58 deletions(-) rename test/e2e/framework/{psp => }/psp.go (88%) delete mode 100644 test/e2e/framework/psp/BUILD diff --git a/test/e2e/auth/BUILD b/test/e2e/auth/BUILD index af36585cefa..ee57ae784eb 100644 --- a/test/e2e/auth/BUILD +++ b/test/e2e/auth/BUILD @@ -58,7 +58,6 @@ go_library( "//test/e2e/framework/job:go_default_library", "//test/e2e/framework/node:go_default_library", "//test/e2e/framework/pod:go_default_library", - "//test/e2e/framework/psp:go_default_library", "//test/utils:go_default_library", "//test/utils/image:go_default_library", "//vendor/github.com/evanphx/json-patch:go_default_library", diff --git a/test/e2e/auth/pod_security_policy.go b/test/e2e/auth/pod_security_policy.go index d5890f62c54..ad14029e592 100644 --- a/test/e2e/auth/pod_security_policy.go +++ b/test/e2e/auth/pod_security_policy.go @@ -35,7 +35,6 @@ import ( "k8s.io/kubernetes/test/e2e/framework" "k8s.io/kubernetes/test/e2e/framework/auth" e2epod "k8s.io/kubernetes/test/e2e/framework/pod" - e2epsp "k8s.io/kubernetes/test/e2e/framework/psp" imageutils "k8s.io/kubernetes/test/utils/image" utilpointer "k8s.io/utils/pointer" @@ -54,7 +53,7 @@ var _ = SIGDescribe("PodSecurityPolicy", func() { var c clientset.Interface var ns string // Test namespace, for convenience ginkgo.BeforeEach(func() { - if !e2epsp.IsPodSecurityPolicyEnabled(f.ClientSet) { + if !framework.IsPodSecurityPolicyEnabled(f.ClientSet) { framework.Skipf("PodSecurityPolicy not enabled") } if !auth.IsRBACEnabled(f.ClientSet.RbacV1()) { diff --git a/test/e2e/framework/BUILD b/test/e2e/framework/BUILD index ada009b6e8d..5d7c402ed38 100644 --- a/test/e2e/framework/BUILD +++ b/test/e2e/framework/BUILD @@ -18,6 +18,7 @@ go_library( "pods.go", "profile_gatherer.go", "provider.go", + "psp.go", "rc_util.go", "resource_usage_gatherer.go", "size.go", @@ -38,9 +39,11 @@ go_library( "//pkg/kubelet/events:go_default_library", "//pkg/kubelet/sysctl:go_default_library", "//pkg/master/ports:go_default_library", + "//pkg/security/podsecuritypolicy/seccomp:go_default_library", "//pkg/util/taints:go_default_library", "//staging/src/k8s.io/api/apps/v1:go_default_library", "//staging/src/k8s.io/api/core/v1:go_default_library", + "//staging/src/k8s.io/api/policy/v1beta1:go_default_library", "//staging/src/k8s.io/api/rbac/v1:go_default_library", "//staging/src/k8s.io/api/storage/v1:go_default_library", "//staging/src/k8s.io/api/storage/v1beta1:go_default_library", @@ -59,6 +62,7 @@ go_library( "//staging/src/k8s.io/apimachinery/pkg/util/wait:go_default_library", "//staging/src/k8s.io/apimachinery/pkg/util/yaml:go_default_library", "//staging/src/k8s.io/apimachinery/pkg/watch:go_default_library", + "//staging/src/k8s.io/apiserver/pkg/authentication/serviceaccount:go_default_library", "//staging/src/k8s.io/apiserver/pkg/util/feature:go_default_library", "//staging/src/k8s.io/client-go/discovery:go_default_library", "//staging/src/k8s.io/client-go/discovery/cached/memory:go_default_library", @@ -76,12 +80,12 @@ go_library( "//staging/src/k8s.io/client-go/tools/watch:go_default_library", "//staging/src/k8s.io/component-base/cli/flag:go_default_library", "//staging/src/k8s.io/component-base/version:go_default_library", + "//test/e2e/framework/auth:go_default_library", "//test/e2e/framework/ginkgowrapper:go_default_library", "//test/e2e/framework/kubelet:go_default_library", "//test/e2e/framework/metrics:go_default_library", "//test/e2e/framework/node:go_default_library", "//test/e2e/framework/pod:go_default_library", - "//test/e2e/framework/psp:go_default_library", "//test/e2e/framework/resource:go_default_library", "//test/e2e/framework/ssh:go_default_library", "//test/e2e/framework/testfiles:go_default_library", @@ -135,7 +139,6 @@ filegroup( "//test/e2e/framework/providers/kubemark:all-srcs", "//test/e2e/framework/providers/openstack:all-srcs", "//test/e2e/framework/providers/vsphere:all-srcs", - "//test/e2e/framework/psp:all-srcs", "//test/e2e/framework/pv:all-srcs", "//test/e2e/framework/replicaset:all-srcs", "//test/e2e/framework/resource:all-srcs", diff --git a/test/e2e/framework/framework.go b/test/e2e/framework/framework.go index 5dfefdb39e4..b84909c5a24 100644 --- a/test/e2e/framework/framework.go +++ b/test/e2e/framework/framework.go @@ -47,7 +47,6 @@ import ( e2emetrics "k8s.io/kubernetes/test/e2e/framework/metrics" e2enode "k8s.io/kubernetes/test/e2e/framework/node" e2epod "k8s.io/kubernetes/test/e2e/framework/pod" - e2epsp "k8s.io/kubernetes/test/e2e/framework/psp" testutils "k8s.io/kubernetes/test/utils" "github.com/onsi/ginkgo" @@ -399,7 +398,7 @@ func (f *Framework) CreateNamespace(baseName string, labels map[string]string) ( f.AddNamespacesToDelete(ns) if err == nil && !f.SkipPrivilegedPSPBinding { - e2epsp.CreatePrivilegedPSPBinding(f.ClientSet, ns.Name) + CreatePrivilegedPSPBinding(f.ClientSet, ns.Name) } return ns, err diff --git a/test/e2e/framework/psp/psp.go b/test/e2e/framework/psp.go similarity index 88% rename from test/e2e/framework/psp/psp.go rename to test/e2e/framework/psp.go index 027d1a0daaf..94d788533b0 100644 --- a/test/e2e/framework/psp/psp.go +++ b/test/e2e/framework/psp.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package psp +package framework import ( "fmt" @@ -30,10 +30,8 @@ import ( clientset "k8s.io/client-go/kubernetes" "k8s.io/kubernetes/pkg/security/podsecuritypolicy/seccomp" "k8s.io/kubernetes/test/e2e/framework/auth" - e2elog "k8s.io/kubernetes/test/e2e/framework/log" "github.com/onsi/ginkgo" - "github.com/onsi/gomega" ) const ( @@ -85,13 +83,13 @@ func IsPodSecurityPolicyEnabled(kubeClient clientset.Interface) bool { isPSPEnabledOnce.Do(func() { psps, err := kubeClient.PolicyV1beta1().PodSecurityPolicies().List(metav1.ListOptions{}) if err != nil { - e2elog.Logf("Error listing PodSecurityPolicies; assuming PodSecurityPolicy is disabled: %v", err) + Logf("Error listing PodSecurityPolicies; assuming PodSecurityPolicy is disabled: %v", err) isPSPEnabled = false } else if psps == nil || len(psps.Items) == 0 { - e2elog.Logf("No PodSecurityPolicies found; assuming PodSecurityPolicy is disabled.") + Logf("No PodSecurityPolicies found; assuming PodSecurityPolicy is disabled.") isPSPEnabled = false } else { - e2elog.Logf("Found PodSecurityPolicies; assuming PodSecurityPolicy is enabled.") + Logf("Found PodSecurityPolicies; assuming PodSecurityPolicy is enabled.") isPSPEnabled = true } }) @@ -157,11 +155,3 @@ func CreatePrivilegedPSPBinding(kubeClient clientset.Interface, namespace string schema.GroupResource{Group: "extensions", Resource: "podsecuritypolicies"}, true)) } } - -// ExpectNoError is a copy from the same name function in file test/e2e/framework.go -func ExpectNoError(err error, explain ...interface{}) { - if err != nil { - e2elog.Logf("Unexpected error occurred: %v", err) - } - gomega.ExpectWithOffset(2, err).NotTo(gomega.HaveOccurred(), explain...) -} diff --git a/test/e2e/framework/psp/BUILD b/test/e2e/framework/psp/BUILD deleted file mode 100644 index 07aeb21c902..00000000000 --- a/test/e2e/framework/psp/BUILD +++ /dev/null @@ -1,37 +0,0 @@ -load("@io_bazel_rules_go//go:def.bzl", "go_library") - -go_library( - name = "go_default_library", - srcs = ["psp.go"], - importpath = "k8s.io/kubernetes/test/e2e/framework/psp", - visibility = ["//visibility:public"], - deps = [ - "//pkg/security/podsecuritypolicy/seccomp:go_default_library", - "//staging/src/k8s.io/api/core/v1:go_default_library", - "//staging/src/k8s.io/api/policy/v1beta1:go_default_library", - "//staging/src/k8s.io/api/rbac/v1:go_default_library", - "//staging/src/k8s.io/apimachinery/pkg/api/errors:go_default_library", - "//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library", - "//staging/src/k8s.io/apimachinery/pkg/runtime/schema:go_default_library", - "//staging/src/k8s.io/apiserver/pkg/authentication/serviceaccount:go_default_library", - "//staging/src/k8s.io/client-go/kubernetes:go_default_library", - "//test/e2e/framework/auth:go_default_library", - "//test/e2e/framework/log:go_default_library", - "//vendor/github.com/onsi/ginkgo:go_default_library", - "//vendor/github.com/onsi/gomega:go_default_library", - ], -) - -filegroup( - name = "package-srcs", - srcs = glob(["**"]), - tags = ["automanaged"], - visibility = ["//visibility:private"], -) - -filegroup( - name = "all-srcs", - srcs = [":package-srcs"], - tags = ["automanaged"], - visibility = ["//visibility:public"], -)