Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump shipyard and address golangci-lint v1.60.3 errors #3202

Merged
merged 1 commit into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ linters:
- bidichk
- bodyclose
- contextcheck
- copyloopvar
# - cyclop # This is equivalent to gocyclo
# - depguard # depguard now denies by default, it should only be enabled if we actually use it
- dogsled
Expand All @@ -67,7 +68,6 @@ linters:
- errname
- exhaustive
# - exhaustivestruct # Not recommended for general use - meant to be used only for special cases
- exportloopref
# - forbidigo # We don't forbid any statements
# - forcetypeassert # There are many unchecked type assertions that would be the result of a programming error so the
# reasonable recourse would be to panic anyway if checked so this doesn't seem useful
Expand Down
8 changes: 6 additions & 2 deletions controllers/submariner/gateway_resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,8 @@ func newGatewayPodTemplate(cr *v1alpha1.Submariner, name string, podSelectorLabe
Ports: []corev1.ContainerPort{
{
Name: encapsPortName,
HostPort: int32(cr.Spec.CeIPSecNATTPort),
ContainerPort: int32(cr.Spec.CeIPSecNATTPort),
HostPort: toInt32(cr.Spec.CeIPSecNATTPort),
ContainerPort: toInt32(cr.Spec.CeIPSecNATTPort),
Protocol: corev1.ProtocolUDP,
},
{
Expand Down Expand Up @@ -325,3 +325,7 @@ func (r *Reconciler) retrieveGateways(ctx context.Context, owner metav1.Object,

return foundGateways.Items, nil
}

func toInt32(from int) int32 {
return int32(from) //nolint:gosec // Need to ignore reported integer overflow conversion
}
4 changes: 2 additions & 2 deletions controllers/submariner/loadbalancer_resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ func newLoadBalancerService(instance *v1alpha1.Submariner, platformTypeOCP strin
Ports: []corev1.ServicePort{
{
Name: encapsPortName,
Port: int32(instance.Spec.CeIPSecNATTPort),
TargetPort: intstr.IntOrString{Type: intstr.Int, IntVal: int32(instance.Spec.CeIPSecNATTPort)},
Port: toInt32(instance.Spec.CeIPSecNATTPort),
TargetPort: intstr.IntOrString{Type: intstr.Int, IntVal: toInt32(instance.Spec.CeIPSecNATTPort)},
Protocol: corev1.ProtocolUDP,
},
{
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.22.0
require (
github.com/coreos/go-semver v0.3.1
github.com/go-logr/logr v1.4.2
github.com/onsi/ginkgo/v2 v2.20.0
github.com/onsi/ginkgo/v2 v2.20.1
github.com/onsi/gomega v1.34.1
github.com/openshift/api v0.0.0-20230714214528-de6ad7979b00
github.com/operator-framework/operator-lib v0.14.0
Expand All @@ -14,7 +14,7 @@ require (
github.com/prometheus-operator/prometheus-operator/pkg/client v0.76.0
github.com/prometheus/client_golang v1.19.1
github.com/submariner-io/admiral v0.19.0-m2.0.20240820215844-1487e5c4b941
github.com/submariner-io/shipyard v0.19.0-m2
github.com/submariner-io/shipyard v0.19.0-m2.0.20240828133900-3d3c2316f606
github.com/submariner-io/submariner v0.19.0-m2
golang.org/x/net v0.28.0
golang.org/x/text v0.17.0
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -303,8 +303,8 @@ github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+W
github.com/onsi/ginkgo v1.11.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk=
github.com/onsi/ginkgo v1.14.0/go.mod h1:iSB4RoI2tjJc9BBv4NKIKWKya62Rps+oPG/Lv9klQyY=
github.com/onsi/ginkgo/v2 v2.20.0 h1:PE84V2mHqoT1sglvHc8ZdQtPcwmvvt29WLEEO3xmdZw=
github.com/onsi/ginkgo/v2 v2.20.0/go.mod h1:lG9ey2Z29hR41WMVthyJBGUBcBhGOtoPF2VFMvBXFCI=
github.com/onsi/ginkgo/v2 v2.20.1 h1:YlVIbqct+ZmnEph770q9Q7NVAz4wwIiVNahee6JyUzo=
github.com/onsi/ginkgo/v2 v2.20.1/go.mod h1:lG9ey2Z29hR41WMVthyJBGUBcBhGOtoPF2VFMvBXFCI=
github.com/onsi/gomega v0.0.0-20170829124025-dcabb60a477c/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA=
github.com/onsi/gomega v1.7.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY=
Expand Down Expand Up @@ -393,8 +393,8 @@ github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsT
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/submariner-io/admiral v0.19.0-m2.0.20240820215844-1487e5c4b941 h1:E504VAAKuggnzhTGOFr3X5/beHOKLYS3tqJIIffRpbg=
github.com/submariner-io/admiral v0.19.0-m2.0.20240820215844-1487e5c4b941/go.mod h1:f4xzFML4SRqETWcyZ32iTy8DH0gLUt2+jrYu6VGXL4Q=
github.com/submariner-io/shipyard v0.19.0-m2 h1:vOVbz4p+391s6H9lO6JL4t+gNoRdhmbESbx2vzmcGQg=
github.com/submariner-io/shipyard v0.19.0-m2/go.mod h1:91eQ4sF5XgbJxJUrXvY7u33gGGjaz5ofjLYaZyYXEls=
github.com/submariner-io/shipyard v0.19.0-m2.0.20240828133900-3d3c2316f606 h1:0C59+84WEc0n8yuFCL4xNKmDhAZ5o/cGLiIzZy1It/s=
github.com/submariner-io/shipyard v0.19.0-m2.0.20240828133900-3d3c2316f606/go.mod h1:Ith3HTqWhsEMmq26xw66OFYlGWO0p9Id86Cw0MIFbqQ=
github.com/submariner-io/submariner v0.19.0-m2 h1:qCNV17T55gIYtgDyMGJevrmUlr+nO4YA5GIlnkJTzLg=
github.com/submariner-io/submariner v0.19.0-m2/go.mod h1:+agj3FglAMfAzOM0d4c/ZTjwBIdvFJjJedMlwJxHboc=
github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
Expand Down
22 changes: 11 additions & 11 deletions pkg/discovery/globalnet/globalnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ type GlobalCIDR struct {
type CIDR struct {
network *net.IPNet
size int
lastIP uint
lastIP uint32
}

type Config struct {
Expand Down Expand Up @@ -99,16 +99,16 @@ func NewCIDR(cidr string) (CIDR, error) {
return clusterCidr, nil
}

func LastIP(network *net.IPNet) uint {
func LastIP(network *net.IPNet) uint32 {
ones, total := network.Mask.Size()
clusterSize := uint(total - ones)
clusterSize := total - ones
firstIPInt := ipToUint(network.IP)
lastIPUint := firstIPInt + 1<<clusterSize - 1

return lastIPUint
}

func allocateByCidr(cidr string, globalCidr *GlobalCIDR) (uint, error) {
func allocateByCidr(cidr string, globalCidr *GlobalCIDR) (uint32, error) {
requestedIP, requestedNetwork, err := net.ParseCIDR(cidr)
if err != nil || !globalCidr.net.Contains(requestedIP) {
return 0, fmt.Errorf("%s not a valid subnet of %v", cidr, globalCidr.net)
Expand Down Expand Up @@ -197,18 +197,18 @@ func AllocateGlobalCIDR(globalnetInfo *Info) (string, error) {
return allocateByClusterSize(globalnetInfo.ClusterSize, globalCidr)
}

func ipToUint(ip net.IP) uint {
func ipToUint(ip net.IP) uint32 {
intIP := ip
if len(ip) == 16 {
intIP = ip[12:16]
}

return uint(binary.BigEndian.Uint32(intIP))
return binary.BigEndian.Uint32(intIP)
}

func uintToIP(ip uint) net.IP {
func uintToIP(ip uint32) net.IP {
netIP := make(net.IP, 4)
binary.BigEndian.PutUint32(netIP, uint32(ip))
binary.BigEndian.PutUint32(netIP, ip)

return netIP
}
Expand All @@ -222,7 +222,7 @@ func GetValidClusterSize(cidrRange string, clusterSize uint) (uint, error) {
ones, totalbits := network.Mask.Size()
availableSize := 1 << uint(totalbits-ones)
userClusterSize := clusterSize
clusterSize = nextPowerOf2(uint32(clusterSize))
clusterSize = nextPowerOf2(clusterSize)

if clusterSize > uint(availableSize/2) {
return 0, fmt.Errorf("cluster size %d, should be <= %d", userClusterSize, availableSize/2)
Expand All @@ -236,7 +236,7 @@ func GetValidClusterSize(cidrRange string, clusterSize uint) (uint, error) {
}

// Refer: https://graphics.stanford.edu/~seander/bithacks.html#RoundUpPowerOf2
func nextPowerOf2(n uint32) uint {
func nextPowerOf2(n uint) uint {
n--
n |= n >> 1
n |= n >> 2
Expand All @@ -245,7 +245,7 @@ func nextPowerOf2(n uint32) uint {
n |= n >> 16
n++

return uint(n)
return n
}

func CheckOverlappingCidrs(globalnetInfo *Info, netconfig Config) error {
Expand Down
Loading