diff --git a/pkg/printers/internalversion/printers.go b/pkg/printers/internalversion/printers.go index a9471c7bbf5..f2fe011c3d7 100644 --- a/pkg/printers/internalversion/printers.go +++ b/pkg/printers/internalversion/printers.go @@ -656,8 +656,7 @@ func AddHandlers(h printers.PrintHandler) { serviceCIDRColumnDefinitions := []metav1.TableColumnDefinition{ {Name: "Name", Type: "string", Format: "name", Description: metav1.ObjectMeta{}.SwaggerDoc()["name"]}, - {Name: "IPv4", Type: "string", Description: networkingv1alpha1.ServiceCIDRSpec{}.SwaggerDoc()["ipv4"]}, - {Name: "IPv6", Type: "string", Description: networkingv1alpha1.ServiceCIDRSpec{}.SwaggerDoc()["ipv6"]}, + {Name: "CIDRs", Type: "string", Description: networkingv1alpha1.ServiceCIDRSpec{}.SwaggerDoc()["cidrs"]}, {Name: "Age", Type: "string", Description: metav1.ObjectMeta{}.SwaggerDoc()["creationTimestamp"]}, } @@ -2852,17 +2851,9 @@ func printServiceCIDR(obj *networking.ServiceCIDR, options printers.GenerateOpti row := metav1.TableRow{ Object: runtime.RawExtension{Object: obj}, } - ipv4 := "" - ipv6 := "" - if obj.Spec.IPv4 != "" { - ipv4 = obj.Spec.IPv4 - } - if obj.Spec.IPv6 != "" { - ipv6 = obj.Spec.IPv6 - } - - row.Cells = append(row.Cells, obj.Name, ipv4, ipv6, translateTimestampSince(obj.CreationTimestamp)) + cidrs := strings.Join(obj.Spec.CIDRs, ",") + row.Cells = append(row.Cells, obj.Name, cidrs, translateTimestampSince(obj.CreationTimestamp)) return []metav1.TableRow{row}, nil } diff --git a/pkg/printers/internalversion/printers_test.go b/pkg/printers/internalversion/printers_test.go index 77623905c57..ead3e5386ed 100644 --- a/pkg/printers/internalversion/printers_test.go +++ b/pkg/printers/internalversion/printers_test.go @@ -6589,37 +6589,36 @@ func TestPrintServiceCIDR(t *testing.T) { ccc: networking.ServiceCIDR{ ObjectMeta: metav1.ObjectMeta{Name: "test1"}, Spec: networking.ServiceCIDRSpec{ - IPv4: ipv4CIDR, + CIDRs: []string{ipv4CIDR}, }, }, options: printers.GenerateOptions{}, // Columns: Name, IPv4, IPv6, Age. - expected: []metav1.TableRow{{Cells: []interface{}{"test1", ipv4CIDR, "", ""}}}, + expected: []metav1.TableRow{{Cells: []interface{}{"test1", ipv4CIDR, ""}}}, }, { // Test name, IPv6 only. ccc: networking.ServiceCIDR{ ObjectMeta: metav1.ObjectMeta{Name: "test5"}, Spec: networking.ServiceCIDRSpec{ - IPv6: ipv6CIDR, + CIDRs: []string{ipv6CIDR}, }, }, options: printers.GenerateOptions{}, // Columns: Name, PerNodeHostBits, IPv4, IPv6, Age - expected: []metav1.TableRow{{Cells: []interface{}{"test5", "", ipv6CIDR, ""}}}, + expected: []metav1.TableRow{{Cells: []interface{}{"test5", ipv6CIDR, ""}}}, }, { // Test name, DualStack. ccc: networking.ServiceCIDR{ ObjectMeta: metav1.ObjectMeta{Name: "test9"}, Spec: networking.ServiceCIDRSpec{ - IPv4: ipv4CIDR, - IPv6: ipv6CIDR, + CIDRs: []string{ipv4CIDR, ipv6CIDR}, }, }, options: printers.GenerateOptions{}, // Columns: Name, PerNodeHostBits, IPv4, IPv6, Age. - expected: []metav1.TableRow{{Cells: []interface{}{"test9", ipv4CIDR, ipv6CIDR, ""}}}, + expected: []metav1.TableRow{{Cells: []interface{}{"test9", ipv4CIDR + "," + ipv6CIDR, ""}}}, }, } @@ -6643,15 +6642,13 @@ func TestPrintServiceCIDRList(t *testing.T) { { ObjectMeta: metav1.ObjectMeta{Name: "ccc1"}, Spec: networking.ServiceCIDRSpec{ - IPv4: "10.1.0.0/16", - IPv6: "fd00:1:1::/64", + CIDRs: []string{"10.1.0.0/16", "fd00:1:1::/64"}, }, }, { ObjectMeta: metav1.ObjectMeta{Name: "ccc2"}, Spec: networking.ServiceCIDRSpec{ - IPv4: "10.2.0.0/16", - IPv6: "fd00:2:1::/64", + CIDRs: []string{"10.2.0.0/16", "fd00:2:1::/64"}, }, }, }, @@ -6666,17 +6663,17 @@ func TestPrintServiceCIDRList(t *testing.T) { options: printers.GenerateOptions{Wide: false}, expected: []metav1.TableRow{ // Columns: Name, IPv4, IPv6, Age. - {Cells: []interface{}{"ccc1", "10.1.0.0/16", "fd00:1:1::/64", ""}}, - {Cells: []interface{}{"ccc2", "10.2.0.0/16", "fd00:2:1::/64", ""}}, + {Cells: []interface{}{"ccc1", "10.1.0.0/16,fd00:1:1::/64", ""}}, + {Cells: []interface{}{"ccc2", "10.2.0.0/16,fd00:2:1::/64", ""}}, }, }, { // Test name, DualStack with node selector, wide. options: printers.GenerateOptions{Wide: true}, expected: []metav1.TableRow{ - // Columns: Name, IPv4, IPv6, Age. - {Cells: []interface{}{"ccc1", "10.1.0.0/16", "fd00:1:1::/64", ""}}, - {Cells: []interface{}{"ccc2", "10.2.0.0/16", "fd00:2:1::/64", ""}}, + // Columns: Name, CIDRs, Age. + {Cells: []interface{}{"ccc1", "10.1.0.0/16,fd00:1:1::/64", ""}}, + {Cells: []interface{}{"ccc2", "10.2.0.0/16,fd00:2:1::/64", ""}}, }, }, }