k8snetworkplumbingwg / whereabouts

A CNI IPAM plugin that assigns IP addresses cluster-wide

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[BUG] go vet fails with undeclared name error

Ayush21298 opened this issue · comments

Describe the bug
A clear and concise description of what the bug is.

go vet throws following error when run in the root directory of source code.

whereabouts$ go vet ./...
# github.com/k8snetworkplumbingwg/whereabouts/pkg/controlloop
vet: pkg/controlloop/pod_controller_test.go:72:10: undeclared name: podSpec

Expected behavior
A clear and concise description of what you expected to happen.

go vet should throw no error

To Reproduce
Steps to reproduce the behavior:

  1. git clone https://github.com/k8snetworkplumbingwg/whereabouts
  2. Run go vet ./...

Environment:

  • Skipping it as it is not a functional error

Additional info / context
Add any other information / context about the problem here.

  • go version go1.18 linux/amd64

You just have to pass the test tags via CLI - go vet --tags=test ./... , as our CI is doing.

You just have to pass the test tags via CLI - go vet --tags=test ./... , as our CI is doing.

But shouldn't all the test related files have +build test tag ? 🤔

the tests ? Why would you put the tests in a binary ?

Actually pod_control_test.go requires podSpec here

pod = podSpec(podName, namespace, networkName)

This is defined in entity_generator.go here

func podSpec(name string, namespace string, networks ...string) *v1.Pod {
return &v1.Pod{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: namespace,
Annotations: podNetworkSelectionElements(networks...),
},
}

But entity_generator.go has build flags

//go:build test
// +build test

Because of this the issue happens.

You just have to pass the test tags via CLI - go vet --tags=test ./... , as our CI is doing.

But shouldn't all the test related files have +build test tag ? thinking

I suggested this because I think pod_control_test.go should not be included in the binary until and unless test tag is present.

@maiqueb What do you think ? ^^

I think I don't understand what you mean; pod_control_test.go - along with anything not reachable from the main entrypoint of either the pod controller or the CNI plugin - will not be present in the binary, hence, there is no need to tag it.

Continuing from the call, yes I agree it will be better to remove the tags from the files which don't require tags :)

I was just concern that all the go vet with and without tag should pass independently (all the dependent files should either have tags or don't i.e. kind of independent sets ) :)