diff --git a/.golangci.yml b/.golangci.yml index 68462c74d..f81dc0d8b 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -36,7 +36,6 @@ linters: - gocheckcompilerdirectives - goconst - gocritic - - err113 - gofmt - goimports - goprintffuncname diff --git a/api/gateway/v1alpha1/gatewaygroup_types.go b/api/gateway/v1alpha1/gatewaygroup_types.go index d4ac05cf1..ca8ad25b6 100644 --- a/api/gateway/v1alpha1/gatewaygroup_types.go +++ b/api/gateway/v1alpha1/gatewaygroup_types.go @@ -70,10 +70,10 @@ func (gg *GatewayGroup) Default() { func (gg *GatewayGroup) Validate(_ context.Context, _ kclient.Reader, fabricCfg *meta.FabricConfig) error { if fabricCfg != nil && !fabricCfg.EnableGateway { - return fmt.Errorf("gateway support is not enabled") //nolint:err113 + return fmt.Errorf("gateway support is not enabled") } if gg.Namespace != kmetav1.NamespaceDefault { - return fmt.Errorf("gatewaygroup namespace must be %s", kmetav1.NamespaceDefault) //nolint:err113 + return fmt.Errorf("gatewaygroup namespace must be %s", kmetav1.NamespaceDefault) } return nil diff --git a/api/gateway/v1alpha1/gatewaypeering_types.go b/api/gateway/v1alpha1/gatewaypeering_types.go index 1a0dafc13..918da2198 100644 --- a/api/gateway/v1alpha1/gatewaypeering_types.go +++ b/api/gateway/v1alpha1/gatewaypeering_types.go @@ -185,18 +185,18 @@ func (p *GatewayPeering) Default() { func (p *GatewayPeering) Validate(ctx context.Context, kube kclient.Reader, fabricCfg *meta.FabricConfig) error { if fabricCfg != nil && !fabricCfg.EnableGateway { - return fmt.Errorf("gateway support is not enabled") //nolint:err113 + return fmt.Errorf("gateway support is not enabled") } if p.Namespace != kmetav1.NamespaceDefault { - return fmt.Errorf("gatewaypeering namespace must be %s", kmetav1.NamespaceDefault) //nolint:err113 + return fmt.Errorf("gatewaypeering namespace must be %s", kmetav1.NamespaceDefault) } if p.Spec.GatewayGroup == "" { - return fmt.Errorf("gateway group must be specified %s", p.Name) //nolint:err113 + return fmt.Errorf("gateway group must be specified %s", p.Name) } vpcs := slices.Collect(maps.Keys(p.Spec.Peering)) if len(vpcs) != 2 { - return fmt.Errorf("peering must have exactly 2 VPCs, got %d", len(vpcs)) //nolint:err113 + return fmt.Errorf("peering must have exactly 2 VPCs, got %d", len(vpcs)) } // track the NAT on each side of the peering and disallow unsupported configurations vpcNAT := make(map[string]struct { @@ -209,10 +209,10 @@ func (p *GatewayPeering) Validate(ctx context.Context, kube kclient.Reader, fabr } for _, expose := range vpc.Expose { if expose.DefaultDestination && (len(expose.IPs) > 0 || len(expose.As) > 0 || expose.NAT != nil) { - return fmt.Errorf("default flag should be the only thing set in expose of VPC %s", name) //nolint:err113 + return fmt.Errorf("default flag should be the only thing set in expose of VPC %s", name) } if len(expose.IPs) == 0 && !expose.DefaultDestination { - return fmt.Errorf("at least one IP block must be specified in peering expose of VPC %s", name) //nolint:err113 + return fmt.Errorf("at least one IP block must be specified in peering expose of VPC %s", name) } for _, ip := range expose.IPs { nonnil := 0 @@ -230,12 +230,12 @@ func (p *GatewayPeering) Validate(ctx context.Context, kube kclient.Reader, fabr } if ip.VPCSubnet != "" { if extName, isExternal := strings.CutPrefix(name, v1beta1.VPCInfoExtPrefix); isExternal { - return fmt.Errorf("external %s cannot have an IP block with VPC Subnets specified", extName) //nolint:err113 + return fmt.Errorf("external %s cannot have an IP block with VPC Subnets specified", extName) } nonnil++ } if nonnil != 1 { - return fmt.Errorf("exactly one of cidr, not or vpcSubnet must be set in peering expose IPs of VPC %s", name) //nolint:err113 + return fmt.Errorf("exactly one of cidr, not or vpcSubnet must be set in peering expose IPs of VPC %s", name) } } for _, as := range expose.As { @@ -253,12 +253,12 @@ func (p *GatewayPeering) Validate(ctx context.Context, kube kclient.Reader, fabr nonnil++ } if nonnil != 1 { - return fmt.Errorf("exactly one of cidr or not must be set in peering expose AS of VPC %s", name) //nolint:err113 + return fmt.Errorf("exactly one of cidr or not must be set in peering expose AS of VPC %s", name) } } if (len(expose.As) == 0) != (expose.NAT == nil) { - return fmt.Errorf("expose.As and expose.NAT must both be set or both be empty in peering expose of VPC %s", name) //nolint:err113 + return fmt.Errorf("expose.As and expose.NAT must both be set or both be empty in peering expose of VPC %s", name) } if expose.NAT != nil { @@ -283,12 +283,12 @@ func (p *GatewayPeering) Validate(ctx context.Context, kube kclient.Reader, fabr } if nonNils != 1 { - return fmt.Errorf("exactly one of masquerade, static, or portForward must be set in NAT section for peering expose of VPC %s", name) //nolint:err113 + return fmt.Errorf("exactly one of masquerade, static, or portForward must be set in NAT section for peering expose of VPC %s", name) } if expose.NAT.PortForward != nil { if len(expose.NAT.PortForward.Ports) == 0 { - return fmt.Errorf("at least one port forwarding rule must be set in NAT section for peering expose of VPC %s", name) //nolint:err113 + return fmt.Errorf("at least one port forwarding rule must be set in NAT section for peering expose of VPC %s", name) } for idx, entry := range expose.NAT.PortForward.Ports { @@ -301,7 +301,7 @@ func (p *GatewayPeering) Validate(ctx context.Context, kube kclient.Reader, fabr } if !slices.Contains(PeeringNATProtocols, entry.Protocol) { - return fmt.Errorf("invalid protocol %q in port forwarding rule %d in NAT section for peering expose of VPC %s", entry.Protocol, idx, name) //nolint:err113 + return fmt.Errorf("invalid protocol %q in port forwarding rule %d in NAT section for peering expose of VPC %s", entry.Protocol, idx, name) } } } @@ -309,17 +309,17 @@ func (p *GatewayPeering) Validate(ctx context.Context, kube kclient.Reader, fabr } } if vpcNAT[vpcs[0]].Stateful && vpcNAT[vpcs[1]].Stateful { - return fmt.Errorf("unsupported configuration, only one side of a peering can use stateful NAT (i.e. masquerade or portForward)") //nolint:err113 + return fmt.Errorf("unsupported configuration, only one side of a peering can use stateful NAT (i.e. masquerade or portForward)") } if (vpcNAT[vpcs[0]].Stateless && vpcNAT[vpcs[1]].Stateful) || (vpcNAT[vpcs[1]].Stateless && vpcNAT[vpcs[0]].Stateful) { - return fmt.Errorf("unsupported configuration, one side of a peering using static NAT cannot peer with a side using stateful NAT") //nolint:err113 + return fmt.Errorf("unsupported configuration, one side of a peering using static NAT cannot peer with a side using stateful NAT") } if kube != nil { gwGroup := &GatewayGroup{} if err := kube.Get(ctx, kclient.ObjectKey{Name: p.Spec.GatewayGroup, Namespace: p.Namespace}, gwGroup); err != nil { if kapierrors.IsNotFound(err) { - return fmt.Errorf("gateway group %s not found", p.Spec.GatewayGroup) //nolint:err113 + return fmt.Errorf("gateway group %s not found", p.Spec.GatewayGroup) } return fmt.Errorf("failed to get gateway group %s: %w", p.Spec.GatewayGroup, err) @@ -370,7 +370,7 @@ func (p *GatewayPeering) Validate(ctx context.Context, kube kclient.Reader, fabr return fmt.Errorf("failed to parse existing exposed CIDR %s: %w", otherCIDR, err) } if ourP.Overlaps(otherP) { - return fmt.Errorf("overlap between existing exposed CIDR %s and new exposed CIDR %s", otherCIDR, ourCIDR) //nolint:err113 + return fmt.Errorf("overlap between existing exposed CIDR %s and new exposed CIDR %s", otherCIDR, ourCIDR) } } } @@ -387,7 +387,7 @@ func (p *GatewayPeering) Validate(ctx context.Context, kube kclient.Reader, fabr var external v1beta1.External if err := kube.Get(ctx, ktypes.NamespacedName{Name: extName, Namespace: kmetav1.NamespaceDefault}, &external); err != nil { if kapierrors.IsNotFound(err) { - return fmt.Errorf("external %s not found", extName) //nolint:err113 + return fmt.Errorf("external %s not found", extName) } return fmt.Errorf("failed to get External %s: %w", extName, err) @@ -401,7 +401,7 @@ func (p *GatewayPeering) Validate(ctx context.Context, kube kclient.Reader, fabr var vpc v1beta1.VPC if err := kube.Get(ctx, ktypes.NamespacedName{Name: vpcName, Namespace: kmetav1.NamespaceDefault}, &vpc); err != nil { if kapierrors.IsNotFound(err) { - return fmt.Errorf("VPC %s not found", vpcName) //nolint:err113 + return fmt.Errorf("VPC %s not found", vpcName) } return fmt.Errorf("failed to get VPC %s: %w", vpcName, err) @@ -429,12 +429,12 @@ func (p *GatewayPeering) Validate(ctx context.Context, kube kclient.Reader, fabr } } if !found { - return fmt.Errorf("CIDR %s is not part of VPC %s", ip.CIDR, vpcName) //nolint:err113 + return fmt.Errorf("CIDR %s is not part of VPC %s", ip.CIDR, vpcName) } } if ip.VPCSubnet != "" { if _, ok := vpc.Spec.Subnets[ip.VPCSubnet]; !ok { - return fmt.Errorf("VPC subnet %s referenced in peering expose does not exist in VPC %s", ip.VPCSubnet, vpcName) //nolint:err113 + return fmt.Errorf("VPC subnet %s referenced in peering expose does not exist in VPC %s", ip.VPCSubnet, vpcName) } } } @@ -468,50 +468,50 @@ func collectExposedCIDRs(entry *PeeringEntry, cidrs []string) []string { func validatePort(in string) error { if strings.TrimSpace(in) != in { - return fmt.Errorf("invalid port %q: should not contain leading or trailing whitespace", in) //nolint:err113 + return fmt.Errorf("invalid port %q: should not contain leading or trailing whitespace", in) } if strings.Contains(in, ",") { - return fmt.Errorf("invalid port %q: should be a single port or range", in) //nolint:err113 + return fmt.Errorf("invalid port %q: should be a single port or range", in) } switch { case in == "": - return fmt.Errorf("port entry should not be empty") //nolint:err113 + return fmt.Errorf("port entry should not be empty") case !strings.Contains(in, "-"): if port, err := strconv.Atoi(in); err != nil { return fmt.Errorf("invalid port %q: %w", in, err) } else if port < 1 || port > 65535 { - return fmt.Errorf("invalid port %d: port should be between 1 and 65535", port) //nolint:err113 + return fmt.Errorf("invalid port %d: port should be between 1 and 65535", port) } default: parts := strings.Split(in, "-") if len(parts) != 2 { - return fmt.Errorf("invalid port range %s: should be in format start-end", in) //nolint:err113 + return fmt.Errorf("invalid port range %s: should be in format start-end", in) } parts[0] = strings.TrimSpace(parts[0]) parts[1] = strings.TrimSpace(parts[1]) if parts[0] == "" || parts[1] == "" { - return fmt.Errorf("invalid port range %s: both start and end should not be empty", in) //nolint:err113 + return fmt.Errorf("invalid port range %s: both start and end should not be empty", in) } start, err := strconv.Atoi(parts[0]) if err != nil { return fmt.Errorf("invalid start port %s: %w", parts[0], err) } else if start < 1 || start > 65535 { - return fmt.Errorf("invalid start port %d: port should be between 1 and 65535", start) //nolint:err113 + return fmt.Errorf("invalid start port %d: port should be between 1 and 65535", start) } end, err := strconv.Atoi(parts[1]) if err != nil { return fmt.Errorf("invalid end port %s: %w", parts[1], err) } else if end < 1 || end > 65535 { - return fmt.Errorf("invalid end port %d: port should be between 1 and 65535", end) //nolint:err113 + return fmt.Errorf("invalid end port %d: port should be between 1 and 65535", end) } if start > end { - return fmt.Errorf("invalid port range %s: start port %d is greater than end port %d", in, start, end) //nolint:err113 + return fmt.Errorf("invalid port range %s: start port %d is greater than end port %d", in, start, end) } } diff --git a/api/gateway/v1alpha1/vpcinfo_types.go b/api/gateway/v1alpha1/vpcinfo_types.go index 2609bea13..341c2acd4 100644 --- a/api/gateway/v1alpha1/vpcinfo_types.go +++ b/api/gateway/v1alpha1/vpcinfo_types.go @@ -81,14 +81,14 @@ func (vpc *VPCInfo) Default() { func (vpc *VPCInfo) Validate(_ context.Context, _ kclient.Reader, fabricCfg *meta.FabricConfig) error { if fabricCfg != nil && !fabricCfg.EnableGateway { - return fmt.Errorf("gateway support is not enabled") //nolint:err113 + return fmt.Errorf("gateway support is not enabled") } if vpc.Namespace != kmetav1.NamespaceDefault { - return fmt.Errorf("vpcinfo namespace must be %s", kmetav1.NamespaceDefault) //nolint:err113 + return fmt.Errorf("vpcinfo namespace must be %s", kmetav1.NamespaceDefault) } if vpc.Spec.VNI == 0 { - return fmt.Errorf("VPCInfo VNI must be set and non-zero") //nolint:goerr113 + return fmt.Errorf("VPCInfo VNI must be set and non-zero") } for name, subnet := range vpc.Spec.Subnets { diff --git a/api/meta/types.go b/api/meta/types.go index dda0237e6..8db3df34d 100644 --- a/api/meta/types.go +++ b/api/meta/types.go @@ -398,7 +398,7 @@ func (cfg *FabricConfig) Init() (*FabricConfig, error) { for _, commStr := range cfg.GatewayCommunities { parts := strings.Split(commStr, ":") if len(parts) != 2 { - return nil, fmt.Errorf("config: gatewayCommunity community %s format is invalid", commStr) //nolint:err113 + return nil, fmt.Errorf("config: gatewayCommunity community %s format is invalid", commStr) } if _, err := strconv.ParseUint(parts[0], 10, 16); err != nil { return nil, fmt.Errorf("config: gatewayCommunity community %s is invalid: %w", commStr, err) diff --git a/api/vpc/v1beta1/external_types.go b/api/vpc/v1beta1/external_types.go index 36dd10541..a3740dc97 100644 --- a/api/vpc/v1beta1/external_types.go +++ b/api/vpc/v1beta1/external_types.go @@ -167,7 +167,7 @@ func (external *External) Validate(ctx context.Context, kube kclient.Reader, _ * for i := range prefixes { for j := i + 1; j < len(prefixes); j++ { if prefixes[i].Overlaps(prefixes[j]) { - return nil, fmt.Errorf("static prefixes %s and %s overlap with each other", prefixes[i].String(), prefixes[j].String()) //nolint:goerr113 + return nil, fmt.Errorf("static prefixes %s and %s overlap with each other", prefixes[i].String(), prefixes[j].String()) } } } diff --git a/api/vpc/v1beta1/externalattachment_types.go b/api/vpc/v1beta1/externalattachment_types.go index fcdfd9fa3..88c9b2247 100644 --- a/api/vpc/v1beta1/externalattachment_types.go +++ b/api/vpc/v1beta1/externalattachment_types.go @@ -310,7 +310,7 @@ func (attach *ExternalAttachment) Validate(ctx context.Context, kube kclient.Rea return nil, errors.Errorf("switch.ip is required") } if _, _, err := net.ParseCIDR(attach.Spec.Switch.IP); err != nil { - return nil, errors.New("switch.ip is not a valid IP CIDR") //nolint: goerr113 + return nil, errors.New("switch.ip is not a valid IP CIDR") } if attach.Spec.Neighbor.ASN == 0 { return nil, errors.Errorf("neighbor.asn is required") @@ -319,7 +319,7 @@ func (attach *ExternalAttachment) Validate(ctx context.Context, kube kclient.Rea return nil, errors.Errorf("neighbor.ip is required") } if ip := net.ParseIP(attach.Spec.Neighbor.IP); ip == nil { - return nil, errors.New("neighbor.ip is not a valid IP address") //nolint: goerr113 + return nil, errors.New("neighbor.ip is not a valid IP address") } } else { if attach.Spec.Switch.IP != "" || attach.Spec.Switch.VLAN != 0 { @@ -333,14 +333,14 @@ func (attach *ExternalAttachment) Validate(ctx context.Context, kube kclient.Rea } _, err := netip.ParseAddr(attach.Spec.Static.RemoteIP) if err != nil { - return nil, errors.New("static.remoteIP is not a valid IP address") //nolint: goerr113 + return nil, errors.New("static.remoteIP is not a valid IP address") } if (attach.Spec.Static.IP == "" && !attach.Spec.Static.Proxy) || (attach.Spec.Static.IP != "" && attach.Spec.Static.Proxy) { return nil, errors.Errorf("either static.ip or static.proxy must be set for static external attachment") } if attach.Spec.Static.IP != "" { if _, _, err := net.ParseCIDR(attach.Spec.Static.IP); err != nil { - return nil, errors.New("static.ip is not a valid IP CIDR") //nolint: goerr113 + return nil, errors.New("static.ip is not a valid IP CIDR") } } } diff --git a/api/vpc/v1beta1/vpcattachment_types.go b/api/vpc/v1beta1/vpcattachment_types.go index bd47459d3..283a8068a 100644 --- a/api/vpc/v1beta1/vpcattachment_types.go +++ b/api/vpc/v1beta1/vpcattachment_types.go @@ -177,14 +177,14 @@ func (attach *VPCAttachment) Validate(ctx context.Context, kube kclient.Reader, if attach.Annotations != nil { if p2pStr, ok := attach.Annotations[AnnotationVPCAttachmentP2PLink]; ok { if p2pStr == "" { - return nil, fmt.Errorf("empty p2p link annotation subnet") //nolint:err113 + return nil, fmt.Errorf("empty p2p link annotation subnet") } p2p, err := netip.ParsePrefix(p2pStr) if err != nil { return nil, fmt.Errorf("p2p link annotation subnet should be a valid prefix, got: %q: %w", p2pStr, err) } if !p2p.IsValid() || !p2p.Addr().Is4() || p2p.Bits() != 31 { - return nil, fmt.Errorf("p2p link annotation subnet must be a valid IPv4 /31 prefix, got: %q", p2pStr) //nolint:err113 + return nil, fmt.Errorf("p2p link annotation subnet must be a valid IPv4 /31 prefix, got: %q", p2pStr) } } } diff --git a/api/wiring/v1beta1/connection_types.go b/api/wiring/v1beta1/connection_types.go index a8e30d4aa..d41ac7e41 100644 --- a/api/wiring/v1beta1/connection_types.go +++ b/api/wiring/v1beta1/connection_types.go @@ -1082,15 +1082,15 @@ func (conn *Connection) Validate(ctx context.Context, kube kclient.Reader, fabri return nil, errors.Wrapf(err, "parsing fabric connection %s link %d spine IP %s", conn.Name, idx, link.Spine.IP) } if spinePrefix.Bits() != 31 { - return nil, errors.Errorf("fabric connection %s link %d spine IP %s is not a /31", conn.Name, idx, spinePrefix) //nolint:goerr113 + return nil, errors.Errorf("fabric connection %s link %d spine IP %s is not a /31", conn.Name, idx, spinePrefix) } spineIP := spinePrefix.Addr() if !fabricSubnet.Contains(spineIP) { - return nil, errors.Errorf("fabric connection %s link %d spine IP %s is not in the fabric subnet %s", conn.Name, idx, spineIP, fabricSubnet) //nolint:goerr113 + return nil, errors.Errorf("fabric connection %s link %d spine IP %s is not in the fabric subnet %s", conn.Name, idx, spineIP, fabricSubnet) } if _, exist := fabricIPs[spineIP]; exist { - return nil, errors.Errorf("fabric connection %s link %d spine IP %s is already in use", conn.Name, idx, spineIP) //nolint:goerr113 + return nil, errors.Errorf("fabric connection %s link %d spine IP %s is already in use", conn.Name, idx, spineIP) } fabricIPs[spineIP] = true @@ -1099,20 +1099,20 @@ func (conn *Connection) Validate(ctx context.Context, kube kclient.Reader, fabri return nil, errors.Wrapf(err, "parsing fabric connection %s link %d leaf IP %s", conn.Name, idx, link.Leaf.IP) } if leafPrefix.Bits() != 31 { - return nil, errors.Errorf("fabric connection %s link %d leaf IP %s is not a /31", conn.Name, idx, leafPrefix) //nolint:goerr113 + return nil, errors.Errorf("fabric connection %s link %d leaf IP %s is not a /31", conn.Name, idx, leafPrefix) } leafIP := leafPrefix.Addr() if !fabricSubnet.Contains(leafIP) { - return nil, errors.Errorf("fabric connection %s link %d leaf IP %s is not in the fabric subnet %s", conn.Name, idx, leafIP, fabricSubnet) //nolint:goerr113 + return nil, errors.Errorf("fabric connection %s link %d leaf IP %s is not in the fabric subnet %s", conn.Name, idx, leafIP, fabricSubnet) } if _, exist := fabricIPs[leafIP]; exist { - return nil, errors.Errorf("fabric connection %s link %d leaf IP %s is already in use", conn.Name, idx, leafIP) //nolint:goerr113 + return nil, errors.Errorf("fabric connection %s link %d leaf IP %s is already in use", conn.Name, idx, leafIP) } fabricIPs[leafIP] = true if spinePrefix.Masked() != leafPrefix.Masked() { - return nil, errors.Errorf("fabric connection %s link %d spine IP %s and leaf IP %s are not in the same subnet", conn.Name, idx, spineIP, leafIP) //nolint:goerr113 + return nil, errors.Errorf("fabric connection %s link %d spine IP %s and leaf IP %s are not in the same subnet", conn.Name, idx, spineIP, leafIP) } } } else if conn.Spec.Mesh != nil { @@ -1127,15 +1127,15 @@ func (conn *Connection) Validate(ctx context.Context, kube kclient.Reader, fabri return nil, errors.Wrapf(err, "parsing mesh connection %s link %d leaf1 IP %s", conn.Name, idx, link.Leaf1.IP) } if leaf1Prefix.Bits() != 31 { - return nil, errors.Errorf("mesh connection %s link %d leaf1 IP %s is not a /31", conn.Name, idx, leaf1Prefix) //nolint:goerr113 + return nil, errors.Errorf("mesh connection %s link %d leaf1 IP %s is not a /31", conn.Name, idx, leaf1Prefix) } leaf1IP := leaf1Prefix.Addr() if !fabricSubnet.Contains(leaf1IP) { - return nil, errors.Errorf("mesh connection %s link %d leaf1 IP %s is not in the fabric subnet %s", conn.Name, idx, leaf1IP, fabricSubnet) //nolint:goerr113 + return nil, errors.Errorf("mesh connection %s link %d leaf1 IP %s is not in the fabric subnet %s", conn.Name, idx, leaf1IP, fabricSubnet) } if _, exist := fabricIPs[leaf1IP]; exist { - return nil, errors.Errorf("mesh connection %s link %d leaf1 IP %s is already in use", conn.Name, idx, leaf1IP) //nolint:goerr113 + return nil, errors.Errorf("mesh connection %s link %d leaf1 IP %s is already in use", conn.Name, idx, leaf1IP) } fabricIPs[leaf1IP] = true @@ -1144,20 +1144,20 @@ func (conn *Connection) Validate(ctx context.Context, kube kclient.Reader, fabri return nil, errors.Wrapf(err, "parsing mesh connection %s link %d leaf2 IP %s", conn.Name, idx, link.Leaf2.IP) } if leaf2Prefix.Bits() != 31 { - return nil, errors.Errorf("mesh connection %s link %d leaf2 IP %s is not a /31", conn.Name, idx, leaf2Prefix) //nolint:goerr113 + return nil, errors.Errorf("mesh connection %s link %d leaf2 IP %s is not a /31", conn.Name, idx, leaf2Prefix) } leaf2IP := leaf2Prefix.Addr() if !fabricSubnet.Contains(leaf2IP) { - return nil, errors.Errorf("mesh connection %s link %d leaf2 IP %s is not in the fabric subnet %s", conn.Name, idx, leaf2IP, fabricSubnet) //nolint:goerr113 + return nil, errors.Errorf("mesh connection %s link %d leaf2 IP %s is not in the fabric subnet %s", conn.Name, idx, leaf2IP, fabricSubnet) } if _, exist := fabricIPs[leaf2IP]; exist { - return nil, errors.Errorf("mesh connection %s link %d leaf2 IP %s is already in use", conn.Name, idx, leaf2IP) //nolint:goerr113 + return nil, errors.Errorf("mesh connection %s link %d leaf2 IP %s is already in use", conn.Name, idx, leaf2IP) } fabricIPs[leaf2IP] = true if leaf1Prefix.Masked() != leaf2Prefix.Masked() { - return nil, errors.Errorf("mesh connection %s link %d leaf1 IP %s and leaf2 IP %s are not in the same subnet", conn.Name, idx, leaf1IP, leaf2IP) //nolint:goerr113 + return nil, errors.Errorf("mesh connection %s link %d leaf1 IP %s and leaf2 IP %s are not in the same subnet", conn.Name, idx, leaf1IP, leaf2IP) } } } else if conn.Spec.Gateway != nil { @@ -1172,15 +1172,15 @@ func (conn *Connection) Validate(ctx context.Context, kube kclient.Reader, fabri return nil, errors.Wrapf(err, "parsing gateway connection %s link %d switch IP %s", conn.Name, idx, link.Switch.IP) } if switchPrefix.Bits() != 31 { - return nil, errors.Errorf("gateway connection %s link %d switch IP %s is not a /31", conn.Name, idx, switchPrefix) //nolint:goerr113 + return nil, errors.Errorf("gateway connection %s link %d switch IP %s is not a /31", conn.Name, idx, switchPrefix) } switchIP := switchPrefix.Addr() if !fabricSubnet.Contains(switchIP) { - return nil, errors.Errorf("gateway connection %s link %d switch IP %s is not in the fabric subnet %s", conn.Name, idx, switchIP, fabricSubnet) //nolint:goerr113 + return nil, errors.Errorf("gateway connection %s link %d switch IP %s is not in the fabric subnet %s", conn.Name, idx, switchIP, fabricSubnet) } if _, exist := fabricIPs[switchIP]; exist { - return nil, errors.Errorf("gateway connection %s link %d switch IP %s is already in use", conn.Name, idx, switchIP) //nolint:goerr113 + return nil, errors.Errorf("gateway connection %s link %d switch IP %s is already in use", conn.Name, idx, switchIP) } fabricIPs[switchIP] = true @@ -1189,20 +1189,20 @@ func (conn *Connection) Validate(ctx context.Context, kube kclient.Reader, fabri return nil, errors.Wrapf(err, "parsing gateway connection %s link %d gateway IP %s", conn.Name, idx, link.Gateway.IP) } if gwPrefix.Bits() != 31 { - return nil, errors.Errorf("gateway connection %s link %d gateway IP %s is not a /31", conn.Name, idx, gwPrefix) //nolint:goerr113 + return nil, errors.Errorf("gateway connection %s link %d gateway IP %s is not a /31", conn.Name, idx, gwPrefix) } gwIP := gwPrefix.Addr() if !fabricSubnet.Contains(gwIP) { - return nil, errors.Errorf("gateway connection %s link %d gateway IP %s is not in the fabric subnet %s", conn.Name, idx, gwIP, fabricSubnet) //nolint:goerr113 + return nil, errors.Errorf("gateway connection %s link %d gateway IP %s is not in the fabric subnet %s", conn.Name, idx, gwIP, fabricSubnet) } if _, exist := fabricIPs[gwIP]; exist { - return nil, errors.Errorf("gateway connection %s link %d gateway IP %s is already in use", conn.Name, idx, gwIP) //nolint:goerr113 + return nil, errors.Errorf("gateway connection %s link %d gateway IP %s is already in use", conn.Name, idx, gwIP) } fabricIPs[gwIP] = true if switchPrefix.Masked() != gwPrefix.Masked() { - return nil, errors.Errorf("gateway connection %s link %d switch IP %s and gateway IP %s are not in the same subnet", conn.Name, idx, switchIP, gwIP) //nolint:goerr113 + return nil, errors.Errorf("gateway connection %s link %d switch IP %s and gateway IP %s are not in the same subnet", conn.Name, idx, switchIP, gwIP) } } } diff --git a/api/wiring/v1beta1/switch_types.go b/api/wiring/v1beta1/switch_types.go index bb96b72c5..bf923b4fa 100644 --- a/api/wiring/v1beta1/switch_types.go +++ b/api/wiring/v1beta1/switch_types.go @@ -366,13 +366,13 @@ func (sw *Switch) HydrationValidation(ctx context.Context, kube kclient.Reader, } if !mgmtSubnet.Contains(swIP.Addr()) { - return errors.Errorf("switch %s management IP %s is not in the management subnet %s", sw.Name, swIP, mgmtSubnet) //nolint:goerr113 + return errors.Errorf("switch %s management IP %s is not in the management subnet %s", sw.Name, swIP, mgmtSubnet) } if swIP.Addr().Compare(mgmtDHCPStart) >= 0 { - return errors.Errorf("switch %s management IP %s is in the management DHCP range starting at %s", sw.Name, swIP, mgmtDHCPStart) //nolint:goerr113 + return errors.Errorf("switch %s management IP %s is in the management DHCP range starting at %s", sw.Name, swIP, mgmtDHCPStart) } if _, exist := mgmtIPs[swIP.Addr()]; exist { - return errors.Errorf("switch %s (management) IP %s is already in use", sw.Name, swIP) //nolint:goerr113 + return errors.Errorf("switch %s (management) IP %s is already in use", sw.Name, swIP) } } @@ -382,15 +382,15 @@ func (sw *Switch) HydrationValidation(ctx context.Context, kube kclient.Reader, return errors.Wrapf(err, "parsing switch %s protocol IP %s", sw.Name, sw.Spec.ProtocolIP) } if swProtoIP.Bits() != 32 { - return errors.Errorf("switch %s protocol IP %s must be a /32", sw.Name, swProtoIP) //nolint:goerr113 + return errors.Errorf("switch %s protocol IP %s must be a /32", sw.Name, swProtoIP) } if !protocolSubnet.Contains(swProtoIP.Addr()) { - return errors.Errorf("switch %s protocol IP %s is not in the protocol subnet %s", sw.Name, swProtoIP, protocolSubnet) //nolint:goerr113 + return errors.Errorf("switch %s protocol IP %s is not in the protocol subnet %s", sw.Name, swProtoIP, protocolSubnet) } if _, exist := protocolIPs[sw.Spec.ProtocolIP]; exist { - return errors.Errorf("switch %s protocol IP %s is already in use", sw.Name, swProtoIP) //nolint:goerr113 + return errors.Errorf("switch %s protocol IP %s is already in use", sw.Name, swProtoIP) } } @@ -399,25 +399,25 @@ func (sw *Switch) HydrationValidation(ctx context.Context, kube kclient.Reader, if sw.Spec.Redundancy.Type == meta.RedundancyTypeMCLAG { if mclagPeer != nil { if mclagPeer.Spec.ASN != sw.Spec.ASN { - return errors.Errorf("mclag peers should have same ASNs: %s and %s", sw.Name, mclagPeer.Name) //nolint:goerr113 + return errors.Errorf("mclag peers should have same ASNs: %s and %s", sw.Name, mclagPeer.Name) } } else { if _, exist := leafASNs[sw.Spec.ASN]; exist { - return errors.Errorf("leaf %s ASN %d is already in use", sw.Name, sw.Spec.ASN) //nolint:goerr113 + return errors.Errorf("leaf %s ASN %d is already in use", sw.Name, sw.Spec.ASN) } } } else if _, exist := leafASNs[sw.Spec.ASN]; exist { - return errors.Errorf("leaf %s ASN %d is already in use", sw.Name, sw.Spec.ASN) //nolint:goerr113 + return errors.Errorf("leaf %s ASN %d is already in use", sw.Name, sw.Spec.ASN) } // also check if it's within the fabric leaf ASN range if sw.Spec.ASN < fabricCfg.LeafASNStart || sw.Spec.ASN > fabricCfg.LeafASNEnd { - return errors.Errorf("leaf %s ASN %d is not within the fabric leaf ASN range %d-%d", sw.Name, sw.Spec.ASN, fabricCfg.LeafASNStart, fabricCfg.LeafASNEnd) //nolint:goerr113 + return errors.Errorf("leaf %s ASN %d is not within the fabric leaf ASN range %d-%d", sw.Name, sw.Spec.ASN, fabricCfg.LeafASNStart, fabricCfg.LeafASNEnd) } } // spine ASN consistency check if sw.Spec.Role.IsSpine() && sw.Spec.ASN != fabricCfg.SpineASN { - return errors.Errorf("spine %s ASN %d is not the expected spine ASN %d", sw.Name, sw.Spec.ASN, fabricCfg.SpineASN) //nolint:goerr113 + return errors.Errorf("spine %s ASN %d is not the expected spine ASN %d", sw.Name, sw.Spec.ASN, fabricCfg.SpineASN) } // leaf vtep IP uniqueness / consistency for mclag peers @@ -427,25 +427,25 @@ func (sw *Switch) HydrationValidation(ctx context.Context, kube kclient.Reader, return errors.Wrapf(err, "parsing switch %s VTEP IP %s", sw.Name, sw.Spec.VTEPIP) } if swVTEPIP.Bits() != 32 { - return errors.Errorf("switch %s VTEP IP %s must be a /32", sw.Name, swVTEPIP) //nolint:goerr113 + return errors.Errorf("switch %s VTEP IP %s must be a /32", sw.Name, swVTEPIP) } if !vtepSubnet.Contains(swVTEPIP.Addr()) { - return errors.Errorf("switch %s VTEP IP %s is not in the VTEP subnet %s", sw.Name, swVTEPIP, vtepSubnet) //nolint:goerr113 + return errors.Errorf("switch %s VTEP IP %s is not in the VTEP subnet %s", sw.Name, swVTEPIP, vtepSubnet) } if sw.Spec.Redundancy.Type == meta.RedundancyTypeMCLAG { if mclagPeer != nil { if mclagPeer.Spec.VTEPIP != sw.Spec.VTEPIP { - return errors.Errorf("mclag peers should have same VTEP IPs: %s and %s", sw.Name, mclagPeer.Name) //nolint:goerr113 + return errors.Errorf("mclag peers should have same VTEP IPs: %s and %s", sw.Name, mclagPeer.Name) } } else { if _, exist := VTEPs[sw.Spec.VTEPIP]; exist { - return errors.Errorf("switch %s VTEP IP %s is already in use", sw.Name, swVTEPIP) //nolint:goerr113 + return errors.Errorf("switch %s VTEP IP %s is already in use", sw.Name, swVTEPIP) } } } else if _, exist := VTEPs[sw.Spec.VTEPIP]; exist { - return errors.Errorf("switch %s VTEP IP %s is already in use", sw.Name, swVTEPIP) //nolint:goerr113 + return errors.Errorf("switch %s VTEP IP %s is already in use", sw.Name, swVTEPIP) } } diff --git a/api/wiring/v1beta1/switchprofile_types.go b/api/wiring/v1beta1/switchprofile_types.go index 62de2363c..2c12c9d1b 100644 --- a/api/wiring/v1beta1/switchprofile_types.go +++ b/api/wiring/v1beta1/switchprofile_types.go @@ -785,7 +785,7 @@ func (sp *SwitchProfileSpec) GetAllBreakoutNOSNames() (map[string]bool, error) { func (sp *SwitchProfileSpec) NormalizePortName(portName string) (string, error) { if sp == nil { - return "", errors.Errorf("switch profile spec is nil") //nolint:goerr113 + return "", errors.Errorf("switch profile spec is nil") } if strings.Count(portName, "/") == 2 { diff --git a/cmd/hhfctl/main.go b/cmd/hhfctl/main.go index 4785087cc..0d6621242 100644 --- a/cmd/hhfctl/main.go +++ b/cmd/hhfctl/main.go @@ -423,17 +423,17 @@ func main() { for idx, rule := range rules { rule = strings.TrimSpace(rule) if rule == "" { - return nil, fmt.Errorf("invalid port-forward rule at index %d: should not be empty", idx) //nolint:goerr113 + return nil, fmt.Errorf("invalid port-forward rule at index %d: should not be empty", idx) } kv := strings.Split(rule, "=") if len(kv) != 2 { - return nil, fmt.Errorf("invalid port-forward rule %q at index %d: must be in format [proto/]port=as", rule, idx) //nolint:goerr113 + return nil, fmt.Errorf("invalid port-forward rule %q at index %d: must be in format [proto/]port=as", rule, idx) } left := strings.TrimSpace(kv[0]) right := strings.TrimSpace(kv[1]) if left == "" || right == "" { - return nil, fmt.Errorf("invalid port-forward rule %q at index %d: port and as must be non-empty", rule, idx) //nolint:goerr113 + return nil, fmt.Errorf("invalid port-forward rule %q at index %d: port and as must be non-empty", rule, idx) } entry := gwapi.PeeringNATPortForwardEntry{ @@ -444,12 +444,12 @@ func main() { if strings.Contains(left, "/") { portParts := strings.Split(left, "/") if len(portParts) != 2 { - return nil, fmt.Errorf("invalid port-forward rule %q at index %d: left side must be in format proto/port", rule, idx) //nolint:goerr113 + return nil, fmt.Errorf("invalid port-forward rule %q at index %d: left side must be in format proto/port", rule, idx) } proto := strings.TrimSpace(portParts[0]) port := strings.TrimSpace(portParts[1]) if proto == "" || port == "" { - return nil, fmt.Errorf("invalid port-forward rule %q at index %d: proto and port must be non-empty", rule, idx) //nolint:goerr113 + return nil, fmt.Errorf("invalid port-forward rule %q at index %d: proto and port must be non-empty", rule, idx) } switch proto { case string(gwapi.PeeringNATProtocolTCP): @@ -459,7 +459,7 @@ func main() { case string(gwapi.PeeringNATProtocolAny): entry.Protocol = gwapi.PeeringNATProtocolAny default: - return nil, fmt.Errorf("invalid port-forward rule %q at index %d: unknown protocol %q (supported: tcp, udp)", rule, idx, proto) //nolint:goerr113 + return nil, fmt.Errorf("invalid port-forward rule %q at index %d: unknown protocol %q (supported: tcp, udp)", rule, idx, proto) } entry.Port = port } else { @@ -470,10 +470,10 @@ func main() { // only the most basic of validation, let's not duplicate code; alternatively, let's make the validation function in gwapi public if strings.Contains(entry.Port, ",") || strings.TrimSpace(entry.Port) != entry.Port || entry.Port == "" { - return nil, fmt.Errorf("invalid port %q in port-forward rule %q at index %d", entry.Port, rule, idx) //nolint:goerr113 + return nil, fmt.Errorf("invalid port %q in port-forward rule %q at index %d", entry.Port, rule, idx) } if strings.Contains(entry.As, ",") || strings.TrimSpace(entry.As) != entry.As || entry.As == "" { - return nil, fmt.Errorf("invalid as %q in port-forward rule %q at index %d", entry.As, rule, idx) //nolint:goerr113 + return nil, fmt.Errorf("invalid as %q in port-forward rule %q at index %d", entry.As, rule, idx) } out = append(out, entry) diff --git a/cmd/main.go b/cmd/main.go index 0eb0afbd3..a969920c5 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -118,7 +118,7 @@ func run(ctx context.Context) error { return fmt.Errorf("creating gateway validator: %w", err) } if gwValid == nil { - return fmt.Errorf("gateway validator is nil") //nolint:err113 + return fmt.Errorf("gateway validator is nil") } defer func() { //nolint:contextcheck closeCtx, cancel := context.WithTimeout(context.Background(), 10*time.Second) diff --git a/pkg/agent/agent.go b/pkg/agent/agent.go index 62f91bd10..073481abf 100644 --- a/pkg/agent/agent.go +++ b/pkg/agent/agent.go @@ -141,7 +141,7 @@ func (svc *Service) Run(ctx context.Context, getClient func() (*gnmi.Client, err cmlsProcessor := cmls.Processor() svc.processor = cmlsProcessor default: - return fmt.Errorf("unsupported nos type: %s", agent.Spec.SwitchProfile.NOSType) //nolint:err113 + return fmt.Errorf("unsupported nos type: %s", agent.Spec.SwitchProfile.NOSType) } if !svc.DryRun { @@ -461,7 +461,7 @@ func enforceState(ctx context.Context, processor dozer.Processor, agent *agentap return cmls.Enforce(ctx, processor, agent, basedir, dryRun) //nolint:wrapcheck } - return fmt.Errorf("NOS type %s not supported", agent.Spec.SwitchProfile.NOSType) //nolint:err113 + return fmt.Errorf("NOS type %s not supported", agent.Spec.SwitchProfile.NOSType) } func enforceBroadcomState(ctx context.Context, processor dozer.Processor, agent *agentapi.Agent, basedir string, dryRun bool) error { @@ -676,7 +676,7 @@ func (svc *Service) processAgentFromKube(ctx context.Context, kube kclient.Clien slog.Info("Waiting for switch to reboot after RoCE change, it may take a while...") time.Sleep(5 * time.Minute) - return fmt.Errorf("switch didn't reboot after switching roce to %t", agent.Spec.Switch.RoCE) //nolint:goerr113 + return fmt.Errorf("switch didn't reboot after switching roce to %t", agent.Spec.Switch.RoCE) } } diff --git a/pkg/agent/clsp/processor.go b/pkg/agent/clsp/processor.go index c0e3646ea..5ce7f2cc7 100644 --- a/pkg/agent/clsp/processor.go +++ b/pkg/agent/clsp/processor.go @@ -35,7 +35,7 @@ func (c *CelesticaPlusProcessor) Reinstall(ctx context.Context) error { // TODO func (c *CelesticaPlusProcessor) FactoryReset(ctx context.Context) error { - return fmt.Errorf("not implemented") //nolint:err113 + return fmt.Errorf("not implemented") } // TODO @@ -50,7 +50,7 @@ func (c *CelesticaPlusProcessor) GetRoCE(ctx context.Context) (bool, error) { // TODO func (c *CelesticaPlusProcessor) SetRoCE(ctx context.Context, enable bool) error { - return fmt.Errorf("not supported") //nolint:err113 + return fmt.Errorf("not supported") } // TODO @@ -95,17 +95,17 @@ func (c *CelesticaPlusProcessor) UpdateSwitchState(ctx context.Context, agent *a // Invalid "type" func (c *CelesticaPlusProcessor) LoadActualState(ctx context.Context, agent *agentapi.Agent) (*dozer.Spec, error) { - return nil, fmt.Errorf("unsupported operation") //nolint:err113 + return nil, fmt.Errorf("unsupported operation") } func (c *CelesticaPlusProcessor) PlanDesiredState(ctx context.Context, agent *agentapi.Agent) (*dozer.Spec, error) { - return nil, fmt.Errorf("unsupported operation") //nolint:err113 + return nil, fmt.Errorf("unsupported operation") } func (c *CelesticaPlusProcessor) ApplyActions(ctx context.Context, actions []dozer.Action) ([]string, error) { - return nil, fmt.Errorf("unsupported operation") //nolint:err113 + return nil, fmt.Errorf("unsupported operation") } func (c *CelesticaPlusProcessor) CalculateActions(ctx context.Context, actual *dozer.Spec, desired *dozer.Spec) ([]dozer.Action, error) { - return nil, fmt.Errorf("unsupported operation") //nolint:err113 + return nil, fmt.Errorf("unsupported operation") } diff --git a/pkg/agent/cmls/cumulus.go b/pkg/agent/cmls/cumulus.go index 21e75da15..04b642607 100644 --- a/pkg/agent/cmls/cumulus.go +++ b/pkg/agent/cmls/cumulus.go @@ -119,14 +119,14 @@ func buildConfigFor(tmpl string, agent *agentapi.Agent) (*bytes.Buffer, error) { } if role == "" { - return nil, fmt.Errorf("invalid role: %s", user.Role) //nolint:err113 + return nil, fmt.Errorf("invalid role: %s", user.Role) } keys := []SSHKey{} for _, key := range user.SSHKeys { parts := strings.Split(key, " ") if len(parts) < 2 { - return nil, fmt.Errorf("invalid SSH key: %s", key) //nolint:err113 + return nil, fmt.Errorf("invalid SSH key: %s", key) } keys = append(keys, SSHKey{ @@ -281,7 +281,7 @@ func buildConfigFor(tmpl string, agent *agentapi.Agent) (*bytes.Buffer, error) { return nil, fmt.Errorf("parsing p2p subnet %q for vpc attachment %q: %w", p2pSubnet, attachName, err) } if !p2p.IsValid() || !p2p.Addr().Is4() || p2p.Bits() != 31 { - return nil, fmt.Errorf("p2p subnet %q for vpc attachment %q is not /31", p2pSubnet, attachName) //nolint:err113 + return nil, fmt.Errorf("p2p subnet %q for vpc attachment %q is not /31", p2pSubnet, attachName) } ip = netip.PrefixFrom(p2p.Masked().Addr().Next(), p2p.Bits()).String() // even goes to the host, odd to the switch } diff --git a/pkg/agent/cmls/processor.go b/pkg/agent/cmls/processor.go index bd8fcbaed..f96d7c298 100644 --- a/pkg/agent/cmls/processor.go +++ b/pkg/agent/cmls/processor.go @@ -27,12 +27,12 @@ func (c *CumulusProcessor) Reboot(ctx context.Context, force bool) error { // TODO: use onie-select -i (it asks for y/N user input...) func (c *CumulusProcessor) Reinstall(ctx context.Context) error { - return fmt.Errorf("not implemented") //nolint:err113 + return fmt.Errorf("not implemented") } // TODO func (c *CumulusProcessor) FactoryReset(ctx context.Context) error { - return fmt.Errorf("not implemented") //nolint:err113 + return fmt.Errorf("not implemented") } // TODO @@ -47,7 +47,7 @@ func (c *CumulusProcessor) GetRoCE(ctx context.Context) (bool, error) { // TODO func (c *CumulusProcessor) SetRoCE(ctx context.Context, enable bool) error { - return fmt.Errorf("not supported") //nolint:err113 + return fmt.Errorf("not supported") } // TODO @@ -58,17 +58,17 @@ func (c *CumulusProcessor) WaitReady(ctx context.Context) error { // Invalid "type" func (c *CumulusProcessor) LoadActualState(ctx context.Context, agent *v1beta1.Agent) (*dozer.Spec, error) { - return nil, fmt.Errorf("unsupported operation") //nolint:err113 + return nil, fmt.Errorf("unsupported operation") } func (c *CumulusProcessor) PlanDesiredState(ctx context.Context, agent *v1beta1.Agent) (*dozer.Spec, error) { - return nil, fmt.Errorf("unsupported operation") //nolint:err113 + return nil, fmt.Errorf("unsupported operation") } func (c *CumulusProcessor) ApplyActions(ctx context.Context, actions []dozer.Action) ([]string, error) { - return nil, fmt.Errorf("unsupported operation") //nolint:err113 + return nil, fmt.Errorf("unsupported operation") } func (c *CumulusProcessor) CalculateActions(ctx context.Context, actual *dozer.Spec, desired *dozer.Spec) ([]dozer.Action, error) { - return nil, fmt.Errorf("unsupported operation") //nolint:err113 + return nil, fmt.Errorf("unsupported operation") } diff --git a/pkg/agent/common/upgrade.go b/pkg/agent/common/upgrade.go index d1bc55b63..0db459b95 100644 --- a/pkg/agent/common/upgrade.go +++ b/pkg/agent/common/upgrade.go @@ -99,7 +99,7 @@ func UpgradeBin(ctx context.Context, source, version, ca, username, password, ta rootCAs := x509.NewCertPool() if !rootCAs.AppendCertsFromPEM([]byte(ca)) { - return fmt.Errorf("failed to append CA cert to rootCAs") //nolint:goerr113 + return fmt.Errorf("failed to append CA cert to rootCAs") } baseTransport := http.DefaultTransport.(*http.Transport).Clone() diff --git a/pkg/agent/dozer/bcm/control_link.go b/pkg/agent/dozer/bcm/control_link.go index 2b0304ece..070069077 100644 --- a/pkg/agent/dozer/bcm/control_link.go +++ b/pkg/agent/dozer/bcm/control_link.go @@ -32,7 +32,7 @@ const ( func (p *BroadcomProcessor) EnsureControlLink(_ context.Context, agent *agentapi.Agent) error { if agent == nil { - return fmt.Errorf("no agent config") //nolint:goerr113 + return fmt.Errorf("no agent config") } controlVIP, err := netip.ParsePrefix(agent.Spec.Config.ControlVIP) @@ -40,7 +40,7 @@ func (p *BroadcomProcessor) EnsureControlLink(_ context.Context, agent *agentapi return fmt.Errorf("parsing control VIP %s: %w", agent.Spec.Config.ControlVIP, err) } if controlVIP.Bits() != 32 { - return fmt.Errorf("control VIP %s is not a /32", agent.Spec.Config.ControlVIP) //nolint:goerr113 + return fmt.Errorf("control VIP %s is not a /32", agent.Spec.Config.ControlVIP) } switchIP, err := netip.ParsePrefix(agent.Spec.Switch.IP) @@ -49,7 +49,7 @@ func (p *BroadcomProcessor) EnsureControlLink(_ context.Context, agent *agentapi } if !switchIP.Contains(controlVIP.Addr()) { - return fmt.Errorf("control VIP %s is not in switch IP subnet %s", controlVIP, switchIP) //nolint:goerr113 + return fmt.Errorf("control VIP %s is not in switch IP subnet %s", controlVIP, switchIP) } mgmtIP, err := netlink.ParseAddr(agent.Spec.Switch.IP) diff --git a/pkg/agent/dozer/bcm/plan.go b/pkg/agent/dozer/bcm/plan.go index 512135e73..1da1a8ea6 100644 --- a/pkg/agent/dozer/bcm/plan.go +++ b/pkg/agent/dozer/bcm/plan.go @@ -449,7 +449,7 @@ func planFabricConnections(agent *agentapi.Agent, spec *dozer.Spec) error { vtepSubnet := agent.Spec.Config.VTEPSubnet if vtepSubnet == "" { - return errors.New("VTEP subnet not set in agent config") //nolint: goerr113 + return errors.New("VTEP subnet not set in agent config") } spec.PrefixLists[PrefixListAllVTEPPrefixes] = &dozer.SpecPrefixList{ @@ -1212,10 +1212,10 @@ func planExternals(agent *agentapi.Agent, spec *dozer.Spec) error { irbVLAN := agent.Spec.Catalog.IRBVLANs[librarian.ReqForExt(externalName)] extVNI := agent.Spec.Catalog.VPCVNIs[librarian.ReqForExt(externalName)] if irbVLAN == 0 { - return fmt.Errorf("IRB VLAN for external %s not found in catalog", externalName) //nolint:goerr113 + return fmt.Errorf("IRB VLAN for external %s not found in catalog", externalName) } if extVNI == 0 { - return fmt.Errorf("VNI for external %s not found in catalog", externalName) //nolint:goerr113 + return fmt.Errorf("VNI for external %s not found in catalog", externalName) } irbIface := vlanName(irbVLAN) spec.Interfaces[irbIface] = &dozer.SpecInterface{ @@ -1271,7 +1271,7 @@ func planExternals(agent *agentapi.Agent, spec *dozer.Spec) error { prefixLength := ipNet.Bits() ip := ipNet.Addr() if !ip.Is4() { - return fmt.Errorf("invalid external attach switch ip %s, expected IPv4", attach.Switch.IP) //nolint:err113 + return fmt.Errorf("invalid external attach switch ip %s, expected IPv4", attach.Switch.IP) } spec.Interfaces[port].Subinterfaces[uint32(attach.Switch.VLAN)] = &dozer.SpecSubinterface{ @@ -1348,7 +1348,7 @@ func planExternals(agent *agentapi.Agent, spec *dozer.Spec) error { return errors.Wrapf(err, "failed to parse static external attach IP %s", attach.Static.IP) } if !fabricEdgeIP.Addr().Is4() { - return fmt.Errorf("invalid static external attach IP %s, expected IPv4", attach.Static.IP) //nolint:err113 + return fmt.Errorf("invalid static external attach IP %s, expected IPv4", attach.Static.IP) } } prefixLen := uint8(fabricEdgeIP.Bits()) //nolint:gosec @@ -1561,7 +1561,7 @@ func planHardenedInboundACL(spec *dozer.Spec, attachName string, switchIP string if userACL != nil { for _, stmt := range userACL.Statements { if stmt.Seq < 10 { - return fmt.Errorf("invalid user ACL statement with sequence number %d in the reserved range", stmt.Seq) //nolint:err113 + return fmt.Errorf("invalid user ACL statement with sequence number %d in the reserved range", stmt.Seq) } entry, err := aclStatementToEntry(stmt) if err != nil { diff --git a/pkg/agent/dozer/bcm/processor.go b/pkg/agent/dozer/bcm/processor.go index ad7320d99..28162d086 100644 --- a/pkg/agent/dozer/bcm/processor.go +++ b/pkg/agent/dozer/bcm/processor.go @@ -118,7 +118,7 @@ func (p *BroadcomProcessor) WaitReady(ctx context.Context) error { time.Sleep(5 * time.Second) } - return fmt.Errorf("system is not ready after %f minutes", timeout.Minutes()) //nolint:err113 + return fmt.Errorf("system is not ready after %f minutes", timeout.Minutes()) } type SystemStatusResponse struct { @@ -169,7 +169,7 @@ func (p *BroadcomProcessor) FactoryReset(_ context.Context) error { // io.WriteString(stdin, "y\n") // }() - return fmt.Errorf("not supported") //nolint:err113 + return fmt.Errorf("not supported") } func (p *BroadcomProcessor) LoadActualState(ctx context.Context, agent *agentapi.Agent) (*dozer.Spec, error) { @@ -371,7 +371,7 @@ func (p *BroadcomProcessor) GetRoCE(ctx context.Context) (bool, error) { ocVal := &oc.SonicSwitch_SonicSwitch_SWITCH{} err := p.client.Get(ctx, "/sonic-switch/SWITCH/SWITCH_LIST[switch=switch]", ocVal) if err != nil { - return false, fmt.Errorf("reading RoCE state: %w", err) //nolint:goerr113 + return false, fmt.Errorf("reading RoCE state: %w", err) } for key, sw := range ocVal.SWITCH_LIST { @@ -408,7 +408,7 @@ func (p *BroadcomProcessor) SetRoCE(ctx context.Context, val bool) error { if err == nil { slog.Warn("RoCE set operation unexpected result", "data", string(resp), "action", action) - return fmt.Errorf("unexpected response from RoCE set operation") //nolint:goerr113 + return fmt.Errorf("unexpected response from RoCE set operation") } return nil diff --git a/pkg/boot/nosinstall/run.go b/pkg/boot/nosinstall/run.go index 1a04e8d6d..7940c42f1 100644 --- a/pkg/boot/nosinstall/run.go +++ b/pkg/boot/nosinstall/run.go @@ -130,7 +130,7 @@ func Run(ctx context.Context, env Env, dryRun bool) (funcErr error) { //nolint:n if env.BootReason != "" && !slices.Contains(AllowedBootReasons, env.BootReason) { slog.Error("Not allowed ONIE boot reason, aborting", "reason", env.BootReason, "allowed", AllowedBootReasons) - return fmt.Errorf("invalid ONIE boot reason") //nolint:goerr113 + return fmt.Errorf("invalid ONIE boot reason") } tmpDir := os.TempDir() @@ -240,7 +240,7 @@ func extractFiles(dest string) error { } if string(magicBytes) != Magic { - return fmt.Errorf("magic mismatch") //nolint:goerr113 + return fmt.Errorf("magic mismatch") } payloadBytes := make([]byte, 8) @@ -285,7 +285,7 @@ func extractFile(dest string, header *tar.Header, r io.Reader, mode os.FileMode) // path traversal check: https://security.snyk.io/research/zip-slip-vulnerability if !strings.HasPrefix(target, filepath.Clean(dest)+string(os.PathSeparator)) { - return fmt.Errorf("illegal file path %s", header.Name) //nolint:goerr113 + return fmt.Errorf("illegal file path %s", header.Name) } f, err := os.OpenFile(target, os.O_CREATE|os.O_RDWR, mode) @@ -360,7 +360,7 @@ func EnsureONIEBootPartition(ctx context.Context) error { } } - return fmt.Errorf("ONIE boot partition not mounted") //nolint:goerr113 + return fmt.Errorf("ONIE boot partition not mounted") } func mountPartition(origCtx context.Context, label string) (string, func(), error) { @@ -426,7 +426,7 @@ func sonicInstallAgent(ctx context.Context, tmp string) error { } } if !ok { - return fmt.Errorf("finding SONiC image dir") //nolint:goerr113 + return fmt.Errorf("finding SONiC image dir") } return installAgentTo(tmp, sonicRoot) diff --git a/pkg/boot/server/cumulus.go b/pkg/boot/server/cumulus.go index e7c060b2c..a62fea963 100644 --- a/pkg/boot/server/cumulus.go +++ b/pkg/boot/server/cumulus.go @@ -103,7 +103,7 @@ func (svc *service) handleCumulusZTP(w http.ResponseWriter, r *http.Request) { func (svc *service) writeCumulusZTP(w http.ResponseWriter, agent *agentapi.Agent, secret *corev1.Secret) error { kubeConfig, ok := secret.Data[ctrl.AgentKubeconfigKey] if !ok { - return fmt.Errorf("kubeconfig not found") //nolint:err113 + return fmt.Errorf("kubeconfig not found") } ztpBuf, err := cmls.BuildZTPFor(agent, kubeConfig) diff --git a/pkg/boot/server/downloader.go b/pkg/boot/server/downloader.go index cae6a8edd..76f4db851 100644 --- a/pkg/boot/server/downloader.go +++ b/pkg/boot/server/downloader.go @@ -87,10 +87,10 @@ func (svc *service) getCachedOrDownload(ctx context.Context, repo, version strin } if len(entries) == 0 { - return "", fmt.Errorf("empty cache dir %s", cachePath) //nolint:goerr113 + return "", fmt.Errorf("empty cache dir %s", cachePath) } if len(entries) > 1 { - return "", fmt.Errorf("multiple entries in cache dir %s", cachePath) //nolint:goerr113 + return "", fmt.Errorf("multiple entries in cache dir %s", cachePath) } return filepath.Join(cachePath, entries[0].Name()), nil diff --git a/pkg/boot/server/onie.go b/pkg/boot/server/onie.go index eacf4f34f..a5927aba3 100644 --- a/pkg/boot/server/onie.go +++ b/pkg/boot/server/onie.go @@ -49,7 +49,7 @@ func (svc *service) preCacheBackground(ctx context.Context) error { for nosType, nosVersion := range svc.cfg.NOSVersions { repo, ok := svc.cfg.NOSRepos[nosType] if !ok { - return fmt.Errorf("NOS repo not found: %s", nosType) //nolint:goerr113 + return fmt.Errorf("NOS repo not found: %s", nosType) } if _, err := svc.getCachedOrDownload(ctx, repo, nosVersion, true); err != nil { @@ -62,7 +62,7 @@ func (svc *service) preCacheBackground(ctx context.Context) error { for platform, version := range svc.cfg.ONIEPlatformVersions { repo, ok := svc.cfg.ONIERepos[platform] if !ok { - return fmt.Errorf("ONIE repo not found: %s", platform) //nolint:goerr113 + return fmt.Errorf("ONIE repo not found: %s", platform) } if _, err := svc.getCachedOrDownload(ctx, repo, version, true); err != nil { @@ -255,26 +255,26 @@ func (svc *service) streamNOSInstaller(ctx context.Context, agent *agentapi.Agen kubeConfig, ok := secret.Data[ctrl.AgentKubeconfigKey] if !ok { - return fmt.Errorf("kubeconfig not found") //nolint:goerr113 + return fmt.Errorf("kubeconfig not found") } if agent.Spec.SwitchProfile == nil { - return fmt.Errorf("switch profile is missing") //nolint:goerr113 + return fmt.Errorf("switch profile is missing") } nosType := agent.Spec.SwitchProfile.NOSType if nosType == "" || !slices.Contains(meta.NOSTypes, nosType) { - return fmt.Errorf("invalid NOS type") //nolint:goerr113 + return fmt.Errorf("invalid NOS type") } nosRepo, ok := svc.cfg.NOSRepos[nosType] if !ok { - return fmt.Errorf("NOS repo not found") //nolint:goerr113 + return fmt.Errorf("NOS repo not found") } nosVersion, ok := svc.cfg.NOSVersions[nosType] if !ok { - return fmt.Errorf("NOS version not found") //nolint:goerr113 + return fmt.Errorf("NOS version not found") } nosPath, err := svc.getCachedOrDownload(ctx, nosRepo, nosVersion, false) @@ -306,12 +306,12 @@ func (svc *service) streamNOSInstaller(ctx context.Context, agent *agentapi.Agen func (svc *service) streamONIEUpdater(ctx context.Context, platform string, w io.Writer) error { repo, ok := svc.cfg.ONIERepos[platform] if !ok { - return fmt.Errorf("onie-updater repo not found") //nolint:goerr113 + return fmt.Errorf("onie-updater repo not found") } version, ok := svc.cfg.ONIEPlatformVersions[platform] if !ok { - return fmt.Errorf("onie-updater version not found") //nolint:goerr113 + return fmt.Errorf("onie-updater version not found") } oniePath, err := svc.getCachedOrDownload(ctx, repo, version, false) diff --git a/pkg/ctrl/gateway_ctrl.go b/pkg/ctrl/gateway_ctrl.go index 3e2063195..cfe6c778b 100644 --- a/pkg/ctrl/gateway_ctrl.go +++ b/pkg/ctrl/gateway_ctrl.go @@ -77,7 +77,7 @@ type GatewayReconciler struct { func SetupGatewayReconcilerWith(mgr kctrl.Manager, cfg *meta.FabricConfig) error { if cfg == nil { - return fmt.Errorf("gateway controller config is nil") //nolint:goerr113 + return fmt.Errorf("gateway controller config is nil") } r := &GatewayReconciler{ @@ -198,10 +198,10 @@ var ErrRetryLater = fmt.Errorf("retry later") func BuildGatewayAgent(ctx context.Context, kube kclient.Reader, cfg *meta.FabricConfig, gw *gwapi.Gateway) (*gwintapi.GatewayAgent, error) { if cfg == nil { - return nil, fmt.Errorf("cfg is nil") //nolint:err113 + return nil, fmt.Errorf("cfg is nil") } if gw == nil { - return nil, fmt.Errorf("gw is nil") //nolint:err113 + return nil, fmt.Errorf("gw is nil") } inGwGroups := map[string]bool{} @@ -307,10 +307,10 @@ func BuildGatewayAgent(ctx context.Context, kube kclient.Reader, cfg *meta.Fabri // BuildGatewayAgentForPeering builds a GatewayAgent for the first gateway that matches the peering gateway group. func BuildGatewayAgentForPeering(ctx context.Context, kube kclient.Reader, cfg *meta.FabricConfig, peering *gwapi.GatewayPeering) (*gwintapi.GatewayAgent, error) { if cfg == nil { - return nil, fmt.Errorf("cfg is nil") //nolint:err113 + return nil, fmt.Errorf("cfg is nil") } if peering == nil { - return nil, fmt.Errorf("peering is nil") //nolint:err113 + return nil, fmt.Errorf("peering is nil") } gws := &gwapi.GatewayList{} @@ -337,7 +337,7 @@ func BuildGatewayAgentForPeering(ctx context.Context, kube kclient.Reader, cfg * } } - return nil, fmt.Errorf("gateway not found for gateway group: %s", peering.Spec.GatewayGroup) //nolint:err113 + return nil, fmt.Errorf("gateway not found for gateway group: %s", peering.Spec.GatewayGroup) } func entityName(gwName string, t ...string) string { @@ -476,7 +476,7 @@ func (r *GatewayReconciler) deployGateway(ctx context.Context, gw *gwapi.Gateway driver = "dpdk" } if pcis > 0 && kernels > 0 { - return fmt.Errorf("cannot use mixed PCI address and kernel name interfaces") //nolint:err113 + return fmt.Errorf("cannot use mixed PCI address and kernel name interfaces") } args = append(args, "--driver", driver) diff --git a/pkg/ctrl/gateway_sync.go b/pkg/ctrl/gateway_sync.go index 24ffb596f..3da9e9c30 100644 --- a/pkg/ctrl/gateway_sync.go +++ b/pkg/ctrl/gateway_sync.go @@ -31,10 +31,10 @@ type GwVPCSync struct { func SetupGwVPCSyncReconcilerWith(mgr kctrl.Manager, cfg *meta.FabricConfig, libMngr *librarian.Manager) error { if cfg == nil { - return fmt.Errorf("fabric config is nil") //nolint:goerr113 + return fmt.Errorf("fabric config is nil") } if libMngr == nil { - return fmt.Errorf("librarian manager is nil") //nolint:goerr113 + return fmt.Errorf("librarian manager is nil") } r := &GwVPCSync{ @@ -138,10 +138,10 @@ type GwExternalSync struct { func SetupGwExternalSyncReconcilerWith(mgr kctrl.Manager, cfg *meta.FabricConfig, libMngr *librarian.Manager) error { if cfg == nil { - return fmt.Errorf("fabric config is nil") //nolint:goerr113 + return fmt.Errorf("fabric config is nil") } if libMngr == nil { - return fmt.Errorf("librarian manager is nil") //nolint:goerr113 + return fmt.Errorf("librarian manager is nil") } r := &GwExternalSync{ diff --git a/pkg/ctrl/gateway_valid.go b/pkg/ctrl/gateway_valid.go index 29fe93ee4..ca62ee5cb 100644 --- a/pkg/ctrl/gateway_valid.go +++ b/pkg/ctrl/gateway_valid.go @@ -41,16 +41,16 @@ type GatewayValidator struct { func NewGatewayValidator(ctx context.Context, fabricCfg *meta.FabricConfig, ca []byte, credsPath string) (*GatewayValidator, error) { if fabricCfg == nil { - return nil, fmt.Errorf("fabricCfg is nil") //nolint:err113 + return nil, fmt.Errorf("fabricCfg is nil") } if fabricCfg.DataplaneValidatorRef == "" { - return nil, fmt.Errorf("dataplane validator ref is empty") //nolint:err113 + return nil, fmt.Errorf("dataplane validator ref is empty") } if len(ca) == 0 { - return nil, fmt.Errorf("ca is empty") //nolint:err113 + return nil, fmt.Errorf("ca is empty") } if credsPath == "" { - return nil, fmt.Errorf("credsPath is empty") //nolint:err113 + return nil, fmt.Errorf("credsPath is empty") } v := &GatewayValidator{ @@ -59,7 +59,7 @@ func NewGatewayValidator(ctx context.Context, fabricCfg *meta.FabricConfig, ca [ colonIdx := strings.LastIndex(fabricCfg.DataplaneValidatorRef, ":") if colonIdx == -1 { - return nil, fmt.Errorf("invalid ref format: %s", fabricCfg.DataplaneValidatorRef) //nolint:err113 + return nil, fmt.Errorf("invalid ref format: %s", fabricCfg.DataplaneValidatorRef) } ref := fabricCfg.DataplaneValidatorRef[:colonIdx] version := fabricCfg.DataplaneValidatorRef[colonIdx+1:] @@ -73,7 +73,7 @@ func NewGatewayValidator(ctx context.Context, fabricCfg *meta.FabricConfig, ca [ rootCAs := x509.NewCertPool() if !rootCAs.AppendCertsFromPEM(ca) { - return nil, fmt.Errorf("failed to append CA cert to rootCAs") //nolint:err113 + return nil, fmt.Errorf("failed to append CA cert to rootCAs") } baseTransport := http.DefaultTransport.(*http.Transport).Clone() @@ -155,10 +155,10 @@ func (v *GatewayValidator) Close(ctx context.Context) { func (v *GatewayValidator) Validate(ctx context.Context, gwAg *gwintapi.GatewayAgent) error { if v == nil || v.compiled == nil || v.runtime == nil { - return fmt.Errorf("validator uninitialized") //nolint:err113 + return fmt.Errorf("validator uninitialized") } if gwAg == nil { - return fmt.Errorf("gateway agent is nil") //nolint:err113 + return fmt.Errorf("gateway agent is nil") } select { @@ -214,7 +214,7 @@ func (v *GatewayValidator) Validate(ctx context.Context, gwAg *gwintapi.GatewayA } } - return fmt.Errorf("dp-validator: %s", strings.Join(msgs, ", ")) //nolint:err113 + return fmt.Errorf("dp-validator: %s", strings.Join(msgs, ", ")) } return nil diff --git a/pkg/ctrl/gateway_wh.go b/pkg/ctrl/gateway_wh.go index ef09b1287..06c673208 100644 --- a/pkg/ctrl/gateway_wh.go +++ b/pkg/ctrl/gateway_wh.go @@ -26,7 +26,7 @@ type GatewayWebhook struct { func SetupGatewayWebhookWith(mgr kctrl.Manager, cfg *meta.FabricConfig, v *GatewayValidator) error { if cfg.EnableGateway && v == nil { - return fmt.Errorf("validator is nil") //nolint:err113 + return fmt.Errorf("validator is nil") } w := &GatewayWebhook{ @@ -39,7 +39,7 @@ func SetupGatewayWebhookWith(mgr kctrl.Manager, cfg *meta.FabricConfig, v *Gatew WithDefaulter(w). WithValidator(w). Complete(); err != nil { - return fmt.Errorf("creating webhook: %w", err) //nolint:goerr113 + return fmt.Errorf("creating webhook: %w", err) } return nil diff --git a/pkg/ctrl/gatewaygroup_wh.go b/pkg/ctrl/gatewaygroup_wh.go index 698af491e..197638fec 100644 --- a/pkg/ctrl/gatewaygroup_wh.go +++ b/pkg/ctrl/gatewaygroup_wh.go @@ -33,7 +33,7 @@ func SetupGatewayGroupWebhookWith(mgr kctrl.Manager, cfg *meta.FabricConfig) err WithDefaulter(w). WithValidator(w). Complete(); err != nil { - return fmt.Errorf("creating webhook: %w", err) //nolint:goerr113 + return fmt.Errorf("creating webhook: %w", err) } return nil diff --git a/pkg/ctrl/gatewaypeering_wh.go b/pkg/ctrl/gatewaypeering_wh.go index 6f9ccbbb0..375203da8 100644 --- a/pkg/ctrl/gatewaypeering_wh.go +++ b/pkg/ctrl/gatewaypeering_wh.go @@ -26,7 +26,7 @@ type GatewayPeeringWebhook struct { func SetupGatewayPeeringWebhookWith(mgr kctrl.Manager, cfg *meta.FabricConfig, v *GatewayValidator) error { if cfg.EnableGateway && v == nil { - return fmt.Errorf("validator is nil") //nolint:err113 + return fmt.Errorf("validator is nil") } w := &GatewayPeeringWebhook{ @@ -39,7 +39,7 @@ func SetupGatewayPeeringWebhookWith(mgr kctrl.Manager, cfg *meta.FabricConfig, v WithDefaulter(w). WithValidator(w). Complete(); err != nil { - return fmt.Errorf("creating webhook: %w", err) //nolint:goerr113 + return fmt.Errorf("creating webhook: %w", err) } return nil diff --git a/pkg/ctrl/vpcinfo_wh.go b/pkg/ctrl/vpcinfo_wh.go index 9723d93d4..62c4d07be 100644 --- a/pkg/ctrl/vpcinfo_wh.go +++ b/pkg/ctrl/vpcinfo_wh.go @@ -32,7 +32,7 @@ func SetupVPCInfoWebhookWith(mgr kctrl.Manager, cfg *meta.FabricConfig) error { WithDefaulter(w). WithValidator(w). Complete(); err != nil { - return fmt.Errorf("creating webhook: %w", err) //nolint:goerr113 + return fmt.Errorf("creating webhook: %w", err) } return nil diff --git a/pkg/dhcp/coredhcp.go b/pkg/dhcp/coredhcp.go index 94e14392d..14a79a020 100644 --- a/pkg/dhcp/coredhcp.go +++ b/pkg/dhcp/coredhcp.go @@ -39,12 +39,12 @@ func (s *Server) startCoreDHCP(ctx context.Context) error { cfgFile := "/etc/coredhcp.conf" if err := os.WriteFile(cfgFile, fmt.Appendf(nil, cfgTmpl, "%"+s.ListenInterface), 0o600); err != nil { - return fmt.Errorf("writing config") //nolint:err113 + return fmt.Errorf("writing config") } config, err := config.Load(cfgFile) if err != nil { - return fmt.Errorf("loading configuration") //nolint:err113 + return fmt.Errorf("loading configuration") } desiredPlugins := []*plugins.Plugin{ @@ -56,7 +56,7 @@ func (s *Server) startCoreDHCP(ctx context.Context) error { } for _, plugin := range desiredPlugins { if err := plugins.RegisterPlugin(plugin); err != nil { - return fmt.Errorf("registering plugin: %s", plugin.Name) //nolint:err113 + return fmt.Errorf("registering plugin: %s", plugin.Name) } } @@ -64,11 +64,11 @@ func (s *Server) startCoreDHCP(ctx context.Context) error { srv, err := server.Start(config) if err != nil { - return fmt.Errorf("starting coredhcp") //nolint:err113 + return fmt.Errorf("starting coredhcp") } if err := srv.Wait(); err != nil { - return fmt.Errorf("waiting for coredhcp") //nolint:err113 + return fmt.Errorf("waiting for coredhcp") } - return fmt.Errorf("coredhcp finished unexpectedly") //nolint:err113 + return fmt.Errorf("coredhcp finished unexpectedly") } diff --git a/pkg/dhcp/coredhcp_fallback.go b/pkg/dhcp/coredhcp_fallback.go index 2bf36b7ef..49b922dc6 100644 --- a/pkg/dhcp/coredhcp_fallback.go +++ b/pkg/dhcp/coredhcp_fallback.go @@ -13,5 +13,5 @@ import ( func (s *Server) startCoreDHCP(ctx context.Context) error { _ = s.setupDHCP4Plugin(ctx) - return fmt.Errorf("only supported on linux") //nolint:err113 + return fmt.Errorf("only supported on linux") } diff --git a/pkg/dhcp/handlers.go b/pkg/dhcp/handlers.go index 77c1f2250..13b713f5a 100644 --- a/pkg/dhcp/handlers.go +++ b/pkg/dhcp/handlers.go @@ -87,7 +87,7 @@ func (s *Server) checkRelayedRequest(giaddr net.IP) error { _, known := s.relayAllowlist[str] s.m.RUnlock() if !known { - return fmt.Errorf("unknown GIADDR %s", str) //nolint:goerr113 + return fmt.Errorf("unknown GIADDR %s", str) } return nil @@ -223,7 +223,7 @@ func (s *Server) handleDHCP4(ctx context.Context, subnet *dhcpapi.DHCPSubnet, re // TODO update response? wasn't done in a previous implementation default: - return fmt.Errorf("unsupported DHCP request type") //nolint:err113 + return fmt.Errorf("unsupported DHCP request type") } return nil diff --git a/pkg/dhcp/kube.go b/pkg/dhcp/kube.go index 7f9b0e21a..436acec35 100644 --- a/pkg/dhcp/kube.go +++ b/pkg/dhcp/kube.go @@ -51,10 +51,10 @@ func (s *Server) watchList( return nil case event, ok := <-watcher.ResultChan(): if !ok { - return fmt.Errorf("%s watch channel closed", name) //nolint:err113 + return fmt.Errorf("%s watch channel closed", name) } if event.Object == nil { - return fmt.Errorf("received nil object from %s watch", name) //nolint:err113 + return fmt.Errorf("received nil object from %s watch", name) } switch event.Type { @@ -63,7 +63,7 @@ func (s *Server) watchList( return fmt.Errorf("%s watch error: %w", name, err) } - return fmt.Errorf("%s watch error", name) //nolint:err113 + return fmt.Errorf("%s watch error", name) case watch.Bookmark: continue case watch.Added, watch.Modified, watch.Deleted: @@ -159,7 +159,7 @@ func (s *Server) updateSubnet(ctx context.Context, subnet *dhcpapi.DHCPSubnet, m } if subnet.UID != uid { - return fmt.Errorf("subnet %s UID mismatch", subnetName) //nolint:err113 + return fmt.Errorf("subnet %s UID mismatch", subnetName) } } attempt++ diff --git a/pkg/dhcp/response.go b/pkg/dhcp/response.go index e89886098..cd9834f16 100644 --- a/pkg/dhcp/response.go +++ b/pkg/dhcp/response.go @@ -25,7 +25,7 @@ func updateResponse(req, resp *dhcpv4.DHCPv4, subnet *dhcpapi.DHCPSubnet, ipnet return fmt.Errorf("getting route: %w", err) } if len(routes) == 0 { - return fmt.Errorf("no route found") //nolint:err113 + return fmt.Errorf("no route found") } // With l3vni VPCs, send a short lease time on the first request to trigger @@ -137,7 +137,7 @@ func updateResponse(req, resp *dhcpv4.DHCPv4, subnet *dhcpapi.DHCPSubnet, ipnet } gateway := net.ParseIP(advertisedRoute.Gateway) if gateway == nil { - return fmt.Errorf("parsing advertised route gateway %s", advertisedRoute.Gateway) //nolint:err113 + return fmt.Errorf("parsing advertised route gateway %s", advertisedRoute.Gateway) } routes = append(routes, &dhcpv4.Route{ Dest: prefix, diff --git a/pkg/gen/profilesref.go b/pkg/gen/profilesref.go index 32935235d..49068d132 100644 --- a/pkg/gen/profilesref.go +++ b/pkg/gen/profilesref.go @@ -94,7 +94,7 @@ func GenerateProfilesRef(ctx context.Context, targetDir string) error { } if !sp.Spec.Features.ACLs { - return fmt.Errorf("switch profile %s does not support ACLs which makes it not suitable for any role", sp.Name) //nolint:goerr113 + return fmt.Errorf("switch profile %s does not support ACLs which makes it not suitable for any role", sp.Name) } roles := getRolesHint(sp) diff --git a/pkg/hhfctl/inspect/bfd.go b/pkg/hhfctl/inspect/bfd.go index decb34847..4e9661851 100644 --- a/pkg/hhfctl/inspect/bfd.go +++ b/pkg/hhfctl/inspect/bfd.go @@ -145,13 +145,13 @@ func BFD(ctx context.Context, kube kclient.Reader, in BFDIn) (*BFDOut, error) { for vrf, vrfPeers := range peers { for addr, peer := range vrfPeers { if !peer.Expected { - out.Errs = append(out.Errs, fmt.Errorf("switch %s: vrf %s: unexpected BFD peer %q", sw.Name, vrf, addr)) //nolint:goerr113 + out.Errs = append(out.Errs, fmt.Errorf("switch %s: vrf %s: unexpected BFD peer %q", sw.Name, vrf, addr)) } if peer.SessionState == v1beta1.BFDSessionStateUnset { - out.Errs = append(out.Errs, fmt.Errorf("switch %s: vrf %s: expected BFD peer %q is missing", sw.Name, vrf, addr)) //nolint:goerr113 + out.Errs = append(out.Errs, fmt.Errorf("switch %s: vrf %s: expected BFD peer %q is missing", sw.Name, vrf, addr)) } else if peer.SessionState != v1beta1.BFDSessionStateUp { - out.Errs = append(out.Errs, fmt.Errorf("switch %s: vrf %s: BFD peer %q is not up (state: %s)", sw.Name, vrf, addr, peer.SessionState)) //nolint:goerr113 + out.Errs = append(out.Errs, fmt.Errorf("switch %s: vrf %s: BFD peer %q is not up (state: %s)", sw.Name, vrf, addr, peer.SessionState)) } } } @@ -162,7 +162,7 @@ func BFD(ctx context.Context, kube kclient.Reader, in BFDIn) (*BFDOut, error) { for _, sw := range in.Switches { if _, ok := out.Peers[sw]; !ok { - return nil, fmt.Errorf("switch %s not found", sw) //nolint:goerr113 + return nil, fmt.Errorf("switch %s not found", sw) } } diff --git a/pkg/hhfctl/inspect/bgp.go b/pkg/hhfctl/inspect/bgp.go index 0fc29a377..0ff0f2aba 100644 --- a/pkg/hhfctl/inspect/bgp.go +++ b/pkg/hhfctl/inspect/bgp.go @@ -149,11 +149,11 @@ func BGP(ctx context.Context, kube kclient.Reader, in BGPIn) (*BGPOut, error) { for vrf, vrfNeighbors := range neighs { for name, neighbor := range vrfNeighbors { if !neighbor.Expected { - out.Errs = append(out.Errs, fmt.Errorf("switch %s: vrf %s: unexpected neighbor %q", sw.Name, vrf, name)) //nolint:goerr113 + out.Errs = append(out.Errs, fmt.Errorf("switch %s: vrf %s: unexpected neighbor %q", sw.Name, vrf, name)) } if neighbor.SessionState != v1beta1.BGPNeighborSessionStateEstablished { - out.Errs = append(out.Errs, fmt.Errorf("switch %s: vrf %s: neighbor %q is not established", sw.Name, vrf, name)) //nolint:goerr113 + out.Errs = append(out.Errs, fmt.Errorf("switch %s: vrf %s: neighbor %q is not established", sw.Name, vrf, name)) } } } @@ -164,7 +164,7 @@ func BGP(ctx context.Context, kube kclient.Reader, in BGPIn) (*BGPOut, error) { for _, sw := range in.Switches { if _, ok := out.Neighbors[sw]; !ok { - return nil, fmt.Errorf("switch %s not found", sw) //nolint:goerr113 + return nil, fmt.Errorf("switch %s not found", sw) } } diff --git a/pkg/hhfctl/inspect/inspect.go b/pkg/hhfctl/inspect/inspect.go index d5c13757c..c33c83e3c 100644 --- a/pkg/hhfctl/inspect/inspect.go +++ b/pkg/hhfctl/inspect/inspect.go @@ -141,7 +141,7 @@ func Render[TIn In, TOut Out[TIn]](now time.Time, output OutputType, w io.Writer } if len(errs) > 0 { - return fmt.Errorf("inspect function reported %d errors", len(errs)) //nolint:err113 + return fmt.Errorf("inspect function reported %d errors", len(errs)) } } diff --git a/pkg/hhfctl/inspect/lldp.go b/pkg/hhfctl/inspect/lldp.go index add0fb4c2..b56481ffe 100644 --- a/pkg/hhfctl/inspect/lldp.go +++ b/pkg/hhfctl/inspect/lldp.go @@ -159,11 +159,11 @@ func LLDP(ctx context.Context, kube kclient.Reader, in LLDPIn) (*LLDPOut, error) found = true if n.Expected.Port != actual.Port { - out.Errs = append(out.Errs, fmt.Errorf("switch %s: %s: expected neighbor port %q, got %q", sw.Name, name, n.Expected.Port, actual.Port)) //nolint:goerr113 + out.Errs = append(out.Errs, fmt.Errorf("switch %s: %s: expected neighbor port %q, got %q", sw.Name, name, n.Expected.Port, actual.Port)) } if n.Expected.Description != "" && n.Expected.Description != actual.Description { - out.Errs = append(out.Errs, fmt.Errorf("switch %s: %s: expected neighbor description %q, got %q", sw.Name, name, n.Expected.Description, actual.Description)) //nolint:goerr113 + out.Errs = append(out.Errs, fmt.Errorf("switch %s: %s: expected neighbor description %q, got %q", sw.Name, name, n.Expected.Description, actual.Description)) } } else { unexpected = append(unexpected, actual.Name) @@ -172,9 +172,9 @@ func LLDP(ctx context.Context, kube kclient.Reader, in LLDPIn) (*LLDPOut, error) if !found { if len(unexpected) == 0 { - out.Errs = append(out.Errs, fmt.Errorf("switch %s: %s: expected neighbor %q not found", sw.Name, name, n.Expected.Name)) //nolint:goerr113 + out.Errs = append(out.Errs, fmt.Errorf("switch %s: %s: expected neighbor %q not found", sw.Name, name, n.Expected.Name)) } else { - out.Errs = append(out.Errs, fmt.Errorf("switch %s: %s: expected neighbor %q not found, but found: %v", sw.Name, name, n.Expected.Name, unexpected)) //nolint:goerr113 + out.Errs = append(out.Errs, fmt.Errorf("switch %s: %s: expected neighbor %q not found, but found: %v", sw.Name, name, n.Expected.Name, unexpected)) } } } @@ -183,7 +183,7 @@ func LLDP(ctx context.Context, kube kclient.Reader, in LLDPIn) (*LLDPOut, error) for _, sw := range in.Switches { if _, ok := out.Neighbors[sw]; !ok { - return nil, fmt.Errorf("switch %s not found", sw) //nolint:goerr113 + return nil, fmt.Errorf("switch %s not found", sw) } } diff --git a/pkg/hhfctl/switch.go b/pkg/hhfctl/switch.go index 7c645250c..b0db541ae 100644 --- a/pkg/hhfctl/switch.go +++ b/pkg/hhfctl/switch.go @@ -68,7 +68,7 @@ func SwitchReboot(ctx context.Context, name string) error { } if agent.Status.BootID == "" { - return fmt.Errorf("agent is not running (missing .status.bootID)") //nolint:goerr113 + return fmt.Errorf("agent is not running (missing .status.bootID)") } agent.Spec.Reboot = agent.Status.BootID @@ -92,7 +92,7 @@ func SwitchPowerReset(ctx context.Context, name string) error { } if agent.Status.BootID == "" { - return fmt.Errorf("agent is not running (missing .status.bootID)") //nolint:goerr113 + return fmt.Errorf("agent is not running (missing .status.bootID)") } agent.Spec.PowerReset = agent.Status.BootID @@ -116,7 +116,7 @@ func SwitchReinstall(ctx context.Context, name string) error { } if agent.Status.InstallID == "" { - return fmt.Errorf("agent is not installed (missing .status.installID)") //nolint:goerr113 + return fmt.Errorf("agent is not installed (missing .status.installID)") } agent.Spec.Reinstall = agent.Status.InstallID @@ -140,7 +140,7 @@ func SwitchIP(ctx context.Context, name string) error { } if sw.Spec.IP == "" { - return fmt.Errorf("switch %q has no management IP address", name) //nolint:goerr113 + return fmt.Errorf("switch %q has no management IP address", name) } fmt.Println(sw.Spec.IP) @@ -150,7 +150,7 @@ func SwitchIP(ctx context.Context, name string) error { func SwitchSSH(ctx context.Context, name, username, run string) error { if username == "" { - return fmt.Errorf("username is required") //nolint:goerr113 + return fmt.Errorf("username is required") } kube, err := kubeutil.NewClient(ctx, "", wiringapi.AddToScheme) @@ -164,7 +164,7 @@ func SwitchSSH(ctx context.Context, name, username, run string) error { } if sw.Spec.IP == "" { - return fmt.Errorf("switch %q has no management IP address", name) //nolint:goerr113 + return fmt.Errorf("switch %q has no management IP address", name) } ip, err := netip.ParsePrefix(sw.Spec.IP) @@ -197,12 +197,12 @@ func SwitchSerial(ctx context.Context, name string) error { serial := GetSerialInfo(sw) if serial == "" { - return fmt.Errorf("switch %q has no serial connection information", name) //nolint:goerr113 + return fmt.Errorf("switch %q has no serial connection information", name) } parts := strings.SplitN(serial, ":", 2) if len(parts) != 2 { - return fmt.Errorf("invalid remote serial (expected host:port): %s", serial) //nolint:goerr113 + return fmt.Errorf("invalid remote serial (expected host:port): %s", serial) } cmd := exec.CommandContext(ctx, "ssh", append(SSHQuietFlags, "-p", parts[1], parts[0])...) //nolint:gosec diff --git a/pkg/hhfctl/vpc.go b/pkg/hhfctl/vpc.go index 8ae4142cd..aa0a1a104 100644 --- a/pkg/hhfctl/vpc.go +++ b/pkg/hhfctl/vpc.go @@ -42,7 +42,7 @@ type VPCCreateOptions struct { func VPCCreate(ctx context.Context, printYaml bool, options *VPCCreateOptions) error { if !slices.Contains(vpcapi.VPCModes, options.Mode) { - return fmt.Errorf("invalid mode %s, must be one of %v", options.Mode, vpcapi.VPCModes) //nolint:err113 + return fmt.Errorf("invalid mode %s, must be one of %v", options.Mode, vpcapi.VPCModes) } vpc := &vpcapi.VPC{ ObjectMeta: kmetav1.ObjectMeta{ diff --git a/pkg/util/apiutil/bfd.go b/pkg/util/apiutil/bfd.go index 1879bcae8..16743ab35 100644 --- a/pkg/util/apiutil/bfd.go +++ b/pkg/util/apiutil/bfd.go @@ -25,10 +25,10 @@ type BFDPeerStatus struct { func GetBFDPeers(ctx context.Context, kube kclient.Reader, fabCfg *meta.FabricConfig, sw *wiringapi.Switch) (map[string]map[string]BFDPeerStatus, error) { if sw == nil { - return nil, fmt.Errorf("switch is nil") //nolint:goerr113 + return nil, fmt.Errorf("switch is nil") } if fabCfg == nil { - return nil, fmt.Errorf("fabric config is nil") //nolint:goerr113 + return nil, fmt.Errorf("fabric config is nil") } ag := &agentapi.Agent{} diff --git a/pkg/util/apiutil/bgp.go b/pkg/util/apiutil/bgp.go index 50cd21d3d..8749c9f7d 100644 --- a/pkg/util/apiutil/bgp.go +++ b/pkg/util/apiutil/bgp.go @@ -38,10 +38,10 @@ const ( func GetBGPNeighbors(ctx context.Context, kube kclient.Reader, fabCfg *meta.FabricConfig, sw *wiringapi.Switch) (map[string]map[string]BGPNeighborStatus, error) { if sw == nil { - return nil, fmt.Errorf("switch is nil") //nolint:goerr113 + return nil, fmt.Errorf("switch is nil") } if fabCfg == nil { - return nil, fmt.Errorf("fabric config is nil") //nolint:goerr113 + return nil, fmt.Errorf("fabric config is nil") } out := map[string]map[string]BGPNeighborStatus{} @@ -108,7 +108,7 @@ func GetBGPNeighbors(ctx context.Context, kube kclient.Reader, fabCfg *meta.Fabr return nil, fmt.Errorf("getting endpoints for %s: %w", conn.Name, err) } if len(switches) != 2 { - return nil, fmt.Errorf("MCLAG Domain connection %s has %d switches, expected 2", conn.Name, len(switches)) //nolint:goerr113 + return nil, fmt.Errorf("MCLAG Domain connection %s has %d switches, expected 2", conn.Name, len(switches)) } slices.Sort(switches) @@ -213,10 +213,10 @@ func GetBGPNeighbors(ctx context.Context, kube kclient.Reader, fabCfg *meta.Fabr for peer := range fabricPeers { peerSpec, ok := ag.Spec.Switches[peer] if !ok { - return nil, fmt.Errorf("no switch found for peer %s", peer) //nolint:goerr113 + return nil, fmt.Errorf("no switch found for peer %s", peer) } if peerSpec.ProtocolIP == "" { - return nil, fmt.Errorf("no protocol IP found for peer %s", peer) //nolint:goerr113 + return nil, fmt.Errorf("no protocol IP found for peer %s", peer) } ip := strings.Split(peerSpec.ProtocolIP, "/")[0] neigh, ok := out["default"][ip] @@ -246,7 +246,7 @@ func GetBGPNeighbors(ctx context.Context, kube kclient.Reader, fabCfg *meta.Fabr ext, ok := exts[extAtt.Spec.External] if !ok { - return nil, fmt.Errorf("external %s not found", extAtt.Spec.External) //nolint:goerr113 + return nil, fmt.Errorf("external %s not found", extAtt.Spec.External) } // TODO dedup with agent code diff --git a/pkg/util/apiutil/lldp.go b/pkg/util/apiutil/lldp.go index f1907b712..e246ae423 100644 --- a/pkg/util/apiutil/lldp.go +++ b/pkg/util/apiutil/lldp.go @@ -39,7 +39,7 @@ type LLDPNeighborStatus struct { func GetLLDPNeighbors(ctx context.Context, kube kclient.Reader, sw *wiringapi.Switch) (map[string]LLDPNeighborStatus, error) { if sw == nil { - return nil, fmt.Errorf("switch is nil") //nolint:goerr113 + return nil, fmt.Errorf("switch is nil") } ag := &agentapi.Agent{} @@ -124,7 +124,7 @@ func GetLLDPNeighbors(ctx context.Context, kube kclient.Reader, sw *wiringapi.Sw } kPort = port } else { - return nil, fmt.Errorf("switch profile not found for %s", kDevice) //nolint:goerr113 + return nil, fmt.Errorf("switch profile not found for %s", kDevice) } if statusType == LLDPNeighborTypeFabric { @@ -135,13 +135,13 @@ func GetLLDPNeighbors(ctx context.Context, kube kclient.Reader, sw *wiringapi.Sw } vPort = port } else { - return nil, fmt.Errorf("switch profile not found for %s", vDevice) //nolint:goerr113 + return nil, fmt.Errorf("switch profile not found for %s", vDevice) } } status, ok := out[kPort] if ok { - return nil, fmt.Errorf("duplicate port %s", kPort) //nolint:goerr113 + return nil, fmt.Errorf("duplicate port %s", kPort) } status.Type = statusType @@ -169,12 +169,12 @@ func GetLLDPNeighbors(ctx context.Context, kube kclient.Reader, sw *wiringapi.Sw if status.Expected.Name != "" { status.Expected.Description = wiringapi.SwitchLLDPDescription(ag.Spec.Config.DeploymentID) } else { - return nil, fmt.Errorf("expected neighbor name not found for %s while type if fabric", ifaceName) //nolint:goerr113 + return nil, fmt.Errorf("expected neighbor name not found for %s while type if fabric", ifaceName) } ports, ok := swNOS2API[status.Expected.Name] if !ok { - return nil, fmt.Errorf("NOS ports mapping for %s not found", status.Expected.Name) //nolint:goerr113 + return nil, fmt.Errorf("NOS ports mapping for %s not found", status.Expected.Name) } if apiPort, ok := ports[port]; ok {