Skip to content

Commit

Permalink
fix lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
jimassa committed Jun 25, 2024
1 parent d4b3f17 commit e24aae7
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 58 deletions.
2 changes: 1 addition & 1 deletion operator/cmd/cilium-crds.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ var (
Short: "Start the Retina operator for Hubble control plane",
Run: func(cobraCmd *cobra.Command, _ []string) {
fmt.Println("Starting Retina Operator with Cilium CRDs")
ciliumcrds.Execute(cobraCmd, h)
ciliumcrds.Execute(h)
},
}
)
Expand Down
32 changes: 0 additions & 32 deletions operator/cmd/cilium-crds/cmdref.go

This file was deleted.

7 changes: 3 additions & 4 deletions operator/cmd/cilium-crds/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (
"github.com/cilium/cilium/pkg/option"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"k8s.io/client-go/tools/leaderelection"
"k8s.io/client-go/tools/leaderelection/resourcelock"
Expand All @@ -41,10 +40,10 @@ var (
// set logger field: subsys=retina-operator
binaryName = filepath.Base(os.Args[0])
logger = logging.DefaultLogger.WithField(logfields.LogSubsys, binaryName)
operatorIdLength = 10
operatorIDLength = 10
)

func Execute(cmd *cobra.Command, h *hive.Hive) {
func Execute(h *hive.Hive) {
initEnv(h.Viper())

if err := h.Run(); err != nil {
Expand Down Expand Up @@ -130,7 +129,7 @@ func runOperator(l logrus.FieldLogger, lc *LeaderLifecycle, clientset k8sClient.
if err != nil {
l.WithError(err).Fatal("Failed to get hostname when generating lease lock identity")
}
operatorID, err = randomStringWithPrefix(operatorID+"-", operatorIdLength)
operatorID, err = randomStringWithPrefix(operatorID+"-", operatorIDLength)
if err != nil {
l.WithError(err).Fatal("Failed to generate random string for lease lock identity")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ type endpointReconciler struct {
identityManager *IdentityManager

// store of processed pods and namespaces
// processedPodCache map in store pod key to podEndpoint.
// processedPodCache map in store pod key to PodEndpoint.
// It contains only pods which we have processed via Pod events.
// It contains endpoint goal state, and is independent of ciliumEndpoints store.
// When endpointReconciler is leading, all endpoint state should be in API Server.
Expand Down Expand Up @@ -304,7 +304,7 @@ func (r *endpointReconciler) reconcilePod(ctx context.Context, podKey resource.K
if err != nil {
return errors.Wrap(err, "failed to get pod labels")
}
newPEP := &podEndpoint{
newPEP := &PodEndpoint{
key: podKey,
lbls: podLabels,
ipv4: pod.Status.PodIP,
Expand Down Expand Up @@ -357,7 +357,7 @@ func (r *endpointReconciler) handlePodDelete(ctx context.Context, n resource.Key
return nil
}

func (r *endpointReconciler) handlePodUpsert(ctx context.Context, newPEP *podEndpoint) error { //nolint:gocyclo // This function is too complex and should be refactored
func (r *endpointReconciler) handlePodUpsert(ctx context.Context, newPEP *PodEndpoint) error { //nolint:gocyclo // This function is too complex and should be refactored
r.l.WithField("podKey", newPEP.key.String()).Trace("handling pod upsert")

oldPEP, inCache := r.store.GetPod(newPEP.key)
Expand All @@ -366,7 +366,7 @@ func (r *endpointReconciler) handlePodUpsert(ctx context.Context, newPEP *podEnd
r.l.WithFields(logrus.Fields{
"podKey": newPEP.key.String(),
"pep": oldPEP,
}).Trace("podEndpoint found in cache")
}).Trace("PodEndpoint found in cache")
} else {
// this call will block until the store is synced with API Server
store, err := r.ciliumEndpoints.Store(ctx)
Expand Down Expand Up @@ -399,7 +399,7 @@ func (r *endpointReconciler) handlePodUpsert(ctx context.Context, newPEP *podEnd
"cep": oldCEP,
}).Warn("CiliumEndpoint has no ipv4 address, ignoring")
} else {
oldPEP = &podEndpoint{
oldPEP = &PodEndpoint{
key: newPEP.key,
endpointID: oldCEP.Status.ID,
ipv4: oldCEP.Status.Networking.Addressing[0].IPV4,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func TestPodCreate(t *testing.T) {
require.Greater(t, identityID, int64(0))

var expectedEndpointID int64 = 1 // FIXME switch to mock allocator once endpoint IDs are allocated by the operator
expectedCache := map[resource.Key]*podEndpoint{
expectedCache := map[resource.Key]*PodEndpoint{
key: {
key: key,
endpointID: expectedEndpointID,
Expand Down Expand Up @@ -153,6 +153,7 @@ func TestPodDeleteNoOp(t *testing.T) {
podKey, pod := podTestX()

require.NoError(t, r.ReconcilePod(context.TODO(), podKey, pod))
pod = nil

Check failure on line 156 in pkg/controllers/operator/cilium-crds/endpoint/endpoint_controller_test.go

View workflow job for this annotation

GitHub Actions / Lint (linux, amd64)

ineffectual assignment to pod (ineffassign)

Check failure on line 156 in pkg/controllers/operator/cilium-crds/endpoint/endpoint_controller_test.go

View workflow job for this annotation

GitHub Actions / Lint (linux, arm64)

ineffectual assignment to pod (ineffassign)

Check failure on line 156 in pkg/controllers/operator/cilium-crds/endpoint/endpoint_controller_test.go

View workflow job for this annotation

GitHub Actions / Lint (windows, amd64)

ineffectual assignment to pod (ineffassign)

Check failure on line 156 in pkg/controllers/operator/cilium-crds/endpoint/endpoint_controller_test.go

View workflow job for this annotation

GitHub Actions / Lint (windows, arm64)

ineffectual assignment to pod (ineffassign)
assertCEPDoesNotExist(t, ciliumEndpoints, podKey)
}

Expand All @@ -171,7 +172,7 @@ func TestPodLabelsChanged(t *testing.T) {
require.Greater(t, identityID, int64(0))

var expectedEndpointID int64 = 1 // FIXME switch to mock allocator once endpoint IDs are allocated by the operator
expectedCache := map[resource.Key]*podEndpoint{
expectedCache := map[resource.Key]*PodEndpoint{
key: {
key: key,
endpointID: expectedEndpointID,
Expand Down Expand Up @@ -240,7 +241,7 @@ func TestPodLabelsChanged(t *testing.T) {
require.NotNil(t, pep)
require.NotEqual(t, identityID, pep.identityID)
identityID = pep.identityID
expectedCacheNew := map[resource.Key]*podEndpoint{
expectedCacheNew := map[resource.Key]*PodEndpoint{
key: {
key: key,
endpointID: expectedEndpointID,
Expand Down Expand Up @@ -353,7 +354,7 @@ func TestPodNetworkingChanged(t *testing.T) {
require.True(t, ok)
require.NotNil(t, pep)
identityID = pep.identityID
expectedCacheNew := map[resource.Key]*podEndpoint{
expectedCacheNew := map[resource.Key]*PodEndpoint{
key: {
key: key,
endpointID: expectedEndpointID,
Expand Down Expand Up @@ -420,7 +421,7 @@ func TestPodNetworkingChanged(t *testing.T) {
require.True(t, ok)
require.NotNil(t, pep)
identityID = pep.identityID
expectedCacheNew = map[resource.Key]*podEndpoint{
expectedCacheNew = map[resource.Key]*PodEndpoint{
key: {
key: key,
endpointID: expectedEndpointID,
Expand Down
22 changes: 11 additions & 11 deletions pkg/controllers/operator/cilium-crds/endpoint/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import (
"k8s.io/apimachinery/pkg/types"
)

// podEndpoint represents a Pod/CiliumEndpoint
type podEndpoint struct {
// PodEndpoint represents a Pod/CiliumEndpoint
type PodEndpoint struct {
key resource.Key
endpointID int64
identityID int64
Expand All @@ -35,7 +35,7 @@ type podEndpoint struct {
podObj *slim_corev1.Pod
}

func (pep *podEndpoint) endpointStatus() ciliumv2.EndpointStatus {
func (pep *PodEndpoint) endpointStatus() ciliumv2.EndpointStatus {
return ciliumv2.EndpointStatus{
ID: pep.endpointID,
Identity: &ciliumv2.EndpointIdentity{
Expand All @@ -55,8 +55,8 @@ func (pep *podEndpoint) endpointStatus() ciliumv2.EndpointStatus {
}
}

func (pep *podEndpoint) deepCopy() *podEndpoint {
return &podEndpoint{
func (pep *PodEndpoint) deepCopy() *PodEndpoint {
return &PodEndpoint{
key: pep.key,
endpointID: pep.endpointID,
identityID: pep.identityID,
Expand All @@ -72,10 +72,10 @@ func (pep *podEndpoint) deepCopy() *podEndpoint {
type Store struct { //nolint:gocritic // This should be rewritten to limit exposure of mutex to external packages.
*sync.RWMutex

// Pods is a map of Pod key to podEndpoint
// Pods is a map of Pod key to PodEndpoint
// this is the expected endpoint state for the pod
// and is used to determine if the pod needs to be updated
Pods map[resource.Key]*podEndpoint
Pods map[resource.Key]*PodEndpoint

// Namespaces is a map of Namespace name to Namespace
// this is used to determine if the namespace needs to be updated
Expand All @@ -85,12 +85,12 @@ type Store struct { //nolint:gocritic // This should be rewritten to limit expos
func NewStore() *Store {
return &Store{
RWMutex: &sync.RWMutex{},
Pods: make(map[resource.Key]*podEndpoint),
Pods: make(map[resource.Key]*PodEndpoint),
Namespaces: make(map[string]*slim_corev1.Namespace),
}
}

func (s *Store) AddPod(pod *podEndpoint) {
func (s *Store) AddPod(pod *PodEndpoint) {
s.Lock()
defer s.Unlock()
s.Pods[pod.key] = pod
Expand All @@ -102,14 +102,14 @@ func (s *Store) AddNamespace(namespace *slim_corev1.Namespace) {
s.Namespaces[namespace.GetName()] = namespace
}

func (s *Store) GetPod(key resource.Key) (*podEndpoint, bool) {
func (s *Store) GetPod(key resource.Key) (*PodEndpoint, bool) {
s.RLock()
defer s.RUnlock()
pod, ok := s.Pods[key]
return pod, ok
}

func (s *Store) GetToDeletePod(key resource.Key) (*podEndpoint, bool) {
func (s *Store) GetToDeletePod(key resource.Key) (*PodEndpoint, bool) {
s.Lock()
defer s.Unlock()
pod, ok := s.Pods[key]
Expand Down

0 comments on commit e24aae7

Please sign in to comment.