Code change:
output, err := hexCIDR(test.input) if test.expectErr { if err == nil { <del> t.Error("unexpected non-error") </del> <ins> t.Errorf("case %s: unexpected non-error", test.name) </ins> } } else { if err != nil { <del> t.Errorf("unexpected error: %v", err) </del> <ins> t.Errorf("case %s: unexpected error: %v", test.name, err) </ins> } if output != test.output { <del> t.Errorf("expected: %s, saw: %s", test.output, output) </del> <ins> t.Errorf("case %s: expected: %s, saw: %s", test.name, test.output, output) </ins> } <del> input, err := asciiCIDR(output) </del> <ins> } } } func TestAsciiCIDR(t *testing.T) { tests := []struct { name      string input     string output    string expectErr bool }{ { name:   "IPv4", input:  "01020000/ffff0000", output: "1.2.0.0/16", }, { name:   "IPv4 host", input:  "ac110002/ffffffff", output: "172.17.0.2/32", }, { name:   "IPv6", input:  "2001deadbeef00000000000000000000/ffffffffffffffff0000000000000000", output: "2001:dead:beef::/64", }, { name:   "IPv6 host", input:  "20010000000000000000000000000005/ffffffffffffffffffffffffffffffff", output: "2001::5/128", }, { name:      "invalid CIDR", input:     "malformed", expectErr: true, }, { name:      "non-hex IP", input:     "nonhex/32", expectErr: true, }, { name:      "non-hex mask", input:     "01020000/badmask", expectErr: true, }, } for _, test := range tests { output, err := asciiCIDR(test.input) if test.expectErr { if err == nil { t.Errorf("case %s: unexpected non-error", test.name) } } else { </ins> if err != nil { <del> t.Errorf("unexpected error: %v", err) </del> <ins> t.Errorf("case %s: unexpected error: %v", test.name, err) </ins> } <del> if input != test.input { t.Errorf("expected: %s, saw: %s", test.input, input) </del> <ins> if output != test.output { t.Errorf("case %s: expected: %s, saw: %s", test.name, test.output, output) </ins> } } }

Related discussion:
text: Appears that it is expecting to reverse hex back to string, but test is not showing case of mask being properly applied. For example, "2001::5/64" when converted to hex and then back to string will be "2001::/64". Will update test to be more accurate.
/area networking
These labels do not exist in this repository: . <detailsIn response to : /area networking Instructions for interacting with me using PR comments are available . If you have questions or suggestions related to my behavior, please file an issue against the repository. I understand the commands that are listed . </details
/sig network
One question I have... Can the callers (bandwidth?) of the function work with an IPv6 based hex CIDR? In the future, if we support pod IPs that are IPv6 addresses, and we modify the code to add /128 vs /32, as is done currently, this would create an IPv6 based hex CIDR.
The only caller is currently the ingress/egress shaping function in kubelet. That code also needs to be updated for IPv6. For example, assumes IPv4 when adding CIDRs to the shaper list.
Agree.I wanted to separate this out, partly to make the change smaller, but also, when I looked at the callers (this shaping functionality) I wasn't sure if it would support IPv6. I looked a bit at the "tc" command and saw some notes that indicate that it doesn't support IPv6 yet. Is that still accurate? Would it be ok to tackle that separately?