Repository: kubernetes/kubernetes (language: go)

Issue:
TestRoundTripFuzzing failing in `pull-kubernetes-unit`
### Which jobs are flaking?

pull-kubernetes-unit

### Which tests are flaking?

TestRoundTripFuzzing

### Since when has it been flaking?

Only noticed the failure once in https://github.com/kubernetes/kubernetes/pull/123642.

### Testgrid link

https://prow.k8s.io/view/gs/kubernetes-jenkins/pr-logs/pull/123642/pull-kubernetes-unit/1815871060902416384

### Reason for failure (if possible)

_No response_

### Anything else we need to know?

_No response_

### Relevant SIG(s)

_No response_


Discussion / hints:
/sig network
may be caused by #126293 

This flakes in https://testgrid.k8s.io/sig-release-master-blocking#ci-kubernetes-unit
/cc @kubernetes/release-team-release-signal 
/assign @aroradaman 

>           		ClusterCIDRs: []string{
>         - 			"Q婻,SK钜ʌ`ÇO0",
>         + 			"Q婻",
>         + 			"SK钜ʌ`ÇO0",
>           		},

so the problem is that sometimes the fuzzer generates a random string value that contains a comma, and when that gets converted back from v1alpha1, the comma is treated as punctuation rather than as part of the value.

we should probably manually fuzz ClusterCIDRs to contain 0-2 actual CIDR values
/triage accepted
Saw here: https://github.com/kubernetes/kubernetes/pull/126220#issuecomment-2247831926

Fix patch:
diff --git a/pkg/proxy/apis/config/fuzzer/fuzzer.go b/pkg/proxy/apis/config/fuzzer/fuzzer.go
index abadf34ee6eb9..c835dce440f47 100644
--- a/pkg/proxy/apis/config/fuzzer/fuzzer.go
+++ b/pkg/proxy/apis/config/fuzzer/fuzzer.go
@@ -18,6 +18,7 @@ package fuzzer
 
 import (
 	"fmt"
+	"net/netip"
 	"time"
 
 	"github.com/google/gofuzz"
@@ -28,6 +29,55 @@ import (
 	"k8s.io/utils/ptr"
 )
 
+// generateRandomIP is copied from pkg/apis/networking/fuzzer/fuzzer.go
+func generateRandomIP(is6 bool, c fuzz.Continue) string {
+	n := 4
+	if is6 {
+		n = 16
+	}
+	bytes := make([]byte, n)
+	for i := 0; i < n; i++ {
+		bytes[i] = uint8(c.Rand.Intn(255))
+	}
+
+	ip, ok := netip.AddrFromSlice(bytes)
+	if ok {
+		return ip.String()
+	}
+	// this should not happen
+	panic(fmt.Sprintf("invalid IP %v", bytes))
+}
+
+// generateRandomCIDR is copied from pkg/apis/networking/fuzzer/fuzzer.go
+func generateRandomCIDR(is6 bool, c fuzz.Continue) string {
+	ip, err := netip.ParseAddr(generateRandomIP(is6, c))
+	if err != nil {
+		// generateRandomIP already panics if returns a not valid ip
+		panic(err)
+	}
+
+	n := 32
+	if is6 {
+		n = 128
+	}
+
+	bits := c.Rand.Intn(n)
+	prefix := netip.PrefixFrom(ip, bits)
+	return prefix.Masked().String()
+}
+
+// getRandomDualStackCIDR returns a random dual-stack CIDR.
+func getRandomDualStackCIDR(c fuzz.Continue) []string {
+	cidrIPv4 := generateRandomCIDR(false, c)
+	cidrIPv6 := generateRandomCIDR(true, c)
+
+	cidrs := []string{cidrIPv4, cidrIPv6}
+	if c.RandBool() {
+		cidrs = []string{cidrIPv6, cidrIPv4}
+	}
+	return cidrs[:1+c.Intn(2)]
+}
+
 // Funcs returns the fuzzer functions for the kube-proxy apis.
 func Funcs(codecs runtimeserializer.CodecFactory) []interface{} {
 	return []interface{}{
@@ -35,6 +85,7 @@ func Funcs(codecs runtimeserializer.CodecFactory) []interface{} {
 			c.FuzzNoCustom(obj)
 			obj.BindAddress = fmt.Sprintf("%d.%d.%d.%d", c.Intn(256), c.Intn(256), c.Intn(256), c.Intn(256))
 			obj.ClientConnection.ContentType = c.RandString()
+			obj.DetectLocal.ClusterCIDRs = getRandomDualStackCIDR(c)
 			obj.Linux.Conntrack.MaxPerCore = ptr.To(c.Int31())
 			obj.Linux.Conntrack.Min = ptr.To(c.Int31())
 			obj.Linux.Conntrack.TCPCloseWaitTimeout = &metav1.Duration{Duration: time.Duration(c.Int63()) * time.Hour}


Test patch: