Showing 1,008 of 1,820 total issues
Function GetNetwork
has 5 return statements (exceeds 4 allowed). Open
func GetNetwork(ctx context.Context, c api.ControlClient, input string) (*api.Network, error) {
// GetService to match via full ID.
rg, err := c.GetNetwork(ctx, &api.GetNetworkRequest{NetworkID: input})
if err != nil {
// If any error (including NotFound), ListServices to match via full name.
Method Network.MarshalToSizedBuffer
has 5 return statements (exceeds 4 allowed). Open
func (m *Network) MarshalToSizedBuffer(dAtA []byte) (int, error) {
i := len(dAtA)
_ = i
var l int
_ = l
Method Node.MarshalToSizedBuffer
has a Cognitive Complexity of 22 (exceeds 20 allowed). Consider refactoring. Open
func (m *Node) MarshalToSizedBuffer(dAtA []byte) (int, error) {
i := len(dAtA)
_ = i
var l int
_ = l
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method Volume.MarshalToSizedBuffer
has 5 return statements (exceeds 4 allowed). Open
func (m *Volume) MarshalToSizedBuffer(dAtA []byte) (int, error) {
i := len(dAtA)
_ = i
var l int
_ = l
Method NetworkSpec.MarshalToSizedBuffer
has 5 return statements (exceeds 4 allowed). Open
func (m *NetworkSpec) MarshalToSizedBuffer(dAtA []byte) (int, error) {
i := len(dAtA)
_ = i
var l int
_ = l
Function GetAndValidateCertificateSubject
has 5 return statements (exceeds 4 allowed). Open
func GetAndValidateCertificateSubject(certs []tls.Certificate) (pkix.Name, error) {
for i := range certs {
cert := &certs[i]
x509Cert, err := x509.ParseCertificate(cert.Certificate[0])
if err != nil {
Method ConstraintEnforcer.rejectNoncompliantTasks
has 5 return statements (exceeds 4 allowed). Open
func (ce *ConstraintEnforcer) rejectNoncompliantTasks(node *api.Node) {
// If the availability is "drain", the orchestrator will
// shut down all tasks.
// If the availability is "pause", we shouldn't touch
// the tasks on this node.
Method tasksByCreationTimestamp.Less
has 5 return statements (exceeds 4 allowed). Open
func (t tasksByCreationTimestamp) Less(i, j int) bool {
if t[i].Meta.CreatedAt == nil {
return true
}
if t[j].Meta.CreatedAt == nil {
Method Orchestrator.Run
has 5 return statements (exceeds 4 allowed). Open
func (r *Orchestrator) Run(ctx context.Context) error {
defer close(r.doneChan)
// Watch changes to services and tasks
queue := r.store.WatchQueue()
Method Supervisor.waitRestart
has 5 return statements (exceeds 4 allowed). Open
func (r *Supervisor) waitRestart(ctx context.Context, oldDelay *delayedStart, cluster *api.Cluster, taskID string) {
// Wait for the last restart delay to elapse.
select {
case <-oldDelay.doneCh:
case <-ctx.Done():
Method Server.UpdateRootCA
has a Cognitive Complexity of 22 (exceeds 20 allowed). Consider refactoring. Open
func (s *Server) UpdateRootCA(ctx context.Context, cluster *api.Cluster, reconciler *rootRotationReconciler) error {
s.mu.Lock()
s.joinTokens = cluster.RootCA.JoinTokens.Copy()
s.mu.Unlock()
rCA := cluster.RootCA.Copy()
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function ConvertToECPrivateKeyPEM
has 5 return statements (exceeds 4 allowed). Open
func ConvertToECPrivateKeyPEM(inPEM []byte) ([]byte, error) {
block, _ := pem.Decode(inPEM)
if block == nil {
return nil, errors.New("invalid pem bytes")
}
Method Updater.useExistingTask
has a Cognitive Complexity of 22 (exceeds 20 allowed). Consider refactoring. Open
func (u *Updater) useExistingTask(ctx context.Context, slot orchestrator.Slot, existing *api.Task) error {
var removeTasks []*api.Task
for _, t := range slot {
if t != existing {
removeTasks = append(removeTasks, t)
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function ConvertECPrivateKeyPEM
has 5 return statements (exceeds 4 allowed). Open
func ConvertECPrivateKeyPEM(inPEM []byte) ([]byte, error) {
block, _ := pem.Decode(inPEM)
if block == nil {
return nil, errors.New("invalid pem bytes")
}
Method SecurityConfig.updateTLSCredentials
has 5 return statements (exceeds 4 allowed). Open
func (s *SecurityConfig) updateTLSCredentials(certificate *tls.Certificate, issuerInfo *IssuerInfo) error {
certs := []tls.Certificate{*certificate}
clientConfig, err := NewClientTLSConfig(certs, s.rootCA.Pool, ManagerRole)
if err != nil {
return errors.Wrap(err, "failed to create a new client config using the new root CA")
Function DownloadRootCA
has 5 return statements (exceeds 4 allowed). Open
func DownloadRootCA(ctx context.Context, paths CertPaths, token string, connBroker *connectionbroker.Broker) (RootCA, error) {
var rootCA RootCA
// Get a digest for the optional CA hash string that we've been provided
// If we were provided a non-empty string, and it is an invalid hash, return
// otherwise, allow the invalid digest through.
Function SetServiceTasksRemove
has 5 return statements (exceeds 4 allowed). Open
func SetServiceTasksRemove(ctx context.Context, s *store.MemoryStore, service *api.Service) {
var (
tasks []*api.Task
err error
)
Method Orchestrator.tickTasks
has 5 return statements (exceeds 4 allowed). Open
func (r *Orchestrator) tickTasks(ctx context.Context) {
if len(r.restartTasks) > 0 {
err := r.store.Batch(func(batch *store.Batch) error {
for taskID := range r.restartTasks {
err := batch.Update(func(tx store.Tx) error {
Method TLSRenewer.Start
has 5 return statements (exceeds 4 allowed). Open
func (t *TLSRenewer) Start(ctx context.Context) <-chan CertificateUpdate {
updates := make(chan CertificateUpdate)
go func() {
var (
Function updateRootThenUpdateCert
has 5 return statements (exceeds 4 allowed). Open
func updateRootThenUpdateCert(ctx context.Context, s *SecurityConfig, connBroker *connectionbroker.Broker, rootPaths CertPaths, failedCert *x509.Certificate) (*tls.Certificate, *IssuerInfo, error) {
if len(failedCert.Subject.OrganizationalUnit) == 0 || failedCert.Subject.OrganizationalUnit[0] != WorkerRole {
return nil, nil, errors.New("cannot update root CA since this is not a worker")
}
// try downloading a new root CA if it's an unknown authority issue, in case there was a root rotation completion