This job view page is being replaced by Spyglass soon. Check out the new job view.
PRserathius: Reduce allocations in api code
ResultFAILURE
Tests 0 failed / 0 succeeded
Started2021-10-05 17:58
Elapsed3m28s
Revision0b7f3c7b1a9208b2c8133d6997c775ef9c261968
Refs 859

No Test Failures!


Error lines from build-log.txt

... skipping 8 lines ...
curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b /home/prow/go/bin latest
golangci/golangci-lint info checking GitHub for tag 'latest'
golangci/golangci-lint info found version: 1.42.1 for v1.42.1/linux/amd64
golangci/golangci-lint info installed /home/prow/go/bin/golangci-lint
golangci-lint run --timeout 10m --modules-download-mode=readonly || (echo 'Run "make update"' && exit 1)
pkg/api/pod.go:101: 101-126 lines are duplicate of `pkg/api/pod_metadata.go:90-114` (dupl)
func (m *podMetrics) Get(ctx context.Context, name string, opts *metav1.GetOptions) (runtime.Object, error) {
	namespace := genericapirequest.NamespaceValue(ctx)

	pod, err := m.podLister.Pods(namespace).Get(name)
	if err != nil {
		if errors.IsNotFound(err) {
			// return not-found errors directly
			return &metrics.PodMetrics{}, err
		}
		klog.ErrorS(err, "Failed getting pod", "pod", klog.KRef(namespace, name))
		return &metrics.PodMetrics{}, fmt.Errorf("failed getting pod: %w", err)
	}
	if pod == nil {
		return &metrics.PodMetrics{}, errors.NewNotFound(v1.Resource("pods"), fmt.Sprintf("%s/%s", namespace, name))
	}

	podMetrics, err := m.podMetrics(pod)
	if err != nil {
		klog.ErrorS(err, "Failed reading pod metrics", "pod", klog.KRef(namespace, name))
		return nil, fmt.Errorf("failed pod metrics: %w", err)
	}
	if len(podMetrics) == 0 {
		return nil, errors.NewNotFound(m.groupResource, fmt.Sprintf("%s/%s", namespace, name))
	}
	return &podMetrics[0], nil
}
pkg/api/pod_metadata.go:90: 90-114 lines are duplicate of `pkg/api/pod.go:101-126` (dupl)
func (m *podMetadataMetrics) Get(ctx context.Context, name string, opts *metav1.GetOptions) (runtime.Object, error) {
	namespace := genericapirequest.NamespaceValue(ctx)

	pod, err := m.podLister.ByNamespace(namespace).Get(name)
	if err != nil {
		if errors.IsNotFound(err) {
			// return not-found errors directly
			return &metrics.PodMetrics{}, err
		}
		klog.ErrorS(err, "Failed getting pod", "pod", klog.KRef(namespace, name))
		return &metrics.PodMetrics{}, fmt.Errorf("failed getting pod: %w", err)
	}
	if pod == nil {
		return &metrics.PodMetrics{}, errors.NewNotFound(v1.Resource("pods"), fmt.Sprintf("%s/%s", namespace, name))
	}
	podMetrics, err := m.podMetrics(pod)
	if err != nil {
		klog.ErrorS(err, "Failed reading pod metrics", "pod", klog.KRef(namespace, name))
		return nil, fmt.Errorf("failed pod metrics: %w", err)
	}
	if len(podMetrics) == 0 {
		return nil, errors.NewNotFound(m.groupResource, fmt.Sprintf("%s/%s", namespace, name))
	}
	return &podMetrics[0], nil
}
pkg/api/pod_metadata_test.go:41: 41-173 lines are duplicate of `pkg/api/pod_test.go:40-172` (dupl)
func TestPodMetadataList(t *testing.T) {
	tcs := []struct {
		name        string
		listOptions *metainternalversion.ListOptions
		listerError error
		wantPods    []apitypes.NamespacedName
		wantError   bool
	}{
		{
			name:     "No error",
			wantPods: []apitypes.NamespacedName{{Name: "pod1", Namespace: "other"}, {Name: "pod2", Namespace: "other"}, {Name: "pod3", Namespace: "testValue"}},
		},
		{
			name: "Empty response",
			listOptions: &metainternalversion.ListOptions{
				FieldSelector: fields.SelectorFromSet(map[string]string{
... skipping 29 lines ...
					"labelKey": "otherValue",
				}),
			},
			wantPods: []apitypes.NamespacedName{{Name: "pod3", Namespace: "testValue"}},
		},
		{
			name:        "Lister error",
			listerError: fmt.Errorf("lister error"),
			wantPods:    []apitypes.NamespacedName{},
			wantError:   true,
		},
	}
	for _, tc := range tcs {
		t.Run(tc.name, func(t *testing.T) {
... skipping 2 lines ...

			// execute
			got, err := r.List(genericapirequest.NewContext(), tc.listOptions)

			// assert
			if (err != nil) != tc.wantError {
				t.Fatalf("Unexpected error: %v", err)
			}
			res := got.(*metrics.PodMetricsList)

			if len(res.Items) != len(tc.wantPods) {
				t.Fatalf("len(res.Items) != %d, got: %d", len(tc.wantPods), len(res.Items))
			}
... skipping 6 lines ...

func TestPodMetadataGet(t *testing.T) {
	tcs := []struct {
		name        string
		pods        *v1.Pod
		get         apitypes.NamespacedName
		listerError error
		wantPod     apitypes.NamespacedName
		wantError   bool
	}{
		{
			name:    "Normal",
			pods:    createTestPods()[0],
			get:     apitypes.NamespacedName{Name: "pod1", Namespace: "other"},
			wantPod: apitypes.NamespacedName{Name: "pod1", Namespace: "other"},
		},
		{
			name:        "Lister error",
			get:         apitypes.NamespacedName{Name: "pod1", Namespace: "other"},
			listerError: fmt.Errorf("lister error"),
			wantError:   true,
		},
		{
			name:      "Pod without metrics",
			get:       apitypes.NamespacedName{Name: "pod4", Namespace: "testValue"},
			wantError: true,
... skipping 11 lines ...

			// execute
			got, err := r.Get(genericapirequest.NewContext(), tc.get.Name, nil)

			// assert
			if (err != nil) != tc.wantError {
				t.Fatalf("Unexpected error: %v", err)
			}
			if tc.wantError {
				return
			}
			res := got.(*metrics.PodMetrics)
			testPod(t, *res, tc.wantPod)
... skipping 2 lines ...
}
pkg/api/pod_test.go:40: 40-172 lines are duplicate of `pkg/api/pod_metadata_test.go:41-173` (dupl)
func TestPodList(t *testing.T) {
	tcs := []struct {
		name        string
		listOptions *metainternalversion.ListOptions
		listerError error
		wantPods    []apitypes.NamespacedName
		wantError   bool
	}{
		{
			name:     "Normal",
			wantPods: []apitypes.NamespacedName{{Name: "pod1", Namespace: "other"}, {Name: "pod2", Namespace: "other"}, {Name: "pod3", Namespace: "testValue"}},
... skipping 34 lines ...
					"labelKey": "otherValue",
				}),
			},
			wantPods: []apitypes.NamespacedName{{Name: "pod3", Namespace: "testValue"}},
		},
		{
			name:        "Lister error",
			listerError: fmt.Errorf("lister error"),
			wantPods:    []apitypes.NamespacedName{},
			wantError:   true,
		},
	}
	for _, tc := range tcs {
		t.Run(tc.name, func(t *testing.T) {
... skipping 2 lines ...

			// execute
			got, err := r.List(genericapirequest.NewContext(), tc.listOptions)

			// assert
			if (err != nil) != tc.wantError {
				t.Fatalf("Unexpected error: %v", err)
			}
			res := got.(*metrics.PodMetricsList)

			if len(res.Items) != len(tc.wantPods) {
				t.Fatalf("len(res.Items) != %d, got: %d", len(tc.wantPods), len(res.Items))
			}
... skipping 6 lines ...

func TestPodGet(t *testing.T) {
	tcs := []struct {
		name        string
		pods        *v1.Pod
		get         apitypes.NamespacedName
		listerError error
		wantPod     apitypes.NamespacedName
		wantError   bool
	}{
		{
			name:    "Normal",
			pods:    createTestPods()[0],
			get:     apitypes.NamespacedName{Name: "pod1", Namespace: "other"},
			wantPod: apitypes.NamespacedName{Name: "pod1", Namespace: "other"},
		},
		{
			name:        "Lister error",
			get:         apitypes.NamespacedName{Name: "pod1", Namespace: "other"},
			listerError: fmt.Errorf("lister error"),
			wantError:   true,
		},
		{
			name:      "Pod without metrics",
			get:       apitypes.NamespacedName{Name: "pod4", Namespace: "testValue"},
			wantError: true,
... skipping 11 lines ...

			// execute
			got, err := r.Get(genericapirequest.NewContext(), tc.get.Name, nil)

			// assert
			if (err != nil) != tc.wantError {
				t.Fatalf("Unexpected error: %v", err)
			}
			if tc.wantError {
				return
			}
			res := got.(*metrics.PodMetrics)
			testPod(t, *res, tc.wantPod)
		})
	}
}
Run "make update"
make: *** [Makefile:200: verify-lint] Error 1
+ EXIT_VALUE=2
+ set +o xtrace