From 3aa366a3eb1beb924332f72a57181126a332ef4a Mon Sep 17 00:00:00 2001 From: Patrick Ohly Date: Wed, 17 Jan 2024 12:31:33 +0100 Subject: [PATCH] e2e: remove dead code The dead code was found with: deadcode -test -filter=k8s.io/kubernetes/test/e2e/framework/... ./test/e2e ./test/e2e_node ./test/e2e_node ./test/e2e_kubeadm See https://go.dev/blog/deadcode for an introduction. Only dead code which is clearly not needed anymore (glog logging), questionable (skipping based on feature gates) or redundant (WaitForPodSuccessInNamespaceSlow) gets removed for now. More removals might make sense in the future. --- test/e2e/framework/ingress/ingress_utils.go | 14 ------- test/e2e/framework/pod/wait.go | 5 --- test/e2e/framework/skipper/skipper.go | 41 ------------------- .../network/scale/localrun/ingress_scale.go | 2 +- 4 files changed, 1 insertion(+), 61 deletions(-) diff --git a/test/e2e/framework/ingress/ingress_utils.go b/test/e2e/framework/ingress/ingress_utils.go index 0275848cacc..bd4be356b3c 100644 --- a/test/e2e/framework/ingress/ingress_utils.go +++ b/test/e2e/framework/ingress/ingress_utils.go @@ -38,7 +38,6 @@ import ( "time" compute "google.golang.org/api/compute/v1" - "k8s.io/klog/v2" netutils "k8s.io/utils/net" appsv1 "k8s.io/api/apps/v1" @@ -125,19 +124,6 @@ type TestLogger interface { Errorf(format string, args ...interface{}) } -// GLogger is test logger. -type GLogger struct{} - -// Infof outputs log with info level. -func (l *GLogger) Infof(format string, args ...interface{}) { - klog.Infof(format, args...) -} - -// Errorf outputs log with error level. -func (l *GLogger) Errorf(format string, args ...interface{}) { - klog.Errorf(format, args...) -} - // E2ELogger is test logger. type E2ELogger struct{} diff --git a/test/e2e/framework/pod/wait.go b/test/e2e/framework/pod/wait.go index cf4997641e7..b760edc43a9 100644 --- a/test/e2e/framework/pod/wait.go +++ b/test/e2e/framework/pod/wait.go @@ -518,11 +518,6 @@ func WaitForPodSuccessInNamespace(ctx context.Context, c clientset.Interface, po return WaitForPodSuccessInNamespaceTimeout(ctx, c, podName, namespace, podStartTimeout) } -// WaitForPodSuccessInNamespaceSlow returns nil if the pod reached state success, or an error if it reached failure or until slowPodStartupTimeout. -func WaitForPodSuccessInNamespaceSlow(ctx context.Context, c clientset.Interface, podName string, namespace string) error { - return WaitForPodSuccessInNamespaceTimeout(ctx, c, podName, namespace, slowPodStartTimeout) -} - // WaitForPodNotFoundInNamespace returns an error if it takes too long for the pod to fully terminate. // Unlike `waitForPodTerminatedInNamespace`, the pod's Phase and Reason are ignored. If the pod Get // api returns IsNotFound then the wait stops and nil is returned. If the Get api returns an error other diff --git a/test/e2e/framework/skipper/skipper.go b/test/e2e/framework/skipper/skipper.go index 3c0a2bf781d..4a509b90a57 100644 --- a/test/e2e/framework/skipper/skipper.go +++ b/test/e2e/framework/skipper/skipper.go @@ -22,13 +22,10 @@ import ( "github.com/onsi/ginkgo/v2" - apierrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/labels" - "k8s.io/apimachinery/pkg/runtime/schema" utilversion "k8s.io/apimachinery/pkg/util/version" "k8s.io/client-go/discovery" - "k8s.io/client-go/dynamic" clientset "k8s.io/client-go/kubernetes" "k8s.io/component-base/featuregate" "k8s.io/kubernetes/test/e2e/framework" @@ -85,34 +82,6 @@ func SkipUnlessFeatureGateEnabled(gate featuregate.Feature) { } } -// SkipIfFeatureGateEnabled skips if the feature is enabled. -// -// Beware that this only works in test suites that have a --feature-gate -// parameter and call InitFeatureGates. In test/e2e, the `Feature: XYZ` tag -// has to be used instead and invocations have to make sure that they -// only run tests that work with the given test cluster. -func SkipIfFeatureGateEnabled(gate featuregate.Feature) { - if featureGate == nil { - framework.Failf("Feature gate checking is not enabled, don't use SkipFeatureGateEnabled(%v). Instead use the Feature tag.", gate) - } - if featureGate.Enabled(gate) { - skipInternalf(1, "Only supported when %v feature is disabled", gate) - } -} - -// SkipIfMissingResource skips if the gvr resource is missing. -func SkipIfMissingResource(ctx context.Context, dynamicClient dynamic.Interface, gvr schema.GroupVersionResource, namespace string) { - resourceClient := dynamicClient.Resource(gvr).Namespace(namespace) - _, err := resourceClient.List(ctx, metav1.ListOptions{}) - if err != nil { - // not all resources support list, so we ignore those - if apierrors.IsMethodNotSupported(err) || apierrors.IsNotFound(err) || apierrors.IsForbidden(err) { - skipInternalf(1, "Could not find %s resource, skipping test: %#v", gvr, err) - } - framework.Failf("Unexpected error getting %v: %v", gvr, err) - } -} - // SkipUnlessNodeCountIsAtLeast skips if the number of nodes is less than the minNodeCount. func SkipUnlessNodeCountIsAtLeast(minNodeCount int) { if framework.TestContext.CloudConfig.NumNodes < minNodeCount { @@ -230,16 +199,6 @@ func SkipIfAppArmorNotSupported() { SkipUnlessNodeOSDistroIs(AppArmorDistros...) } -// RunIfSystemSpecNameIs runs if the system spec name is included in the names. -func RunIfSystemSpecNameIs(names ...string) { - for _, name := range names { - if name == framework.TestContext.SystemSpecName { - return - } - } - skipInternalf(1, "Skipped because system spec name %q is not in %v", framework.TestContext.SystemSpecName, names) -} - // SkipUnlessComponentRunsAsPodsAndClientCanDeleteThem run if the component run as pods and client can delete them func SkipUnlessComponentRunsAsPodsAndClientCanDeleteThem(ctx context.Context, componentName string, c clientset.Interface, ns string, labelSet labels.Set) { // verify if component run as pod diff --git a/test/e2e/network/scale/localrun/ingress_scale.go b/test/e2e/network/scale/localrun/ingress_scale.go index ab1ef7aae6b..91c87892d98 100644 --- a/test/e2e/network/scale/localrun/ingress_scale.go +++ b/test/e2e/network/scale/localrun/ingress_scale.go @@ -162,7 +162,7 @@ func main() { // Setting up a localized scale test framework. f := scale.NewIngressScaleFramework(cs, ns.Name, cloudConfig) - f.Logger = &e2eingress.GLogger{} + f.Logger = &e2eingress.E2ELogger{} // Customizing scale test. f.EnableTLS = enableTLS f.OutputFile = outputFile