Skip to content

Commit

Permalink
Removed dupe imports (linkerd#10049)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
alpeb authored Jan 10, 2023
1 parent c415abd commit 7428d4a
Show file tree
Hide file tree
Showing 19 changed files with 49 additions and 65 deletions.
4 changes: 3 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ linters:
- nakedret
- revive
- staticcheck
- stylecheck
- typecheck
- unconvert
- unparam
Expand All @@ -42,7 +43,6 @@ linters:
# - lll
# - maligned
# - prealloc
# - stylecheck

disable:
# https://github.com/golangci/golangci-lint/issues/2649
Expand All @@ -53,6 +53,8 @@ linters-settings:
rules:
- name: package-comments
disabled: true
stylecheck:
checks: ["ST1019"]

issues:
exclude-use-default: false
Expand Down
3 changes: 1 addition & 2 deletions cli/cmd/install_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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 {
Expand Down
5 changes: 2 additions & 3 deletions cli/cmd/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}),
Expand Down Expand Up @@ -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,
Expand Down
5 changes: 2 additions & 3 deletions cli/cmd/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
Expand Down
11 changes: 5 additions & 6 deletions cli/cmd/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
}
Expand Down Expand Up @@ -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,
}
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 2 additions & 4 deletions controller/api/destination/test_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -482,7 +480,7 @@ metadata:
map[uint32]struct{}{},
k8sAPI.Node(),
mockGetServer,
logrus.WithField("test", t.Name()),
logging.WithField("test", t.Name()),
)
return mockGetServer, translator
}
3 changes: 1 addition & 2 deletions controller/proxy-injector/webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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
}

Expand Down
3 changes: 1 addition & 2 deletions controller/webhook/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
})
Expand Down
3 changes: 1 addition & 2 deletions jaeger/cmd/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down
7 changes: 3 additions & 4 deletions multicluster/service-mirror/cluster_watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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),
})

Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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{
Expand Down
3 changes: 1 addition & 2 deletions multicluster/service-mirror/cluster_watcher_headless.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}

Expand Down
25 changes: 12 additions & 13 deletions pkg/addr/addr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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,
},
},
Expand Down Expand Up @@ -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{
Expand All @@ -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,
},
Expand Down
8 changes: 4 additions & 4 deletions pkg/healthcheck/healthcheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down
Loading

0 comments on commit 7428d4a

Please sign in to comment.