From 3ff9e5a69e0acef886bfcf8ff7ec11cc00488e09 Mon Sep 17 00:00:00 2001 From: Stefan Majer Date: Mon, 4 Nov 2024 13:20:41 +0100 Subject: [PATCH] Fix regression that IPs are not placed in correct IP pool (#105) --- go.mod | 32 +- go.sum | 82 +++--- main.go | 15 +- pkg/controllers/housekeeping/housekeeper.go | 2 +- pkg/controllers/housekeeping/tags.go | 3 +- .../loadbalancer/config/addresspool.go | 22 +- .../loadbalancer/config/addresspool_test.go | 14 +- .../loadbalancer/config/cilium_config_test.go | 20 +- pkg/controllers/loadbalancer/config/config.go | 5 +- .../loadbalancer/config/metallb_config.go | 16 +- .../config/metallb_config_test.go | 273 +++++++++++++++--- 11 files changed, 344 insertions(+), 140 deletions(-) diff --git a/go.mod b/go.mod index 1bc8c40..2726897 100644 --- a/go.mod +++ b/go.mod @@ -12,11 +12,11 @@ require ( github.com/metal-stack/v v1.0.3 github.com/spf13/pflag v1.0.5 go.universe.tf/metallb v0.14.8 - k8s.io/api v0.30.2 - k8s.io/apimachinery v0.31.0 - k8s.io/client-go v0.30.2 - k8s.io/cloud-provider v0.29.3 - k8s.io/component-base v0.30.2 + k8s.io/api v0.31.2 + k8s.io/apimachinery v0.31.2 + k8s.io/client-go v0.31.2 + k8s.io/cloud-provider v0.31.2 + k8s.io/component-base v0.31.2 k8s.io/klog/v2 v2.130.1 sigs.k8s.io/controller-runtime v0.18.4 ) @@ -24,7 +24,7 @@ require ( require ( github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 // indirect github.com/NYTimes/gziphandler v1.1.1 // indirect - github.com/antlr/antlr4/runtime/Go/antlr/v4 v4.0.0-20230305170008-8188dc5388df // indirect + github.com/antlr4-go/antlr/v4 v4.13.0 // indirect github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 // indirect github.com/beorn7/perks v1.0.1 // indirect github.com/blang/semver/v4 v4.0.0 // indirect @@ -38,7 +38,6 @@ require ( github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 // indirect github.com/emicklei/go-restful/v3 v3.12.1 // indirect - github.com/evanphx/json-patch v5.7.0+incompatible // indirect github.com/evanphx/json-patch/v5 v5.9.0 // indirect github.com/felixge/httpsnoop v1.0.4 // indirect github.com/fsnotify/fsnotify v1.7.0 // indirect @@ -62,7 +61,7 @@ require ( github.com/golang-jwt/jwt/v4 v4.5.0 // indirect github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect github.com/golang/protobuf v1.5.4 // indirect - github.com/google/cel-go v0.17.8 // indirect + github.com/google/cel-go v0.20.1 // indirect github.com/google/gnostic-models v0.6.8 // indirect github.com/google/gofuzz v1.2.0 // indirect github.com/google/gopacket v1.1.19 // indirect @@ -125,9 +124,9 @@ require ( github.com/vishvananda/netns v0.0.4 // indirect github.com/x448/float16 v0.8.4 // indirect github.com/yusufpapurcu/wmi v1.2.3 // indirect - go.etcd.io/etcd/api/v3 v3.5.12 // indirect - go.etcd.io/etcd/client/pkg/v3 v3.5.12 // indirect - go.etcd.io/etcd/client/v3 v3.5.12 // indirect + go.etcd.io/etcd/api/v3 v3.5.14 // indirect + go.etcd.io/etcd/client/pkg/v3 v3.5.14 // indirect + go.etcd.io/etcd/client/v3 v3.5.14 // indirect go.mongodb.org/mongo-driver v1.16.0 // indirect go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.56.0 // indirect go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.56.0 // indirect @@ -156,18 +155,19 @@ require ( google.golang.org/genproto/googleapis/rpc v0.0.0-20241015192408-796eee8c2d53 // indirect google.golang.org/grpc v1.67.1 // indirect google.golang.org/protobuf v1.35.1 // indirect + gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect gopkg.in/inf.v0 v0.9.1 // indirect gopkg.in/ini.v1 v1.67.0 // indirect gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect - k8s.io/apiserver v0.30.1 // indirect - k8s.io/component-helpers v0.29.3 // indirect - k8s.io/controller-manager v0.29.3 // indirect - k8s.io/kms v0.30.1 // indirect + k8s.io/apiserver v0.31.2 // indirect + k8s.io/component-helpers v0.31.2 // indirect + k8s.io/controller-manager v0.31.2 // indirect + k8s.io/kms v0.31.2 // indirect k8s.io/kube-openapi v0.0.0-20240521193020-835d969ad83a // indirect k8s.io/utils v0.0.0-20240711033017-18e509b52bc8 // indirect - sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.29.0 // indirect + sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.30.3 // indirect sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect sigs.k8s.io/yaml v1.4.0 // indirect diff --git a/go.sum b/go.sum index a5d3e8e..2d949ab 100644 --- a/go.sum +++ b/go.sum @@ -6,8 +6,8 @@ github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 h1:L/gRVlceqvL25 github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E= github.com/NYTimes/gziphandler v1.1.1 h1:ZUDjpQae29j0ryrS0u/B8HZfJBtBQHjqw2rQ2cqUQ3I= github.com/NYTimes/gziphandler v1.1.1/go.mod h1:n/CVRwUEOgIxrgPvAQhUUr9oeUtvrhMomdKFjzJNB0c= -github.com/antlr/antlr4/runtime/Go/antlr/v4 v4.0.0-20230305170008-8188dc5388df h1:7RFfzj4SSt6nnvCPbCqijJi1nWCd+TqAT3bYCStRC18= -github.com/antlr/antlr4/runtime/Go/antlr/v4 v4.0.0-20230305170008-8188dc5388df/go.mod h1:pSwJ0fSY5KhvocuWSx4fz3BA8OrA1bQn+K1Eli3BRwM= +github.com/antlr4-go/antlr/v4 v4.13.0 h1:lxCg3LAv+EUK6t1i0y1V6/SLeUi0eKEKdhQAlS8TVTI= +github.com/antlr4-go/antlr/v4 v4.13.0/go.mod h1:pfChB/xh/Unjila75QW7+VU4TSnWnnk9UTnmpPaOR2g= github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 h1:DklsrG3dyBCFEj5IhUbnKptjxatkF07cF2ak3yi77so= github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2/go.mod h1:WaHUgvxTVq04UNunO+XhnAqY/wQc+bxr74GqbsZ/Jqw= github.com/avast/retry-go/v4 v4.6.0 h1:K9xNA+KeB8HHc2aWFuLb25Offp+0iVRXEvFx8IinRJA= @@ -114,8 +114,8 @@ github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps= github.com/google/btree v1.1.2 h1:xf4v41cLI2Z6FxbKm+8Bu+m8ifhj15JuZ9sa0jZCMUU= github.com/google/btree v1.1.2/go.mod h1:qOPhT0dTNdNzV6Z/lhRX0YXUafgPLFUh+gZMl761Gm4= -github.com/google/cel-go v0.17.8 h1:j9m730pMZt1Fc4oKhCLUHfjj6527LuhYcYw0Rl8gqto= -github.com/google/cel-go v0.17.8/go.mod h1:HXZKzB0LXqer5lHHgfWAnlYwJaQBDKMjxjulNQzhwhY= +github.com/google/cel-go v0.20.1 h1:nDx9r8S3L4pE61eDdt8igGj8rf5kjYR3ILxWIpWNi84= +github.com/google/cel-go v0.20.1/go.mod h1:kWcIzTsPX0zmQ+H3TirHstLLf9ep5QTsZBN9u4dOYLg= github.com/google/gnostic-models v0.6.8 h1:yo/ABAfM5IMRsS1VnXjTBvUb61tFIHozhlYvRgGre9I= github.com/google/gnostic-models v0.6.8/go.mod h1:5n7qKqH0f5wFt+aWF8CW6pZLLNOfYuF5OpfBSENuI8U= github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= @@ -306,22 +306,22 @@ github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9de github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yusufpapurcu/wmi v1.2.3 h1:E1ctvB7uKFMOJw3fdOW32DwGE9I7t++CRUEMKvFoFiw= github.com/yusufpapurcu/wmi v1.2.3/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0= -go.etcd.io/bbolt v1.3.8 h1:xs88BrvEv273UsB79e0hcVrlUWmS0a8upikMFhSyAtA= -go.etcd.io/bbolt v1.3.8/go.mod h1:N9Mkw9X8x5fupy0IKsmuqVtoGDyxsaDlbk4Rd05IAQw= -go.etcd.io/etcd/api/v3 v3.5.12 h1:W4sw5ZoU2Juc9gBWuLk5U6fHfNVyY1WC5g9uiXZio/c= -go.etcd.io/etcd/api/v3 v3.5.12/go.mod h1:Ot+o0SWSyT6uHhA56al1oCED0JImsRiU9Dc26+C2a+4= -go.etcd.io/etcd/client/pkg/v3 v3.5.12 h1:EYDL6pWwyOsylrQyLp2w+HkQ46ATiOvoEdMarindU2A= -go.etcd.io/etcd/client/pkg/v3 v3.5.12/go.mod h1:seTzl2d9APP8R5Y2hFL3NVlD6qC/dOT+3kvrqPyTas4= -go.etcd.io/etcd/client/v2 v2.305.12 h1:0m4ovXYo1CHaA/Mp3X/Fak5sRNIWf01wk/X1/G3sGKI= -go.etcd.io/etcd/client/v2 v2.305.12/go.mod h1:aQ/yhsxMu+Oht1FOupSr60oBvcS9cKXHrzBpDsPTf9E= -go.etcd.io/etcd/client/v3 v3.5.12 h1:v5lCPXn1pf1Uu3M4laUE2hp/geOTc5uPcYYsNe1lDxg= -go.etcd.io/etcd/client/v3 v3.5.12/go.mod h1:tSbBCakoWmmddL+BKVAJHa9km+O/E+bumDe9mSbPiqw= -go.etcd.io/etcd/pkg/v3 v3.5.10 h1:WPR8K0e9kWl1gAhB5A7gEa5ZBTNkT9NdNWrR8Qpo1CM= -go.etcd.io/etcd/pkg/v3 v3.5.10/go.mod h1:TKTuCKKcF1zxmfKWDkfz5qqYaE3JncKKZPFf8c1nFUs= -go.etcd.io/etcd/raft/v3 v3.5.10 h1:cgNAYe7xrsrn/5kXMSaH8kM/Ky8mAdMqGOxyYwpP0LA= -go.etcd.io/etcd/raft/v3 v3.5.10/go.mod h1:odD6kr8XQXTy9oQnyMPBOr0TVe+gT0neQhElQ6jbGRc= -go.etcd.io/etcd/server/v3 v3.5.10 h1:4NOGyOwD5sUZ22PiWYKmfxqoeh72z6EhYjNosKGLmZg= -go.etcd.io/etcd/server/v3 v3.5.10/go.mod h1:gBplPHfs6YI0L+RpGkTQO7buDbHv5HJGG/Bst0/zIPo= +go.etcd.io/bbolt v1.3.9 h1:8x7aARPEXiXbHmtUwAIv7eV2fQFHrLLavdiJ3uzJXoI= +go.etcd.io/bbolt v1.3.9/go.mod h1:zaO32+Ti0PK1ivdPtgMESzuzL2VPoIG1PCQNvOdo/dE= +go.etcd.io/etcd/api/v3 v3.5.14 h1:vHObSCxyB9zlF60w7qzAdTcGaglbJOpSj1Xj9+WGxq0= +go.etcd.io/etcd/api/v3 v3.5.14/go.mod h1:BmtWcRlQvwa1h3G2jvKYwIQy4PkHlDej5t7uLMUdJUU= +go.etcd.io/etcd/client/pkg/v3 v3.5.14 h1:SaNH6Y+rVEdxfpA2Jr5wkEvN6Zykme5+YnbCkxvuWxQ= +go.etcd.io/etcd/client/pkg/v3 v3.5.14/go.mod h1:8uMgAokyG1czCtIdsq+AGyYQMvpIKnSvPjFMunkgeZI= +go.etcd.io/etcd/client/v2 v2.305.13 h1:RWfV1SX5jTU0lbCvpVQe3iPQeAHETWdOTb6pxhd77C8= +go.etcd.io/etcd/client/v2 v2.305.13/go.mod h1:iQnL7fepbiomdXMb3om1rHq96htNNGv2sJkEcZGDRRg= +go.etcd.io/etcd/client/v3 v3.5.14 h1:CWfRs4FDaDoSz81giL7zPpZH2Z35tbOrAJkkjMqOupg= +go.etcd.io/etcd/client/v3 v3.5.14/go.mod h1:k3XfdV/VIHy/97rqWjoUzrj9tk7GgJGH9J8L4dNXmAk= +go.etcd.io/etcd/pkg/v3 v3.5.13 h1:st9bDWNsKkBNpP4PR1MvM/9NqUPfvYZx/YXegsYEH8M= +go.etcd.io/etcd/pkg/v3 v3.5.13/go.mod h1:N+4PLrp7agI/Viy+dUYpX7iRtSPvKq+w8Y14d1vX+m0= +go.etcd.io/etcd/raft/v3 v3.5.13 h1:7r/NKAOups1YnKcfro2RvGGo2PTuizF/xh26Z2CTAzA= +go.etcd.io/etcd/raft/v3 v3.5.13/go.mod h1:uUFibGLn2Ksm2URMxN1fICGhk8Wu96EfDQyuLhAcAmw= +go.etcd.io/etcd/server/v3 v3.5.13 h1:V6KG+yMfMSqWt+lGnhFpP5z5dRUj1BDRJ5k1fQ9DFok= +go.etcd.io/etcd/server/v3 v3.5.13/go.mod h1:K/8nbsGupHqmr5MkgaZpLlH1QdX1pcNQLAkODy44XcQ= go.mongodb.org/mongo-driver v1.16.0 h1:tpRsfBJMROVHKpdGyc1BBEzzjDUWjItxbVSZ8Ls4BQ4= go.mongodb.org/mongo-driver v1.16.0/go.mod h1:oB6AhJQvFQL4LEHyXi6aJzQJtBiTQHiAd83l0GdFaiw= go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.56.0 h1:yMkBS9yViCc7U7yeLzJPM2XizlfdVvBRSmsQDWu6qc0= @@ -425,6 +425,8 @@ google.golang.org/protobuf v1.35.1/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojt gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= +gopkg.in/evanphx/json-patch.v4 v4.12.0 h1:n6jtcsulIzXPJaxegRbvFNNrZDjbij7ny3gmSPG+6V4= +gopkg.in/evanphx/json-patch.v4 v4.12.0/go.mod h1:p8EYWUEYMpynmqDbY58zCKCFZw8pRWMG4EsWvDvM72M= gopkg.in/inf.v0 v0.9.1 h1:73M5CoZyi3ZLMOyDlQh031Cx6N9NDJ2Vvfl76EDAgDc= gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw= gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA= @@ -437,34 +439,34 @@ gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -k8s.io/api v0.30.2 h1:+ZhRj+28QT4UOH+BKznu4CBgPWgkXO7XAvMcMl0qKvI= -k8s.io/api v0.30.2/go.mod h1:ULg5g9JvOev2dG0u2hig4Z7tQ2hHIuS+m8MNZ+X6EmI= +k8s.io/api v0.31.2 h1:3wLBbL5Uom/8Zy98GRPXpJ254nEFpl+hwndmk9RwmL0= +k8s.io/api v0.31.2/go.mod h1:bWmGvrGPssSK1ljmLzd3pwCQ9MgoTsRCuK35u6SygUk= k8s.io/apiextensions-apiserver v0.30.2 h1:l7Eue2t6QiLHErfn2vwK4KgF4NeDgjQkCXtEbOocKIE= k8s.io/apiextensions-apiserver v0.30.2/go.mod h1:lsJFLYyK40iguuinsb3nt+Sj6CmodSI4ACDLep1rgjw= -k8s.io/apimachinery v0.31.0 h1:m9jOiSr3FoSSL5WO9bjm1n6B9KROYYgNZOb4tyZ1lBc= -k8s.io/apimachinery v0.31.0/go.mod h1:rsPdaZJfTfLsNJSQzNHQvYoTmxhoOEofxtOsF3rtsMo= -k8s.io/apiserver v0.30.1 h1:BEWEe8bzS12nMtDKXzCF5Q5ovp6LjjYkSp8qOPk8LZ8= -k8s.io/apiserver v0.30.1/go.mod h1:i87ZnQ+/PGAmSbD/iEKM68bm1D5reX8fO4Ito4B01mo= -k8s.io/client-go v0.30.2 h1:sBIVJdojUNPDU/jObC+18tXWcTJVcwyqS9diGdWHk50= -k8s.io/client-go v0.30.2/go.mod h1:JglKSWULm9xlJLx4KCkfLLQ7XwtlbflV6uFFSHTMgVs= -k8s.io/cloud-provider v0.29.3 h1:y39hNq0lrPD1qmqQ2ykwMJGeWF9LsepVkR2a4wskwLc= -k8s.io/cloud-provider v0.29.3/go.mod h1:daDV1WkAO6pTrdsn7v8TpN/q9n75ExUC4RJDl7vlPKk= -k8s.io/component-base v0.30.2 h1:pqGBczYoW1sno8q9ObExUqrYSKhtE5rW3y6gX88GZII= -k8s.io/component-base v0.30.2/go.mod h1:yQLkQDrkK8J6NtP+MGJOws+/PPeEXNpwFixsUI7h/OE= -k8s.io/component-helpers v0.29.3 h1:1dqZswuZgT2ZMixYeORyCUOAApXxgsvjVSgfoUT+P4o= -k8s.io/component-helpers v0.29.3/go.mod h1:yiDqbRQrnQY+sPju/bL7EkwDJb6LVOots53uZNMZBos= -k8s.io/controller-manager v0.29.3 h1:pvm3mirypgW7kM6dHRk6O5ANZj4bZTWirfk5gO6RlCo= -k8s.io/controller-manager v0.29.3/go.mod h1:RNxpf0d1WAo59sOLd32isWJP0oZ7Zxr+q4VEEaSq4gk= +k8s.io/apimachinery v0.31.2 h1:i4vUt2hPK56W6mlT7Ry+AO8eEsyxMD1U44NR22CLTYw= +k8s.io/apimachinery v0.31.2/go.mod h1:rsPdaZJfTfLsNJSQzNHQvYoTmxhoOEofxtOsF3rtsMo= +k8s.io/apiserver v0.31.2 h1:VUzOEUGRCDi6kX1OyQ801m4A7AUPglpsmGvdsekmcI4= +k8s.io/apiserver v0.31.2/go.mod h1:o3nKZR7lPlJqkU5I3Ove+Zx3JuoFjQobGX1Gctw6XuE= +k8s.io/client-go v0.31.2 h1:Y2F4dxU5d3AQj+ybwSMqQnpZH9F30//1ObxOKlTI9yc= +k8s.io/client-go v0.31.2/go.mod h1:NPa74jSVR/+eez2dFsEIHNa+3o09vtNaWwWwb1qSxSs= +k8s.io/cloud-provider v0.31.2 h1:ZdstxJOcHzP45j8giE79VJmgNckBbw1ldtIqnhZvKIA= +k8s.io/cloud-provider v0.31.2/go.mod h1:+4L8YpYCEx1Ko5EKS/PzXyBY5YREwDKChsJjAxHRf08= +k8s.io/component-base v0.31.2 h1:Z1J1LIaC0AV+nzcPRFqfK09af6bZ4D1nAOpWsy9owlA= +k8s.io/component-base v0.31.2/go.mod h1:9PeyyFN/drHjtJZMCTkSpQJS3U9OXORnHQqMLDz0sUQ= +k8s.io/component-helpers v0.31.2 h1:V2yjoNeyg8WfvwrJwzfYz+RUwjlbcAIaDaHEStBbaZM= +k8s.io/component-helpers v0.31.2/go.mod h1:cNz+1ck38R0qWrjcw/rhQgGP6+Gwgw8ngr2ziDNmSXM= +k8s.io/controller-manager v0.31.2 h1:S5FPrZo6wpcTwQHfwcklOkr3MKGvKYtroOtCqri67Ns= +k8s.io/controller-manager v0.31.2/go.mod h1:+MymA0Dg2pC+hYYNsca9shRZbrkK3HKIg2B11p6eC+Q= k8s.io/klog/v2 v2.130.1 h1:n9Xl7H1Xvksem4KFG4PYbdQCQxqc/tTUyrgXaOhHSzk= k8s.io/klog/v2 v2.130.1/go.mod h1:3Jpz1GvMt720eyJH1ckRHK1EDfpxISzJ7I9OYgaDtPE= -k8s.io/kms v0.30.1 h1:gEIbEeCbFiaN2tNfp/EUhFdGr5/CSj8Eyq6Mkr7cCiY= -k8s.io/kms v0.30.1/go.mod h1:GrMurD0qk3G4yNgGcsCEmepqf9KyyIrTXYR2lyUOJC4= +k8s.io/kms v0.31.2 h1:pyx7l2qVOkClzFMIWMVF/FxsSkgd+OIGH7DecpbscJI= +k8s.io/kms v0.31.2/go.mod h1:OZKwl1fan3n3N5FFxnW5C4V3ygrah/3YXeJWS3O6+94= k8s.io/kube-openapi v0.0.0-20240521193020-835d969ad83a h1:zD1uj3Jf+mD4zmA7W+goE5TxDkI7OGJjBNBzq5fJtLA= k8s.io/kube-openapi v0.0.0-20240521193020-835d969ad83a/go.mod h1:UxDHUPsUwTOOxSU+oXURfFBcAS6JwiRXTYqYwfuGowc= k8s.io/utils v0.0.0-20240711033017-18e509b52bc8 h1:pUdcCO1Lk/tbT5ztQWOBi5HBgbBP1J8+AsQnQCKsi8A= k8s.io/utils v0.0.0-20240711033017-18e509b52bc8/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0= -sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.29.0 h1:/U5vjBbQn3RChhv7P11uhYvCSm5G2GaIi5AIGBS6r4c= -sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.29.0/go.mod h1:z7+wmGM2dfIiLRfrC6jb5kV2Mq/sK1ZP303cxzkV5Y4= +sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.30.3 h1:2770sDpzrjjsAtVhSeUFseziht227YAWYHLGNM8QPwY= +sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.30.3/go.mod h1:Ve9uj1L+deCXFrPOk1LpFXqTg7LCFzFso6PA48q/XZw= sigs.k8s.io/controller-runtime v0.18.4 h1:87+guW1zhvuPLh1PHybKdYFLU0YJp4FhJRmiHvm5BZw= sigs.k8s.io/controller-runtime v0.18.4/go.mod h1:TVoGrfdpbA9VRFaRnKgk9P5/atA0pMwq+f+msb9M8Sg= sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd h1:EDPBXCAspyGV4jQlpZSudPeMmr1bNJefnuqLsRAsHZo= diff --git a/main.go b/main.go index 727c83b..a5b1ee7 100644 --- a/main.go +++ b/main.go @@ -3,15 +3,20 @@ package main import ( "flag" "io" + "os" "k8s.io/apimachinery/pkg/util/wait" cloudprovider "k8s.io/cloud-provider" "k8s.io/cloud-provider/app" "k8s.io/cloud-provider/options" + "k8s.io/cloud-provider/names" + cloudcontrollerconfig "k8s.io/cloud-provider/app/config" + "k8s.io/component-base/cli" cliflag "k8s.io/component-base/cli/flag" + _ "k8s.io/component-base/metrics/prometheus/clientgo" // load all the prometheus client-go plugins _ "k8s.io/component-base/metrics/prometheus/version" // for version metric registration "k8s.io/klog/v2" @@ -30,9 +35,6 @@ func main() { opts.KubeCloudShared.CloudProvider.Name = constants.ProviderName controllerInitializers := app.DefaultInitFuncConstructors - // remove unneeded controllers, - // TODO add once we support the route interface - delete(controllerInitializers, "route") fss := cliflag.NamedFlagSets{ NormalizeNameFunc: cliflag.WordSepNormalizeFunc, } @@ -40,12 +42,11 @@ func main() { pflag.CommandLine.SetNormalizeFunc(cliflag.WordSepNormalizeFunc) pflag.CommandLine.AddGoFlagSet(flag.CommandLine) - command := app.NewCloudControllerManagerCommand(opts, cloudInitializer, controllerInitializers, nil, fss, wait.NeverStop) + command := app.NewCloudControllerManagerCommand(opts, cloudInitializer, controllerInitializers, names.CCMControllerAliases(), fss, wait.NeverStop) klog.Infof("starting version %s", v.V.String()) - if err := command.Execute(); err != nil { - klog.Fatalf("error: %v", err) - } + code := cli.Run(command) + os.Exit(code) } func cloudInitializer(config *cloudcontrollerconfig.CompletedConfig) cloudprovider.Interface { cloudConfig := config.ComponentConfig.KubeCloudShared.CloudProvider diff --git a/pkg/controllers/housekeeping/housekeeper.go b/pkg/controllers/housekeeping/housekeeper.go index 5e21f61..d7d03fa 100644 --- a/pkg/controllers/housekeeping/housekeeper.go +++ b/pkg/controllers/housekeeping/housekeeper.go @@ -57,7 +57,7 @@ func (h *Housekeeper) Run() { func (h *Housekeeper) watchNodes() { klog.Info("start watching nodes") watchlist := cache.NewListWatchFromClient(h.k8sClient.CoreV1().RESTClient(), "nodes", "", fields.Everything()) - _, controller := cache.NewInformer( + _, controller := cache.NewInformer( // nolint:staticcheck watchlist, &v1.Node{}, time.Second*0, diff --git a/pkg/controllers/housekeeping/tags.go b/pkg/controllers/housekeeping/tags.go index e31a189..39b9e02 100644 --- a/pkg/controllers/housekeeping/tags.go +++ b/pkg/controllers/housekeeping/tags.go @@ -11,7 +11,6 @@ import ( "k8s.io/klog/v2" "github.com/metal-stack/metal-ccm/pkg/resources/kubernetes" - "github.com/metal-stack/metal-lib/pkg/tag" metaltag "github.com/metal-stack/metal-lib/pkg/tag" ) @@ -62,7 +61,7 @@ func (h *Housekeeper) syncMachineTagsToNodeLabels() error { } // check if machine has a cluster tag, if not add it - if machineClusterTag, found := tag.NewTagMap(tags).Value(tag.ClusterID); !found || machineClusterTag != h.clusterID { + if machineClusterTag, found := metaltag.NewTagMap(tags).Value(metaltag.ClusterID); !found || machineClusterTag != h.clusterID { m, err := h.ms.GetMachineFromNode(context.Background(), &n) if err != nil { diff --git a/pkg/controllers/loadbalancer/config/addresspool.go b/pkg/controllers/loadbalancer/config/addresspool.go index 6e06800..001e309 100644 --- a/pkg/controllers/loadbalancer/config/addresspool.go +++ b/pkg/controllers/loadbalancer/config/addresspool.go @@ -22,7 +22,7 @@ type addressPool struct { CIDRs []string // It is assumed that only host addresses (/32 for ipv4 or /128 for ipv6) are used. } -type addressPools []addressPool +type addressPools map[string]addressPool func newBGPAddressPool(name string) addressPool { return addressPool{ @@ -55,22 +55,20 @@ func (pool *addressPool) appendIP(ip *models.V1IPResponse) error { return nil } -func (as addressPools) addPoolIP(poolName string, ip *models.V1IPResponse) (addressPools, error) { - idx := slices.IndexFunc(as, func(a addressPool) bool { - return a.Name == poolName - }) +func (as addressPools) addPoolIP(poolName string, ip *models.V1IPResponse) error { - if idx < 0 { - as = append(as, newBGPAddressPool(poolName)) - idx = 0 + pool, ok := as[poolName] + if !ok { + as[poolName] = newBGPAddressPool(poolName) + pool = as[poolName] } - err := as[idx].appendIP(ip) + err := pool.appendIP(ip) if err != nil { - return nil, err + return err } - - return as, nil + as[poolName] = pool + return nil } func getPoolName(network string, ip *models.V1IPResponse) string { diff --git a/pkg/controllers/loadbalancer/config/addresspool_test.go b/pkg/controllers/loadbalancer/config/addresspool_test.go index 833366c..8522ff5 100644 --- a/pkg/controllers/loadbalancer/config/addresspool_test.go +++ b/pkg/controllers/loadbalancer/config/addresspool_test.go @@ -86,7 +86,7 @@ func Test_addressPools_addPoolIP(t *testing.T) { }, existing: addressPools{}, want: addressPools{ - addressPool{ + "my-pool-static": addressPool{ Name: "my-pool-static", Protocol: bgpProtocol, AutoAssign: pointer.Pointer(false), @@ -102,13 +102,13 @@ func Test_addressPools_addPoolIP(t *testing.T) { Type: pointer.Pointer(models.V1IPResponseTypeStatic), }, existing: addressPools{ - addressPool{ + "my-pool-ephemeral": addressPool{ Name: "my-pool-ephemeral", Protocol: bgpProtocol, AutoAssign: pointer.Pointer(false), CIDRs: []string{"192.168.2.1/32"}, }, - addressPool{ + "my-pool-static": addressPool{ Name: "my-pool-static", Protocol: bgpProtocol, AutoAssign: pointer.Pointer(false), @@ -116,13 +116,13 @@ func Test_addressPools_addPoolIP(t *testing.T) { }, }, want: addressPools{ - addressPool{ + "my-pool-ephemeral": addressPool{ Name: "my-pool-ephemeral", Protocol: bgpProtocol, AutoAssign: pointer.Pointer(false), CIDRs: []string{"192.168.2.1/32"}, }, - addressPool{ + "my-pool-static": addressPool{ Name: "my-pool-static", Protocol: bgpProtocol, AutoAssign: pointer.Pointer(false), @@ -133,13 +133,13 @@ func Test_addressPools_addPoolIP(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - newPool, err := tt.existing.addPoolIP(tt.poolName, tt.ip) + err := tt.existing.addPoolIP(tt.poolName, tt.ip) if diff := cmp.Diff(err, tt.wantErr); diff != "" { t.Errorf("error = %v", diff) return } - if diff := cmp.Diff(newPool, tt.want); diff != "" { + if diff := cmp.Diff(tt.existing, tt.want); diff != "" { t.Errorf("diff = %v", diff) } }) diff --git a/pkg/controllers/loadbalancer/config/cilium_config_test.go b/pkg/controllers/loadbalancer/config/cilium_config_test.go index d89a34d..05ef3b1 100644 --- a/pkg/controllers/loadbalancer/config/cilium_config_test.go +++ b/pkg/controllers/loadbalancer/config/cilium_config_test.go @@ -42,7 +42,7 @@ func TestCiliumConfig(t *testing.T) { want: &ciliumConfig{ base: &baseConfig{ AddressPools: addressPools{ - { + "internet-ephemeral": { Name: "internet-ephemeral", Protocol: "bgp", AutoAssign: pointer.Pointer(false), @@ -85,7 +85,7 @@ func TestCiliumConfig(t *testing.T) { want: &ciliumConfig{ base: &baseConfig{ AddressPools: addressPools{ - { + "internet-ephemeral": { Name: "internet-ephemeral", Protocol: "bgp", AutoAssign: pointer.Pointer(false), @@ -139,7 +139,7 @@ func TestCiliumConfig(t *testing.T) { want: &ciliumConfig{ base: &baseConfig{ AddressPools: addressPools{ - { + "internet-ephemeral": { Name: "internet-ephemeral", Protocol: "bgp", AutoAssign: pointer.Pointer(false), @@ -148,7 +148,7 @@ func TestCiliumConfig(t *testing.T) { "84.1.1.2/32", }, }, - { + "internet-static": { Name: "internet-static", Protocol: "bgp", AutoAssign: pointer.Pointer(false), @@ -241,7 +241,7 @@ func TestCiliumConfig(t *testing.T) { want: &ciliumConfig{ base: &baseConfig{ AddressPools: addressPools{ - { + "internet-ephemeral": { Name: "internet-ephemeral", Protocol: "bgp", AutoAssign: pointer.Pointer(false), @@ -250,7 +250,7 @@ func TestCiliumConfig(t *testing.T) { "84.1.1.2/32", }, }, - { + "internet-static": { Name: "internet-static", Protocol: "bgp", AutoAssign: pointer.Pointer(false), @@ -258,7 +258,7 @@ func TestCiliumConfig(t *testing.T) { "84.1.1.3/32", }, }, - { + "shared-storage-network-static": { Name: "shared-storage-network-static", Protocol: "bgp", AutoAssign: pointer.Pointer(false), @@ -266,7 +266,7 @@ func TestCiliumConfig(t *testing.T) { "10.131.44.2/32", }, }, - { + "mpls-network-static": { Name: "mpls-network-static", Protocol: "bgp", AutoAssign: pointer.Pointer(false), @@ -274,7 +274,7 @@ func TestCiliumConfig(t *testing.T) { "100.127.130.2/32", }, }, - { + "mpls-network-ephemeral": { Name: "mpls-network-ephemeral", Protocol: "bgp", AutoAssign: pointer.Pointer(false), @@ -282,7 +282,7 @@ func TestCiliumConfig(t *testing.T) { "100.127.130.3/32", }, }, - { + "dmz-network-static": { Name: "dmz-network-static", Protocol: "bgp", AutoAssign: pointer.Pointer(false), diff --git a/pkg/controllers/loadbalancer/config/config.go b/pkg/controllers/loadbalancer/config/config.go index 136cff5..b176715 100644 --- a/pkg/controllers/loadbalancer/config/config.go +++ b/pkg/controllers/loadbalancer/config/config.go @@ -73,7 +73,7 @@ func newBaseConfig(ips []*models.V1IPResponse, nws sets.Set[string], nodes []v1. func computeAddressPools(ips []*models.V1IPResponse, nws sets.Set[string]) (addressPools, error) { var ( - pools addressPools + pools = addressPools{} errs []error ) @@ -92,8 +92,7 @@ func computeAddressPools(ips []*models.V1IPResponse, nws sets.Set[string]) (addr poolName = getPoolName(net, ip) ) - var err error - pools, err = pools.addPoolIP(poolName, ip) + err := pools.addPoolIP(poolName, ip) if err != nil { errs = append(errs, err) } diff --git a/pkg/controllers/loadbalancer/config/metallb_config.go b/pkg/controllers/loadbalancer/config/metallb_config.go index 7dfc8de..2512359 100644 --- a/pkg/controllers/loadbalancer/config/metallb_config.go +++ b/pkg/controllers/loadbalancer/config/metallb_config.go @@ -22,12 +22,12 @@ const ( ) type metalLBConfig struct { - base *baseConfig + Base *baseConfig client client.Client } func newMetalLBConfig(base *baseConfig, c client.Client) *metalLBConfig { - return &metalLBConfig{base: base, client: c} + return &metalLBConfig{Base: base, client: c} } func (m *metalLBConfig) WriteCRs(ctx context.Context) error { @@ -40,7 +40,7 @@ func (m *metalLBConfig) WriteCRs(ctx context.Context) error { existingPeer := existingPeer found := false - for _, peer := range m.base.Peers { + for _, peer := range m.Base.Peers { if fmt.Sprintf("peer-%d", peer.ASN) == existingPeer.Name { found = true break @@ -55,7 +55,7 @@ func (m *metalLBConfig) WriteCRs(ctx context.Context) error { } } - for _, peer := range m.base.Peers { + for _, peer := range m.Base.Peers { bgpPeer := &metallbv1beta2.BGPPeer{ TypeMeta: metav1.TypeMeta{ APIVersion: "metallb.io/v1beta2", @@ -94,7 +94,7 @@ func (m *metalLBConfig) WriteCRs(ctx context.Context) error { } for _, existingPool := range addressPoolList.Items { found := false - for _, pool := range m.base.AddressPools { + for _, pool := range m.Base.AddressPools { if pool.Name == existingPool.Name { found = true break @@ -108,7 +108,7 @@ func (m *metalLBConfig) WriteCRs(ctx context.Context) error { } } - for _, pool := range m.base.AddressPools { + for _, pool := range m.Base.AddressPools { ipAddressPool := &metallbv1beta1.IPAddressPool{ TypeMeta: metav1.TypeMeta{ APIVersion: "metallb.io/v1beta1", @@ -137,7 +137,7 @@ func (m *metalLBConfig) WriteCRs(ctx context.Context) error { } } - for _, pool := range m.base.AddressPools { + for _, pool := range m.Base.AddressPools { bgpAdvertisementList := metallbv1beta1.BGPAdvertisementList{} err = m.client.List(ctx, &bgpAdvertisementList, client.InNamespace(metallbNamespace)) if err != nil { @@ -147,7 +147,7 @@ func (m *metalLBConfig) WriteCRs(ctx context.Context) error { for _, existingAdvertisement := range bgpAdvertisementList.Items { existingAdvertisement := existingAdvertisement found := false - for _, pool := range m.base.AddressPools { + for _, pool := range m.Base.AddressPools { if pool.Name == existingAdvertisement.Name { found = true break diff --git a/pkg/controllers/loadbalancer/config/metallb_config_test.go b/pkg/controllers/loadbalancer/config/metallb_config_test.go index 99a2b6b..4525e4d 100644 --- a/pkg/controllers/loadbalancer/config/metallb_config_test.go +++ b/pkg/controllers/loadbalancer/config/metallb_config_test.go @@ -10,6 +10,7 @@ import ( "github.com/metal-stack/metal-lib/pkg/pointer" "github.com/metal-stack/metal-lib/pkg/tag" v1 "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/sets" ) @@ -24,13 +25,120 @@ var ( func TestMetalLBConfig(t *testing.T) { tests := []struct { - name string - nws sets.Set[string] - ips []*models.V1IPResponse - nodes []v1.Node - wantErr error - want *metalLBConfig + name string + nws sets.Set[string] + ips []*models.V1IPResponse + nodes []v1.Node + wantErrmessage *string + want *metalLBConfig }{ + { + name: "two ips, one with missing networkID acquired, no nodes", + nws: testNetworks, + ips: []*models.V1IPResponse{ + { + Ipaddress: pointer.Pointer("84.1.1.1"), + Name: "acquired-before", + Networkid: pointer.Pointer("internet"), + Projectid: pointer.Pointer("project-a"), + Tags: []string{ + fmt.Sprintf("%s=%s", tag.ClusterID, "this-cluster"), + }, + Type: pointer.Pointer("ephemeral"), + }, + { + Ipaddress: pointer.Pointer("84.1.1.2"), + Name: "acquired-before", + Networkid: nil, + Projectid: pointer.Pointer("project-a"), + Tags: []string{ + fmt.Sprintf("%s=%s", tag.ClusterID, "this-cluster"), + }, + Type: pointer.Pointer("ephemeral"), + }, + }, + nodes: []v1.Node{}, + wantErrmessage: pointer.Pointer("ip has no network id set: 84.1.1.2"), + want: nil, + }, + { + name: "two ips, one with missing IP acquired, no nodes", + nws: testNetworks, + ips: []*models.V1IPResponse{ + { + Ipaddress: pointer.Pointer("84.1.1.1"), + Name: "acquired-before", + Networkid: pointer.Pointer("internet"), + Projectid: pointer.Pointer("project-a"), + Tags: []string{ + fmt.Sprintf("%s=%s", tag.ClusterID, "this-cluster"), + }, + Type: pointer.Pointer("ephemeral"), + }, + { + Name: "acquired-before", + Networkid: pointer.Pointer("internet"), + Projectid: pointer.Pointer("project-a"), + Tags: []string{ + fmt.Sprintf("%s=%s", tag.ClusterID, "this-cluster"), + }, + Type: pointer.Pointer("ephemeral"), + }, + }, + nodes: []v1.Node{}, + wantErrmessage: pointer.Pointer("ip address is not set on ip"), + want: nil, + }, + { + name: "one malformed ip acquired, no nodes", + nws: testNetworks, + ips: []*models.V1IPResponse{ + { + Ipaddress: pointer.Pointer("84.1.1.1.1"), + Name: "acquired-before", + Networkid: pointer.Pointer("internet"), + Projectid: pointer.Pointer("project-a"), + Tags: []string{ + fmt.Sprintf("%s=%s", tag.ClusterID, "this-cluster"), + }, + Type: pointer.Pointer("ephemeral"), + }, + }, + nodes: []v1.Node{}, + wantErrmessage: pointer.Pointer("ParseAddr(\"84.1.1.1.1\"): IPv4 address too long"), + want: nil, + }, + { + name: "one ipv6 acquired, no nodes", + nws: testNetworks, + ips: []*models.V1IPResponse{ + { + Ipaddress: pointer.Pointer("2001::a:b:c"), + Name: "acquired-before", + Networkid: pointer.Pointer("internet"), + Projectid: pointer.Pointer("project-a"), + Tags: []string{ + fmt.Sprintf("%s=%s", tag.ClusterID, "this-cluster"), + }, + Type: pointer.Pointer("ephemeral"), + }, + }, + nodes: []v1.Node{}, + wantErrmessage: nil, + want: &metalLBConfig{ + Base: &baseConfig{ + AddressPools: addressPools{ + "internet-ephemeral": { + Name: "internet-ephemeral", + Protocol: "bgp", + AutoAssign: pointer.Pointer(false), + CIDRs: []string{"2001::a:b:c/128"}, + }, + }, + Peers: nil, + }, + }, + }, { name: "one ip acquired, no nodes", nws: testNetworks, @@ -46,22 +154,117 @@ func TestMetalLBConfig(t *testing.T) { Type: pointer.Pointer("ephemeral"), }, }, - nodes: []v1.Node{}, - wantErr: nil, + nodes: []v1.Node{}, + wantErrmessage: nil, want: &metalLBConfig{ - base: &baseConfig{ + Base: &baseConfig{ AddressPools: addressPools{ - { + "internet-ephemeral": { Name: "internet-ephemeral", Protocol: "bgp", AutoAssign: pointer.Pointer(false), CIDRs: []string{"84.1.1.1/32"}, }, }, - Peers: []*peer{}, + Peers: nil, }, }, }, + { + name: "one ip acquired, one node with malformed ASN label", + nws: testNetworks, + ips: []*models.V1IPResponse{ + { + Ipaddress: pointer.Pointer("84.1.1.1"), + Name: "acquired-before", + Networkid: pointer.Pointer("internet"), + Projectid: pointer.Pointer("project-a"), + Tags: []string{ + fmt.Sprintf("%s=%s", tag.ClusterID, "this-cluster"), + }, + Type: pointer.Pointer("ephemeral"), + }, + }, + nodes: []v1.Node{ + { + ObjectMeta: metav1.ObjectMeta{ + Name: "node-1", + Labels: map[string]string{ + tag.MachineNetworkPrimaryASN: "abc", + }, + }, + }, + }, + wantErrmessage: pointer.Pointer("unable to parse valid integer from asn annotation: strconv.ParseInt: parsing \"abc\": invalid syntax"), + want: nil, + }, + { + name: "one ip acquired, one node without ASN label", + nws: testNetworks, + ips: []*models.V1IPResponse{ + { + Ipaddress: pointer.Pointer("84.1.1.1"), + Name: "acquired-before", + Networkid: pointer.Pointer("internet"), + Projectid: pointer.Pointer("project-a"), + Tags: []string{ + fmt.Sprintf("%s=%s", tag.ClusterID, "this-cluster"), + }, + Type: pointer.Pointer("ephemeral"), + }, + }, + nodes: []v1.Node{ + { + ObjectMeta: metav1.ObjectMeta{ + Name: "node-1", + Labels: nil, + }, + }, + }, + wantErrmessage: pointer.Pointer("node \"node-1\" misses label: machine.metal-stack.io/network.primary.asn"), + want: nil, + }, + { + name: "one ip acquired, one node with malformed ASN label", + nws: testNetworks, + ips: []*models.V1IPResponse{ + { + Ipaddress: pointer.Pointer("84.1.1.1"), + Name: "acquired-before", + Networkid: pointer.Pointer("internet"), + Projectid: pointer.Pointer("project-a"), + Tags: []string{ + fmt.Sprintf("%s=%s", tag.ClusterID, "this-cluster"), + }, + Type: pointer.Pointer("ephemeral"), + }, + }, + nodes: []v1.Node{ + { + ObjectMeta: metav1.ObjectMeta{ + Name: "node-1", + Labels: map[string]string{ + tag.MachineNetworkPrimaryASN: "42", + }, + }, + }, + }, + wantErrmessage: nil, + want: &metalLBConfig{ + Base: &baseConfig{ + AddressPools: addressPools{ + "internet-ephemeral": { + Name: "internet-ephemeral", + Protocol: "bgp", + AutoAssign: pointer.Pointer(false), + CIDRs: []string{"84.1.1.1/32"}, + }, + }, + Peers: nil, + }, + }, + }, + { name: "two ips acquired, no nodes", nws: testNetworks, @@ -87,12 +290,12 @@ func TestMetalLBConfig(t *testing.T) { Type: pointer.Pointer("ephemeral"), }, }, - nodes: []v1.Node{}, - wantErr: nil, + nodes: []v1.Node{}, + wantErrmessage: nil, want: &metalLBConfig{ - base: &baseConfig{ + Base: &baseConfig{ AddressPools: addressPools{ - { + "internet-ephemeral": { Name: "internet-ephemeral", Protocol: "bgp", AutoAssign: pointer.Pointer(false), @@ -102,7 +305,7 @@ func TestMetalLBConfig(t *testing.T) { }, }, }, - Peers: []*peer{}, + Peers: nil, }, }, }, @@ -141,12 +344,12 @@ func TestMetalLBConfig(t *testing.T) { Type: pointer.Pointer("static"), }, }, - nodes: []v1.Node{}, - wantErr: nil, + nodes: []v1.Node{}, + wantErrmessage: nil, want: &metalLBConfig{ - base: &baseConfig{ + Base: &baseConfig{ AddressPools: addressPools{ - { + "internet-ephemeral": { Name: "internet-ephemeral", Protocol: "bgp", AutoAssign: pointer.Pointer(false), @@ -155,7 +358,7 @@ func TestMetalLBConfig(t *testing.T) { "84.1.1.2/32", }, }, - { + "internet-static": { Name: "internet-static", Protocol: "bgp", AutoAssign: pointer.Pointer(false), @@ -164,7 +367,7 @@ func TestMetalLBConfig(t *testing.T) { }, }, }, - Peers: []*peer{}, + Peers: nil, }, }, }, @@ -243,12 +446,12 @@ func TestMetalLBConfig(t *testing.T) { Type: pointer.Pointer("static"), }, }, - nodes: []v1.Node{}, - wantErr: nil, + nodes: []v1.Node{}, + wantErrmessage: nil, want: &metalLBConfig{ - base: &baseConfig{ + Base: &baseConfig{ AddressPools: addressPools{ - { + "internet-ephemeral": { Name: "internet-ephemeral", Protocol: "bgp", AutoAssign: pointer.Pointer(false), @@ -257,7 +460,7 @@ func TestMetalLBConfig(t *testing.T) { "84.1.1.2/32", }, }, - { + "internet-static": { Name: "internet-static", Protocol: "bgp", AutoAssign: pointer.Pointer(false), @@ -265,7 +468,7 @@ func TestMetalLBConfig(t *testing.T) { "84.1.1.3/32", }, }, - { + "shared-storage-network-static": { Name: "shared-storage-network-static", Protocol: "bgp", AutoAssign: pointer.Pointer(false), @@ -273,7 +476,7 @@ func TestMetalLBConfig(t *testing.T) { "10.131.44.2/32", }, }, - { + "mpls-network-static": { Name: "mpls-network-static", Protocol: "bgp", AutoAssign: pointer.Pointer(false), @@ -281,7 +484,7 @@ func TestMetalLBConfig(t *testing.T) { "100.127.130.2/32", }, }, - { + "mpls-network-ephemeral": { Name: "mpls-network-ephemeral", Protocol: "bgp", AutoAssign: pointer.Pointer(false), @@ -289,7 +492,7 @@ func TestMetalLBConfig(t *testing.T) { "100.127.130.3/32", }, }, - { + "dmz-network-static": { Name: "dmz-network-static", Protocol: "bgp", AutoAssign: pointer.Pointer(false), @@ -298,7 +501,7 @@ func TestMetalLBConfig(t *testing.T) { }, }, }, - Peers: []*peer{}, + Peers: nil, }, }, }, @@ -307,8 +510,10 @@ func TestMetalLBConfig(t *testing.T) { tt := tt t.Run(tt.name, func(t *testing.T) { cfg, err := New(LoadBalancerTypeMetalLB, tt.ips, tt.nws, tt.nodes, nil, nil) - if diff := cmp.Diff(err, tt.wantErr); diff != "" { - t.Errorf("error = %v", diff) + if err != nil { + if diff := cmp.Diff(err.Error(), *tt.wantErrmessage); diff != "" { + t.Errorf("error = %v", diff) + } return }