Removed dupe imports (#10049)

* Removed dupe imports

My IDE (vim-gopls) has been complaining for a while, so I decided to take
care of it. Found via
[staticcheck](https://github.com/dominikh/go-tools)

* Add stylecheck to go-lint checks
This commit is contained in:
Alejandro Pedraza 2023-01-10 14:34:56 -05:00 committed by GitHub
parent c415abd400
commit 7428d4aa51
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
19 changed files with 49 additions and 65 deletions

View File

@ -28,6 +28,7 @@ linters:
- nakedret
- revive
- staticcheck
- stylecheck
- typecheck
- unconvert
- unparam
@ -42,7 +43,6 @@ linters:
# - lll
# - maligned
# - prealloc
# - stylecheck
disable:
# https://github.com/golangci/golangci-lint/issues/2649
@ -53,6 +53,8 @@ linters-settings:
rules:
- name: package-comments
disabled: true
stylecheck:
checks: ["ST1019"]
issues:
exclude-use-default: false

View File

@ -12,7 +12,6 @@ import (
charts "github.com/linkerd/linkerd2/pkg/charts/linkerd2"
"github.com/linkerd/linkerd2/pkg/tls"
"helm.sh/helm/v3/pkg/cli/values"
valuespkg "helm.sh/helm/v3/pkg/cli/values"
corev1 "k8s.io/api/core/v1"
)
@ -282,7 +281,7 @@ func TestRenderCRDs(t *testing.T) {
addFakeTLSSecrets(defaultValues)
var buf bytes.Buffer
if err := renderCRDs(&buf, valuespkg.Options{}); err != nil {
if err := renderCRDs(&buf, values.Options{}); err != nil {
t.Fatalf("Failed to render templates: %v", err)
}
if err := testDataDiffer.DiffTestYAML("install_crds.golden", buf.String()); err != nil {

View File

@ -18,7 +18,6 @@ import (
"github.com/linkerd/linkerd2/pkg/inject"
"github.com/linkerd/linkerd2/pkg/issuercerts"
"github.com/linkerd/linkerd2/pkg/k8s"
consts "github.com/linkerd/linkerd2/pkg/k8s"
"github.com/linkerd/linkerd2/pkg/tls"
"github.com/linkerd/linkerd2/pkg/version"
log "github.com/sirupsen/logrus"
@ -234,7 +233,7 @@ func makeInstallFlags(defaults *l5dcharts.Values) ([]flag.Flag, *pflag.FlagSet)
if value {
values.Identity.Issuer.Scheme = string(corev1.SecretTypeTLS)
} else {
values.Identity.Issuer.Scheme = consts.IdentityIssuerSchemeLinkerd
values.Identity.Issuer.Scheme = k8s.IdentityIssuerSchemeLinkerd
}
return nil
}),
@ -532,7 +531,7 @@ func validateValues(ctx context.Context, k *k8s.KubernetesAPI, values *l5dcharts
}
}
if values.Identity.Issuer.Scheme == consts.IdentityIssuerSchemeLinkerd {
if values.Identity.Issuer.Scheme == k8s.IdentityIssuerSchemeLinkerd {
issuerData := issuercerts.IssuerCertData{
IssuerCrt: values.Identity.Issuer.TLS.CrtPEM,
IssuerKey: values.Identity.Issuer.TLS.KeyPEM,

View File

@ -10,7 +10,6 @@ import (
"time"
"github.com/linkerd/linkerd2/cli/flag"
charts "github.com/linkerd/linkerd2/pkg/charts/linkerd2"
l5dcharts "github.com/linkerd/linkerd2/pkg/charts/linkerd2"
"github.com/linkerd/linkerd2/pkg/config"
flagspkg "github.com/linkerd/linkerd2/pkg/flags"
@ -262,9 +261,9 @@ func upgradeControlPlane(ctx context.Context, k *k8s.KubernetesAPI, flags []flag
return &buf, nil
}
func loadStoredValues(ctx context.Context, k *k8s.KubernetesAPI) (*charts.Values, error) {
func loadStoredValues(ctx context.Context, k *k8s.KubernetesAPI) (*l5dcharts.Values, error) {
// Load the default values from the chart.
values, err := charts.NewValues()
values, err := l5dcharts.NewValues()
if err != nil {
return nil, err
}

View File

@ -11,7 +11,6 @@ import (
"testing"
"github.com/linkerd/linkerd2/cli/flag"
"github.com/linkerd/linkerd2/pkg/charts/linkerd2"
charts "github.com/linkerd/linkerd2/pkg/charts/linkerd2"
flagspkg "github.com/linkerd/linkerd2/pkg/flags"
"github.com/linkerd/linkerd2/pkg/k8s"
@ -312,14 +311,14 @@ func TestUpgradeWebhookCrtsNameChange(t *testing.T) {
injectorCerts := generateCerts(t, "linkerd-proxy-injector.linkerd.svc", false)
defer injectorCerts.cleanup()
installOpts.ProxyInjector.TLS = &linkerd2.TLS{
installOpts.ProxyInjector.TLS = &charts.TLS{
ExternalSecret: true,
CaBundle: injectorCerts.ca,
}
validatorCerts := generateCerts(t, "linkerd-sp-validator.linkerd.svc", false)
defer validatorCerts.cleanup()
installOpts.ProfileValidator.TLS = &linkerd2.TLS{
installOpts.ProfileValidator.TLS = &charts.TLS{
ExternalSecret: true,
CaBundle: validatorCerts.ca,
}
@ -363,14 +362,14 @@ func TestUpgradeTwoLevelWebhookCrts(t *testing.T) {
// This tests the case where the webhook certs are not self-signed.
injectorCerts := generateCerts(t, "linkerd-proxy-injector.linkerd.svc", false)
defer injectorCerts.cleanup()
installOpts.ProxyInjector.TLS = &linkerd2.TLS{
installOpts.ProxyInjector.TLS = &charts.TLS{
ExternalSecret: true,
CaBundle: injectorCerts.ca,
}
validatorCerts := generateCerts(t, "linkerd-sp-validator.linkerd.svc", false)
defer validatorCerts.cleanup()
installOpts.ProfileValidator.TLS = &linkerd2.TLS{
installOpts.ProfileValidator.TLS = &charts.TLS{
ExternalSecret: true,
CaBundle: validatorCerts.ca,
}
@ -572,7 +571,7 @@ func pathMatch(path []string, template []string) bool {
return true
}
func renderInstall(t *testing.T, values *linkerd2.Values) *bytes.Buffer {
func renderInstall(t *testing.T, values *charts.Values) *bytes.Buffer {
var buf bytes.Buffer
if err := renderCRDs(&buf, valuespkg.Options{}); err != nil {
t.Fatalf("could not render install manifests: %s", err)

View File

@ -7,8 +7,6 @@ import (
"github.com/linkerd/linkerd2/controller/api/destination/watcher"
"github.com/linkerd/linkerd2/controller/api/util"
"github.com/linkerd/linkerd2/controller/k8s"
pkgk8s "github.com/linkerd/linkerd2/controller/k8s"
"github.com/sirupsen/logrus"
logging "github.com/sirupsen/logrus"
)
@ -449,7 +447,7 @@ func (m *mockDestinationGetProfileServer) Send(profile *pb.DestinationProfile) e
}
func makeEndpointTranslator(t *testing.T) (*mockDestinationGetServer, *endpointTranslator) {
k8sAPI, err := pkgk8s.NewFakeAPI(`
k8sAPI, err := k8s.NewFakeAPI(`
apiVersion: v1
kind: Node
metadata:
@ -482,7 +480,7 @@ metadata:
map[uint32]struct{}{},
k8sAPI.Node(),
mockGetServer,
logrus.WithField("test", t.Name()),
logging.WithField("test", t.Name()),
)
return mockGetServer, translator
}

View File

@ -13,7 +13,6 @@ import (
pkgK8s "github.com/linkerd/linkerd2/pkg/k8s"
admissionv1beta1 "k8s.io/api/admission/v1beta1"
corev1 "k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
)
@ -415,7 +414,7 @@ func getFakeServiceReq(b []byte) *admissionv1beta1.AdmissionRequest {
}
}
func ownerRetrieverFake(p *v1.Pod) (string, string, error) {
func ownerRetrieverFake(p *corev1.Pod) (string, string, error) {
return pkgK8s.Deployment, "owner-deployment", nil
}

View File

@ -14,7 +14,6 @@ import (
pkgk8s "github.com/linkerd/linkerd2/pkg/k8s"
pkgTls "github.com/linkerd/linkerd2/pkg/tls"
"github.com/linkerd/linkerd2/pkg/util"
"github.com/sirupsen/logrus"
log "github.com/sirupsen/logrus"
admissionv1beta1 "k8s.io/api/admission/v1beta1"
v1 "k8s.io/api/core/v1"
@ -83,7 +82,7 @@ func NewServer(
log.Fatalf("Failed to initialized certificate: %s", err)
}
log := logrus.WithFields(logrus.Fields{
log := log.WithFields(log.Fields{
"component": "proxy-injector",
"addr": addr,
})

View File

@ -7,7 +7,6 @@ import (
"github.com/linkerd/linkerd2/jaeger/pkg/labels"
pkgcmd "github.com/linkerd/linkerd2/pkg/cmd"
"github.com/linkerd/linkerd2/pkg/k8s"
pkgK8s "github.com/linkerd/linkerd2/pkg/k8s"
"github.com/spf13/cobra"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@ -48,7 +47,7 @@ func newCmdList() *cobra.Command {
for _, pod := range pods.Items {
pod := pod
if pkgK8s.IsMeshed(&pod, controlPlaneNamespace) {
if k8s.IsMeshed(&pod, controlPlaneNamespace) {
if labels.IsTracingEnabled(&pod) {
tracingEnabled = append(tracingEnabled, pod)
} else {

View File

@ -14,7 +14,6 @@ import (
"github.com/prometheus/client_golang/prometheus"
logging "github.com/sirupsen/logrus"
corev1 "k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
kerrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
@ -174,7 +173,7 @@ func NewRemoteClusterServiceWatcher(
eventBroadcaster.StartRecordingToSink(&typedcorev1.EventSinkImpl{
Interface: remoteAPI.Client.CoreV1().Events(""),
})
recorder := eventBroadcaster.NewRecorder(scheme.Scheme, v1.EventSource{
recorder := eventBroadcaster.NewRecorder(scheme.Scheme, corev1.EventSource{
Component: fmt.Sprintf("linkerd-service-mirror-%s", clusterName),
})
@ -481,7 +480,7 @@ func (rcsw *RemoteClusterServiceWatcher) handleRemoteServiceCreated(ctx context.
// Ensure the namespace exists, and skip mirroring if it doesn't
if _, err := rcsw.localAPIClient.Client.CoreV1().Namespaces().Get(ctx, remoteService.Namespace, metav1.GetOptions{}); err != nil {
if kerrors.IsNotFound(err) {
rcsw.recorder.Event(remoteService, v1.EventTypeNormal, eventTypeSkipped, "Skipped mirroring service: namespace does not exist")
rcsw.recorder.Event(remoteService, corev1.EventTypeNormal, eventTypeSkipped, "Skipped mirroring service: namespace does not exist")
rcsw.log.Warnf("Skipping mirroring of service %s: namespace %s does not exist", serviceInfo, remoteService.Namespace)
return nil
}
@ -1001,7 +1000,7 @@ func (rcsw *RemoteClusterServiceWatcher) repairEndpoints(ctx context.Context) er
// endpoints for a remote cluster. These endpoints are required for the probe
// worker responsible for probing gateway liveness, so these endpoints are
// never in a not ready state.
func (rcsw *RemoteClusterServiceWatcher) createOrUpdateGatewayEndpoints(ctx context.Context, addressses []v1.EndpointAddress) error {
func (rcsw *RemoteClusterServiceWatcher) createOrUpdateGatewayEndpoints(ctx context.Context, addressses []corev1.EndpointAddress) error {
gatewayMirrorName := fmt.Sprintf("probe-gateway-%s", rcsw.link.TargetClusterName)
endpoints := &corev1.Endpoints{
ObjectMeta: metav1.ObjectMeta{

View File

@ -7,7 +7,6 @@ import (
consts "github.com/linkerd/linkerd2/pkg/k8s"
logging "github.com/sirupsen/logrus"
corev1 "k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
kerrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
@ -47,7 +46,7 @@ func (rcsw *RemoteClusterServiceWatcher) createOrUpdateHeadlessEndpoints(ctx con
// as a headless mirror. If the service does not have any named addresses in
// its Endpoints object, then the endpoints should not be processed.
if len(exportedService.Spec.Ports) == 0 {
rcsw.recorder.Event(exportedService, v1.EventTypeNormal, eventTypeSkipped, "Skipped mirroring service: object spec has no exposed ports")
rcsw.recorder.Event(exportedService, corev1.EventTypeNormal, eventTypeSkipped, "Skipped mirroring service: object spec has no exposed ports")
rcsw.log.Infof("Skipped creating headless mirror for %s/%s: service object spec has no exposed ports", exportedService.Namespace, exportedService.Name)
return nil
}

View File

@ -11,7 +11,6 @@ import (
"github.com/linkerd/linkerd2/pkg/multicluster"
logging "github.com/sirupsen/logrus"
corev1 "k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/tools/record"
@ -274,7 +273,7 @@ func TestLocalNamespaceCreatedAfterServiceExport(t *testing.T) {
}
skippedEvent := <-eventRecorder.Events
if skippedEvent != fmt.Sprintf("%s %s %s", v1.EventTypeNormal, eventTypeSkipped, "Skipped mirroring service: namespace does not exist") {
if skippedEvent != fmt.Sprintf("%s %s %s", corev1.EventTypeNormal, eventTypeSkipped, "Skipped mirroring service: namespace does not exist") {
t.Error("Expected skipped event, got:", skippedEvent)
}

View File

@ -5,7 +5,6 @@ import (
"testing"
pb "github.com/linkerd/linkerd2-proxy-api/go/net"
proxy "github.com/linkerd/linkerd2-proxy-api/go/net"
l5dNetPb "github.com/linkerd/linkerd2/controller/gen/common/net"
"google.golang.org/protobuf/proto"
)
@ -128,16 +127,16 @@ func TestProxyAddressesToString(t *testing.T) {
name: "ipv4",
addrs: []pb.TcpAddress{
{
Ip: &proxy.IPAddress{
Ip: &proxy.IPAddress_Ipv4{
Ip: &pb.IPAddress{
Ip: &pb.IPAddress_Ipv4{
Ipv4: 3232235521,
},
},
Port: 1234,
},
{
Ip: &proxy.IPAddress{
Ip: &proxy.IPAddress_Ipv4{
Ip: &pb.IPAddress{
Ip: &pb.IPAddress_Ipv4{
Ipv4: 3232235522,
},
},
@ -200,18 +199,18 @@ func TestProxyIPToString(t *testing.T) {
func TestNetToPublic(t *testing.T) {
type addrExp struct {
proxyAddr *proxy.TcpAddress
proxyAddr *pb.TcpAddress
publicAddress *l5dNetPb.TcpAddress
}
expectations := []addrExp{
{
proxyAddr: &proxy.TcpAddress{},
proxyAddr: &pb.TcpAddress{},
publicAddress: &l5dNetPb.TcpAddress{},
},
{
proxyAddr: &proxy.TcpAddress{
Ip: &proxy.IPAddress{Ip: &proxy.IPAddress_Ipv4{Ipv4: 1}},
proxyAddr: &pb.TcpAddress{
Ip: &pb.IPAddress{Ip: &pb.IPAddress_Ipv4{Ipv4: 1}},
Port: 1234,
},
publicAddress: &l5dNetPb.TcpAddress{
@ -220,10 +219,10 @@ func TestNetToPublic(t *testing.T) {
},
},
{
proxyAddr: &proxy.TcpAddress{
Ip: &proxy.IPAddress{
Ip: &proxy.IPAddress_Ipv6{
Ipv6: &proxy.IPv6{
proxyAddr: &pb.TcpAddress{
Ip: &pb.IPAddress{
Ip: &pb.IPAddress_Ipv6{
Ipv6: &pb.IPv6{
First: 2345,
Last: 6789,
},

View File

@ -28,7 +28,6 @@ import (
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
apiextv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
v1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
kerrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@ -2203,7 +2202,7 @@ func CheckCustomResourceDefinitions(ctx context.Context, k8sAPI *k8s.KubernetesA
return nil
}
func crdHasVersion(crd *v1.CustomResourceDefinition, version string) bool {
func crdHasVersion(crd *apiextv1.CustomResourceDefinition, version string) bool {
for _, crdVersion := range crd.Spec.Versions {
if crdVersion.Name == version {
return true
@ -2760,8 +2759,9 @@ func CheckCanPerformAction(ctx context.Context, api *k8s.KubernetesAPI, verb, na
// getPodStatuses returns a map of all Linkerd container statuses:
// component =>
// pod name =>
// container statuses
//
// pod name =>
// container statuses
func getPodStatuses(pods []corev1.Pod) map[string]map[string][]corev1.ContainerStatus {
statuses := make(map[string]map[string][]corev1.ContainerStatus)

View File

@ -18,7 +18,6 @@ import (
jsonfilter "github.com/clarketm/json"
"github.com/linkerd/linkerd2/pkg/charts"
"github.com/linkerd/linkerd2/pkg/charts/linkerd2"
l5dcharts "github.com/linkerd/linkerd2/pkg/charts/linkerd2"
"github.com/linkerd/linkerd2/pkg/charts/static"
"github.com/linkerd/linkerd2/pkg/k8s"
@ -250,13 +249,13 @@ func (conf *ResourceConfig) ParseMetaAndYAML(bytes []byte) (*Report, error) {
}
// GetValues returns the values used for rendering patches.
func (conf *ResourceConfig) GetValues() *linkerd2.Values {
func (conf *ResourceConfig) GetValues() *l5dcharts.Values {
return conf.values
}
// GetOverriddenValues returns the final Values struct which is created
// by overriding annotated configuration on top of default Values
func (conf *ResourceConfig) GetOverriddenValues() (*linkerd2.Values, error) {
func (conf *ResourceConfig) GetOverriddenValues() (*l5dcharts.Values, error) {
// Make a copy of Values and mutate that
copyValues, err := conf.values.DeepCopy()
if err != nil {

View File

@ -10,7 +10,6 @@ import (
"time"
"github.com/linkerd/linkerd2/pkg/k8s"
consts "github.com/linkerd/linkerd2/pkg/k8s"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
@ -195,17 +194,17 @@ func (l Link) ToUnstructured() (unstructured.Unstructured, error) {
// ExtractProbeSpec parses the ProbSpec from a gateway service's annotations.
func ExtractProbeSpec(gateway *corev1.Service) (ProbeSpec, error) {
path := gateway.Annotations[consts.GatewayProbePath]
path := gateway.Annotations[k8s.GatewayProbePath]
if path == "" {
return ProbeSpec{}, errors.New("probe path is empty")
}
port, err := extractPort(gateway.Spec, consts.ProbePortName)
port, err := extractPort(gateway.Spec, k8s.ProbePortName)
if err != nil {
return ProbeSpec{}, err
}
period, err := strconv.ParseUint(gateway.Annotations[consts.GatewayProbePeriod], 10, 32)
period, err := strconv.ParseUint(gateway.Annotations[k8s.GatewayProbePeriod], 10, 32)
if err != nil {
return ProbeSpec{}, err
}

View File

@ -8,7 +8,6 @@ import (
"sync/atomic"
"github.com/fsnotify/fsnotify"
"github.com/sirupsen/logrus"
log "github.com/sirupsen/logrus"
)
@ -93,7 +92,7 @@ func (fscw *FsCredsWatcher) UpdateCert(certVal *atomic.Value) error {
// ProcessEvents reads from the update and error channels and reloads the certs when necessary
func (fscw *FsCredsWatcher) ProcessEvents(
log *logrus.Entry,
log *log.Entry,
certVal *atomic.Value,
updateEvent <-chan struct{},
errEvent <-chan error,

View File

@ -11,7 +11,6 @@ import (
"text/tabwriter"
"time"
"github.com/linkerd/linkerd2/pkg/cmd"
pkgcmd "github.com/linkerd/linkerd2/pkg/cmd"
"github.com/linkerd/linkerd2/pkg/healthcheck"
"github.com/linkerd/linkerd2/pkg/k8s"
@ -904,7 +903,7 @@ func (o *statOptions) validateConflictingFlags() error {
return fmt.Errorf("--to-namespace and --from-namespace flags are mutually exclusive")
}
if o.allNamespaces && o.namespace != cmd.GetDefaultNamespace(kubeconfigPath, kubeContext) {
if o.allNamespaces && o.namespace != pkgcmd.GetDefaultNamespace(kubeconfigPath, kubeContext) {
return fmt.Errorf("--all-namespaces and --namespace flags are mutually exclusive")
}
@ -924,7 +923,7 @@ func (o *statOptions) validateNamespaceFlags() error {
// Note: technically, this allows you to say `stat ns --namespace <default-namespace-from-kubectl-context>`, but that
// seems like an edge case.
if o.namespace != cmd.GetDefaultNamespace(kubeconfigPath, kubeContext) {
if o.namespace != pkgcmd.GetDefaultNamespace(kubeconfigPath, kubeContext) {
return fmt.Errorf("--namespace flag is incompatible with namespace resource type")
}

View File

@ -18,7 +18,6 @@ import (
"github.com/linkerd/linkerd2/pkg/prometheus"
pkgTls "github.com/linkerd/linkerd2/pkg/tls"
pb "github.com/linkerd/linkerd2/viz/tap/gen/tap"
"github.com/sirupsen/logrus"
log "github.com/sirupsen/logrus"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
@ -30,7 +29,7 @@ type Server struct {
router *httprouter.Router
allowedNames []string
certValue *atomic.Value
log *logrus.Entry
log *log.Entry
}
// NewServer creates a new server that implements the Tap APIService.
@ -61,7 +60,7 @@ func NewServer(
allowedNames = []string{}
}
log := logrus.WithFields(logrus.Fields{
log := log.WithFields(log.Fields{
"component": "tap",
"addr": addr,
})