Skip to content

Commit

Permalink
Replace sync with github.com/cilium/cilium/pkg/lock
Browse files Browse the repository at this point in the history
[ cherry-picked from cilium/cilium-cli repository ]

Replace sync package with github.com/cilium/cilium/pkg/lock package so
that lock-check.sh [^1] doesn't complain when cilium-cli gets merged
with cilium repo [^2].

[^1]: https://github.com/cilium/cilium/blob/main/contrib/scripts/lock-check.sh
[^2]: cilium/design-cfps#9

Signed-off-by: Michi Mutsuzaki <michi@isovalent.com>
  • Loading branch information
michi-covalent committed Aug 16, 2024
1 parent ed109f3 commit b0432ec
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 29 deletions.
10 changes: 5 additions & 5 deletions cilium-cli/connectivity/check/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ import (
"sync"
"time"

hubprinter "github.com/cilium/cilium/hubble/pkg/printer"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"

"github.com/cilium/cilium/api/v1/flow"
"github.com/cilium/cilium/api/v1/observer"
"github.com/cilium/cilium/api/v1/relay"
hubprinter "github.com/cilium/cilium/hubble/pkg/printer"
"github.com/cilium/cilium/pkg/lock"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"

"github.com/cilium/cilium-cli/connectivity/filters"
"github.com/cilium/cilium-cli/defaults"
Expand Down Expand Up @@ -68,7 +68,7 @@ type Action struct {
expIngress Result

// flowsMu protects flows.
flowsMu sync.Mutex
flowsMu lock.Mutex
// flows is a map of all flow logs generated during the Action.
flows flowsSet

Expand Down
8 changes: 4 additions & 4 deletions cilium-cli/connectivity/check/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ import (
"time"

"github.com/blang/semver/v4"
"github.com/cilium/cilium/api/v1/observer"
ciliumv2 "github.com/cilium/cilium/pkg/k8s/apis/cilium.io/v2"
"github.com/cilium/cilium/pkg/lock"
"golang.org/x/exp/maps"
"golang.org/x/exp/slices"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/cilium/cilium/api/v1/observer"
ciliumv2 "github.com/cilium/cilium/pkg/k8s/apis/cilium.io/v2"

"github.com/cilium/cilium-cli/connectivity/internal/junit"
"github.com/cilium/cilium-cli/connectivity/perf/common"
"github.com/cilium/cilium-cli/defaults"
Expand Down Expand Up @@ -817,7 +817,7 @@ func (ct *ConnectivityTest) modifyStaticRoutesForNodesWithoutCilium(ctx context.

// multiClusterClientLock protects K8S client instantiation (Scheme registration)
// for the cluster mesh setup in case of connectivity test concurrency > 1
var multiClusterClientLock = sync.Mutex{}
var multiClusterClientLock = lock.Mutex{}

// determine if only single node tests can be ran.
// if the user specified SingleNode on the CLI this is taken as the truth and
Expand Down
7 changes: 4 additions & 3 deletions cilium-cli/connectivity/check/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ import (
"context"
"fmt"
"io"
"sync"
"sync/atomic"
"time"

"github.com/cilium/cilium/pkg/lock"
)

// NewConcurrentLogger factory function that returns ConcurrentLogger.
Expand All @@ -24,7 +25,7 @@ func NewConcurrentLogger(writer io.Writer, concurrency int) *ConcurrentLogger {
// goroutine to avoid deadlock in case if buffer is full.
nsTestsCh: make(chan string, concurrency*10),
nsTestMsgs: make(map[string][]message),
nsTestMsgsLock: sync.Mutex{},
nsTestMsgsLock: lock.Mutex{},
collectorStarted: atomic.Bool{},
printerDoneCh: make(chan bool),
}
Expand All @@ -35,7 +36,7 @@ type ConcurrentLogger struct {
writer io.Writer
nsTestsCh chan string
nsTestMsgs map[string][]message
nsTestMsgsLock sync.Mutex
nsTestMsgsLock lock.Mutex
collectorStarted atomic.Bool
printerDoneCh chan bool
nsTestFinishCount int
Expand Down
11 changes: 5 additions & 6 deletions cilium-cli/connectivity/check/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,19 @@ import (
"reflect"
"strconv"
"strings"
"sync"
"time"

flowpb "github.com/cilium/cilium/api/v1/flow"
ciliumv2 "github.com/cilium/cilium/pkg/k8s/apis/cilium.io/v2"
"github.com/cilium/cilium/pkg/k8s/client/clientset/versioned/scheme"
"github.com/cilium/cilium/pkg/lock"
networkingv1 "k8s.io/api/networking/v1"
k8serrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/serializer"
clientsetscheme "k8s.io/client-go/kubernetes/scheme"

flowpb "github.com/cilium/cilium/api/v1/flow"
ciliumv2 "github.com/cilium/cilium/pkg/k8s/apis/cilium.io/v2"
"github.com/cilium/cilium/pkg/k8s/client/clientset/versioned/scheme"

"github.com/cilium/cilium-cli/defaults"
"github.com/cilium/cilium-cli/k8s"
)
Expand Down Expand Up @@ -375,7 +374,7 @@ func sumMap(m map[string]int) int {

// policyApplyDeleteLock guarantees that only one connectivity test instance
// can apply or delete policies in case of connectivity test concurrency > 1
var policyApplyDeleteLock = sync.Mutex{}
var policyApplyDeleteLock = lock.Mutex{}

// applyPolicies applies all the Test's registered network policies.
func (t *Test) applyPolicies(ctx context.Context) error {
Expand Down
13 changes: 6 additions & 7 deletions cilium-cli/connectivity/check/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,14 @@ import (
"fmt"
"io"
"net"
"sync"
"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"
"github.com/cilium/cilium/pkg/lock"
"github.com/cilium/cilium/pkg/policy/api"
"github.com/cilium/cilium/pkg/versioncheck"
"github.com/cloudflare/cfssl/cli/genkey"
"github.com/cloudflare/cfssl/config"
"github.com/cloudflare/cfssl/csr"
Expand All @@ -25,11 +29,6 @@ import (
networkingv1 "k8s.io/api/networking/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

k8sConst "github.com/cilium/cilium/pkg/k8s/apis/cilium.io"
ciliumv2 "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"
Expand Down Expand Up @@ -148,7 +147,7 @@ type Test struct {

// Buffer to store output until it's flushed by a failure.
// Unused when run in verbose or debug mode.
logMu sync.RWMutex
logMu lock.RWMutex
logBuf io.ReadWriter

// conditionFn is a function that returns true if the test needs to run,
Expand Down
6 changes: 3 additions & 3 deletions cilium-cli/status/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import (
"bytes"
"fmt"
"strings"
"sync"
"text/tabwriter"
"time"

"github.com/cilium/cilium/api/v1/models"
"github.com/cilium/cilium/pkg/lock"

"github.com/cilium/cilium-cli/defaults"
)
Expand Down Expand Up @@ -115,7 +115,7 @@ type Status struct {
// For Helm mode only.
HelmChartVersion string `json:"helm_chart_version,omitempty"`

mutex *sync.Mutex
mutex *lock.Mutex
}

func newStatus() *Status {
Expand All @@ -127,7 +127,7 @@ func newStatus() *Status {
CiliumStatus: CiliumStatusMap{},
CiliumEndpoints: CiliumEndpointsMap{},
Errors: ErrorCountMapMap{},
mutex: &sync.Mutex{},
mutex: &lock.Mutex{},
}
}

Expand Down
4 changes: 3 additions & 1 deletion cilium-cli/utils/runner/multierror.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@ package runner
import (
"errors"
"sync"

"github.com/cilium/cilium/pkg/lock"
)

// MultiError can be used to run multiple goroutines that
// might return an error, wait for all the goroutines and
// return joined errors as a single one.
type MultiError struct {
wg sync.WaitGroup
lock sync.Mutex
lock lock.Mutex
err error
}

Expand Down

0 comments on commit b0432ec

Please sign in to comment.