Skip to content

🌱 Remove klog from tests #2072

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 0 additions & 29 deletions hack/logcheck.out
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 1 addition & 2 deletions test/e2e/reconciler/cluster/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions test/e2e/reconciler/clusterworkspace/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
11 changes: 5 additions & 6 deletions test/e2e/reconciler/namespace/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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] != ""
Expand All @@ -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] != ""
Expand Down
15 changes: 7 additions & 8 deletions test/e2e/reconciler/scheduling/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}

Expand All @@ -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
}

Expand All @@ -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)
Expand All @@ -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
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions test/e2e/reconciler/scheduling/multi_placements_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
7 changes: 3 additions & 4 deletions test/e2e/reconciler/scheduling/placement_scheduler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
9 changes: 4 additions & 5 deletions test/e2e/syncer/syncer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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.
}

Expand All @@ -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.
}

Expand All @@ -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 {
Expand All @@ -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") {
Expand Down
5 changes: 1 addition & 4 deletions test/e2e/virtual/apiexport/virtualworkspace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 3 additions & 4 deletions test/e2e/virtual/syncer/virtualworkspace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand All @@ -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 {
Expand All @@ -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
Expand Down
9 changes: 4 additions & 5 deletions test/e2e/virtual/workspaces/virtual_workspace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down