cmd/containerboot: handle v6 pod ips that are missing square brackets (#18519)
This commit fixes an issue within containerboot that arose from the kubernetes operator. When users enable metrics on custom resources that are running on dual stack or ipv6 only clusters, they end up with an error as we pass the hostport combintation using $(POD_IP):PORT. In go, `netip.ParseAddrPort` expects square brackets `[]` to wrap the host portion of an ipv6 address and would naturally, crash. When loading the containerboot configuration from the environment we now check if the `TS_LOCAL_ADDR_PORT` value contains the pod's v6 ip address. If it does & does not already contain brackets, we add the brackets in. Closes: #15762 Closes: #15467 Signed-off-by: David Bond <davidsbond93@gmail.com>
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"net/netip"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
@@ -226,3 +227,30 @@ func TestValidateAuthMethods(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestHandlesKubeIPV6(t *testing.T) {
|
||||
t.Setenv("TS_LOCAL_ADDR_PORT", "fd7a:115c:a1e0::6c34:352:9002")
|
||||
t.Setenv("POD_IPS", "fd7a:115c:a1e0::6c34:352")
|
||||
|
||||
cfg, err := configFromEnv()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if cfg.LocalAddrPort != "[fd7a:115c:a1e0::6c34:352]:9002" {
|
||||
t.Errorf("LocalAddrPort is not set correctly")
|
||||
}
|
||||
|
||||
parsed, err := netip.ParseAddrPort(cfg.LocalAddrPort)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if !parsed.Addr().Is6() {
|
||||
t.Errorf("expected v6 address but got %s", parsed)
|
||||
}
|
||||
|
||||
if parsed.Port() != 9002 {
|
||||
t.Errorf("expected port 9002 but got %d", parsed.Port())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user