diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 41d34f473..cbc6b6647 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -89,10 +89,10 @@ jobs: just --timestamp _lint - name: More Go lint - uses: golangci/golangci-lint-action@v6 + uses: golangci/golangci-lint-action@v8 with: # keep in sync with hack/tools.just - version: v1.64.8 + version: v2.2.2 - name: Run tests run: | diff --git a/.golangci.yml b/.golangci.yml index 1ea566e89..9bfd42aca 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,47 +1,38 @@ +version: "2" run: timeout: 10m allow-parallel-runners: true build-tags: - containers_image_openpgp - containers_image_storage_stub - linters: - disable-all: true - # Look at this for details: https://golangci-lint.run/usage/linters/ + default: none enable: - # enabled by default - - typecheck - - errcheck - - gosimple - - govet - - ineffassign - - staticcheck - - unused - # disabled by default - asasalint - asciicheck - bidichk - bodyclose - containedctx - contextcheck + - copyloopvar - depguard - dogsled - durationcheck + - err113 + - errcheck - errchkjson - errname - errorlint - exhaustive - - copyloopvar - ginkgolinter - gocheckcompilerdirectives - goconst - gocritic - - err113 - - gofmt - - goimports - goprintffuncname - gosec + - govet - importas + - ineffassign - loggercheck - makezero - misspell @@ -53,97 +44,138 @@ linters: - noctx - nolintlint - nonamedreturns + - nosprintfhostport - prealloc - predeclared - promlinter - reassign - revive - - stylecheck - # - tagliatelle + - staticcheck - unconvert - unparam + - unused - usestdlibvars - usetesting - whitespace - wrapcheck - -linters-settings: - exhaustive: - check: - - switch - - map - govet: - enable-all: true - disable: - - fieldalignment - - shadow - importas: - no-unaliased: true - alias: - - pkg: k8s.io/apimachinery/pkg/types - alias: ktypes - - pkg: k8s.io/apimachinery/pkg/apis/meta/v1 - alias: kmetav1 - - pkg: k8s.io/apimachinery/pkg/api/errors - alias: kapierrors - - pkg: k8s.io/apimachinery/pkg/util/errors - alias: kerrors - - pkg: k8s.io/apimachinery/pkg/api/meta - alias: kmeta - - pkg: sigs.k8s.io/controller-runtime/pkg/log - alias: kctrllog - - pkg: sigs.k8s.io/yaml - alias: kyaml - - pkg: sigs.k8s.io/controller-runtime - alias: kctrl - - pkg: sigs.k8s.io/controller-runtime/pkg/client - alias: kclient - depguard: - rules: - main: - deny: - # - pkg: "github.com/pkg/errors$" - # desc: use stdlib errors package - - pkg: "golang.org/x/exp/maps$" - desc: use stdlib maps or samber/lo package - - pkg: "golang.org/x/exp/slices$" - desc: use stdlib slices or samber/lo package - - pkg: "golang.org/x/exp/slog$" - desc: use stdlib slog package - - pkg: "k8s.io/utils/strings/slices$" - desc: use stdlib slices or samber/lo package - - pkg: gopkg.in/yaml - desc: use sigs.k8s.io/yaml - reassign: - patterns: - - ".*" - revive: - # By default, revive will enable only the linting rules that are named in the configuration file. - # So, it's needed to explicitly enable all required rules here. + settings: + depguard: + rules: + main: + deny: + # - pkg: "github.com/pkg/errors$" + # desc: use stdlib errors package + - pkg: golang.org/x/exp/maps$ + desc: use stdlib maps or samber/lo package + - pkg: golang.org/x/exp/slices$ + desc: use stdlib slices or samber/lo package + - pkg: golang.org/x/exp/slog$ + desc: use stdlib slog package + - pkg: k8s.io/utils/strings/slices$ + desc: use stdlib slices or samber/lo package + - pkg: gopkg.in/yaml + desc: use sigs.k8s.io/yaml + embeddedstructfieldcheck: + # Checks that sync.Mutex and sync.RWMutex are not used as embedded fields. + forbid-mutex: true + exhaustive: + check: + - switch + - map + ginkgolinter: + forbid-focus-container: true + forbid-spec-pollution: true + govet: + enable-all: true + disable: + - fieldalignment + - shadow # TODO consider restricting shadowing in future + importas: + no-unaliased: true + alias: + - pkg: k8s.io/apimachinery/pkg/types + alias: ktypes + - pkg: k8s.io/apimachinery/pkg/apis/meta/v1 + alias: kmetav1 + - pkg: k8s.io/apimachinery/pkg/api/errors + alias: kapierrors + - pkg: k8s.io/apimachinery/pkg/util/errors + alias: kerrors + - pkg: k8s.io/apimachinery/pkg/api/meta + alias: kmeta + - pkg: sigs.k8s.io/controller-runtime/pkg/log + alias: kctrllog + - pkg: sigs.k8s.io/yaml + alias: kyaml + - pkg: sigs.k8s.io/controller-runtime + alias: kctrl + - pkg: sigs.k8s.io/controller-runtime/pkg/client + alias: kclient + nolintlint: + allow-unused: false + reassign: + patterns: + - .* + revive: + rules: + - name: blank-imports + - name: context-as-argument + - name: context-keys-type + - name: dot-imports + arguments: + - allowedPackages: + - github.com/onsi/ginkgo/v2 + - github.com/onsi/gomega + - name: error-return + - name: error-strings + - name: error-naming + - name: if-return + - name: import-shadowing + - name: increment-decrement + - name: var-naming + - name: var-declaration + - name: package-comments + disabled: true + - name: range + - name: receiver-naming + - name: time-naming + - name: unexported-return + - name: indent-error-flow + - name: errorf + - name: empty-block + - name: superfluous-else + - name: unused-parameter + - name: unreachable-code + - name: redefines-builtin-id + - name: bool-literal-in-expr + - name: constant-logical-expr + exclusions: + generated: strict + paths: + - ^vendor/ + - zz_generated.*\.go$ + - .*conversion.*\.go$ rules: - # The following rules are recommended https://github.com/mgechev/revive#recommended-configuration - - name: blank-imports - - name: context-as-argument - - name: context-keys-type - - name: dot-imports - - name: error-return - - name: error-strings - - name: error-naming - - name: if-return - - name: increment-decrement - - name: var-naming - - name: var-declaration - - name: range - - name: receiver-naming - - name: time-naming - - name: unexported-return - - name: indent-error-flow - - name: errorf - - name: superfluous-else - - name: unreachable-code - - name: redefines-builtin-id - # - # Rules in addition to the recommended configuration above. - # - - name: bool-literal-in-expr - - name: constant-logical-expr + - linters: + - errcheck + text: Error return value of .((os\.)?std(out|err)\..*|.*Close|.*Flush|os\.Remove(All)?|.*print(f|ln)?|os\.(Un)?Setenv). is not checked + - linters: + - gosec + text: "G304: Potential file inclusion via variable" + - path: (.+)\.go$ + text: Subprocess launch(ed with variable|ing should be audited) + - linters: + - staticcheck + text: "QF1001:" +formatters: + enable: + - gofmt + - gofumpt + - goimports + exclusions: + generated: lax + paths: + - ^vendor/ + - third_party$ + - builtin$ + - examples$ diff --git a/api/agent/v1beta1/agent_types.go b/api/agent/v1beta1/agent_types.go index 5895a122b..3ad067cc7 100644 --- a/api/agent/v1beta1/agent_types.go +++ b/api/agent/v1beta1/agent_types.go @@ -564,7 +564,7 @@ type Agent struct { const KindAgent = "Agent" -//+kubebuilder:object:root=true +// +kubebuilder:object:root=true // AgentList contains a list of Agent type AgentList struct { diff --git a/api/agent/v1beta1/catalog_types.go b/api/agent/v1beta1/catalog_types.go index 9ca9ec898..05b99adad 100644 --- a/api/agent/v1beta1/catalog_types.go +++ b/api/agent/v1beta1/catalog_types.go @@ -65,7 +65,7 @@ type Catalog struct { Status CatalogStatus `json:"status,omitempty"` } -//+kubebuilder:object:root=true +// +kubebuilder:object:root=true // CatalogList contains a list of Catalog type CatalogList struct { diff --git a/api/dhcp/v1beta1/dhcpsubnet_types.go b/api/dhcp/v1beta1/dhcpsubnet_types.go index 015eb4546..4ec83ef0c 100644 --- a/api/dhcp/v1beta1/dhcpsubnet_types.go +++ b/api/dhcp/v1beta1/dhcpsubnet_types.go @@ -113,7 +113,7 @@ type DHCPSubnet struct { Status DHCPSubnetStatus `json:"status,omitempty"` } -//+kubebuilder:object:root=true +// +kubebuilder:object:root=true // DHCPSubnetList contains a list of DHCPSubnet type DHCPSubnetList struct { diff --git a/api/vpc/v1beta1/external_types.go b/api/vpc/v1beta1/external_types.go index ddf98f9ea..58430f249 100644 --- a/api/vpc/v1beta1/external_types.go +++ b/api/vpc/v1beta1/external_types.go @@ -66,7 +66,7 @@ type External struct { Status ExternalStatus `json:"status,omitempty"` } -//+kubebuilder:object:root=true +// +kubebuilder:object:root=true // ExternalList contains a list of External type ExternalList struct { diff --git a/api/vpc/v1beta1/externalattachment_types.go b/api/vpc/v1beta1/externalattachment_types.go index c94de62c8..f5a103b06 100644 --- a/api/vpc/v1beta1/externalattachment_types.go +++ b/api/vpc/v1beta1/externalattachment_types.go @@ -82,7 +82,7 @@ type ExternalAttachment struct { Status ExternalAttachmentStatus `json:"status,omitempty"` } -//+kubebuilder:object:root=true +// +kubebuilder:object:root=true // ExternalAttachmentList contains a list of ExternalAttachment type ExternalAttachmentList struct { diff --git a/api/vpc/v1beta1/externalpeering_types.go b/api/vpc/v1beta1/externalpeering_types.go index ffdab5e57..f0196d038 100644 --- a/api/vpc/v1beta1/externalpeering_types.go +++ b/api/vpc/v1beta1/externalpeering_types.go @@ -96,7 +96,7 @@ type ExternalPeering struct { const KindExternalPeering = "ExternalPeering" -//+kubebuilder:object:root=true +// +kubebuilder:object:root=true // ExternalPeeringList contains a list of ExternalPeering type ExternalPeeringList struct { @@ -157,15 +157,18 @@ func (peering *ExternalPeering) Validate(ctx context.Context, kube kclient.Reade if permit.Prefix == "" { return nil, errors.Errorf("external.prefixes.prefix is required") } - /*if permit.Ge > permit.Le { - return nil, errors.Errorf("external.prefixes.ge must be <= external.prefixes.le") - } - if permit.Ge > 32 { - return nil, errors.Errorf("external.prefixes.ge must be <= 32") - } - if permit.Le > 32 { - return nil, errors.Errorf("external.prefixes.le must be <= 32") - }*/ + + /* + if permit.Ge > permit.Le { + return nil, errors.Errorf("external.prefixes.ge must be <= external.prefixes.le") + } + if permit.Ge > 32 { + return nil, errors.Errorf("external.prefixes.ge must be <= 32") + } + if permit.Le > 32 { + return nil, errors.Errorf("external.prefixes.le must be <= 32") + } + */ // TODO add more validation for prefix/ge/le } diff --git a/api/vpc/v1beta1/ipv4namespace_types.go b/api/vpc/v1beta1/ipv4namespace_types.go index 621612f19..2c3704877 100644 --- a/api/vpc/v1beta1/ipv4namespace_types.go +++ b/api/vpc/v1beta1/ipv4namespace_types.go @@ -33,8 +33,8 @@ import ( // IPv4NamespaceSpec defines the desired state of IPv4Namespace type IPv4NamespaceSpec struct { - //+kubebuilder:validation:MinItems=1 - //+kubebuilder:validation:MaxItems=20 + // +kubebuilder:validation:MinItems=1 + // +kubebuilder:validation:MaxItems=20 // Subnets is the list of subnets to allocate VPC subnets from, couldn't overlap between each other and with Fabric reserved subnets Subnets []string `json:"subnets,omitempty"` } @@ -61,7 +61,7 @@ type IPv4Namespace struct { const KindIPv4Namespace = "IPv4Namespace" -//+kubebuilder:object:root=true +// +kubebuilder:object:root=true // IPv4NamespaceList contains a list of IPv4Namespace type IPv4NamespaceList struct { diff --git a/api/vpc/v1beta1/vpc_types.go b/api/vpc/v1beta1/vpc_types.go index 5476d6ebb..7ffbb921d 100644 --- a/api/vpc/v1beta1/vpc_types.go +++ b/api/vpc/v1beta1/vpc_types.go @@ -195,7 +195,7 @@ type VPC struct { const KindVPC = "VPC" -//+kubebuilder:object:root=true +// +kubebuilder:object:root=true // VPCList contains a list of VPC type VPCList struct { diff --git a/api/vpc/v1beta1/vpcattachment_types.go b/api/vpc/v1beta1/vpcattachment_types.go index ee1c9543c..23035e914 100644 --- a/api/vpc/v1beta1/vpcattachment_types.go +++ b/api/vpc/v1beta1/vpcattachment_types.go @@ -65,7 +65,7 @@ type VPCAttachment struct { const KindVPCAttachment = "VPCAttachment" -//+kubebuilder:object:root=true +// +kubebuilder:object:root=true // VPCAttachmentList contains a list of VPCAttachment type VPCAttachmentList struct { diff --git a/api/vpc/v1beta1/vpcpeering_types.go b/api/vpc/v1beta1/vpcpeering_types.go index dca123df3..c445b4791 100644 --- a/api/vpc/v1beta1/vpcpeering_types.go +++ b/api/vpc/v1beta1/vpcpeering_types.go @@ -34,15 +34,15 @@ import ( // VPCPeeringSpec defines the desired state of VPCPeering type VPCPeeringSpec struct { Remote string `json:"remote,omitempty"` - //+kubebuilder:validation:MinItems=1 - //+kubebuilder:validation:MaxItems=10 + // +kubebuilder:validation:MinItems=1 + // +kubebuilder:validation:MaxItems=10 // Permit defines a list of the peering policies - which VPC subnets will have access to the peer VPC subnets. Permit []map[string]VPCPeer `json:"permit,omitempty"` } type VPCPeer struct { - //+kubebuilder:validation:MinItems=1 - //+kubebuilder:validation:MaxItems=10 + // +kubebuilder:validation:MinItems=1 + // +kubebuilder:validation:MaxItems=10 // Subnets is the list of subnets to advertise from current VPC to the peer VPC Subnets []string `json:"subnets,omitempty"` } @@ -76,7 +76,7 @@ type VPCPeering struct { const KindVPCPeering = "VPCPeering" -//+kubebuilder:object:root=true +// +kubebuilder:object:root=true // VPCPeeringList contains a list of VPCPeering type VPCPeeringList struct { diff --git a/api/wiring/v1beta1/connection_types.go b/api/wiring/v1beta1/connection_types.go index 7d21230a9..03867ed1c 100644 --- a/api/wiring/v1beta1/connection_types.go +++ b/api/wiring/v1beta1/connection_types.go @@ -96,7 +96,7 @@ type ConnBundled struct { // ConnMCLAG defines the MCLAG connection (port channel, single server to pair of switches with multiple links) type ConnMCLAG struct { - //+kubebuilder:validation:MinItems=2 + // +kubebuilder:validation:MinItems=2 // Links is the list of server-to-switch links Links []ServerToSwitchLink `json:"links,omitempty"` // ServerFacingConnectionConfig defines any server-facing connection (unbundled, bundled, mclag, etc.) configuration @@ -107,7 +107,7 @@ type ConnMCLAG struct { // ConnESLAG defines the ESLAG connection (port channel, single server to 2-4 switches with multiple links) type ConnESLAG struct { - //+kubebuilder:validation:MinItems=2 + // +kubebuilder:validation:MinItems=2 // Links is the list of server-to-switch links Links []ServerToSwitchLink `json:"links,omitempty"` // ServerFacingConnectionConfig defines any server-facing connection (unbundled, bundled, eslag, etc.) configuration @@ -127,11 +127,11 @@ type SwitchToSwitchLink struct { // ConnMCLAGDomain defines the MCLAG domain connection which makes two switches into a single logical switch or // redundancy group and allows to use MCLAG connections to connect servers in a multi-homed way. type ConnMCLAGDomain struct { - //+kubebuilder:validation:MinItems=1 + // +kubebuilder:validation:MinItems=1 // PeerLinks is the list of peer links between the switches, used to pass server traffic between switch PeerLinks []SwitchToSwitchLink `json:"peerLinks,omitempty"` - //+kubebuilder:validation:MinItems=1 + // +kubebuilder:validation:MinItems=1 // SessionLinks is the list of session links between the switches, used only to pass MCLAG control plane and BGP // traffic between switches SessionLinks []SwitchToSwitchLink `json:"sessionLinks,omitempty"` @@ -141,7 +141,7 @@ type ConnMCLAGDomain struct { type ConnFabricLinkSwitch struct { // BasePortName defines the full name of the switch port BasePortName `json:",inline"` - //+kubebuilder:validation:Pattern=`^((25[0-5]|(2[0-4]|1\d|[1-9]|)\d)\.?\b){4}/([1-2]?[0-9]|3[0-2])$` + // +kubebuilder:validation:Pattern=`^((25[0-5]|(2[0-4]|1\d|[1-9]|)\d)\.?\b){4}/([1-2]?[0-9]|3[0-2])$` // IP is the IP address of the switch side of the fabric link (switch port configuration) IP string `json:"ip,omitempty"` } @@ -156,7 +156,7 @@ type FabricLink struct { // ConnFabric defines the fabric connection (single spine to a single leaf with at least one link) type ConnFabric struct { - //+kubebuilder:validation:MinItems=1 + // +kubebuilder:validation:MinItems=1 // Links is the list of spine-to-leaf links Links []FabricLink `json:"links,omitempty"` } @@ -165,7 +165,7 @@ type ConnFabric struct { type ConnGatewayLinkGateway struct { // BasePortName defines the full name of the gateway port BasePortName `json:",inline"` - //+kubebuilder:validation:Pattern=`^((25[0-5]|(2[0-4]|1\d|[1-9]|)\d)\.?\b){4}/([1-2]?[0-9]|3[0-2])$` + // +kubebuilder:validation:Pattern=`^((25[0-5]|(2[0-4]|1\d|[1-9]|)\d)\.?\b){4}/([1-2]?[0-9]|3[0-2])$` // IP is the IP address of the switch side of the fabric link (switch port configuration) IP string `json:"ip,omitempty"` } @@ -180,7 +180,7 @@ type GatewayLink struct { // ConnGateway defines the gateway connection (single spine to a single gateway with at least one link) type ConnGateway struct { - //+kubebuilder:validation:MinItems=1 + // +kubebuilder:validation:MinItems=1 // Links is the list of spine to gateway links Links []GatewayLink `json:"links,omitempty"` } @@ -189,7 +189,7 @@ type ConnGateway struct { // workaround named "VPC Loopback" that allow to avoid switch hardware limitations and traffic going through CPU in some // cases type ConnVPCLoopback struct { - //+kubebuilder:validation:MinItems=1 + // +kubebuilder:validation:MinItems=1 // Links is the list of VPC loopback links Links []SwitchToSwitchLink `json:"links,omitempty"` } @@ -209,10 +209,10 @@ type ConnExternal struct { type ConnStaticExternalLinkSwitch struct { // BasePortName defines the full name of the switch port BasePortName `json:",inline"` - //+kubebuilder:validation:Pattern=`^((25[0-5]|(2[0-4]|1\d|[1-9]|)\d)\.?\b){4}/([1-2]?[0-9]|3[0-2])$` + // +kubebuilder:validation:Pattern=`^((25[0-5]|(2[0-4]|1\d|[1-9]|)\d)\.?\b){4}/([1-2]?[0-9]|3[0-2])$` // IP is the IP address of the switch side of the static external connection link (switch port configuration) IP string `json:"ip,omitempty"` - //+kubebuilder:validation:Pattern=`^((25[0-5]|(2[0-4]|1\d|[1-9]|)\d)\.?\b){4}$` + // +kubebuilder:validation:Pattern=`^((25[0-5]|(2[0-4]|1\d|[1-9]|)\d)\.?\b){4}$` // NextHop is the next hop IP address for static routes that will be created for the subnets NextHop string `json:"nextHop,omitempty"` // Subnets is the list of subnets that will get static routes using the specified next hop @@ -283,7 +283,7 @@ type Connection struct { const KindConnection = "Connection" -//+kubebuilder:object:root=true +// +kubebuilder:object:root=true // ConnectionList contains a list of Connection type ConnectionList struct { diff --git a/api/wiring/v1beta1/server_types.go b/api/wiring/v1beta1/server_types.go index 22db20f4a..317e5111c 100644 --- a/api/wiring/v1beta1/server_types.go +++ b/api/wiring/v1beta1/server_types.go @@ -56,7 +56,7 @@ type Server struct { const KindServer = "Server" -//+kubebuilder:object:root=true +// +kubebuilder:object:root=true // ServerList contains a list of Server type ServerList struct { diff --git a/api/wiring/v1beta1/serverprofile_types.go b/api/wiring/v1beta1/serverprofile_types.go index b3abaf9ef..4b24a49e9 100644 --- a/api/wiring/v1beta1/serverprofile_types.go +++ b/api/wiring/v1beta1/serverprofile_types.go @@ -43,9 +43,9 @@ type ServerProfileSpec struct { // ServerProfileStatus defines the observed state of ServerProfile type ServerProfileStatus struct{} -//+kubebuilder:object:root=true -//+kubebuilder:subresource:status -//+kubebuilder:resource:categories=hedgehog;wiring;fabric +// +kubebuilder:object:root=true +// +kubebuilder:subresource:status +// +kubebuilder:resource:categories=hedgehog;wiring;fabric // ServerProfile is currently not used/implemented in the Fabric API type ServerProfile struct { @@ -58,7 +58,7 @@ type ServerProfile struct { const KindServerProfile = "ServerProfile" -//+kubebuilder:object:root=true +// +kubebuilder:object:root=true // ServerProfileList contains a list of ServerProfile type ServerProfileList struct { diff --git a/api/wiring/v1beta1/switch_types.go b/api/wiring/v1beta1/switch_types.go index 149280f00..f80da8191 100644 --- a/api/wiring/v1beta1/switch_types.go +++ b/api/wiring/v1beta1/switch_types.go @@ -152,7 +152,7 @@ type Switch struct { const KindSwitch = "Switch" -//+kubebuilder:object:root=true +// +kubebuilder:object:root=true // SwitchList contains a list of Switch type SwitchList struct { diff --git a/api/wiring/v1beta1/switchgroup_types.go b/api/wiring/v1beta1/switchgroup_types.go index e292e67a6..2cae35453 100644 --- a/api/wiring/v1beta1/switchgroup_types.go +++ b/api/wiring/v1beta1/switchgroup_types.go @@ -49,7 +49,7 @@ type SwitchGroup struct { const KindSwitchGroup = "SwitchGroup" -//+kubebuilder:object:root=true +// +kubebuilder:object:root=true // SwitchGroupList contains a list of SwitchGroup type SwitchGroupList struct { diff --git a/api/wiring/v1beta1/switchprofile_types.go b/api/wiring/v1beta1/switchprofile_types.go index 90ef06993..71ace7363 100644 --- a/api/wiring/v1beta1/switchprofile_types.go +++ b/api/wiring/v1beta1/switchprofile_types.go @@ -181,7 +181,7 @@ type SwitchProfile struct { const KindSwitchProfile = "SwitchProfile" -//+kubebuilder:object:root=true +// +kubebuilder:object:root=true // SwitchProfileList contains a list of SwitchProfile type SwitchProfileList struct { @@ -751,7 +751,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/api/wiring/v1beta1/vlannamespace_types.go b/api/wiring/v1beta1/vlannamespace_types.go index a02de29ea..e674481e0 100644 --- a/api/wiring/v1beta1/vlannamespace_types.go +++ b/api/wiring/v1beta1/vlannamespace_types.go @@ -30,8 +30,8 @@ import ( // VLANNamespaceSpec defines the desired state of VLANNamespace type VLANNamespaceSpec struct { - //+kubebuilder:validation:MinItems=1 - //+kubebuilder:validation:MaxItems=20 + // +kubebuilder:validation:MinItems=1 + // +kubebuilder:validation:MaxItems=20 // Ranges is a list of VLAN ranges to be used in this namespace, couldn't overlap between each other and with Fabric reserved VLAN ranges Ranges []meta.VLANRange `json:"ranges,omitempty"` } @@ -56,7 +56,7 @@ type VLANNamespace struct { const KindVLANNamespace = "VLANNamespace" -//+kubebuilder:object:root=true +// +kubebuilder:object:root=true // VLANNamespaceList contains a list of VLANNamespace type VLANNamespaceList struct { diff --git a/cmd/main.go b/cmd/main.go index 589edf726..b1ba4845d 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -60,7 +60,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/healthz" metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server" "sigs.k8s.io/controller-runtime/pkg/webhook" - //+kubebuilder:scaffold:imports + // +kubebuilder:scaffold:imports ) func main() { @@ -130,7 +130,7 @@ func run() error { return fmt.Errorf("adding gatewayapi scheme: %w", err) } } - //+kubebuilder:scaffold:scheme + // +kubebuilder:scaffold:scheme mgr, err := kctrl.NewManager(kctrl.GetConfigOrDie(), kctrl.Options{ Scheme: scheme, @@ -229,7 +229,7 @@ func run() error { if err = switchprofilewh.SetupWithManager(mgr, cfg, profiles); err != nil { return fmt.Errorf("setting up switch profile webhook: %w", err) } - //+kubebuilder:scaffold:builder + // +kubebuilder:scaffold:builder if err := mgr.AddHealthzCheck("healthz", healthz.Ping); err != nil { return fmt.Errorf("setting up health check: %w", err) diff --git a/hack/tools.just b/hack/tools.just index 1eb8a50c6..dc1432587 100644 --- a/hack/tools.just +++ b/hack/tools.just @@ -44,10 +44,10 @@ envtest := localbin / "setup-envtest" + "-" + envtest_version [ -f {{envtest}} ] || just _goinstall "sigs.k8s.io/controller-runtime/tools/setup-envtest" {{envtest_version}} "setup-envtest" {{envtest}} # golangci-lint, keep version in sync with ci.yaml -golangci_lint_version := "v1.64.8" +golangci_lint_version := "v2.2.2" golangci_lint := localbin / "golangci-lint" + "-" + golangci_lint_version @_golangci_lint: _localbin - [ -f {{golangci_lint}} ] || just _goinstall "github.com/golangci/golangci-lint/cmd/golangci-lint" {{golangci_lint_version}} "golangci-lint" {{golangci_lint}} + [ -f {{golangci_lint}} ] || just _goinstall "github.com/golangci/golangci-lint/v2/cmd/golangci-lint" {{golangci_lint_version}} "golangci-lint" {{golangci_lint}} # butane butane_version := "v0.23.0" diff --git a/justfile b/justfile index ed8471f16..ba715b764 100644 --- a/justfile +++ b/justfile @@ -20,11 +20,11 @@ all: gen lint lint-gha test build kube-build && version # Run linters against code (incl. license headers) lint: _lint _golangci_lint - {{golangci_lint}} run --show-stats ./... + {{golangci_lint}} run ./... # Run golangci-lint to attempt to fix issues lint-fix: _lint _golangci_lint - {{golangci_lint}} run --show-stats --fix ./... + {{golangci_lint}} run --fix ./... go_base_flags := "--tags containers_image_openpgp,containers_image_storage_stub" go_flags := go_base_flags + " -ldflags=\"-w -s -X go.githedgehog.com/fabric/pkg/version.Version=" + version + "\"" diff --git a/pkg/agent/agent.go b/pkg/agent/agent.go index 16bdc479a..f7a6552c5 100644 --- a/pkg/agent/agent.go +++ b/pkg/agent/agent.go @@ -505,7 +505,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) //nolint:err113 } // report that we've been able to apply config diff --git a/pkg/agent/common/upgrade.go b/pkg/agent/common/upgrade.go index d1bc55b63..345a6d7cb 100644 --- a/pkg/agent/common/upgrade.go +++ b/pkg/agent/common/upgrade.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package common +package common //nolint:revive import ( "context" @@ -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") //nolint:err113 } baseTransport := http.DefaultTransport.(*http.Transport).Clone() @@ -133,7 +133,7 @@ func UpgradeBin(ctx context.Context, source, version, ca, username, password, ta binPath := filepath.Join(tmpPath, name) - err = os.Chmod(binPath, 0o755) + err = os.Chmod(binPath, 0o755) //nolint:gosec if err != nil { return fmt.Errorf("failed to chmod new %s bin in %s: %w", name, tmpPath, err) } diff --git a/pkg/agent/dozer/bcm/control_link.go b/pkg/agent/dozer/bcm/control_link.go index 5ac3b7de4..58f21b1f7 100644 --- a/pkg/agent/dozer/bcm/control_link.go +++ b/pkg/agent/dozer/bcm/control_link.go @@ -29,7 +29,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") //nolint:err113 } controlVIP, err := netip.ParsePrefix(agent.Spec.Config.ControlVIP) @@ -37,7 +37,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) //nolint:err113 } switchIP, err := netip.ParsePrefix(agent.Spec.Switch.IP) @@ -46,7 +46,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) //nolint:err113 } link, err := netlink.LinkByName(mgmtPort) diff --git a/pkg/agent/dozer/bcm/plan.go b/pkg/agent/dozer/bcm/plan.go index 8f8ac4189..87a308859 100644 --- a/pkg/agent/dozer/bcm/plan.go +++ b/pkg/agent/dozer/bcm/plan.go @@ -180,12 +180,15 @@ func (p *BroadcomProcessor) PlanDesiredState(_ context.Context, agent *agentapi. } } - if agent.Spec.Switch.Redundancy.Type == meta.RedundancyTypeMCLAG { + switch agent.Spec.Switch.Redundancy.Type { + case meta.RedundancyTypeNone: + // noop + case meta.RedundancyTypeMCLAG: _ /* first */, err = planMCLAGDomain(agent, spec) if err != nil { return nil, errors.Wrap(err, "failed to plan mclag domain") } - } else if agent.Spec.Switch.Redundancy.Type == meta.RedundancyTypeESLAG { + case meta.RedundancyTypeESLAG: err = planESLAG(agent, spec) if err != nil { return nil, errors.Wrap(err, "failed to plan eslag") @@ -993,14 +996,15 @@ func planServerConnections(agent *agentapi.Agent, spec *dozer.Spec) error { } spec.Interfaces[connPortChannelName] = connPortChannel - if connType == "MCLAG" { + switch connType { + case "MCLAG": spec.MCLAGInterfaces[connPortChannelName] = &dozer.SpecMCLAGInterface{ DomainID: MCLAGDomainID, } spec.PortChannelConfigs[connPortChannelName] = &dozer.SpecPortChannelConfig{ Fallback: pointer.To(fallback), } - } else if connType == "ESLAG" { + case "ESLAG": mac, err := net.ParseMAC(agent.Spec.Config.ESLAGMACBase) if err != nil { return errors.Wrapf(err, "failed to parse ESLAG MAC base %s", agent.Spec.Config.ESLAGMACBase) diff --git a/pkg/agent/dozer/bcm/processor.go b/pkg/agent/dozer/bcm/processor.go index 777c8b30a..20ac330c7 100644 --- a/pkg/agent/dozer/bcm/processor.go +++ b/pkg/agent/dozer/bcm/processor.go @@ -194,7 +194,7 @@ func (p *BroadcomProcessor) ApplyActions(ctx context.Context, actions []dozer.Ac return nil, errors.Errorf("unsupported gnmi action %+v", act) } - for attempt := 0; attempt < 50; attempt++ { + for range 50 { req, err := api.NewSetRequest(options...) if err != nil { return nil, errors.Wrapf(err, "cannot create GNMI set request") @@ -226,7 +226,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 { @@ -252,7 +252,7 @@ func (p *BroadcomProcessor) SetRoCE(ctx context.Context, val bool) error { } resp, err := p.client.CallOperation(ctx, "openconfig-qos-private:qos-roce-config", - []byte(fmt.Sprintf(`{"openconfig-qos-private:input":{"operation":"%s"}}`, action))) + fmt.Appendf(nil, `{"openconfig-qos-private:input":{"operation":"%s"}}`, action)) // it just hangs so timeout is expected if err != nil && !errors.Is(err, context.DeadlineExceeded) { @@ -263,7 +263,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") //nolint:err113 } return nil diff --git a/pkg/agent/dozer/bcm/spec_acl.go b/pkg/agent/dozer/bcm/spec_acl.go index 5fe6ecbe9..ecae90595 100644 --- a/pkg/agent/dozer/bcm/spec_acl.go +++ b/pkg/agent/dozer/bcm/spec_acl.go @@ -291,9 +291,10 @@ func unmarshalOCACLs(ocVal *oc.OpenconfigAcl_Acl) (map[string]*dozer.SpecACL, er } var action dozer.SpecACLEntryAction - if entry.Actions.Config.ForwardingAction == oc.OpenconfigAcl_FORWARDING_ACTION_ACCEPT { + switch entry.Actions.Config.ForwardingAction { //nolint:exhaustive + case oc.OpenconfigAcl_FORWARDING_ACTION_ACCEPT: action = dozer.SpecACLEntryActionAccept - } else if entry.Actions.Config.ForwardingAction == oc.OpenconfigAcl_FORWARDING_ACTION_DROP { + case oc.OpenconfigAcl_FORWARDING_ACTION_DROP: action = dozer.SpecACLEntryActionDrop } diff --git a/pkg/agent/dozer/bcm/spec_prefix_lists.go b/pkg/agent/dozer/bcm/spec_prefix_lists.go index 5f2f1c31a..0f2fa4f91 100644 --- a/pkg/agent/dozer/bcm/spec_prefix_lists.go +++ b/pkg/agent/dozer/bcm/spec_prefix_lists.go @@ -58,7 +58,7 @@ var specPrefixListEnforcer = &DefaultValueEnforcer[string, *dozer.SpecPrefixList var specPrefixListBaseEnforcer = &DefaultValueEnforcer[string, *dozer.SpecPrefixList]{ Summary: "Prefix List Base %s", NoReplace: true, // we don't want to replace the whole prefix list, just update the entries - Getter: func(name string, value *dozer.SpecPrefixList) any { + Getter: func(name string, _ *dozer.SpecPrefixList) any { return name // we do only care about the name of the prefix list }, UpdateWeight: ActionWeightPrefixListUpdate, @@ -122,9 +122,10 @@ var specPrefixListEntryEnforcer = &DefaultValueEnforcer[uint32, *dozer.SpecPrefi DeleteWeight: ActionWeightPrefixListEntryDelete, Marshal: func(seq uint32, entry *dozer.SpecPrefixListEntry) (ygot.ValidatedGoStruct, error) { action := oc.OpenconfigRoutingPolicyExt_RoutingPolicyExtActionType_UNSET - if entry.Action == dozer.SpecPrefixListActionPermit { + switch entry.Action { + case dozer.SpecPrefixListActionPermit: action = oc.OpenconfigRoutingPolicyExt_RoutingPolicyExtActionType_PERMIT - } else if entry.Action == dozer.SpecPrefixListActionDeny { + case dozer.SpecPrefixListActionDeny: action = oc.OpenconfigRoutingPolicyExt_RoutingPolicyExtActionType_DENY } @@ -195,10 +196,11 @@ func unmarshalOCPrefixLists(ocVal *oc.OpenconfigRoutingPolicy_RoutingPolicy_Defi continue } - action := dozer.SpecPrefixListActionUnset - if ocPrefix.Config.Action == oc.OpenconfigRoutingPolicyExt_RoutingPolicyExtActionType_PERMIT { + var action dozer.SpecPrefixListAction + switch ocPrefix.Config.Action { //nolint:exhaustive + case oc.OpenconfigRoutingPolicyExt_RoutingPolicyExtActionType_PERMIT: action = dozer.SpecPrefixListActionPermit - } else if ocPrefix.Config.Action == oc.OpenconfigRoutingPolicyExt_RoutingPolicyExtActionType_DENY { + case oc.OpenconfigRoutingPolicyExt_RoutingPolicyExtActionType_DENY: action = dozer.SpecPrefixListActionDeny } diff --git a/pkg/agent/dozer/bcm/spec_route_maps.go b/pkg/agent/dozer/bcm/spec_route_maps.go index 5224bff5d..0e4db1035 100644 --- a/pkg/agent/dozer/bcm/spec_route_maps.go +++ b/pkg/agent/dozer/bcm/spec_route_maps.go @@ -55,7 +55,7 @@ var specRouteMapEnforcer = &DefaultValueEnforcer[string, *dozer.SpecRouteMap]{ var specRouteMapBaseEnforcer = &DefaultValueEnforcer[string, *dozer.SpecRouteMap]{ Summary: "Route Maps Base %s", NoReplace: true, // we don't want to replace the whole route map, just update the statements - Getter: func(name string, value *dozer.SpecRouteMap) any { + Getter: func(name string, _ *dozer.SpecRouteMap) any { return name // we do only care about the name of the route map }, UpdateWeight: ActionWeightRouteMapUpdate, @@ -268,9 +268,10 @@ func unmarshalOCRouteMaps(ocVal *oc.OpenconfigRoutingPolicy_RoutingPolicy) (map[ conditions := dozer.SpecRouteMapConditions{} if statement.Conditions != nil { if statement.Conditions.Config != nil { - if statement.Conditions.Config.InstallProtocolEq == oc.OpenconfigPolicyTypes_INSTALL_PROTOCOL_TYPE_DIRECTLY_CONNECTED { + switch statement.Conditions.Config.InstallProtocolEq { //nolint:exhaustive + case oc.OpenconfigPolicyTypes_INSTALL_PROTOCOL_TYPE_DIRECTLY_CONNECTED: conditions.DirectlyConnected = pointer.To(true) - } else if statement.Conditions.Config.InstallProtocolEq == oc.OpenconfigPolicyTypes_INSTALL_PROTOCOL_TYPE_ATTACHED_HOST { + case oc.OpenconfigPolicyTypes_INSTALL_PROTOCOL_TYPE_ATTACHED_HOST: conditions.AttachedHost = pointer.To(true) } diff --git a/pkg/agent/dozer/bcm/spec_vrf.go b/pkg/agent/dozer/bcm/spec_vrf.go index 75f091b4b..a142464d0 100644 --- a/pkg/agent/dozer/bcm/spec_vrf.go +++ b/pkg/agent/dozer/bcm/spec_vrf.go @@ -360,11 +360,12 @@ var specVRFBGPNeighborEnforcer = &DefaultValueEnforcer[string, *dozer.SpecVRFBGP Marshal: func(name string, value *dozer.SpecVRFBGPNeighbor) (ygot.ValidatedGoStruct, error) { var peerType oc.E_OpenconfigBgp_PeerType if value.PeerType != nil { - if *value.PeerType == dozer.SpecVRFBGPNeighborPeerTypeInternal { + switch *value.PeerType { + case dozer.SpecVRFBGPNeighborPeerTypeInternal: peerType = oc.OpenconfigBgp_PeerType_INTERNAL - } else if *value.PeerType == dozer.SpecVRFBGPNeighborPeerTypeExternal { + case dozer.SpecVRFBGPNeighborPeerTypeExternal: peerType = oc.OpenconfigBgp_PeerType_EXTERNAL - } else { + default: return nil, errors.Errorf("unknown peer type %s", *value.PeerType) } } @@ -540,13 +541,14 @@ var specVRFTableConnectionEnforcer = &DefaultValueEnforcer[string, *dozer.SpecVR Marshal: func(key string, value *dozer.SpecVRFTableConnection) (ygot.ValidatedGoStruct, error) { var proto oc.E_OpenconfigPolicyTypes_INSTALL_PROTOCOL_TYPE - if key == dozer.SpecVRFBGPTableConnectionConnected { + switch key { + case dozer.SpecVRFBGPTableConnectionConnected: proto = oc.OpenconfigPolicyTypes_INSTALL_PROTOCOL_TYPE_DIRECTLY_CONNECTED - } else if key == dozer.SpecVRFBGPTableConnectionStatic { + case dozer.SpecVRFBGPTableConnectionStatic: proto = oc.OpenconfigPolicyTypes_INSTALL_PROTOCOL_TYPE_STATIC - } else if key == dozer.SpecVRFBGPTableConnectionAttachedHost { + case dozer.SpecVRFBGPTableConnectionAttachedHost: proto = oc.OpenconfigPolicyTypes_INSTALL_PROTOCOL_TYPE_ATTACHED_HOST - } else { + default: return nil, errors.Errorf("unknown table connection key %s", key) } @@ -635,7 +637,7 @@ var specVRFAttachedHostEnforcer = &DefaultValueEnforcer[string, *dozer.SpecVRFAt // CreatePath: "/protocols/protocol[identifier=ATTACHED_HOST][name=attached-host]/attached-host/interfaces/interface", UpdateWeight: ActionWeightVRFAttachedHostUpdate, DeleteWeight: ActionWeightVRFAttachedHostDelete, - Marshal: func(iface string, value *dozer.SpecVRFAttachedHost) (ygot.ValidatedGoStruct, error) { + Marshal: func(iface string, _ *dozer.SpecVRFAttachedHost) (ygot.ValidatedGoStruct, error) { return &oc.OpenconfigNetworkInstance_NetworkInstances_NetworkInstance_Protocols_Protocol_AttachedHost_Interfaces{ Interface: map[oc.OpenconfigNetworkInstance_NetworkInstances_NetworkInstance_Protocols_Protocol_AttachedHost_Interfaces_Interface_Key]*oc.OpenconfigNetworkInstance_NetworkInstances_NetworkInstance_Protocols_Protocol_AttachedHost_Interfaces_Interface{ { @@ -816,9 +818,10 @@ func unmarshalOCVRFs(ocVal *oc.OpenconfigNetworkInstance_NetworkInstances) (map[ } var peerType *string - if neighbor.Config.PeerType == oc.OpenconfigBgp_PeerType_INTERNAL { + switch neighbor.Config.PeerType { //nolint:exhaustive + case oc.OpenconfigBgp_PeerType_INTERNAL: peerType = pointer.To(dozer.SpecVRFBGPNeighborPeerTypeInternal) - } else if neighbor.Config.PeerType == oc.OpenconfigBgp_PeerType_EXTERNAL { + case oc.OpenconfigBgp_PeerType_EXTERNAL: peerType = pointer.To(dozer.SpecVRFBGPNeighborPeerTypeExternal) } diff --git a/pkg/agent/dozer/dozer.go b/pkg/agent/dozer/dozer.go index 6d4f20e1c..6a179c707 100644 --- a/pkg/agent/dozer/dozer.go +++ b/pkg/agent/dozer/dozer.go @@ -284,7 +284,6 @@ type SpecCommunityList struct { } const ( - SpecPrefixListActionUnset SpecPrefixListAction = "" SpecPrefixListActionPermit SpecPrefixListAction = "permit" SpecPrefixListActionDeny SpecPrefixListAction = "deny" ) diff --git a/pkg/boot/nosinstall/run.go b/pkg/boot/nosinstall/run.go index 58cbe111c..c74ae1107 100644 --- a/pkg/boot/nosinstall/run.go +++ b/pkg/boot/nosinstall/run.go @@ -127,7 +127,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") //nolint:err113 } tmpDir := os.TempDir() @@ -220,7 +220,7 @@ func extractFiles(dest string) error { } if string(magicBytes) != Magic { - return fmt.Errorf("magic mismatch") //nolint:goerr113 + return fmt.Errorf("magic mismatch") //nolint:err113 } payloadBytes := make([]byte, 8) @@ -265,7 +265,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) //nolint:err113 } f, err := os.OpenFile(target, os.O_CREATE|os.O_RDWR, mode) @@ -335,7 +335,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") //nolint:err113 } func mountSONiCPartition(origCtx context.Context) (string, func(), error) { @@ -401,12 +401,12 @@ func installAgent(ctx context.Context, tmp string) error { } } if !ok { - return fmt.Errorf("finding SONiC image dir") //nolint:goerr113 + return fmt.Errorf("finding SONiC image dir") //nolint:err113 } slog.Info("Installing Fabric Agent binary") binDir := filepath.Join(sonicRoot, "/opt/hedgehog/bin") - if err := os.MkdirAll(binDir, 0o755); err != nil { + if err := os.MkdirAll(binDir, 0o755); err != nil { //nolint:gosec return fmt.Errorf("creating bin dir: %w", err) } if err := installFile(tmp, binDir, AgentBinaryName, 0o755); err != nil { @@ -415,7 +415,7 @@ func installAgent(ctx context.Context, tmp string) error { slog.Info("Installing Fabric Agent configs") confDir := filepath.Join(sonicRoot, "/etc/sonic/hedgehog") - if err := os.MkdirAll(confDir, 0o755); err != nil { + if err := os.MkdirAll(confDir, 0o755); err != nil { //nolint:gosec return fmt.Errorf("creating agent conf dir: %w", err) } if err := installFile(tmp, confDir, AgentKubeConfigName, 0o600); err != nil { @@ -427,7 +427,7 @@ func installAgent(ctx context.Context, tmp string) error { slog.Info("Installing Fabric Agent systemd unit") systemdPath := filepath.Join(sonicRoot, "/etc/systemd/system") - if err := os.MkdirAll(systemdPath, 0o755); err != nil { + if err := os.MkdirAll(systemdPath, 0o755); err != nil { //nolint:gosec return fmt.Errorf("creating systemd dir: %w", err) } if err := installFile(tmp, systemdPath, AgentUnitName, 0o644); err != nil { @@ -435,7 +435,7 @@ func installAgent(ctx context.Context, tmp string) error { } wantsPath := filepath.Join(sonicRoot, "/etc/systemd/system/multi-user.target.wants") - if err := os.MkdirAll(wantsPath, 0o755); err != nil { + if err := os.MkdirAll(wantsPath, 0o755); err != nil { //nolint:gosec return fmt.Errorf("creating systemd wants dir: %w", err) } if err := os.Symlink(filepath.Join(systemdPath, AgentUnitName), filepath.Join(wantsPath, AgentUnitName)); err != nil { diff --git a/pkg/boot/server/downloader.go b/pkg/boot/server/downloader.go index cae6a8edd..450c88666 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) //nolint:err113 } 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) //nolint:err113 } return filepath.Join(cachePath, entries[0].Name()), nil diff --git a/pkg/boot/server/onie.go b/pkg/boot/server/onie.go index 64b6670cb..302f25fa9 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) //nolint:err113 } 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) //nolint:err113 } 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") //nolint:err113 } if agent.Spec.SwitchProfile == nil { - return fmt.Errorf("switch profile is missing") //nolint:goerr113 + return fmt.Errorf("switch profile is missing") //nolint:err113 } 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") //nolint:err113 } nosRepo, ok := svc.cfg.NOSRepos[nosType] if !ok { - return fmt.Errorf("NOS repo not found") //nolint:goerr113 + return fmt.Errorf("NOS repo not found") //nolint:err113 } nosVersion, ok := svc.cfg.NOSVersions[nosType] if !ok { - return fmt.Errorf("NOS version not found") //nolint:goerr113 + return fmt.Errorf("NOS version not found") //nolint:err113 } nosPath, err := svc.getCachedOrDownload(ctx, nosRepo, nosVersion, false) @@ -305,12 +305,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") //nolint:err113 } 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") //nolint:err113 } oniePath, err := svc.getCachedOrDownload(ctx, repo, version, false) diff --git a/pkg/boot/server/server.go b/pkg/boot/server/server.go index ed9d4fc8e..896f65384 100644 --- a/pkg/boot/server/server.go +++ b/pkg/boot/server/server.go @@ -60,7 +60,7 @@ type service struct { func Run(ctx context.Context) error { // TODO think about cache cleanup - if err := os.MkdirAll(CacheDir, 0o755); err != nil { + if err := os.MkdirAll(CacheDir, 0o755); err != nil { //nolint:gosec return errors.Wrapf(err, "creating cache dir %s", CacheDir) } diff --git a/pkg/ctrl/agent_ctrl.go b/pkg/ctrl/agent_ctrl.go index 755b05756..369dfcb7b 100644 --- a/pkg/ctrl/agent_ctrl.go +++ b/pkg/ctrl/agent_ctrl.go @@ -66,6 +66,7 @@ const ( type AgentReconciler struct { kclient.Client + cfg *meta.FabricConfig libr *librarian.Manager regCA string @@ -185,55 +186,55 @@ func (r *AgentReconciler) enqueueAllSwitches(ctx context.Context, obj kclient.Ob return res } -//+kubebuilder:rbac:groups=agent.githedgehog.com,resources=agents,verbs=get;list;watch;create;update;patch;delete -//+kubebuilder:rbac:groups=agent.githedgehog.com,resources=agents/status,verbs=get;get;list;watch;create;update;patch;delete -//+kubebuilder:rbac:groups=agent.githedgehog.com,resources=agents/finalizers,verbs=update +// +kubebuilder:rbac:groups=agent.githedgehog.com,resources=agents,verbs=get;list;watch;create;update;patch;delete +// +kubebuilder:rbac:groups=agent.githedgehog.com,resources=agents/status,verbs=get;get;list;watch;create;update;patch;delete +// +kubebuilder:rbac:groups=agent.githedgehog.com,resources=agents/finalizers,verbs=update -//+kubebuilder:rbac:groups=wiring.githedgehog.com,resources=switches,verbs=get;list;watch -//+kubebuilder:rbac:groups=wiring.githedgehog.com,resources=switches/status,verbs=get;update;patch +// +kubebuilder:rbac:groups=wiring.githedgehog.com,resources=switches,verbs=get;list;watch +// +kubebuilder:rbac:groups=wiring.githedgehog.com,resources=switches/status,verbs=get;update;patch -//+kubebuilder:rbac:groups=wiring.githedgehog.com,resources=switchprofiles,verbs=get;list;watch -//+kubebuilder:rbac:groups=wiring.githedgehog.com,resources=switchprofiles/status,verbs=get;update;patch +// +kubebuilder:rbac:groups=wiring.githedgehog.com,resources=switchprofiles,verbs=get;list;watch +// +kubebuilder:rbac:groups=wiring.githedgehog.com,resources=switchprofiles/status,verbs=get;update;patch -//+kubebuilder:rbac:groups=wiring.githedgehog.com,resources=switchgroups,verbs=get;list;watch -//+kubebuilder:rbac:groups=wiring.githedgehog.com,resources=switchgroups/status,verbs=get;update;patch +// +kubebuilder:rbac:groups=wiring.githedgehog.com,resources=switchgroups,verbs=get;list;watch +// +kubebuilder:rbac:groups=wiring.githedgehog.com,resources=switchgroups/status,verbs=get;update;patch -//+kubebuilder:rbac:groups=wiring.githedgehog.com,resources=servers,verbs=get;list;watch -//+kubebuilder:rbac:groups=wiring.githedgehog.com,resources=servers/status,verbs=get;update;patch +// +kubebuilder:rbac:groups=wiring.githedgehog.com,resources=servers,verbs=get;list;watch +// +kubebuilder:rbac:groups=wiring.githedgehog.com,resources=servers/status,verbs=get;update;patch -//+kubebuilder:rbac:groups=wiring.githedgehog.com,resources=connections,verbs=get;list;watch -//+kubebuilder:rbac:groups=wiring.githedgehog.com,resources=connections/status,verbs=get;update;patch +// +kubebuilder:rbac:groups=wiring.githedgehog.com,resources=connections,verbs=get;list;watch +// +kubebuilder:rbac:groups=wiring.githedgehog.com,resources=connections/status,verbs=get;update;patch -//+kubebuilder:rbac:groups=wiring.githedgehog.com,resources=vlannamespaces,verbs=get;list;watch -//+kubebuilder:rbac:groups=wiring.githedgehog.com,resources=vlannamespaces/status,verbs=get;update;patch +// +kubebuilder:rbac:groups=wiring.githedgehog.com,resources=vlannamespaces,verbs=get;list;watch +// +kubebuilder:rbac:groups=wiring.githedgehog.com,resources=vlannamespaces/status,verbs=get;update;patch -//+kubebuilder:rbac:groups=vpc.githedgehog.com,resources=vpcs,verbs=get;list;watch -//+kubebuilder:rbac:groups=vpc.githedgehog.com,resources=vpcs/status,verbs=get;update;patch +// +kubebuilder:rbac:groups=vpc.githedgehog.com,resources=vpcs,verbs=get;list;watch +// +kubebuilder:rbac:groups=vpc.githedgehog.com,resources=vpcs/status,verbs=get;update;patch -//+kubebuilder:rbac:groups=vpc.githedgehog.com,resources=vpcattachments,verbs=get;list;watch -//+kubebuilder:rbac:groups=vpc.githedgehog.com,resources=vpcattachments/status,verbs=get;update;patch +// +kubebuilder:rbac:groups=vpc.githedgehog.com,resources=vpcattachments,verbs=get;list;watch +// +kubebuilder:rbac:groups=vpc.githedgehog.com,resources=vpcattachments/status,verbs=get;update;patch -//+kubebuilder:rbac:groups=vpc.githedgehog.com,resources=vpcpeerings,verbs=get;list;watch -//+kubebuilder:rbac:groups=vpc.githedgehog.com,resources=vpcpeerings/status,verbs=get;update;patch +// +kubebuilder:rbac:groups=vpc.githedgehog.com,resources=vpcpeerings,verbs=get;list;watch +// +kubebuilder:rbac:groups=vpc.githedgehog.com,resources=vpcpeerings/status,verbs=get;update;patch -//+kubebuilder:rbac:groups=vpc.githedgehog.com,resources=ipv4namespaces,verbs=get;list;watch -//+kubebuilder:rbac:groups=vpc.githedgehog.com,resources=ipv4namespaces/status,verbs=get;update;patch +// +kubebuilder:rbac:groups=vpc.githedgehog.com,resources=ipv4namespaces,verbs=get;list;watch +// +kubebuilder:rbac:groups=vpc.githedgehog.com,resources=ipv4namespaces/status,verbs=get;update;patch -//+kubebuilder:rbac:groups=vpc.githedgehog.com,resources=externals,verbs=get;list;watch -//+kubebuilder:rbac:groups=vpc.githedgehog.com,resources=externals/status,verbs=get;update;patch +// +kubebuilder:rbac:groups=vpc.githedgehog.com,resources=externals,verbs=get;list;watch +// +kubebuilder:rbac:groups=vpc.githedgehog.com,resources=externals/status,verbs=get;update;patch -//+kubebuilder:rbac:groups=vpc.githedgehog.com,resources=externalattachments,verbs=get;list;watch -//+kubebuilder:rbac:groups=vpc.githedgehog.com,resources=externalattachments/status,verbs=get;update;patch +// +kubebuilder:rbac:groups=vpc.githedgehog.com,resources=externalattachments,verbs=get;list;watch +// +kubebuilder:rbac:groups=vpc.githedgehog.com,resources=externalattachments/status,verbs=get;update;patch -//+kubebuilder:rbac:groups=vpc.githedgehog.com,resources=externalpeerings,verbs=get;list;watch -//+kubebuilder:rbac:groups=vpc.githedgehog.com,resources=externalpeerings/status,verbs=get;update;patch +// +kubebuilder:rbac:groups=vpc.githedgehog.com,resources=externalpeerings,verbs=get;list;watch +// +kubebuilder:rbac:groups=vpc.githedgehog.com,resources=externalpeerings/status,verbs=get;update;patch -//+kubebuilder:rbac:groups=agent.githedgehog.com,resources=catalogs,verbs=get;list;watch;create;update;patch;delete +// +kubebuilder:rbac:groups=agent.githedgehog.com,resources=catalogs,verbs=get;list;watch;create;update;patch;delete -//+kubebuilder:rbac:groups=core,resources=serviceaccounts,verbs=get;list;watch;create;update;patch;delete -//+kubebuilder:rbac:groups=core,resources=secrets,verbs=get;list;watch;create;update;patch;delete -//+kubebuilder:rbac:groups=rbac.authorization.k8s.io,resources=roles,verbs=get;list;watch;create;update;patch;delete -//+kubebuilder:rbac:groups=rbac.authorization.k8s.io,resources=rolebindings,verbs=get;list;watch;create;update;patch;delete +// +kubebuilder:rbac:groups=core,resources=serviceaccounts,verbs=get;list;watch;create;update;patch;delete +// +kubebuilder:rbac:groups=core,resources=secrets,verbs=get;list;watch;create;update;patch;delete +// +kubebuilder:rbac:groups=rbac.authorization.k8s.io,resources=roles,verbs=get;list;watch;create;update;patch;delete +// +kubebuilder:rbac:groups=rbac.authorization.k8s.io,resources=rolebindings,verbs=get;list;watch;create;update;patch;delete func (r *AgentReconciler) Reconcile(ctx context.Context, req kctrl.Request) (kctrl.Result, error) { l := kctrllog.FromContext(ctx) @@ -717,9 +718,10 @@ func (r *AgentReconciler) Reconcile(ctx context.Context, req kctrl.Request) (kct GatewayASN: r.cfg.GatewayASN, LoopbackWorkaround: r.cfg.LoopbackWorkaround, } - if r.cfg.FabricMode == meta.FabricModeCollapsedCore { + switch r.cfg.FabricMode { + case meta.FabricModeCollapsedCore: agent.Spec.Config.CollapsedCore = &agentapi.AgentSpecConfigCollapsedCore{} - } else if r.cfg.FabricMode == meta.FabricModeSpineLeaf { + case meta.FabricModeSpineLeaf: agent.Spec.Config.SpineLeaf = &agentapi.AgentSpecConfigSpineLeaf{} } diff --git a/pkg/ctrl/connection_ctrl.go b/pkg/ctrl/connection_ctrl.go index eb88a8e56..6c53a1b38 100644 --- a/pkg/ctrl/connection_ctrl.go +++ b/pkg/ctrl/connection_ctrl.go @@ -47,10 +47,10 @@ func SetupConnectionReconcilerWith(mgr kctrl.Manager, libMngr *librarian.Manager Complete(r), "failed to setup connection controller") } -//+kubebuilder:rbac:groups=wiring.githedgehog.com,resources=connections,verbs=get;list;watch -//+kubebuilder:rbac:groups=wiring.githedgehog.com,resources=connections/status,verbs=get;update;patch +// +kubebuilder:rbac:groups=wiring.githedgehog.com,resources=connections,verbs=get;list;watch +// +kubebuilder:rbac:groups=wiring.githedgehog.com,resources=connections/status,verbs=get;update;patch -//+kubebuilder:rbac:groups=agent.githedgehog.com,resources=catalogs,verbs=get;list;watch;create;update;patch;delete +// +kubebuilder:rbac:groups=agent.githedgehog.com,resources=catalogs,verbs=get;list;watch;create;update;patch;delete func (r *ConnectionReconciler) Reconcile(ctx context.Context, req kctrl.Request) (kctrl.Result, error) { l := kctrllog.FromContext(ctx) diff --git a/pkg/ctrl/gw_vpc_sync.go b/pkg/ctrl/gw_vpc_sync.go index 30cfa8337..e62cdc9a5 100644 --- a/pkg/ctrl/gw_vpc_sync.go +++ b/pkg/ctrl/gw_vpc_sync.go @@ -30,10 +30,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") //nolint:err113 } if libMngr == nil { - return fmt.Errorf("librarian manager is nil") //nolint:goerr113 + return fmt.Errorf("librarian manager is nil") //nolint:err113 } r := &GwVPCSync{ @@ -70,13 +70,13 @@ func (r *GwVPCSync) enqueueForVPCInfo(ctx context.Context, obj kclient.Object) [ } } -//+kubebuilder:rbac:groups=vpc.githedgehog.com,resources=vpcs,verbs=get;list;watch -//+kubebuilder:rbac:groups=vpc.githedgehog.com,resources=vpcs/status,verbs=get;update;patch -//+kubebuilder:rbac:groups=vpc.githedgehog.com,resources=vpcs/finalizers,verbs=update +// +kubebuilder:rbac:groups=vpc.githedgehog.com,resources=vpcs,verbs=get;list;watch +// +kubebuilder:rbac:groups=vpc.githedgehog.com,resources=vpcs/status,verbs=get;update;patch +// +kubebuilder:rbac:groups=vpc.githedgehog.com,resources=vpcs/finalizers,verbs=update -//+kubebuilder:rbac:groups=gateway.githedgehog.com,resources=vpcinfos,verbs=get;list;watch;create;update;patch;delete -//+kubebuilder:rbac:groups=gateway.githedgehog.com,resources=vpcinfos/status,verbs=get;update;patch -//+kubebuilder:rbac:groups=gateway.githedgehog.com,resources=vpcinfos/finalizers,verbs=update +// +kubebuilder:rbac:groups=gateway.githedgehog.com,resources=vpcinfos,verbs=get;list;watch;create;update;patch;delete +// +kubebuilder:rbac:groups=gateway.githedgehog.com,resources=vpcinfos/status,verbs=get;update;patch +// +kubebuilder:rbac:groups=gateway.githedgehog.com,resources=vpcinfos/finalizers,verbs=update func (r *GwVPCSync) Reconcile(ctx context.Context, req kctrl.Request) (kctrl.Result, error) { l := kctrllog.FromContext(ctx) diff --git a/pkg/ctrl/suite_test.go b/pkg/ctrl/suite_test.go index 84162afb0..c6307592e 100644 --- a/pkg/ctrl/suite_test.go +++ b/pkg/ctrl/suite_test.go @@ -20,8 +20,8 @@ import ( "runtime" "testing" - . "github.com/onsi/ginkgo/v2" //nolint:revive - . "github.com/onsi/gomega" //nolint:revive + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" "k8s.io/client-go/kubernetes/scheme" "k8s.io/client-go/rest" @@ -29,7 +29,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/envtest" kctrllog "sigs.k8s.io/controller-runtime/pkg/log" "sigs.k8s.io/controller-runtime/pkg/log/zap" - //+kubebuilder:scaffold:imports + // +kubebuilder:scaffold:imports ) // These tests use Ginkgo (BDD-style Go testing framework). Refer to @@ -70,7 +70,7 @@ var _ = BeforeSuite(func() { Expect(err).NotTo(HaveOccurred()) Expect(cfg).NotTo(BeNil()) - //+kubebuilder:scaffold:scheme + // +kubebuilder:scaffold:scheme k8sClient, err = kclient.New(cfg, kclient.Options{Scheme: scheme.Scheme}) Expect(err).NotTo(HaveOccurred()) diff --git a/pkg/ctrl/switchprofile/silicons.go b/pkg/ctrl/switchprofile/silicons.go index 73e9698c9..fe13265c0 100644 --- a/pkg/ctrl/switchprofile/silicons.go +++ b/pkg/ctrl/switchprofile/silicons.go @@ -5,9 +5,9 @@ package switchprofile const ( SiliconVS = "vs" - SiliconBroadcomTD3_X3 = "Broadcom TD3-X3" //nolint:revive,stylecheck - SiliconBroadcomTD3_X7_2_0T = "Broadcom TD3-X7 2.0T" //nolint:revive,stylecheck - SiliconBroadcomTD3_X7_3_2T = "Broadcom TD3-X7 3.2T" //nolint:revive,stylecheck + SiliconBroadcomTD3_X3 = "Broadcom TD3-X3" //nolint:revive + SiliconBroadcomTD3_X7_2_0T = "Broadcom TD3-X7 2.0T" //nolint:revive + SiliconBroadcomTD3_X7_3_2T = "Broadcom TD3-X7 3.2T" //nolint:revive SiliconBroadcomTH = "Broadcom TH" SiliconBroadcomTH3 = "Broadcom TH3" SiliconBroadcomTH4G = "Broadcom TH4G" diff --git a/pkg/ctrl/switchprofile_ctrl.go b/pkg/ctrl/switchprofile_ctrl.go index 6f976ffe6..3aace6f3d 100644 --- a/pkg/ctrl/switchprofile_ctrl.go +++ b/pkg/ctrl/switchprofile_ctrl.go @@ -55,8 +55,8 @@ func SetupSwitchProfileReconcilerWith(mgr kctrl.Manager, cfg *meta.FabricConfig, Complete(r), "failed to setup switch profile controller") } -//+kubebuilder:rbac:groups=wiring.githedgehog.com,resources=switchprofiles,verbs=get;list;watch;create;update;patch;delete -//+kubebuilder:rbac:groups=wiring.githedgehog.com,resources=switchprofiles/status,verbs=get;update;patch +// +kubebuilder:rbac:groups=wiring.githedgehog.com,resources=switchprofiles,verbs=get;list;watch;create;update;patch;delete +// +kubebuilder:rbac:groups=wiring.githedgehog.com,resources=switchprofiles/status,verbs=get;update;patch func (r *SwitchProfileReconciler) Reconcile(ctx context.Context, _ kctrl.Request) (kctrl.Result, error) { l := kctrllog.FromContext(ctx) diff --git a/pkg/ctrl/vpc_ctrl.go b/pkg/ctrl/vpc_ctrl.go index 1f5c523b2..ec470f90b 100644 --- a/pkg/ctrl/vpc_ctrl.go +++ b/pkg/ctrl/vpc_ctrl.go @@ -83,21 +83,21 @@ func (r *VPCReconciler) enqueueOneVPC(ctx context.Context, _ kclient.Object) []r return res } -//+kubebuilder:rbac:groups=vpc.githedgehog.com,resources=vpcs,verbs=get;list;watch;create;update;patch;delete -//+kubebuilder:rbac:groups=vpc.githedgehog.com,resources=vpcs/status,verbs=get;update;patch -//+kubebuilder:rbac:groups=vpc.githedgehog.com,resources=vpcs/finalizers,verbs=update +// +kubebuilder:rbac:groups=vpc.githedgehog.com,resources=vpcs,verbs=get;list;watch;create;update;patch;delete +// +kubebuilder:rbac:groups=vpc.githedgehog.com,resources=vpcs/status,verbs=get;update;patch +// +kubebuilder:rbac:groups=vpc.githedgehog.com,resources=vpcs/finalizers,verbs=update -//+kubebuilder:rbac:groups=wiring.githedgehog.com,resources=switches,verbs=get;list;watch;create;update;patch;delete -//+kubebuilder:rbac:groups=wiring.githedgehog.com,resources=switches/status,verbs=get;update;patch -//+kubebuilder:rbac:groups=wiring.githedgehog.com,resources=switches/finalizers,verbs=update +// +kubebuilder:rbac:groups=wiring.githedgehog.com,resources=switches,verbs=get;list;watch;create;update;patch;delete +// +kubebuilder:rbac:groups=wiring.githedgehog.com,resources=switches/status,verbs=get;update;patch +// +kubebuilder:rbac:groups=wiring.githedgehog.com,resources=switches/finalizers,verbs=update -//+kubebuilder:rbac:groups=core,resources=configmaps,verbs=get;list;watch;create;update;patch;delete +// +kubebuilder:rbac:groups=core,resources=configmaps,verbs=get;list;watch;create;update;patch;delete -//+kubebuilder:rbac:groups=dhcp.githedgehog.com,resources=dhcpsubnets,verbs=get;list;watch;create;update;patch;delete -//+kubebuilder:rbac:groups=dhcp.githedgehog.com,resources=dhcpsubnets/status,verbs=get;update;patch -//+kubebuilder:rbac:groups=dhcp.githedgehog.com,resources=dhcpsubnets/finalizers,verbs=update +// +kubebuilder:rbac:groups=dhcp.githedgehog.com,resources=dhcpsubnets,verbs=get;list;watch;create;update;patch;delete +// +kubebuilder:rbac:groups=dhcp.githedgehog.com,resources=dhcpsubnets/status,verbs=get;update;patch +// +kubebuilder:rbac:groups=dhcp.githedgehog.com,resources=dhcpsubnets/finalizers,verbs=update -//+kubebuilder:rbac:groups=agent.githedgehog.com,resources=catalogs,verbs=get;list;watch;create;update;patch;delete +// +kubebuilder:rbac:groups=agent.githedgehog.com,resources=catalogs,verbs=get;list;watch;create;update;patch;delete func (r *VPCReconciler) Reconcile(ctx context.Context, req kctrl.Request) (kctrl.Result, error) { l := kctrllog.FromContext(ctx) diff --git a/pkg/gen/profilesref.go b/pkg/gen/profilesref.go index 0f9fffb74..d5e073932 100644 --- a/pkg/gen/profilesref.go +++ b/pkg/gen/profilesref.go @@ -62,7 +62,7 @@ features and port naming scheme. ) func GenerateProfilesRef(ctx context.Context, targetDir string) error { - if err := os.MkdirAll(targetDir, 0o755); err != nil { + if err := os.MkdirAll(targetDir, 0o755); err != nil { //nolint:gosec return fmt.Errorf("creating target directory %s: %w", targetDir, err) } @@ -93,7 +93,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) //nolint:err113 } roles := getRolesHint(sp) diff --git a/pkg/hhfctl/external.go b/pkg/hhfctl/external.go index f28100391..9b327af89 100644 --- a/pkg/hhfctl/external.go +++ b/pkg/hhfctl/external.go @@ -70,9 +70,9 @@ func ExternalCreate(ctx context.Context, printYaml bool, options *ExternalCreate slog.Info("External created", "name", ext.Name) if printYaml { - ext.ObjectMeta.ManagedFields = nil - ext.ObjectMeta.Generation = 0 - ext.ObjectMeta.ResourceVersion = "" + ext.ManagedFields = nil + ext.Generation = 0 + ext.ResourceVersion = "" out, err := kyaml.Marshal(ext) if err != nil { @@ -176,9 +176,9 @@ func ExternalPeering(ctx context.Context, printYaml bool, options *ExternalPeeri slog.Info("ExternalPeering created", "name", extPeering.Name) if printYaml { - extPeering.ObjectMeta.ManagedFields = nil - extPeering.ObjectMeta.Generation = 0 - extPeering.ObjectMeta.ResourceVersion = "" + extPeering.ManagedFields = nil + extPeering.Generation = 0 + extPeering.ResourceVersion = "" out, err := kyaml.Marshal(extPeering) if err != nil { diff --git a/pkg/hhfctl/inspect/access.go b/pkg/hhfctl/inspect/access.go index 1f9a6ef94..540c18640 100644 --- a/pkg/hhfctl/inspect/access.go +++ b/pkg/hhfctl/inspect/access.go @@ -44,7 +44,7 @@ type AccessOut struct { StaticExternalReachable map[string]bool `json:"staticExternalReachable,omitempty"` } -func (out *AccessOut) MarshalText(now time.Time) (string, error) { +func (out *AccessOut) MarshalText(_ time.Time) (string, error) { str := strings.Builder{} str.WriteString("Source VPCSubnets: " + strings.Join(out.SourceSubnets, ", ") + "\n") diff --git a/pkg/hhfctl/inspect/bgp.go b/pkg/hhfctl/inspect/bgp.go index c2e1eb902..6b6998e62 100644 --- a/pkg/hhfctl/inspect/bgp.go +++ b/pkg/hhfctl/inspect/bgp.go @@ -137,7 +137,7 @@ 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)) //nolint:err113 } if !in.GatewayStrict && neighbor.Type == apiutil.BGPNeighborTypeGateway { @@ -145,7 +145,7 @@ func BGP(ctx context.Context, kube kclient.Reader, in BGPIn) (*BGPOut, error) { } 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)) //nolint:err113 } } } @@ -156,7 +156,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) //nolint:err113 } } diff --git a/pkg/hhfctl/inspect/conn.go b/pkg/hhfctl/inspect/conn.go index bbdeaad1f..0493a71e5 100644 --- a/pkg/hhfctl/inspect/conn.go +++ b/pkg/hhfctl/inspect/conn.go @@ -64,7 +64,7 @@ type OutLoopbackWorkaround struct { ExternalPeerings map[string]*vpcapi.ExternalPeeringSpec `json:"externalPeerings,omitempty"` } -func (out *ConnectionOut) MarshalText(now time.Time) (string, error) { +func (out *ConnectionOut) MarshalText(_ time.Time) (string, error) { str := &strings.Builder{} data, err := kyaml.Marshal(out.Spec) diff --git a/pkg/hhfctl/inspect/lldp.go b/pkg/hhfctl/inspect/lldp.go index 45f98a2d8..39dc77f5c 100644 --- a/pkg/hhfctl/inspect/lldp.go +++ b/pkg/hhfctl/inspect/lldp.go @@ -33,7 +33,7 @@ type LLDPOut struct { Errs []error `json:"errors"` } -func (out *LLDPOut) MarshalText(now time.Time) (string, error) { +func (out *LLDPOut) MarshalText(_ time.Time) (string, error) { // TODO pass to a marshal func? noColor := !isatty.IsTerminal(os.Stdout.Fd()) @@ -160,11 +160,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)) //nolint:err113 } 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)) //nolint:err113 } } else { unexpected = append(unexpected, actual.Name) @@ -173,9 +173,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)) //nolint:err113 } 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)) //nolint:err113 } } } @@ -184,7 +184,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) //nolint:err113 } } diff --git a/pkg/hhfctl/inspect/server.go b/pkg/hhfctl/inspect/server.go index 1da71f0fd..c2db03ac9 100644 --- a/pkg/hhfctl/inspect/server.go +++ b/pkg/hhfctl/inspect/server.go @@ -43,7 +43,7 @@ type ServerOut struct { AttachedVPCs map[string]*vpcapi.VPCSpec `json:"attachedVPCs,omitempty"` } -func (out *ServerOut) MarshalText(now time.Time) (string, error) { +func (out *ServerOut) MarshalText(_ time.Time) (string, error) { str := &strings.Builder{} // TODO pass to a marshal func? diff --git a/pkg/hhfctl/inspect/vpc.go b/pkg/hhfctl/inspect/vpc.go index 5474ad88e..b9ecd7e09 100644 --- a/pkg/hhfctl/inspect/vpc.go +++ b/pkg/hhfctl/inspect/vpc.go @@ -44,7 +44,7 @@ type VPCOut struct { Access map[string]*apiutil.ReachableFromSubnet `json:"access,omitempty"` } -func (out *VPCOut) MarshalText(now time.Time) (string, error) { +func (out *VPCOut) MarshalText(_ time.Time) (string, error) { str := strings.Builder{} // TODO helper func diff --git a/pkg/hhfctl/switch.go b/pkg/hhfctl/switch.go index 6ecb71f50..43efbc578 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)") //nolint:err113 } 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)") //nolint:err113 } 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)") //nolint:err113 } 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) //nolint:err113 } 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") //nolint:err113 } kube, err := kubeutil.NewClient(ctx, "", wiringapi.SchemeBuilder) @@ -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) //nolint:err113 } 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) //nolint:err113 } 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) //nolint:err113 } cmd := exec.CommandContext(ctx, "ssh", append(SSHQuietFlags, "-p", parts[1], parts[0])...) //nolint:gosec diff --git a/pkg/hhfctl/switchgroup.go b/pkg/hhfctl/switchgroup.go index 094484c11..482851e1a 100644 --- a/pkg/hhfctl/switchgroup.go +++ b/pkg/hhfctl/switchgroup.go @@ -52,9 +52,9 @@ func SwitchGroupCreate(ctx context.Context, printYaml bool, options *SwitchGroup slog.Info("SwitchGroup created", "name", sg.Name) if printYaml { - sg.ObjectMeta.ManagedFields = nil - sg.ObjectMeta.Generation = 0 - sg.ObjectMeta.ResourceVersion = "" + sg.ManagedFields = nil + sg.Generation = 0 + sg.ResourceVersion = "" out, err := kyaml.Marshal(sg) if err != nil { diff --git a/pkg/hhfctl/vpc.go b/pkg/hhfctl/vpc.go index 03cebfcec..c7416757b 100644 --- a/pkg/hhfctl/vpc.go +++ b/pkg/hhfctl/vpc.go @@ -83,9 +83,9 @@ func VPCCreate(ctx context.Context, printYaml bool, options *VPCCreateOptions) e slog.Info("VPC created", "name", vpc.Name) if printYaml { - vpc.ObjectMeta.ManagedFields = nil - vpc.ObjectMeta.Generation = 0 - vpc.ObjectMeta.ResourceVersion = "" + vpc.ManagedFields = nil + vpc.Generation = 0 + vpc.ResourceVersion = "" out, err := kyaml.Marshal(vpc) if err != nil { @@ -147,9 +147,9 @@ func VPCAttach(ctx context.Context, printYaml bool, options *VPCAttachOptions) e slog.Info("VPCAttachment created", "name", attach.Name) if printYaml { - attach.ObjectMeta.ManagedFields = nil - attach.ObjectMeta.Generation = 0 - attach.ObjectMeta.ResourceVersion = "" + attach.ManagedFields = nil + attach.Generation = 0 + attach.ResourceVersion = "" out, err := kyaml.Marshal(attach) if err != nil { @@ -214,9 +214,9 @@ func VPCPeer(ctx context.Context, printYaml bool, options *VPCPeerOptions) error slog.Info("VPCPeering created", "name", peering.Name) if printYaml { - peering.ObjectMeta.ManagedFields = nil - peering.ObjectMeta.Generation = 0 - peering.ObjectMeta.ResourceVersion = "" + peering.ManagedFields = nil + peering.Generation = 0 + peering.ResourceVersion = "" out, err := kyaml.Marshal(peering) if err != nil { @@ -262,73 +262,9 @@ func VPCSNAT(ctx context.Context, printYaml bool, options *VPCSNATOptions) error // slog.Info("VPC SNAT set", "vpc", vpc.Name, "snat", vpc.Spec.SNAT) if printYaml { - vpc.ObjectMeta.ManagedFields = nil - vpc.ObjectMeta.Generation = 0 - vpc.ObjectMeta.ResourceVersion = "" - vpc.Status = vpcapi.VPCStatus{} - - out, err := kyaml.Marshal(vpc) - if err != nil { - return errors.Wrap(err, "cannot marshal vpc") - } - - fmt.Println(string(out)) - } - - return nil -} - -type VPCDNATOptions struct { - VPC string - Requests []string -} - -func VPCDNATRequest(ctx context.Context, printYaml bool, options *VPCDNATOptions) error { - if options.VPC == "" { - return errors.Errorf("vpc is required") - } - if len(options.Requests) == 0 { - return errors.Errorf("at least one request is required") - } - - kube, err := kubeutil.NewClient(ctx, "", vpcapi.SchemeBuilder) - if err != nil { - return errors.Wrap(err, "cannot create kube client") - } - - vpc := &vpcapi.VPC{} - err = kube.Get(ctx, ktypes.NamespacedName{Name: options.VPC, Namespace: kmetav1.NamespaceDefault}, vpc) - if err != nil { - return errors.Wrapf(err, "cannot get vpc %s", options.VPC) - } - - // TODO fix - // if vpc.Spec.DNATRequests == nil { - // vpc.Spec.DNATRequests = map[string]string{} - // } - - // for _, req := range options.Requests { - // parts := strings.Split(req, "=") - // if len(parts) == 1 { - // vpc.Spec.DNATRequests[parts[0]] = "" - // } else if len(parts) == 2 { - // vpc.Spec.DNATRequests[parts[0]] = parts[1] - // } else { - // return errors.Errorf("request should be privateIP=externalIP or privateIP, found: %s", req) - // } - // } - - err = kube.Update(ctx, vpc) - if err != nil { - return errors.Wrapf(err, "cannot update vpc %s", options.VPC) - } - - slog.Info("VPC DNAT requests", "vpc", vpc.Name, "requests", strings.Join(options.Requests, ", ")) - - if printYaml { - vpc.ObjectMeta.ManagedFields = nil - vpc.ObjectMeta.Generation = 0 - vpc.ObjectMeta.ResourceVersion = "" + vpc.ManagedFields = nil + vpc.Generation = 0 + vpc.ResourceVersion = "" vpc.Status = vpcapi.VPCStatus{} out, err := kyaml.Marshal(vpc) diff --git a/pkg/util/apiutil/bgp.go b/pkg/util/apiutil/bgp.go index c8874ee73..ca2542ed4 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") //nolint:err113 } if fabCfg == nil { - return nil, fmt.Errorf("fabric config is nil") //nolint:goerr113 + return nil, fmt.Errorf("fabric config is nil") //nolint:err113 } out := map[string]map[string]BGPNeighborStatus{} @@ -103,7 +103,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)) //nolint:err113 } slices.Sort(switches) @@ -191,7 +191,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) //nolint:err113 } // TODO dedup with agent code diff --git a/pkg/util/apiutil/lldp.go b/pkg/util/apiutil/lldp.go index c7389e165..dd54a27c5 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") //nolint:err113 } ag := &agentapi.Agent{} @@ -120,7 +120,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) //nolint:err113 } if statusType == LLDPNeighborTypeFabric { @@ -131,13 +131,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) //nolint:err113 } } status, ok := out[kPort] if ok { - return nil, fmt.Errorf("duplicate port %s", kPort) //nolint:goerr113 + return nil, fmt.Errorf("duplicate port %s", kPort) //nolint:err113 } status.Type = statusType @@ -165,12 +165,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) //nolint:err113 } 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) //nolint:err113 } if apiPort, ok := ports[port]; ok { diff --git a/pkg/util/kubeutil/kube.go b/pkg/util/kubeutil/kube.go index 1688635ea..7fe2b7996 100644 --- a/pkg/util/kubeutil/kube.go +++ b/pkg/util/kubeutil/kube.go @@ -58,13 +58,13 @@ func newClient(ctx context.Context, kubeconfigPath string, core, cached bool, sc return cancel, nil, errors.Wrapf(err, "failed to create kube config") } - scheme, err := NewScheme(schemeBuilders...) + sch, err := NewScheme(schemeBuilders...) if err != nil { return cancel, nil, errors.Wrapf(err, "failed to create scheme") } if core { - if err := corev1.AddToScheme(scheme); err != nil { + if err := corev1.AddToScheme(sch); err != nil { return cancel, nil, errors.Wrapf(err, "failed to add core scheme to runtime") } } @@ -72,7 +72,7 @@ func newClient(ctx context.Context, kubeconfigPath string, core, cached bool, sc var cacheOpts *kclient.CacheOptions if cached { clientCache, err := cache.New(cfg, cache.Options{ - Scheme: scheme, + Scheme: sch, DefaultWatchErrorHandler: cacheWatchErrorHandler, }) if err != nil { @@ -100,7 +100,7 @@ func newClient(ctx context.Context, kubeconfigPath string, core, cached bool, sc } kubeClient, err := kclient.NewWithWatch(cfg, kclient.Options{ - Scheme: scheme, + Scheme: sch, Cache: cacheOpts, }) if err != nil { @@ -125,7 +125,7 @@ func cacheWatchErrorHandler(r *clientcache.Reflector, err error) { } } -func NewClientConfig(ctx context.Context, kubeconfigPath string) (*rest.Config, error) { +func NewClientConfig(_ context.Context, kubeconfigPath string) (*rest.Config, error) { var cfg *rest.Config var err error @@ -146,15 +146,15 @@ func NewClientConfig(ctx context.Context, kubeconfigPath string) (*rest.Config, } func NewScheme(schemeBuilders ...*scheme.Builder) (*runtime.Scheme, error) { - scheme := runtime.NewScheme() + sch := runtime.NewScheme() for _, schemeBuilder := range schemeBuilders { - if err := schemeBuilder.AddToScheme(scheme); err != nil { + if err := schemeBuilder.AddToScheme(sch); err != nil { return nil, fmt.Errorf("adding scheme %s to runtime: %w", schemeBuilder.GroupVersion.String(), err) } } - return scheme, nil + return sch, nil } func NewClientset(ctx context.Context, kubeconfigPath string) (*kubernetes.Clientset, error) { diff --git a/pkg/webhook/connection/connection_webhook.go b/pkg/webhook/connection/connection_webhook.go index ea7c2a024..a41fecdf9 100644 --- a/pkg/webhook/connection/connection_webhook.go +++ b/pkg/webhook/connection/connection_webhook.go @@ -56,8 +56,8 @@ var ( _ admission.CustomValidator = (*Webhook)(nil) ) -//+kubebuilder:webhook:path=/mutate-wiring-githedgehog-com-v1beta1-connection,mutating=true,failurePolicy=fail,sideEffects=None,groups=wiring.githedgehog.com,resources=connections,verbs=create;update,versions=v1beta1,name=mconnection.kb.io,admissionReviewVersions=v1 -//+kubebuilder:webhook:path=/validate-wiring-githedgehog-com-v1beta1-connection,mutating=false,failurePolicy=fail,sideEffects=None,groups=wiring.githedgehog.com,resources=connections,verbs=create;update;delete,versions=v1beta1,name=vconnection.kb.io,admissionReviewVersions=v1 +// +kubebuilder:webhook:path=/mutate-wiring-githedgehog-com-v1beta1-connection,mutating=true,failurePolicy=fail,sideEffects=None,groups=wiring.githedgehog.com,resources=connections,verbs=create;update,versions=v1beta1,name=mconnection.kb.io,admissionReviewVersions=v1 +// +kubebuilder:webhook:path=/validate-wiring-githedgehog-com-v1beta1-connection,mutating=false,failurePolicy=fail,sideEffects=None,groups=wiring.githedgehog.com,resources=connections,verbs=create;update;delete,versions=v1beta1,name=vconnection.kb.io,admissionReviewVersions=v1 // var log = ctrl.Log.WithName("connection-webhook") @@ -124,7 +124,7 @@ func (w *Webhook) ValidateDelete(ctx context.Context, obj runtime.Object) (admis conn := obj.(*wiringapi.Connection) vpcAttachments := &vpcapi.VPCAttachmentList{} - if err := w.Client.List(ctx, vpcAttachments, kclient.MatchingLabels{ + if err := w.List(ctx, vpcAttachments, kclient.MatchingLabels{ wiringapi.LabelConnection: conn.Name, }); err != nil { return nil, errors.Wrapf(err, "error listing vpc attachments") // TODO hide internal error @@ -134,7 +134,7 @@ func (w *Webhook) ValidateDelete(ctx context.Context, obj runtime.Object) (admis } extAttachments := &vpcapi.ExternalAttachmentList{} - if err := w.Client.List(ctx, extAttachments, kclient.MatchingLabels{ + if err := w.List(ctx, extAttachments, kclient.MatchingLabels{ wiringapi.LabelConnection: conn.Name, }); err != nil { return nil, errors.Wrapf(err, "error listing external attachments") // TODO hide internal error @@ -151,7 +151,7 @@ func (w *Webhook) ValidateDelete(ctx context.Context, obj runtime.Object) (admis mclagList := &wiringapi.ConnectionList{} // The matching here, will logically and the key/vals in labels together // giving just the relevant connections - if err := w.Client.List(ctx, mclagList, kclient.MatchingLabels(labels)); err != nil { + if err := w.List(ctx, mclagList, kclient.MatchingLabels(labels)); err != nil { return nil, errors.Errorf("error listing MCLAG connections") } if len(mclagList.Items) > 0 { diff --git a/pkg/webhook/external/external_webhook.go b/pkg/webhook/external/external_webhook.go index 44560548e..282681d11 100644 --- a/pkg/webhook/external/external_webhook.go +++ b/pkg/webhook/external/external_webhook.go @@ -53,8 +53,8 @@ var ( _ admission.CustomValidator = (*Webhook)(nil) ) -//+kubebuilder:webhook:path=/mutate-vpc-githedgehog-com-v1beta1-external,mutating=true,failurePolicy=fail,sideEffects=None,groups=vpc.githedgehog.com,resources=externals,verbs=create;update,versions=v1beta1,name=mexternal.kb.io,admissionReviewVersions=v1 -//+kubebuilder:webhook:path=/validate-vpc-githedgehog-com-v1beta1-external,mutating=false,failurePolicy=fail,sideEffects=None,groups=vpc.githedgehog.com,resources=externals,verbs=create;update;delete,versions=v1beta1,name=vexternal.kb.io,admissionReviewVersions=v1 +// +kubebuilder:webhook:path=/mutate-vpc-githedgehog-com-v1beta1-external,mutating=true,failurePolicy=fail,sideEffects=None,groups=vpc.githedgehog.com,resources=externals,verbs=create;update,versions=v1beta1,name=mexternal.kb.io,admissionReviewVersions=v1 +// +kubebuilder:webhook:path=/validate-vpc-githedgehog-com-v1beta1-external,mutating=false,failurePolicy=fail,sideEffects=None,groups=vpc.githedgehog.com,resources=externals,verbs=create;update;delete,versions=v1beta1,name=vexternal.kb.io,admissionReviewVersions=v1 // var log = ctrl.Log.WithName("external-webhook") @@ -97,7 +97,7 @@ func (w *Webhook) ValidateDelete(ctx context.Context, obj runtime.Object) (admis ext := obj.(*vpcapi.External) extAttachments := &vpcapi.ExternalAttachmentList{} - if err := w.Client.List(ctx, extAttachments, kclient.MatchingLabels{ + if err := w.List(ctx, extAttachments, kclient.MatchingLabels{ vpcapi.LabelExternal: ext.Name, }); err != nil { return nil, errors.Wrapf(err, "error listing external attachments") // TODO hide internal error @@ -107,7 +107,7 @@ func (w *Webhook) ValidateDelete(ctx context.Context, obj runtime.Object) (admis } extPeerings := &vpcapi.ExternalPeeringList{} - if err := w.Client.List(ctx, extPeerings, kclient.MatchingLabels{ + if err := w.List(ctx, extPeerings, kclient.MatchingLabels{ vpcapi.LabelExternal: ext.Name, }); err != nil { return nil, errors.Wrapf(err, "error listing external peerings") // TODO hide internal error diff --git a/pkg/webhook/externalattachment/externalattachment_webhook.go b/pkg/webhook/externalattachment/externalattachment_webhook.go index ffaf372cc..cd3886eb2 100644 --- a/pkg/webhook/externalattachment/externalattachment_webhook.go +++ b/pkg/webhook/externalattachment/externalattachment_webhook.go @@ -53,8 +53,8 @@ var ( _ admission.CustomValidator = (*Webhook)(nil) ) -//+kubebuilder:webhook:path=/mutate-vpc-githedgehog-com-v1beta1-externalattachment,mutating=true,failurePolicy=fail,sideEffects=None,groups=vpc.githedgehog.com,resources=externalattachments,verbs=create;update,versions=v1beta1,name=mexternalattachment.kb.io,admissionReviewVersions=v1 -//+kubebuilder:webhook:path=/validate-vpc-githedgehog-com-v1beta1-externalattachment,mutating=false,failurePolicy=fail,sideEffects=None,groups=vpc.githedgehog.com,resources=externalattachments,verbs=create;update;delete,versions=v1beta1,name=vexternalattachment.kb.io,admissionReviewVersions=v1 +// +kubebuilder:webhook:path=/mutate-vpc-githedgehog-com-v1beta1-externalattachment,mutating=true,failurePolicy=fail,sideEffects=None,groups=vpc.githedgehog.com,resources=externalattachments,verbs=create;update,versions=v1beta1,name=mexternalattachment.kb.io,admissionReviewVersions=v1 +// +kubebuilder:webhook:path=/validate-vpc-githedgehog-com-v1beta1-externalattachment,mutating=false,failurePolicy=fail,sideEffects=None,groups=vpc.githedgehog.com,resources=externalattachments,verbs=create;update;delete,versions=v1beta1,name=vexternalattachment.kb.io,admissionReviewVersions=v1 // var log = ctrl.Log.WithName("externalattachment-webhook") diff --git a/pkg/webhook/externalpeering/externalpeering_webhook.go b/pkg/webhook/externalpeering/externalpeering_webhook.go index 616b08133..7ec4f5d7e 100644 --- a/pkg/webhook/externalpeering/externalpeering_webhook.go +++ b/pkg/webhook/externalpeering/externalpeering_webhook.go @@ -53,8 +53,8 @@ var ( _ admission.CustomValidator = (*Webhook)(nil) ) -//+kubebuilder:webhook:path=/mutate-vpc-githedgehog-com-v1beta1-externalpeering,mutating=true,failurePolicy=fail,sideEffects=None,groups=vpc.githedgehog.com,resources=externalpeerings,verbs=create;update,versions=v1beta1,name=mexternalpeering.kb.io,admissionReviewVersions=v1 -//+kubebuilder:webhook:path=/validate-vpc-githedgehog-com-v1beta1-externalpeering,mutating=false,failurePolicy=fail,sideEffects=None,groups=vpc.githedgehog.com,resources=externalpeerings,verbs=create;update;delete,versions=v1beta1,name=vexternalpeering.kb.io,admissionReviewVersions=v1 +// +kubebuilder:webhook:path=/mutate-vpc-githedgehog-com-v1beta1-externalpeering,mutating=true,failurePolicy=fail,sideEffects=None,groups=vpc.githedgehog.com,resources=externalpeerings,verbs=create;update,versions=v1beta1,name=mexternalpeering.kb.io,admissionReviewVersions=v1 +// +kubebuilder:webhook:path=/validate-vpc-githedgehog-com-v1beta1-externalpeering,mutating=false,failurePolicy=fail,sideEffects=None,groups=vpc.githedgehog.com,resources=externalpeerings,verbs=create;update;delete,versions=v1beta1,name=vexternalpeering.kb.io,admissionReviewVersions=v1 // var log = ctrl.Log.WithName("externalpeering-webhook") diff --git a/pkg/webhook/ipv4ns/ipv4ns_webhook.go b/pkg/webhook/ipv4ns/ipv4ns_webhook.go index 2dba3d521..b9866d726 100644 --- a/pkg/webhook/ipv4ns/ipv4ns_webhook.go +++ b/pkg/webhook/ipv4ns/ipv4ns_webhook.go @@ -54,8 +54,8 @@ var ( _ admission.CustomValidator = (*Webhook)(nil) ) -//+kubebuilder:webhook:path=/mutate-vpc-githedgehog-com-v1beta1-ipv4namespace,mutating=true,failurePolicy=fail,sideEffects=None,groups=vpc.githedgehog.com,resources=ipv4namespaces,verbs=create;update,versions=v1beta1,name=mipv4namespace.kb.io,admissionReviewVersions=v1 -//+kubebuilder:webhook:path=/validate-vpc-githedgehog-com-v1beta1-ipv4namespace,mutating=false,failurePolicy=fail,sideEffects=None,groups=vpc.githedgehog.com,resources=ipv4namespaces,verbs=create;update;delete,versions=v1beta1,name=vipv4namespace.kb.io,admissionReviewVersions=v1 +// +kubebuilder:webhook:path=/mutate-vpc-githedgehog-com-v1beta1-ipv4namespace,mutating=true,failurePolicy=fail,sideEffects=None,groups=vpc.githedgehog.com,resources=ipv4namespaces,verbs=create;update,versions=v1beta1,name=mipv4namespace.kb.io,admissionReviewVersions=v1 +// +kubebuilder:webhook:path=/validate-vpc-githedgehog-com-v1beta1-ipv4namespace,mutating=false,failurePolicy=fail,sideEffects=None,groups=vpc.githedgehog.com,resources=ipv4namespaces,verbs=create;update;delete,versions=v1beta1,name=vipv4namespace.kb.io,admissionReviewVersions=v1 // var log = ctrl.Log.WithName("ipv4namespace-webhook") @@ -79,7 +79,7 @@ func (w *Webhook) ValidateCreate(ctx context.Context, obj runtime.Object) (admis } func (w *Webhook) ValidateUpdate(ctx context.Context, oldObj runtime.Object, newObj runtime.Object) (admission.Warnings, error) { - // oldNs := oldObj.(*vpcapi.IPv4Namespace) + _ = oldObj.(*vpcapi.IPv4Namespace) ns := newObj.(*vpcapi.IPv4Namespace) if warn, err := ns.Validate(ctx, w.Client, w.Cfg); err != nil { @@ -97,7 +97,7 @@ func (w *Webhook) ValidateUpdate(ctx context.Context, oldObj runtime.Object, new } vpcs := &vpcapi.VPCList{} - if err := w.Client.List(ctx, vpcs, kclient.MatchingLabels{ + if err := w.List(ctx, vpcs, kclient.MatchingLabels{ vpcapi.LabelIPv4NS: ns.Name, }); err != nil { return nil, errors.Wrapf(err, "error listing vpcs") // TODO hide internal error @@ -132,7 +132,7 @@ func (w *Webhook) ValidateDelete(ctx context.Context, obj runtime.Object) (admis ipns := obj.(*vpcapi.IPv4Namespace) vpcs := &vpcapi.VPCList{} - if err := w.Client.List(ctx, vpcs, kclient.MatchingLabels{ + if err := w.List(ctx, vpcs, kclient.MatchingLabels{ vpcapi.LabelIPv4NS: ipns.Name, }); err != nil { return nil, errors.Wrapf(err, "error listing vpcs") // TODO hide internal error @@ -142,7 +142,7 @@ func (w *Webhook) ValidateDelete(ctx context.Context, obj runtime.Object) (admis } externals := &vpcapi.ExternalList{} - if err := w.Client.List(ctx, externals, kclient.MatchingLabels{ + if err := w.List(ctx, externals, kclient.MatchingLabels{ vpcapi.LabelIPv4NS: ipns.Name, }); err != nil { return nil, errors.Wrapf(err, "error listing externals") // TODO hide internal error diff --git a/pkg/webhook/server/server_webhook.go b/pkg/webhook/server/server_webhook.go index 34973c134..d151e21be 100644 --- a/pkg/webhook/server/server_webhook.go +++ b/pkg/webhook/server/server_webhook.go @@ -51,8 +51,8 @@ var ( _ admission.CustomValidator = (*Webhook)(nil) ) -//+kubebuilder:webhook:path=/mutate-wiring-githedgehog-com-v1beta1-server,mutating=true,failurePolicy=fail,sideEffects=None,groups=wiring.githedgehog.com,resources=servers,verbs=create;update,versions=v1beta1,name=mserver.kb.io,admissionReviewVersions=v1 -//+kubebuilder:webhook:path=/validate-wiring-githedgehog-com-v1beta1-server,mutating=false,failurePolicy=fail,sideEffects=None,groups=wiring.githedgehog.com,resources=servers,verbs=create;update;delete,versions=v1beta1,name=vserver.kb.io,admissionReviewVersions=v1 +// +kubebuilder:webhook:path=/mutate-wiring-githedgehog-com-v1beta1-server,mutating=true,failurePolicy=fail,sideEffects=None,groups=wiring.githedgehog.com,resources=servers,verbs=create;update,versions=v1beta1,name=mserver.kb.io,admissionReviewVersions=v1 +// +kubebuilder:webhook:path=/validate-wiring-githedgehog-com-v1beta1-server,mutating=false,failurePolicy=fail,sideEffects=None,groups=wiring.githedgehog.com,resources=servers,verbs=create;update;delete,versions=v1beta1,name=vserver.kb.io,admissionReviewVersions=v1 // var log = ctrl.Log.WithName("server-webhook") @@ -90,7 +90,7 @@ func (w *Webhook) ValidateDelete(ctx context.Context, obj runtime.Object) (admis server := obj.(*wiringapi.Server) conns := &wiringapi.ConnectionList{} - if err := w.Client.List(ctx, conns, kclient.MatchingLabels{ + if err := w.List(ctx, conns, kclient.MatchingLabels{ wiringapi.ListLabelServer(server.Name): wiringapi.ListLabelValue, }); err != nil { return nil, errors.Wrapf(err, "error listing connections") // TODO hide internal error diff --git a/pkg/webhook/switchh/switch_webhook.go b/pkg/webhook/switchh/switch_webhook.go index 6d7946fd5..933b78e69 100644 --- a/pkg/webhook/switchh/switch_webhook.go +++ b/pkg/webhook/switchh/switch_webhook.go @@ -54,8 +54,8 @@ var ( _ admission.CustomValidator = (*Webhook)(nil) ) -//+kubebuilder:webhook:path=/mutate-wiring-githedgehog-com-v1beta1-switch,mutating=true,failurePolicy=fail,sideEffects=None,groups=wiring.githedgehog.com,resources=switches,verbs=create;update,versions=v1beta1,name=mswitch.kb.io,admissionReviewVersions=v1 -//+kubebuilder:webhook:path=/validate-wiring-githedgehog-com-v1beta1-switch,mutating=false,failurePolicy=fail,sideEffects=None,groups=wiring.githedgehog.com,resources=switches,verbs=create;update;delete,versions=v1beta1,name=vswitch.kb.io,admissionReviewVersions=v1 +// +kubebuilder:webhook:path=/mutate-wiring-githedgehog-com-v1beta1-switch,mutating=true,failurePolicy=fail,sideEffects=None,groups=wiring.githedgehog.com,resources=switches,verbs=create;update,versions=v1beta1,name=mswitch.kb.io,admissionReviewVersions=v1 +// +kubebuilder:webhook:path=/validate-wiring-githedgehog-com-v1beta1-switch,mutating=false,failurePolicy=fail,sideEffects=None,groups=wiring.githedgehog.com,resources=switches,verbs=create;update;delete,versions=v1beta1,name=vswitch.kb.io,admissionReviewVersions=v1 // var log = ctrl.Log.WithName("switch-webhook") @@ -98,7 +98,7 @@ func (w *Webhook) ValidateDelete(ctx context.Context, obj runtime.Object) (admis sw := obj.(*wiringapi.Switch) conns := &wiringapi.ConnectionList{} - if err := w.Client.List(ctx, conns, kclient.MatchingLabels{ + if err := w.List(ctx, conns, kclient.MatchingLabels{ wiringapi.ListLabelSwitch(sw.Name): wiringapi.ListLabelValue, }); err != nil { return nil, errors.Wrapf(err, "error listing connections") // TODO hide internal error diff --git a/pkg/webhook/switchprofile/switchprofile_webhook.go b/pkg/webhook/switchprofile/switchprofile_webhook.go index 7c5db39bb..680542ef4 100644 --- a/pkg/webhook/switchprofile/switchprofile_webhook.go +++ b/pkg/webhook/switchprofile/switchprofile_webhook.go @@ -57,8 +57,8 @@ var ( _ admission.CustomValidator = (*Webhook)(nil) ) -//+kubebuilder:webhook:path=/mutate-wiring-githedgehog-com-v1beta1-switchprofile,mutating=true,failurePolicy=fail,sideEffects=None,groups=wiring.githedgehog.com,resources=switchprofiles,verbs=create;update,versions=v1beta1,name=mswitchprofile.kb.io,admissionReviewVersions=v1 -//+kubebuilder:webhook:path=/validate-wiring-githedgehog-com-v1beta1-switchprofile,mutating=false,failurePolicy=fail,sideEffects=None,groups=wiring.githedgehog.com,resources=switchprofiles,verbs=create;update;delete,versions=v1beta1,name=vswitchprofile.kb.io,admissionReviewVersions=v1 +// +kubebuilder:webhook:path=/mutate-wiring-githedgehog-com-v1beta1-switchprofile,mutating=true,failurePolicy=fail,sideEffects=None,groups=wiring.githedgehog.com,resources=switchprofiles,verbs=create;update,versions=v1beta1,name=mswitchprofile.kb.io,admissionReviewVersions=v1 +// +kubebuilder:webhook:path=/validate-wiring-githedgehog-com-v1beta1-switchprofile,mutating=false,failurePolicy=fail,sideEffects=None,groups=wiring.githedgehog.com,resources=switchprofiles,verbs=create;update;delete,versions=v1beta1,name=vswitchprofile.kb.io,admissionReviewVersions=v1 // var log = ctrl.Log.WithName("switchprofile-webhook") diff --git a/pkg/webhook/vlanns/vlanns_webhook.go b/pkg/webhook/vlanns/vlanns_webhook.go index ff7289dda..a4b4ac553 100644 --- a/pkg/webhook/vlanns/vlanns_webhook.go +++ b/pkg/webhook/vlanns/vlanns_webhook.go @@ -54,8 +54,8 @@ var ( _ admission.CustomValidator = (*Webhook)(nil) ) -//+kubebuilder:webhook:path=/mutate-wiring-githedgehog-com-v1beta1-vlannamespace,mutating=true,failurePolicy=fail,sideEffects=None,groups=wiring.githedgehog.com,resources=vlannamespaces,verbs=create;update,versions=v1beta1,name=mvlannamespace.kb.io,admissionReviewVersions=v1 -//+kubebuilder:webhook:path=/validate-wiring-githedgehog-com-v1beta1-vlannamespace,mutating=false,failurePolicy=fail,sideEffects=None,groups=wiring.githedgehog.com,resources=vlannamespaces,verbs=create;update;delete,versions=v1beta1,name=vvlannamespace.kb.io,admissionReviewVersions=v1 +// +kubebuilder:webhook:path=/mutate-wiring-githedgehog-com-v1beta1-vlannamespace,mutating=true,failurePolicy=fail,sideEffects=None,groups=wiring.githedgehog.com,resources=vlannamespaces,verbs=create;update,versions=v1beta1,name=mvlannamespace.kb.io,admissionReviewVersions=v1 +// +kubebuilder:webhook:path=/validate-wiring-githedgehog-com-v1beta1-vlannamespace,mutating=false,failurePolicy=fail,sideEffects=None,groups=wiring.githedgehog.com,resources=vlannamespaces,verbs=create;update;delete,versions=v1beta1,name=vvlannamespace.kb.io,admissionReviewVersions=v1 // var log = ctrl.Log.WithName("vlannamespace-webhook") @@ -79,7 +79,7 @@ func (w *Webhook) ValidateCreate(ctx context.Context, obj runtime.Object) (admis } func (w *Webhook) ValidateUpdate(ctx context.Context, oldObj runtime.Object, newObj runtime.Object) (admission.Warnings, error) { - // oldNs := oldObj.(*wiringapi.VLANNamespace) + _ = oldObj.(*wiringapi.VLANNamespace) ns := newObj.(*wiringapi.VLANNamespace) if warn, err := ns.Validate(ctx, w.Client, w.Cfg); err != nil { @@ -87,7 +87,7 @@ func (w *Webhook) ValidateUpdate(ctx context.Context, oldObj runtime.Object, new } vpcs := &vpcapi.VPCList{} - if err := w.Client.List(ctx, vpcs, kclient.MatchingLabels{ + if err := w.List(ctx, vpcs, kclient.MatchingLabels{ vpcapi.LabelIPv4NS: ns.Name, }); err != nil { return nil, errors.Wrapf(err, "error listing vpcs") // TODO hide internal error @@ -108,7 +108,7 @@ func (w *Webhook) ValidateDelete(ctx context.Context, obj runtime.Object) (admis ns := obj.(*wiringapi.VLANNamespace) switches := &wiringapi.SwitchList{} - if err := w.Client.List(ctx, switches, kclient.MatchingLabels{ + if err := w.List(ctx, switches, kclient.MatchingLabels{ wiringapi.ListLabelVLANNamespace(ns.Name): wiringapi.ListLabelValue, }); err != nil { return nil, errors.Wrapf(err, "error listing switches") // TODO hide internal error @@ -118,7 +118,7 @@ func (w *Webhook) ValidateDelete(ctx context.Context, obj runtime.Object) (admis } vpcs := &vpcapi.VPCList{} - if err := w.Client.List(ctx, vpcs, kclient.MatchingLabels{ + if err := w.List(ctx, vpcs, kclient.MatchingLabels{ vpcapi.LabelVLANNS: ns.Name, }); err != nil { return nil, errors.Wrapf(err, "error listing vpcs") // TODO hide internal error diff --git a/pkg/webhook/vpc/vpc_webhook.go b/pkg/webhook/vpc/vpc_webhook.go index 5d6c5acfd..69e9e0ca1 100644 --- a/pkg/webhook/vpc/vpc_webhook.go +++ b/pkg/webhook/vpc/vpc_webhook.go @@ -54,8 +54,8 @@ var ( _ admission.CustomValidator = (*Webhook)(nil) ) -//+kubebuilder:webhook:path=/mutate-vpc-githedgehog-com-v1beta1-vpc,mutating=true,failurePolicy=fail,sideEffects=None,groups=vpc.githedgehog.com,resources=vpcs,verbs=create;update,versions=v1beta1,name=mvpc.kb.io,admissionReviewVersions=v1 -//+kubebuilder:webhook:path=/validate-vpc-githedgehog-com-v1beta1-vpc,mutating=false,failurePolicy=fail,sideEffects=None,groups=vpc.githedgehog.com,resources=vpcs,verbs=create;update;delete,versions=v1beta1,name=vvpc.kb.io,admissionReviewVersions=v1 +// +kubebuilder:webhook:path=/mutate-vpc-githedgehog-com-v1beta1-vpc,mutating=true,failurePolicy=fail,sideEffects=None,groups=vpc.githedgehog.com,resources=vpcs,verbs=create;update,versions=v1beta1,name=mvpc.kb.io,admissionReviewVersions=v1 +// +kubebuilder:webhook:path=/validate-vpc-githedgehog-com-v1beta1-vpc,mutating=false,failurePolicy=fail,sideEffects=None,groups=vpc.githedgehog.com,resources=vpcs,verbs=create;update;delete,versions=v1beta1,name=vvpc.kb.io,admissionReviewVersions=v1 // var log = ctrl.Log.WithName("vpc-webhook") @@ -107,7 +107,7 @@ func (w *Webhook) ValidateDelete(ctx context.Context, obj runtime.Object) (admis vpc := obj.(*vpcapi.VPC) vpcAttachments := &vpcapi.VPCAttachmentList{} - if err := w.Client.List(ctx, vpcAttachments, kclient.MatchingLabels{ + if err := w.List(ctx, vpcAttachments, kclient.MatchingLabels{ vpcapi.LabelVPC: vpc.Name, }); err != nil { return nil, errors.Wrapf(err, "error listing vpc attachments") // TODO hide internal error @@ -117,7 +117,7 @@ func (w *Webhook) ValidateDelete(ctx context.Context, obj runtime.Object) (admis } vpcPeerings := &vpcapi.VPCPeeringList{} - if err := w.Client.List(ctx, vpcPeerings, kclient.MatchingLabels{ + if err := w.List(ctx, vpcPeerings, kclient.MatchingLabels{ vpcapi.ListLabelVPC(vpc.Name): vpcapi.ListLabelValue, }); err != nil { return nil, errors.Wrapf(err, "error listing vpc peerings") // TODO hide internal error @@ -127,7 +127,7 @@ func (w *Webhook) ValidateDelete(ctx context.Context, obj runtime.Object) (admis } extPeerings := &vpcapi.ExternalPeeringList{} - if err := w.Client.List(ctx, extPeerings, kclient.MatchingLabels{ + if err := w.List(ctx, extPeerings, kclient.MatchingLabels{ vpcapi.LabelVPC: vpc.Name, }); err != nil { return nil, errors.Wrapf(err, "error listing external peerings") // TODO hide internal error @@ -137,7 +137,7 @@ func (w *Webhook) ValidateDelete(ctx context.Context, obj runtime.Object) (admis } staticExts := &wiringapi.ConnectionList{} - if err := w.Client.List(ctx, staticExts, kclient.MatchingLabels{ + if err := w.List(ctx, staticExts, kclient.MatchingLabels{ wiringapi.LabelVPC: vpc.Name, }); err != nil { return nil, errors.Wrapf(err, "error listing connections") // TODO hide internal error diff --git a/pkg/webhook/vpcattachment/vpcattachment_webhook.go b/pkg/webhook/vpcattachment/vpcattachment_webhook.go index 3ee8189cf..2721495bd 100644 --- a/pkg/webhook/vpcattachment/vpcattachment_webhook.go +++ b/pkg/webhook/vpcattachment/vpcattachment_webhook.go @@ -53,8 +53,8 @@ var ( _ admission.CustomValidator = (*Webhook)(nil) ) -//+kubebuilder:webhook:path=/mutate-vpc-githedgehog-com-v1beta1-vpcattachment,mutating=true,failurePolicy=fail,sideEffects=None,groups=vpc.githedgehog.com,resources=vpcattachments,verbs=create;update,versions=v1beta1,name=mvpcattachment.kb.io,admissionReviewVersions=v1 -//+kubebuilder:webhook:path=/validate-vpc-githedgehog-com-v1beta1-vpcattachment,mutating=false,failurePolicy=fail,sideEffects=None,groups=vpc.githedgehog.com,resources=vpcattachments,verbs=create;update;delete,versions=v1beta1,name=vvpcattachment.kb.io,admissionReviewVersions=v1 +// +kubebuilder:webhook:path=/mutate-vpc-githedgehog-com-v1beta1-vpcattachment,mutating=true,failurePolicy=fail,sideEffects=None,groups=vpc.githedgehog.com,resources=vpcattachments,verbs=create;update,versions=v1beta1,name=mvpcattachment.kb.io,admissionReviewVersions=v1 +// +kubebuilder:webhook:path=/validate-vpc-githedgehog-com-v1beta1-vpcattachment,mutating=false,failurePolicy=fail,sideEffects=None,groups=vpc.githedgehog.com,resources=vpcattachments,verbs=create;update;delete,versions=v1beta1,name=vvpcattachment.kb.io,admissionReviewVersions=v1 // var log = ctrl.Log.WithName("vpcattachment-webhook") diff --git a/pkg/webhook/vpcpeering/vpcpeering_webhook.go b/pkg/webhook/vpcpeering/vpcpeering_webhook.go index 18dd0037c..799f47556 100644 --- a/pkg/webhook/vpcpeering/vpcpeering_webhook.go +++ b/pkg/webhook/vpcpeering/vpcpeering_webhook.go @@ -53,8 +53,8 @@ var ( _ admission.CustomValidator = (*Webhook)(nil) ) -//+kubebuilder:webhook:path=/mutate-vpc-githedgehog-com-v1beta1-vpcpeering,mutating=true,failurePolicy=fail,sideEffects=None,groups=vpc.githedgehog.com,resources=vpcpeerings,verbs=create;update,versions=v1beta1,name=mvpcpeering.kb.io,admissionReviewVersions=v1 -//+kubebuilder:webhook:path=/validate-vpc-githedgehog-com-v1beta1-vpcpeering,mutating=false,failurePolicy=fail,sideEffects=None,groups=vpc.githedgehog.com,resources=vpcpeerings,verbs=create;update;delete,versions=v1beta1,name=vvpcpeering.kb.io,admissionReviewVersions=v1 +// +kubebuilder:webhook:path=/mutate-vpc-githedgehog-com-v1beta1-vpcpeering,mutating=true,failurePolicy=fail,sideEffects=None,groups=vpc.githedgehog.com,resources=vpcpeerings,verbs=create;update,versions=v1beta1,name=mvpcpeering.kb.io,admissionReviewVersions=v1 +// +kubebuilder:webhook:path=/validate-vpc-githedgehog-com-v1beta1-vpcpeering,mutating=false,failurePolicy=fail,sideEffects=None,groups=vpc.githedgehog.com,resources=vpcpeerings,verbs=create;update;delete,versions=v1beta1,name=vvpcpeering.kb.io,admissionReviewVersions=v1 // var log = ctrl.Log.WithName("vpcpeering-webhook") diff --git a/pkg/webhook/webhook_suite_test.go b/pkg/webhook/webhook_suite_test.go index 472b4eb91..a40791434 100644 --- a/pkg/webhook/webhook_suite_test.go +++ b/pkg/webhook/webhook_suite_test.go @@ -24,12 +24,12 @@ import ( "testing" "time" - . "github.com/onsi/ginkgo/v2" //nolint:revive - . "github.com/onsi/gomega" //nolint:revive + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" "github.com/pkg/errors" admissionv1 "k8s.io/api/admission/v1" - //+kubebuilder:scaffold:imports + // +kubebuilder:scaffold:imports wiringapi "go.githedgehog.com/fabric/api/wiring/v1beta1" "go.githedgehog.com/fabric/pkg/webhook/connection" "go.githedgehog.com/fabric/pkg/webhook/server" @@ -100,7 +100,7 @@ var _ = BeforeSuite(func() { err = admissionv1.AddToScheme(scheme) Expect(err).NotTo(HaveOccurred()) - //+kubebuilder:scaffold:scheme + // +kubebuilder:scaffold:scheme k8sClient, err = kclient.New(cfg, kclient.Options{Scheme: scheme}) Expect(err).NotTo(HaveOccurred()) @@ -135,7 +135,7 @@ var _ = BeforeSuite(func() { err = vpcattachment.SetupWithManager(mgr, nil) Expect(err).NotTo(HaveOccurred()) - //+kubebuilder:scaffold:webhook + // +kubebuilder:scaffold:webhook go func() { defer GinkgoRecover() @@ -151,8 +151,13 @@ var _ = BeforeSuite(func() { if err != nil { return errors.Wrapf(err, "failed to dial %s", addrPort) } - conn.Close() - return nil //nolint: nlreturn + if err := conn.Close(); err != nil { + // TODO probably just log + + return errors.Wrapf(err, "failed to close connection to %s", addrPort) + } + + return nil }).Should(Succeed()) })