Skip to content

Commit

Permalink
Removing existing duplicate package imports with stylecheck
Browse files Browse the repository at this point in the history
After adding stylecheck in the previous commit, we do fix all the issues
it found.

The used command was:
make golangci-lint

Signed-off-by: Archisman Mridha <[email protected]>
Signed-off-by: Nikolay Nikolaev <[email protected]>
  • Loading branch information
Archisman-Mridha authored and nickolaev committed Jan 27, 2024
1 parent d687f91 commit ac2c269
Show file tree
Hide file tree
Showing 28 changed files with 92 additions and 126 deletions.
3 changes: 1 addition & 2 deletions daemon/cmd/local_node_sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
k8sLabels "k8s.io/apimachinery/pkg/labels"
k8sRuntime "k8s.io/apimachinery/pkg/runtime"
k8stypes "k8s.io/apimachinery/pkg/types"
Expand Down Expand Up @@ -87,7 +86,7 @@ func TestLocalNodeSync(t *testing.T) {
Config: &option.DaemonConfig{
IPv4NodeAddr: "1.2.3.4",
IPv6NodeAddr: "fd00::1",
NodeEncryptionOptOutLabels: labels.Nothing(),
NodeEncryptionOptOutLabels: k8sLabels.Nothing(),
},
K8sLocalNode: fln,
K8sCiliumLocalNode: &mockResource[*v2.CiliumNode]{
Expand Down
3 changes: 1 addition & 2 deletions operator/cmd/kvstore_watchdog.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"time"

"github.com/cilium/cilium/pkg/allocator"
"github.com/cilium/cilium/pkg/clustermesh/types"
cmtypes "github.com/cilium/cilium/pkg/clustermesh/types"
cmutils "github.com/cilium/cilium/pkg/clustermesh/utils"
"github.com/cilium/cilium/pkg/defaults"
Expand Down Expand Up @@ -107,7 +106,7 @@ func startKvstoreWatchdog() {
// insertion to prevent issues in case of, e.g., unexpected lease expiration.
cfg := cmtypes.CiliumClusterConfig{
ID: option.Config.ClusterID,
Capabilities: types.CiliumClusterConfigCapabilities{MaxConnectedClusters: option.Config.MaxConnectedClusters}}
Capabilities: cmtypes.CiliumClusterConfigCapabilities{MaxConnectedClusters: option.Config.MaxConnectedClusters}}
if err := cmutils.SetClusterConfig(ctx, option.Config.ClusterName, &cfg, kvstore.Client()); err != nil {
log.WithError(err).Warning("Unable to set local cluster config")
}
Expand Down
13 changes: 5 additions & 8 deletions operator/endpointgc/gc.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,13 @@ import (
"time"

"github.com/sirupsen/logrus"
k8sErrors "k8s.io/apimachinery/pkg/api/errors"
k8serrors "k8s.io/apimachinery/pkg/api/errors"
meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/cilium/cilium/pkg/controller"
"github.com/cilium/cilium/pkg/hive"
"github.com/cilium/cilium/pkg/hive/cell"
cilium_api_v2 "github.com/cilium/cilium/pkg/k8s/apis/cilium.io/v2"
k8sconstv2 "github.com/cilium/cilium/pkg/k8s/apis/cilium.io/v2"
k8sClient "github.com/cilium/cilium/pkg/k8s/client"
"github.com/cilium/cilium/pkg/k8s/resource"
slim_corev1 "github.com/cilium/cilium/pkg/k8s/slim/k8s/api/core/v1"
Expand Down Expand Up @@ -112,11 +109,11 @@ func (g *GC) Stop(ctx hive.HookContext) error {

func (g *GC) checkForCiliumEndpointCRD(ctx hive.HookContext) bool {
_, err := g.clientset.ApiextensionsV1().CustomResourceDefinitions().Get(
ctx, k8sconstv2.CEPName, metav1.GetOptions{ResourceVersion: "0"},
ctx, cilium_api_v2.CEPName, metav1.GetOptions{ResourceVersion: "0"},
)
if err == nil {
return true
} else if k8sErrors.IsNotFound(err) {
} else if k8serrors.IsNotFound(err) {
g.logger.WithError(err).Info("CiliumEndpoint CRD cannot be found, skipping garbage collection")
} else {
g.logger.WithError(err).Error(
Expand Down Expand Up @@ -244,15 +241,15 @@ func (g *GC) deleteCEP(cep *cilium_api_v2.CiliumEndpoint, scopedLog *logrus.Entr
logfields.EndpointID: cep.Status.ID,
})
scopedLog.Debug("Orphaned CiliumEndpoint is being garbage collected")
propagationPolicy := meta_v1.DeletePropagationBackground // because these are const strings but the API wants pointers
propagationPolicy := metav1.DeletePropagationBackground // because these are const strings but the API wants pointers
err := ciliumClient.CiliumEndpoints(cep.Namespace).Delete(
ctx,
cep.Name,
meta_v1.DeleteOptions{
metav1.DeleteOptions{
PropagationPolicy: &propagationPolicy,
// Set precondition to ensure we are only deleting CEPs owned by
// this agent.
Preconditions: &meta_v1.Preconditions{
Preconditions: &metav1.Preconditions{
UID: &cep.UID,
},
})
Expand Down
7 changes: 3 additions & 4 deletions operator/endpointgc/gc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
k8sClient "github.com/cilium/cilium/pkg/k8s/client"
"github.com/cilium/cilium/pkg/k8s/resource"
slim_corev1 "github.com/cilium/cilium/pkg/k8s/slim/k8s/api/core/v1"
v1 "github.com/cilium/cilium/pkg/k8s/slim/k8s/api/core/v1"
slim_metav1 "github.com/cilium/cilium/pkg/k8s/slim/k8s/apis/meta/v1"
"github.com/cilium/cilium/pkg/testutils"
)
Expand Down Expand Up @@ -212,19 +211,19 @@ func createOwnerReference(kind, name string) meta_v1.OwnerReference {
}
}

func createPod(name, namespace string, isRunning bool) *v1.Pod {
func createPod(name, namespace string, isRunning bool) *slim_corev1.Pod {
var phase slim_corev1.PodPhase
if isRunning {
phase = slim_corev1.PodRunning
} else {
phase = slim_corev1.PodSucceeded
}
return &v1.Pod{
return &slim_corev1.Pod{
ObjectMeta: slim_metav1.ObjectMeta{
Name: name,
Namespace: namespace,
},
Status: v1.PodStatus{
Status: slim_corev1.PodStatus{
Phase: phase,
},
}
Expand Down
9 changes: 4 additions & 5 deletions operator/pkg/bgpv2/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"k8s.io/apimachinery/pkg/api/errors"
k8sErrors "k8s.io/apimachinery/pkg/api/errors"
meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/utils/ptr"
Expand Down Expand Up @@ -634,7 +633,7 @@ func Test_Cleanup(t *testing.T) {

func upsertNode(req *require.Assertions, ctx context.Context, f *fixture, node *cilium_api_v2.CiliumNode) {
_, err := f.nodeClient.Get(ctx, node.Name, meta_v1.GetOptions{})
if err != nil && errors.IsNotFound(err) {
if err != nil && k8sErrors.IsNotFound(err) {
_, err = f.nodeClient.Create(ctx, node, meta_v1.CreateOptions{})
} else if err != nil {
req.Fail(err.Error())
Expand All @@ -650,7 +649,7 @@ func upsertBGPCC(req *require.Assertions, ctx context.Context, f *fixture, bgpcc
}

_, err := f.bgpcClient.Get(ctx, bgpcc.Name, meta_v1.GetOptions{})
if err != nil && errors.IsNotFound(err) {
if err != nil && k8sErrors.IsNotFound(err) {
_, err = f.bgpcClient.Create(ctx, bgpcc, meta_v1.CreateOptions{})
} else if err != nil {
req.Fail(err.Error())
Expand All @@ -662,7 +661,7 @@ func upsertBGPCC(req *require.Assertions, ctx context.Context, f *fixture, bgpcc

func deleteBGPCC(req *require.Assertions, ctx context.Context, f *fixture, name string) {
_, err := f.bgpcClient.Get(ctx, name, meta_v1.GetOptions{})
if err != nil && errors.IsNotFound(err) {
if err != nil && k8sErrors.IsNotFound(err) {
return // already deleted
} else if err != nil {
req.Fail(err.Error())
Expand All @@ -674,7 +673,7 @@ func deleteBGPCC(req *require.Assertions, ctx context.Context, f *fixture, name

func upsertNodeOverrides(req *require.Assertions, ctx context.Context, f *fixture, nodeOverride *cilium_api_v2alpha1.CiliumBGPNodeConfigOverride) {
_, err := f.bgpncoClient.Get(ctx, nodeOverride.Name, meta_v1.GetOptions{})
if err != nil && errors.IsNotFound(err) {
if err != nil && k8sErrors.IsNotFound(err) {
_, err = f.bgpncoClient.Create(ctx, nodeOverride, meta_v1.CreateOptions{})
} else {
_, err = f.bgpncoClient.Update(ctx, nodeOverride, meta_v1.UpdateOptions{})
Expand Down
13 changes: 6 additions & 7 deletions operator/pkg/ciliumendpointslice/reconciler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"github.com/cilium/cilium/pkg/hive"
"github.com/cilium/cilium/pkg/hive/cell"
cilium_v2 "github.com/cilium/cilium/pkg/k8s/apis/cilium.io/v2"
"github.com/cilium/cilium/pkg/k8s/apis/cilium.io/v2alpha1"
cilium_v2a1 "github.com/cilium/cilium/pkg/k8s/apis/cilium.io/v2alpha1"
k8sClient "github.com/cilium/cilium/pkg/k8s/client"
"github.com/cilium/cilium/pkg/k8s/resource"
Expand Down Expand Up @@ -53,10 +52,10 @@ func TestReconcileCreate(t *testing.T) {
r = newReconciler(context.Background(), fakeClient.CiliumFakeClientset.CiliumV2alpha1(), m, log, ciliumEndpoint, ciliumEndpointSlice, cesMetrics)
cepStore, _ := ciliumEndpoint.Store(context.Background())

var createdSlice *v2alpha1.CiliumEndpointSlice
var createdSlice *cilium_v2a1.CiliumEndpointSlice
fakeClient.CiliumFakeClientset.PrependReactor("create", "*", func(action k8sTesting.Action) (handled bool, ret runtime.Object, err error) {
pa := action.(k8sTesting.CreateAction)
createdSlice = pa.GetObject().(*v2alpha1.CiliumEndpointSlice)
createdSlice = pa.GetObject().(*cilium_v2a1.CiliumEndpointSlice)
return true, nil, nil
})

Expand Down Expand Up @@ -112,10 +111,10 @@ func TestReconcileUpdate(t *testing.T) {
cepStore, _ := ciliumEndpoint.Store(context.Background())
cesStore, _ := ciliumEndpointSlice.Store(context.Background())

var updatedSlice *v2alpha1.CiliumEndpointSlice
var updatedSlice *cilium_v2a1.CiliumEndpointSlice
fakeClient.CiliumFakeClientset.PrependReactor("update", "*", func(action k8sTesting.Action) (handled bool, ret runtime.Object, err error) {
pa := action.(k8sTesting.UpdateAction)
updatedSlice = pa.GetObject().(*v2alpha1.CiliumEndpointSlice)
updatedSlice = pa.GetObject().(*cilium_v2a1.CiliumEndpointSlice)
return true, nil, nil
})

Expand All @@ -125,7 +124,7 @@ func TestReconcileUpdate(t *testing.T) {
cepStore.CacheStore().Add(cep2)
cep3 := createStoreEndpoint("cep3", "ns", 2)
cepStore.CacheStore().Add(cep3)
ces1 := createStoreEndpointSlice("ces1", "ns", []v2alpha1.CoreCiliumEndpoint{createManagerEndpoint("cep1", 1), createManagerEndpoint("cep3", 2)})
ces1 := createStoreEndpointSlice("ces1", "ns", []cilium_v2a1.CoreCiliumEndpoint{createManagerEndpoint("cep1", 1), createManagerEndpoint("cep3", 2)})
cesStore.CacheStore().Add(ces1)
m.mapping.insertCES(NewCESName("ces1"), "ns")
m.mapping.insertCES(NewCESName("ces2"), "ns")
Expand Down Expand Up @@ -188,7 +187,7 @@ func TestReconcileDelete(t *testing.T) {
cepStore.CacheStore().Add(cep2)
cep3 := createStoreEndpoint("cep3", "ns", 2)
cepStore.CacheStore().Add(cep3)
ces1 := createStoreEndpointSlice("ces1", "ns", []v2alpha1.CoreCiliumEndpoint{createManagerEndpoint("cep1", 1), createManagerEndpoint("cep3", 2)})
ces1 := createStoreEndpointSlice("ces1", "ns", []cilium_v2a1.CoreCiliumEndpoint{createManagerEndpoint("cep1", 1), createManagerEndpoint("cep3", 2)})
cesStore.CacheStore().Add(ces1)
m.mapping.insertCES(NewCESName("ces1"), "ns")
m.mapping.insertCES(NewCESName("ces2"), "ns")
Expand Down
4 changes: 1 addition & 3 deletions operator/pkg/lbipam/lbipam.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"go4.org/netipx"
meta "k8s.io/apimachinery/pkg/api/meta"
meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/util/workqueue"

Expand All @@ -28,7 +27,6 @@ import (
"github.com/cilium/cilium/pkg/hive/job"
"github.com/cilium/cilium/pkg/ipalloc"
"github.com/cilium/cilium/pkg/k8s"
"github.com/cilium/cilium/pkg/k8s/apis/cilium.io/v2alpha1"
cilium_api_v2alpha1 "github.com/cilium/cilium/pkg/k8s/apis/cilium.io/v2alpha1"
"github.com/cilium/cilium/pkg/k8s/resource"
slim_core_v1 "github.com/cilium/cilium/pkg/k8s/slim/k8s/api/core/v1"
Expand Down Expand Up @@ -65,7 +63,7 @@ var (
)

type poolClient interface {
Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v2alpha1.CiliumLoadBalancerIPPool, err error)
Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts meta_v1.PatchOptions, subresources ...string) (result *cilium_api_v2alpha1.CiliumLoadBalancerIPPool, err error)
}

type lbIPAMParams struct {
Expand Down
25 changes: 11 additions & 14 deletions operator/pkg/lbipam/lbipam_fixture_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,13 @@ import (
"testing"
"time"

meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/watch"

jsonpatch "github.com/evanphx/json-patch"
"github.com/sirupsen/logrus"

"github.com/cilium/cilium/pkg/k8s/apis/cilium.io/v2alpha1"
cilium_api_v2alpha1 "github.com/cilium/cilium/pkg/k8s/apis/cilium.io/v2alpha1"
"github.com/cilium/cilium/pkg/k8s/resource"
slim_core_v1 "github.com/cilium/cilium/pkg/k8s/slim/k8s/api/core/v1"
Expand All @@ -39,10 +36,10 @@ const (
)

type fakeIPPoolClient struct {
resources map[resource.Key]*v2alpha1.CiliumLoadBalancerIPPool
resources map[resource.Key]*cilium_api_v2alpha1.CiliumLoadBalancerIPPool
}

func (fic *fakeIPPoolClient) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v2alpha1.CiliumLoadBalancerIPPool, err error) {
func (fic *fakeIPPoolClient) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (result *cilium_api_v2alpha1.CiliumLoadBalancerIPPool, err error) {
existing, found := fic.resources[resource.Key{Name: name}]
if !found {
return nil, fmt.Errorf("No IP pool found with name %q", name)
Expand Down Expand Up @@ -121,7 +118,7 @@ func (fsc *fakeSvcClient) Watch(ctx context.Context, opts metav1.ListOptions) (w
return nil, nil
}

func (fsc *fakeSvcClient) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *slim_core_v1.Service, err error) {
func (fsc *fakeSvcClient) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (result *slim_core_v1.Service, err error) {
existing, found := fsc.getter.resources[resource.Key{Namespace: fsc.namespace, Name: name}]
if !found {
return nil, fmt.Errorf("No service found with name %q", name)
Expand Down Expand Up @@ -170,14 +167,14 @@ type newFixture struct {
svcClient *fakeSvcClientGetter
}

func (nf *newFixture) GetPool(name string) *v2alpha1.CiliumLoadBalancerIPPool {
func (nf *newFixture) GetPool(name string) *cilium_api_v2alpha1.CiliumLoadBalancerIPPool {
return nf.poolClient.resources[resource.Key{Name: name}]
}

func (nf *newFixture) UpsertPool(t *testing.T, pool *v2alpha1.CiliumLoadBalancerIPPool) {
func (nf *newFixture) UpsertPool(t *testing.T, pool *cilium_api_v2alpha1.CiliumLoadBalancerIPPool) {
key := resource.Key{Name: pool.Name}
nf.poolClient.resources[key] = pool
nf.lbipam.handlePoolEvent(context.Background(), resource.Event[*v2alpha1.CiliumLoadBalancerIPPool]{
nf.lbipam.handlePoolEvent(context.Background(), resource.Event[*cilium_api_v2alpha1.CiliumLoadBalancerIPPool]{
Kind: resource.Upsert,
Key: key,
Object: pool,
Expand All @@ -189,10 +186,10 @@ func (nf *newFixture) UpsertPool(t *testing.T, pool *v2alpha1.CiliumLoadBalancer
})
}

func (nf *newFixture) DeletePool(t *testing.T, pool *v2alpha1.CiliumLoadBalancerIPPool) {
func (nf *newFixture) DeletePool(t *testing.T, pool *cilium_api_v2alpha1.CiliumLoadBalancerIPPool) {
key := resource.Key{Name: pool.Name}
delete(nf.poolClient.resources, key)
nf.lbipam.handlePoolEvent(context.Background(), resource.Event[*v2alpha1.CiliumLoadBalancerIPPool]{
nf.lbipam.handlePoolEvent(context.Background(), resource.Event[*cilium_api_v2alpha1.CiliumLoadBalancerIPPool]{
Kind: resource.Delete,
Key: key,
Object: pool,
Expand Down Expand Up @@ -248,7 +245,7 @@ func mkTestFixture(ipv4Enabled, ipv6Enabled bool) newFixture {
}

poolClient := &fakeIPPoolClient{
resources: make(map[resource.Key]*v2alpha1.CiliumLoadBalancerIPPool),
resources: make(map[resource.Key]*cilium_api_v2alpha1.CiliumLoadBalancerIPPool),
}
svcClient := &fakeSvcClientGetter{
resources: make(map[resource.Key]*slim_core_v1.Service),
Expand Down Expand Up @@ -284,10 +281,10 @@ func mkPool(uid types.UID, name string, cidrs []string) *cilium_api_v2alpha1.Cil
}

return &cilium_api_v2alpha1.CiliumLoadBalancerIPPool{
ObjectMeta: meta_v1.ObjectMeta{
ObjectMeta: metav1.ObjectMeta{
Name: name,
UID: uid,
CreationTimestamp: meta_v1.Date(2022, 10, 16, 12, 00, 00, 0, time.UTC),
CreationTimestamp: metav1.Date(2022, 10, 16, 12, 00, 00, 0, time.UTC),
},
Spec: cilium_api_v2alpha1.CiliumLoadBalancerIPPoolSpec{
Cidrs: blocks,
Expand Down
11 changes: 5 additions & 6 deletions pkg/bgp/manager/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (

"github.com/google/go-cmp/cmp"
metallbk8s "go.universe.tf/metallb/pkg/k8s"
mlbk8s "go.universe.tf/metallb/pkg/k8s"
"go.universe.tf/metallb/pkg/k8s/types"
v1 "k8s.io/api/core/v1"
"k8s.io/client-go/util/workqueue"
Expand All @@ -26,7 +25,7 @@ const (

var (
errTimeout = errors.New("timeout occurred before mock received event")
emptyEps = mlbk8s.EpsOrSlices{
emptyEps = metallbk8s.EpsOrSlices{
Type: metallbk8s.Eps,
}
)
Expand All @@ -44,11 +43,11 @@ func TestManagerEventNoService(t *testing.T) {
lock.Mutex
name string
srvRo *v1.Service
eps mlbk8s.EpsOrSlices
eps metallbk8s.EpsOrSlices
}

mockCtrl := &mock.MockMetalLBController{
SetBalancer_: func(name string, srvRo *v1.Service, eps mlbk8s.EpsOrSlices) types.SyncState {
SetBalancer_: func(name string, srvRo *v1.Service, eps metallbk8s.EpsOrSlices) types.SyncState {
rr.Lock()
rr.name, rr.srvRo, rr.eps = name, srvRo, eps
rr.Unlock()
Expand Down Expand Up @@ -114,11 +113,11 @@ func TestManagerEvent(t *testing.T) {
lock.Mutex
name string
srvRo *v1.Service
eps mlbk8s.EpsOrSlices
eps metallbk8s.EpsOrSlices
}

mockCtrl := &mock.MockMetalLBController{
SetBalancer_: func(name string, srvRo *v1.Service, eps mlbk8s.EpsOrSlices) types.SyncState {
SetBalancer_: func(name string, srvRo *v1.Service, eps metallbk8s.EpsOrSlices) types.SyncState {
rr.Lock()
rr.name, rr.srvRo, rr.eps = name, srvRo, eps
rr.Unlock()
Expand Down
Loading

0 comments on commit ac2c269

Please sign in to comment.