Skip to content
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

Remove duplicate imports and enable stylecheck linter to prevent them #2364

Merged
merged 2 commits into from
Mar 5, 2024
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
3 changes: 3 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ linters:
- reassign
- revive
- staticcheck
- stylecheck
- typecheck
- unused

Expand All @@ -44,6 +45,8 @@ linters-settings:
- shadow
staticcheck:
go: "1.21"
stylecheck:
checks: ["ST1019"]
unused:
go: "1.21"

Expand Down
5 changes: 2 additions & 3 deletions connectivity/check/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
networkingv1 "k8s.io/api/networking/v1"
"k8s.io/apimachinery/pkg/api/errors"
k8sErrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
Expand Down Expand Up @@ -725,11 +724,11 @@ func (ct *ConnectivityTest) deploy(ctx context.Context) error {
},
})
_, err = ct.clients.src.CreateServiceAccount(ctx, ct.params.TestNamespace, k8s.NewServiceAccount(clientCPDeployment), metav1.CreateOptions{})
if err != nil && !errors.IsAlreadyExists(err) {
if err != nil && !k8sErrors.IsAlreadyExists(err) {
return fmt.Errorf("unable to create service account %s: %s", clientCPDeployment, err)
}
_, err = ct.clients.src.CreateDeployment(ctx, ct.params.TestNamespace, clientDeployment, metav1.CreateOptions{})
if err != nil && !errors.IsAlreadyExists(err) {
if err != nil && !k8sErrors.IsAlreadyExists(err) {
return fmt.Errorf("unable to create deployment %s: %s", clientCPDeployment, err)
}
}
Expand Down
9 changes: 4 additions & 5 deletions connectivity/check/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"strings"
"testing"

dto "github.com/prometheus/client_model/go"
prommodel "github.com/prometheus/client_model/go"
"github.com/stretchr/testify/assert"
)
Expand Down Expand Up @@ -66,7 +65,7 @@ func TestMetricsIncrease(t *testing.T) {
valueEgressAfter := 1599128.
valueIngressAfter := 3789798.

ciliumForwardCountTotalBefore := dto.MetricFamily{
ciliumForwardCountTotalBefore := prommodel.MetricFamily{
Name: &metricName,
Help: &metricHelp,
Type: &metricTypeCounter,
Expand All @@ -82,7 +81,7 @@ func TestMetricsIncrease(t *testing.T) {
},
}

ciliumForwardCountTotalAfter := dto.MetricFamily{
ciliumForwardCountTotalAfter := prommodel.MetricFamily{
Name: &metricName,
Help: &metricHelp,
Type: &metricTypeCounter,
Expand All @@ -99,8 +98,8 @@ func TestMetricsIncrease(t *testing.T) {
}

tt := map[string]struct {
before *dto.MetricFamily
after *dto.MetricFamily
before *prommodel.MetricFamily
after *prommodel.MetricFamily
err bool
}{
"metric increases": {
Expand Down
13 changes: 6 additions & 7 deletions connectivity/check/peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"github.com/cilium/cilium/api/v1/flow"
ciliumv2 "github.com/cilium/cilium/pkg/k8s/apis/cilium.io/v2"
corev1 "k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"

"github.com/cilium/cilium-cli/k8s"
"github.com/cilium/cilium-cli/utils/features"
Expand Down Expand Up @@ -206,7 +205,7 @@ func (s Service) Address(family features.IPFamily) string {
return fmt.Sprintf("%s.%s", s.Service.Name, s.Service.Namespace)
}

getClusterIPForIPFamily := func(family v1.IPFamily) string {
getClusterIPForIPFamily := func(family corev1.IPFamily) string {
for i, f := range s.Service.Spec.IPFamilies {
if f == family {
return s.Service.Spec.ClusterIPs[i]
Expand All @@ -218,9 +217,9 @@ func (s Service) Address(family features.IPFamily) string {

switch family {
case features.IPFamilyV4:
return getClusterIPForIPFamily(v1.IPv4Protocol)
return getClusterIPForIPFamily(corev1.IPv4Protocol)
case features.IPFamilyV6:
return getClusterIPForIPFamily(v1.IPv6Protocol)
return getClusterIPForIPFamily(corev1.IPv6Protocol)
}

return ""
Expand Down Expand Up @@ -250,7 +249,7 @@ func (s Service) FlowFilters() []*flow.FlowFilter {
return nil
}

func (s Service) ToNodeportService(node *v1.Node) NodeportService {
func (s Service) ToNodeportService(node *corev1.Node) NodeportService {
return NodeportService{
Service: s,
Node: node,
Expand All @@ -261,7 +260,7 @@ func (s Service) ToNodeportService(node *v1.Node) NodeportService {
// It implements interface TestPeer.
type NodeportService struct {
Service
Node *v1.Node
Node *corev1.Node
}

// Address returns the node IP of the wrapped Service.
Expand All @@ -271,7 +270,7 @@ func (s NodeportService) Address(family features.IPFamily) string {
}

for _, address := range s.Node.Status.Addresses {
if address.Type == v1.NodeInternalIP {
if address.Type == corev1.NodeInternalIP {
parsedAddress := net.ParseIP(address.Address)

switch family {
Expand Down
24 changes: 10 additions & 14 deletions connectivity/check/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,24 @@ import (
"time"

"github.com/blang/semver/v4"

k8sConst "github.com/cilium/cilium/pkg/k8s/apis/cilium.io"
ciliumv2 "github.com/cilium/cilium/pkg/k8s/apis/cilium.io/v2"
v2 "github.com/cilium/cilium/pkg/k8s/apis/cilium.io/v2"
"github.com/cilium/cilium/pkg/policy/api"
"github.com/cilium/cilium/pkg/versioncheck"

"github.com/cilium/cilium-cli/defaults"
"github.com/cilium/cilium-cli/sysdump"
"github.com/cilium/cilium-cli/utils/features"

corev1 "k8s.io/api/core/v1"
networkingv1 "k8s.io/api/networking/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/cloudflare/cfssl/cli/genkey"
"github.com/cloudflare/cfssl/config"
"github.com/cloudflare/cfssl/csr"
"github.com/cloudflare/cfssl/helpers"
"github.com/cloudflare/cfssl/initca"
"github.com/cloudflare/cfssl/signer"
"github.com/cloudflare/cfssl/signer/local"
corev1 "k8s.io/api/core/v1"
networkingv1 "k8s.io/api/networking/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/cilium/cilium-cli/defaults"
"github.com/cilium/cilium-cli/sysdump"
"github.com/cilium/cilium-cli/utils/features"
)

const (
Expand Down Expand Up @@ -100,7 +96,7 @@ type Test struct {
knps map[string]*networkingv1.NetworkPolicy

// Cilium Egress Gateway Policies active during this test.
cegps map[string]*v2.CiliumEgressGatewayPolicy
cegps map[string]*ciliumv2.CiliumEgressGatewayPolicy

// Secrets that have to be present during the test.
secrets map[string]*corev1.Secret
Expand Down Expand Up @@ -565,7 +561,7 @@ func (t *Test) WithCiliumEgressGatewayPolicy(params CiliumEgressGatewayPolicyPar
pl[i].Spec.EgressGateway.NodeSelector.MatchLabels["kubernetes.io/hostname"] = egressGatewayNode

// Set the excluded CIDRs
pl[i].Spec.ExcludedCIDRs = []v2.IPv4CIDR{}
pl[i].Spec.ExcludedCIDRs = []ciliumv2.IPv4CIDR{}

switch params.ExcludedCIDRsConf {
case ExternalNodeExcludedCIDRs:
Expand All @@ -574,7 +570,7 @@ func (t *Test) WithCiliumEgressGatewayPolicy(params CiliumEgressGatewayPolicyPar
continue
}

cidr := v2.IPv4CIDR(fmt.Sprintf("%s/32", nodeWithoutCiliumIP.IP))
cidr := ciliumv2.IPv4CIDR(fmt.Sprintf("%s/32", nodeWithoutCiliumIP.IP))
pl[i].Spec.ExcludedCIDRs = append(pl[i].Spec.ExcludedCIDRs, cidr)
}
}
Expand Down
5 changes: 2 additions & 3 deletions connectivity/tests/ipsec_xfrm.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package tests
import (
"context"
"encoding/json"
gojson "encoding/json"
"fmt"
"os"
"slices"
Expand Down Expand Up @@ -108,7 +107,7 @@ func (n *noIPsecXfrmErrors) storeIPsecXfrmErrors(t *check.Test, xfrmErrors map[s
}
defer file.Close()

j, err := gojson.Marshal(xfrmErrors)
j, err := json.Marshal(xfrmErrors)
if err != nil {
t.Fatalf("Failed to marshal JSON: %s", err)
}
Expand All @@ -124,7 +123,7 @@ func (n *noIPsecXfrmErrors) loadIPsecXfrmErrors(t *check.Test) map[string]string
t.Fatalf("Failed to read conn disrupt test result files: %s", err)
}
xfrmErrors := map[string]string{}
if err := gojson.Unmarshal(b, &xfrmErrors); err != nil {
if err := json.Unmarshal(b, &xfrmErrors); err != nil {
t.Fatalf("Failed to unmarshal JSON test result file: %s", err)
}
return xfrmErrors
Expand Down
3 changes: 1 addition & 2 deletions sysdump/sysdump.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"github.com/spf13/cobra"
"github.com/spf13/pflag"
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/apimachinery/pkg/runtime"
Expand Down Expand Up @@ -2369,7 +2368,7 @@ func (c *Collector) submitKVStoreTasks(ctx context.Context, pod *corev1.Pod) err
func (c *Collector) submitMetricsSubtask(pods *corev1.PodList, containerName, portName, filenameTmpl string) error {
for _, p := range pods.Items {
p := p
if p.Status.Phase != v1.PodRunning {
if p.Status.Phase != corev1.PodRunning {
continue
}
err := c.Pool.Submit(fmt.Sprintf("metrics-%s-%s-%s", p.Name, containerName, portName), func(ctx context.Context) error {
Expand Down
Loading