@@ -10,7 +10,7 @@ import (
1010 "strings"
1111 "sync"
1212
13- openv1alpha1 "github.com/openmcp-project/openmcp-operator/api/clusters/v1alpha1"
13+ clustersv1alpha1 "github.com/openmcp-project/openmcp-operator/api/clusters/v1alpha1"
1414
1515 "sigs.k8s.io/controller-runtime/pkg/client"
1616)
2727 errNoSubnetsAvailable = errors .New ("no subnets available" )
2828 errInvalidIP = errors .New ("invalid textual representation of an IP address" )
2929
30- AnnotationAssignedSubnet = openv1alpha1 .GroupVersion .Group + "/assigned-subnet"
30+ // AnnotationAssignedSubnet is the annotation used to store the assigned subnet for a cluster
31+ AnnotationAssignedSubnet = clustersv1alpha1 .GroupVersion .Group + "/assigned-subnet"
3132 lockListClusters = sync.Mutex {}
3233)
3334
@@ -46,6 +47,7 @@ func getDockerContainerIP(containerName string) (net.IP, error) {
4647 return parsed , nil
4748}
4849
50+ // GetDockerV4Network retrieves the IPv4 network configuration of the Docker network named "kind".
4951func GetDockerV4Network (ctx context.Context ) (net.IPNet , error ) {
5052 cmd := exec .CommandContext (ctx , "docker" , "network" , "inspect" , "-f" , "json" , networkName )
5153 cmdOut , err := cmd .Output ()
@@ -80,6 +82,7 @@ func isIPv4(ipNet *net.IPNet) bool {
8082 return ipNet .IP .To4 () != nil
8183}
8284
85+ // NextAvailableLBNetwork finds the next available subnet for MetalLB in the Docker network.
8386func NextAvailableLBNetwork (ctx context.Context , c client.Client ) (net.IPNet , error ) {
8487 lockListClusters .Lock ()
8588 defer lockListClusters .Unlock ()
@@ -89,7 +92,7 @@ func NextAvailableLBNetwork(ctx context.Context, c client.Client) (net.IPNet, er
8992 return net.IPNet {}, err
9093 }
9194
92- clusters := & openv1alpha1 .ClusterList {}
95+ clusters := & clustersv1alpha1 .ClusterList {}
9396 if err := c .List (ctx , clusters ); err != nil {
9497 return net.IPNet {}, err
9598 }
@@ -100,7 +103,7 @@ func NextAvailableLBNetwork(ctx context.Context, c client.Client) (net.IPNet, er
100103 return net.IPNet {}, err
101104 }
102105
103- taken , err := isIpNetTaken (subnet , clusters )
106+ taken , err := isIPNetTaken (subnet , clusters )
104107 if err != nil {
105108 return net.IPNet {}, err
106109 }
@@ -119,6 +122,7 @@ func calculateV4Subnet(input net.IPNet, offset int) (net.IPNet, error) {
119122 ones , bits := input .Mask .Size ()
120123
121124 // Subnet mask should be either 8 or 16 out of 32
125+ // nolint:staticcheck
122126 if ! (ones == 8 || ones == 16 ) || bits != 32 {
123127 return net.IPNet {}, errUnsupportedNetwork
124128 }
@@ -132,7 +136,7 @@ func calculateV4Subnet(input net.IPNet, offset int) (net.IPNet, error) {
132136 }, nil
133137}
134138
135- func isIpNetTaken (ipnet net.IPNet , clusters * openv1alpha1 .ClusterList ) (bool , error ) {
139+ func isIPNetTaken (ipnet net.IPNet , clusters * clustersv1alpha1 .ClusterList ) (bool , error ) {
136140 for _ , c := range clusters .Items {
137141 cNet , err := SubnetFromCluster (& c )
138142 if err != nil {
@@ -148,7 +152,8 @@ func isIpNetTaken(ipnet net.IPNet, clusters *openv1alpha1.ClusterList) (bool, er
148152 return false , nil
149153}
150154
151- func SubnetFromCluster (c * openv1alpha1.Cluster ) (* net.IPNet , error ) {
155+ // SubnetFromCluster extracts the assigned subnet from the cluster annotations.
156+ func SubnetFromCluster (c * clustersv1alpha1.Cluster ) (* net.IPNet , error ) {
152157 ipNetStr , ok := c .Annotations [AnnotationAssignedSubnet ]
153158 if ! ok {
154159 return nil , nil
0 commit comments