From 1942ffad65d47a5d645456d2b92570f2ad2fb8b1 Mon Sep 17 00:00:00 2001 From: Nolan Brubaker Date: Fri, 23 Sep 2022 16:28:09 -0400 Subject: [PATCH] Remove klog from tests Signed-off-by: Nolan Brubaker --- hack/logcheck.out | 29 ------------------- .../e2e/reconciler/cluster/controller_test.go | 3 +- .../clusterworkspace/controller_test.go | 2 -- .../reconciler/namespace/controller_test.go | 11 ++++--- .../reconciler/scheduling/controller_test.go | 15 +++++----- .../scheduling/multi_placements_test.go | 3 +- .../scheduling/placement_scheduler_test.go | 7 ++--- test/e2e/syncer/syncer_test.go | 9 +++--- .../apiexport/virtualworkspace_test.go | 5 +--- .../virtual/syncer/virtualworkspace_test.go | 7 ++--- .../workspaces/virtual_workspace_test.go | 9 +++--- 11 files changed, 29 insertions(+), 71 deletions(-) diff --git a/hack/logcheck.out b/hack/logcheck.out index 5ccdcaf0c84..668368cb7a4 100644 --- a/hack/logcheck.out +++ b/hack/logcheck.out @@ -242,32 +242,3 @@ /pkg/virtual/workspaces/cache/cache.go:88:3: function "Infof" should not be used, convert to contextual logging /pkg/virtual/workspaces/cache/cache.go:88:3: function "V" should not be used, convert to contextual logging /test/e2e/framework/config.go:42:2: function "InitFlags" should not be used, convert to contextual logging -/test/e2e/reconciler/cluster/controller_test.go:135:7: function "Errorf" should not be used, convert to contextual logging -/test/e2e/reconciler/clusterworkspace/controller_test.go:235:3: function "Infof" should not be used, convert to contextual logging -/test/e2e/reconciler/namespace/controller_test.go:107:7: function "Error" should not be used, convert to contextual logging -/test/e2e/reconciler/namespace/controller_test.go:118:7: function "Error" should not be used, convert to contextual logging -/test/e2e/reconciler/namespace/controller_test.go:168:7: function "Errorf" should not be used, convert to contextual logging -/test/e2e/reconciler/namespace/controller_test.go:194:7: function "Errorf" should not be used, convert to contextual logging -/test/e2e/reconciler/namespace/controller_test.go:220:7: function "Errorf" should not be used, convert to contextual logging -/test/e2e/reconciler/scheduling/controller_test.go:110:4: function "Errorf" should not be used, convert to contextual logging -/test/e2e/reconciler/scheduling/controller_test.go:128:4: function "Error" should not be used, convert to contextual logging -/test/e2e/reconciler/scheduling/controller_test.go:138:4: function "Errorf" should not be used, convert to contextual logging -/test/e2e/reconciler/scheduling/controller_test.go:219:4: function "Errorf" should not be used, convert to contextual logging -/test/e2e/reconciler/scheduling/controller_test.go:255:4: function "Errorf" should not be used, convert to contextual logging -/test/e2e/reconciler/scheduling/controller_test.go:310:4: function "Errorf" should not be used, convert to contextual logging -/test/e2e/reconciler/scheduling/controller_test.go:99:4: function "Errorf" should not be used, convert to contextual logging -/test/e2e/reconciler/scheduling/multi_placements_test.go:245:4: function "Errorf" should not be used, convert to contextual logging -/test/e2e/reconciler/scheduling/placement_scheduler_test.go:134:4: function "Errorf" should not be used, convert to contextual logging -/test/e2e/reconciler/scheduling/placement_scheduler_test.go:245:4: function "Errorf" should not be used, convert to contextual logging -/test/e2e/reconciler/scheduling/placement_scheduler_test.go:333:4: function "Errorf" should not be used, convert to contextual logging -/test/e2e/syncer/syncer_test.go:381:3: function "Errorf" should not be used, convert to contextual logging -/test/e2e/syncer/syncer_test.go:404:3: function "Errorf" should not be used, convert to contextual logging -/test/e2e/syncer/syncer_test.go:429:3: function "Errorf" should not be used, convert to contextual logging -/test/e2e/syncer/syncer_test.go:441:5: function "Errorf" should not be used, convert to contextual logging -/test/e2e/virtual/syncer/virtualworkspace_test.go:457:7: function "Errorf" should not be used, convert to contextual logging -/test/e2e/virtual/syncer/virtualworkspace_test.go:467:7: function "Errorf" should not be used, convert to contextual logging -/test/e2e/virtual/syncer/virtualworkspace_test.go:487:7: function "Errorf" should not be used, convert to contextual logging -/test/e2e/virtual/workspaces/virtual_workspace_test.go:214:6: function "Errorf" should not be used, convert to contextual logging -/test/e2e/virtual/workspaces/virtual_workspace_test.go:287:6: function "Errorf" should not be used, convert to contextual logging -/test/e2e/virtual/workspaces/virtual_workspace_test.go:661:5: function "Warningf" should not be used, convert to contextual logging -/test/e2e/virtual/workspaces/virtual_workspace_test.go:668:4: function "Infof" should not be used, convert to contextual logging diff --git a/test/e2e/reconciler/cluster/controller_test.go b/test/e2e/reconciler/cluster/controller_test.go index d5340c658e1..aeff1ea558d 100644 --- a/test/e2e/reconciler/cluster/controller_test.go +++ b/test/e2e/reconciler/cluster/controller_test.go @@ -36,7 +36,6 @@ import ( kubernetesclient "k8s.io/client-go/kubernetes" corev1client "k8s.io/client-go/kubernetes/typed/core/v1" "k8s.io/client-go/rest" - "k8s.io/klog/v2" "sigs.k8s.io/yaml" workloadv1alpha1 "github.com/kcp-dev/kcp/pkg/apis/workload/v1alpha1" @@ -132,7 +131,7 @@ func TestClusterController(t *testing.T) { if apierrors.IsNotFound(err) { return false } - klog.Errorf("Error getting cowboy %q in source: %v", cowboy.Name, err) + t.Logf("Error getting cowboy %q in source: %v", cowboy.Name, err) return false } else if diff := cmp.Diff(updated.Status, got.Status); diff != "" { return false diff --git a/test/e2e/reconciler/clusterworkspace/controller_test.go b/test/e2e/reconciler/clusterworkspace/controller_test.go index 6af08435a90..a715591e061 100644 --- a/test/e2e/reconciler/clusterworkspace/controller_test.go +++ b/test/e2e/reconciler/clusterworkspace/controller_test.go @@ -31,7 +31,6 @@ import ( "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/util/wait" "k8s.io/client-go/rest" - "k8s.io/klog/v2" "sigs.k8s.io/yaml" tenancyv1alpha1 "github.com/kcp-dev/kcp/pkg/apis/tenancy/v1alpha1" @@ -232,7 +231,6 @@ func isUnschedulable(workspace *tenancyv1alpha1.ClusterWorkspace) bool { func unschedulable(object *tenancyv1alpha1.ClusterWorkspace) error { if !isUnschedulable(object) { - klog.Infof("Workspace is not unscheduled: %v", utilconditions.Get(object, tenancyv1alpha1.WorkspaceScheduled)) return fmt.Errorf("expected an unschedulable workspace, got status.conditions: %#v", object.Status.Conditions) } return nil diff --git a/test/e2e/reconciler/namespace/controller_test.go b/test/e2e/reconciler/namespace/controller_test.go index f977864cb66..b40968cbe19 100644 --- a/test/e2e/reconciler/namespace/controller_test.go +++ b/test/e2e/reconciler/namespace/controller_test.go @@ -42,7 +42,6 @@ import ( "k8s.io/client-go/rest" "k8s.io/client-go/tools/cache" "k8s.io/client-go/util/retry" - "k8s.io/klog/v2" configcrds "github.com/kcp-dev/kcp/config/crds" apisv1alpha1 "github.com/kcp-dev/kcp/pkg/apis/apis/v1alpha1" @@ -104,7 +103,7 @@ func TestNamespaceScheduler(t *testing.T) { require.Eventually(t, func() bool { binding, err := server.kcpClient.ApisV1alpha1().APIBindings().Get(ctx, "kubernetes", metav1.GetOptions{}) if err != nil { - klog.Error(err) + t.Log(err) return false } return binding.Status.Phase == apisv1alpha1.APIBindingPhaseBound @@ -115,7 +114,7 @@ func TestNamespaceScheduler(t *testing.T) { require.Eventually(t, func() bool { ns, err := server.client.CoreV1().Namespaces().Get(ctx, namespace.Name, metav1.GetOptions{}) if err != nil { - klog.Error(err) + t.Log(err) return false } return scheduledMatcher(syncTargetKey)(ns) == nil @@ -165,7 +164,7 @@ func TestNamespaceScheduler(t *testing.T) { if err != nil { // we can survive several of these errors. If 6 in a row fail and the sync target is marked // non-ready, we likely have other problems than these failures here. - klog.Errorf("failed to set status.lastSyncerHeartbeatTime: %v", err) + t.Logf("failed to set status.lastSyncerHeartbeatTime: %v", err) return } }, time.Second*10) @@ -191,7 +190,7 @@ func TestNamespaceScheduler(t *testing.T) { require.Eventually(t, func() bool { obj, err := dynamicClusterClient.Cluster(server.clusterName).Resource(gvr).Namespace("default").Get(ctx, "woody", metav1.GetOptions{}) if err != nil { - klog.Errorf("failed to get sheriff: %v", err) + t.Logf("failed to get sheriff: %v", err) return false } return obj.GetLabels()[workloadv1alpha1.ClusterResourceStateLabelPrefix+syncTargetKey] != "" @@ -217,7 +216,7 @@ func TestNamespaceScheduler(t *testing.T) { require.Eventually(t, func() bool { obj, err := dynamicClusterClient.Cluster(server.clusterName).Resource(gvr).Namespace("default").Get(ctx, "lucky-luke", metav1.GetOptions{}) if err != nil { - klog.Errorf("failed to get sheriff: %v", err) + t.Logf("failed to get sheriff: %v", err) return false } return obj.GetLabels()[workloadv1alpha1.ClusterResourceStateLabelPrefix+syncTargetKey] != "" diff --git a/test/e2e/reconciler/scheduling/controller_test.go b/test/e2e/reconciler/scheduling/controller_test.go index 58c813a629d..2a1d8ed401e 100644 --- a/test/e2e/reconciler/scheduling/controller_test.go +++ b/test/e2e/reconciler/scheduling/controller_test.go @@ -34,7 +34,6 @@ import ( "k8s.io/apimachinery/pkg/util/wait" "k8s.io/client-go/kubernetes" "k8s.io/client-go/rest" - "k8s.io/klog/v2" "sigs.k8s.io/yaml" apisv1alpha1 "github.com/kcp-dev/kcp/pkg/apis/apis/v1alpha1" @@ -96,7 +95,7 @@ func TestScheduling(t *testing.T) { require.Eventually(t, func() bool { imports, err := kcpClusterClient.ApiresourceV1alpha1().APIResourceImports().List(logicalcluster.WithCluster(ctx, negotiationClusterName), metav1.ListOptions{}) if err != nil { - klog.Errorf("Failed to list APIResourceImports: %v", err) + t.Logf("Failed to list APIResourceImports: %v", err) return false } @@ -107,7 +106,7 @@ func TestScheduling(t *testing.T) { require.Eventually(t, func() bool { resources, err := kcpClusterClient.ApiresourceV1alpha1().NegotiatedAPIResources().List(logicalcluster.WithCluster(ctx, negotiationClusterName), metav1.ListOptions{}) if err != nil { - klog.Errorf("Failed to list NegotiatedAPIResources: %v", err) + t.Logf("Failed to list NegotiatedAPIResources: %v", err) return false } @@ -125,7 +124,7 @@ func TestScheduling(t *testing.T) { framework.Eventually(t, func() (bool, string) { binding, err := kcpClusterClient.ApisV1alpha1().APIBindings().Get(logicalcluster.WithCluster(ctx, negotiationClusterName), "kubernetes", metav1.GetOptions{}) if err != nil { - klog.Error(err) + t.Log(err) return false, "" } return binding.Status.Phase == apisv1alpha1.APIBindingPhaseBound, toYaml(binding) @@ -135,7 +134,7 @@ func TestScheduling(t *testing.T) { require.Eventually(t, func() bool { schemas, err := kcpClusterClient.ApisV1alpha1().APIResourceSchemas().List(logicalcluster.WithCluster(ctx, negotiationClusterName), metav1.ListOptions{}) if err != nil { - klog.Errorf("Failed to list APIResourceSchemas: %v", err) + t.Logf("Failed to list APIResourceSchemas: %v", err) return false } @@ -216,7 +215,7 @@ func TestScheduling(t *testing.T) { if errors.IsNotFound(err) { return false } else if err != nil { - klog.Errorf("Failed to list Services: %v", err) + t.Logf("Failed to list Services: %v", err) return false } return true @@ -252,7 +251,7 @@ func TestScheduling(t *testing.T) { if errors.IsNotFound(err) { return false } else if err != nil { - klog.Errorf("Failed to list Services: %v", err) + t.Logf("Failed to list Services: %v", err) return false } return true @@ -307,7 +306,7 @@ func TestScheduling(t *testing.T) { if errors.IsNotFound(err) { return false } else if err != nil { - klog.Errorf("Failed to list Services: %v", err) + t.Logf("Failed to list Services: %v", err) return false } else if len(downstreamServices.Items) < 2 { return false diff --git a/test/e2e/reconciler/scheduling/multi_placements_test.go b/test/e2e/reconciler/scheduling/multi_placements_test.go index 177c73d9b5d..4791796cf2e 100644 --- a/test/e2e/reconciler/scheduling/multi_placements_test.go +++ b/test/e2e/reconciler/scheduling/multi_placements_test.go @@ -34,7 +34,6 @@ import ( "k8s.io/apimachinery/pkg/util/wait" "k8s.io/client-go/kubernetes" "k8s.io/client-go/rest" - "k8s.io/klog/v2" apisv1alpha1 "github.com/kcp-dev/kcp/pkg/apis/apis/v1alpha1" schedulingv1alpha1 "github.com/kcp-dev/kcp/pkg/apis/scheduling/v1alpha1" @@ -242,7 +241,7 @@ func TestMultiPlacement(t *testing.T) { if errors.IsNotFound(err) { return false } else if err != nil { - klog.Errorf("Failed to list Services: %v", err) + t.Logf("Failed to list Services: %v", err) return false } return true diff --git a/test/e2e/reconciler/scheduling/placement_scheduler_test.go b/test/e2e/reconciler/scheduling/placement_scheduler_test.go index 12f37ccfdcc..2868f00b9c2 100644 --- a/test/e2e/reconciler/scheduling/placement_scheduler_test.go +++ b/test/e2e/reconciler/scheduling/placement_scheduler_test.go @@ -33,7 +33,6 @@ import ( "k8s.io/apimachinery/pkg/util/wait" "k8s.io/client-go/kubernetes" "k8s.io/client-go/rest" - "k8s.io/klog/v2" apisv1alpha1 "github.com/kcp-dev/kcp/pkg/apis/apis/v1alpha1" schedulingv1alpha1 "github.com/kcp-dev/kcp/pkg/apis/scheduling/v1alpha1" @@ -131,7 +130,7 @@ func TestPlacementUpdate(t *testing.T) { if errors.IsNotFound(err) { return false } else if err != nil { - klog.Errorf("Failed to list Services: %v", err) + t.Logf("Failed to list Services: %v", err) return false } return true @@ -242,7 +241,7 @@ func TestPlacementUpdate(t *testing.T) { if errors.IsNotFound(err) { return false } else if err != nil { - klog.Errorf("Failed to list Services: %v", err) + t.Logf("Failed to list Services: %v", err) return false } else if len(downstreamServices.Items) != 0 { return false @@ -330,7 +329,7 @@ func TestPlacementUpdate(t *testing.T) { if errors.IsNotFound(err) { return false } else if err != nil { - klog.Errorf("Failed to list Services: %v", err) + t.Logf("Failed to list Services: %v", err) return false } else if len(downstreamServices.Items) < 1 { return false diff --git a/test/e2e/syncer/syncer_test.go b/test/e2e/syncer/syncer_test.go index 559905bac12..17ee29d7428 100644 --- a/test/e2e/syncer/syncer_test.go +++ b/test/e2e/syncer/syncer_test.go @@ -37,7 +37,6 @@ import ( "k8s.io/apimachinery/pkg/util/wait" "k8s.io/apimachinery/pkg/util/yaml" kubernetesclientset "k8s.io/client-go/kubernetes" - "k8s.io/klog/v2" "k8s.io/utils/pointer" kyaml "sigs.k8s.io/yaml" @@ -378,7 +377,7 @@ func dumpPodEvents(t *testing.T, startAfter time.Time, downstreamKubeClient *kub eventList, err := downstreamKubeClient.CoreV1().Events(downstreamNamespaceName).List(ctx, metav1.ListOptions{}) if err != nil { - klog.Errorf("Error getting events: %v", err) + t.Logf("Error getting events: %v", err) return startAfter // ignore. Error here are not the ones we care for. } @@ -401,7 +400,7 @@ func dumpPodEvents(t *testing.T, startAfter time.Time, downstreamKubeClient *kub pods, err := downstreamKubeClient.CoreV1().Pods(downstreamNamespaceName).List(ctx, metav1.ListOptions{}) if err != nil { - klog.Errorf("Error getting pods: %v", err) + t.Logf("Error getting pods: %v", err) return last // ignore. Error here are not the ones we care for. } @@ -426,7 +425,7 @@ func dumpPodLogs(t *testing.T, startAfter map[string]*metav1.Time, downstreamKub pods, err := downstreamKubeClient.CoreV1().Pods(downstreamNamespaceName).List(ctx, metav1.ListOptions{}) if err != nil { - klog.Errorf("Error getting pods: %v", err) + t.Logf("Error getting pods: %v", err) return startAfter // ignore. Error here are not the ones we care for. } for _, pod := range pods.Items { @@ -438,7 +437,7 @@ func dumpPodLogs(t *testing.T, startAfter map[string]*metav1.Time, downstreamKub Container: c.Name, }).DoRaw(ctx) if err != nil { - klog.Errorf("Failed to get logs for pod %s/%s container %s: %v", pod.Namespace, pod.Name, c.Name, err) + t.Logf("Failed to get logs for pod %s/%s container %s: %v", pod.Namespace, pod.Name, c.Name, err) continue } for _, line := range strings.Split(string(res), "\n") { diff --git a/test/e2e/virtual/apiexport/virtualworkspace_test.go b/test/e2e/virtual/apiexport/virtualworkspace_test.go index 9b4893da457..5e801f35708 100644 --- a/test/e2e/virtual/apiexport/virtualworkspace_test.go +++ b/test/e2e/virtual/apiexport/virtualworkspace_test.go @@ -584,10 +584,7 @@ func gatherInternalAPIs(discoveryClient discovery.DiscoveryInterface, t *testing for _, apiResourcesList := range apiResourcesLists { gv, err := schema.ParseGroupVersion(apiResourcesList.GroupVersion) - if err != nil { - t.Errorf("error parsing group version %v, err: %v", apiResourcesList.GroupVersion, err) - continue - } + require.NoError(t, err) // ignore kcp resources if strings.HasSuffix(gv.Group, ".kcp.dev") { continue diff --git a/test/e2e/virtual/syncer/virtualworkspace_test.go b/test/e2e/virtual/syncer/virtualworkspace_test.go index d66308a7a9d..445cc39fe59 100644 --- a/test/e2e/virtual/syncer/virtualworkspace_test.go +++ b/test/e2e/virtual/syncer/virtualworkspace_test.go @@ -41,7 +41,6 @@ import ( kubernetesclientset "k8s.io/client-go/kubernetes" "k8s.io/client-go/rest" "k8s.io/client-go/tools/clientcmd" - "k8s.io/klog/v2" "sigs.k8s.io/yaml" apisv1alpha1 "github.com/kcp-dev/kcp/pkg/apis/apis/v1alpha1" @@ -454,7 +453,7 @@ func TestSyncerVirtualWorkspace(t *testing.T) { require.Eventually(t, func() bool { binding, err := kcpClusterClient.ApisV1alpha1().APIBindings().Get(logicalcluster.WithCluster(ctx, otherWorkspace), binding.Name, metav1.GetOptions{}) if err != nil { - klog.Errorf("Failed to list Locations: %v", err) + t.Logf("Failed to list Locations: %v", err) return false } return conditions.IsTrue(binding, apisv1alpha1.InitialBindingCompleted) @@ -464,7 +463,7 @@ func TestSyncerVirtualWorkspace(t *testing.T) { require.Eventually(t, func() bool { binding, err := kcpClusterClient.ApisV1alpha1().APIBindings().Get(logicalcluster.WithCluster(ctx, otherWorkspace), binding.Name, metav1.GetOptions{}) if err != nil { - klog.Errorf("Failed to list Locations: %v", err) + t.Logf("Failed to list Locations: %v", err) return false } for _, r := range binding.Status.BoundResources { @@ -484,7 +483,7 @@ func TestSyncerVirtualWorkspace(t *testing.T) { if errors.IsNotFound(err) { return false } else if err != nil { - klog.Errorf("Failed to list Services: %v", err) + t.Logf("Failed to list Services: %v", err) return false } return true diff --git a/test/e2e/virtual/workspaces/virtual_workspace_test.go b/test/e2e/virtual/workspaces/virtual_workspace_test.go index e55ce3cb004..bcade106d20 100644 --- a/test/e2e/virtual/workspaces/virtual_workspace_test.go +++ b/test/e2e/virtual/workspaces/virtual_workspace_test.go @@ -42,7 +42,6 @@ import ( "k8s.io/client-go/rest" "k8s.io/client-go/tools/clientcmd" clientcmdapi "k8s.io/client-go/tools/clientcmd/api" - "k8s.io/klog/v2" virtualcommand "github.com/kcp-dev/kcp/cmd/virtual-workspaces/command" virtualoptions "github.com/kcp-dev/kcp/cmd/virtual-workspaces/options" @@ -211,7 +210,7 @@ var testCases = []struct { var err error workspace1, err = vwUser1Client.Cluster(server.orgClusterName).TenancyV1beta1().Workspaces().Create(ctx, testData.workspace1.DeepCopy(), metav1.CreateOptions{}) if err != nil { - klog.Errorf("Failed to create workspace1: %v", err) + t.Logf("Failed to create workspace1: %v", err) return false } return true @@ -284,7 +283,7 @@ var testCases = []struct { var err error workspace1, err = vwUser1Client.Cluster(server.orgClusterName).TenancyV1beta1().Workspaces().Create(ctx, testData.workspace1.DeepCopy(), metav1.CreateOptions{}) if err != nil { - klog.Errorf("Failed to create workspace1: %v", err) + t.Logf("Failed to create workspace1: %v", err) return false } return true @@ -658,14 +657,14 @@ func testWorkspacesVirtualWorkspaces(t *testing.T, standalone bool) { require.Eventually(t, func() bool { resp, err := client.Get(fmt.Sprintf("%s/readyz", virtualWorkspaceServerHost)) if err != nil { - klog.Warningf("error checking virtual workspace readiness: %v", err) + t.Logf("error checking virtual workspace readiness: %v", err) return false } defer resp.Body.Close() if resp.StatusCode == http.StatusOK { return true } - klog.Infof("virtual workspace is not ready yet, status code: %d", resp.StatusCode) + t.Logf("virtual workspace is not ready yet, status code: %d", resp.StatusCode) return false }, wait.ForeverTestTimeout, time.Millisecond*100, "virtual workspace apiserver not ready") } else {