mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-31 15:25:57 +00:00
printers: use new ServiceCIDR API
Change-Id: Iaedeb99fcdb6e27e9987bccb1ccc32fab7da71f6
This commit is contained in:
parent
c3d9b77d94
commit
5123a93b34
@ -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 := "<none>"
|
||||
ipv6 := "<none>"
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
|
@ -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, "<none>", "<unknown>"}}},
|
||||
expected: []metav1.TableRow{{Cells: []interface{}{"test1", ipv4CIDR, "<unknown>"}}},
|
||||
},
|
||||
{
|
||||
// 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", "<none>", ipv6CIDR, "<unknown>"}}},
|
||||
expected: []metav1.TableRow{{Cells: []interface{}{"test5", ipv6CIDR, "<unknown>"}}},
|
||||
},
|
||||
{
|
||||
// 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, "<unknown>"}}},
|
||||
expected: []metav1.TableRow{{Cells: []interface{}{"test9", ipv4CIDR + "," + ipv6CIDR, "<unknown>"}}},
|
||||
},
|
||||
}
|
||||
|
||||
@ -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", "<unknown>"}},
|
||||
{Cells: []interface{}{"ccc2", "10.2.0.0/16", "fd00:2:1::/64", "<unknown>"}},
|
||||
{Cells: []interface{}{"ccc1", "10.1.0.0/16,fd00:1:1::/64", "<unknown>"}},
|
||||
{Cells: []interface{}{"ccc2", "10.2.0.0/16,fd00:2:1::/64", "<unknown>"}},
|
||||
},
|
||||
},
|
||||
{
|
||||
// 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", "<unknown>"}},
|
||||
{Cells: []interface{}{"ccc2", "10.2.0.0/16", "fd00:2:1::/64", "<unknown>"}},
|
||||
// Columns: Name, CIDRs, Age.
|
||||
{Cells: []interface{}{"ccc1", "10.1.0.0/16,fd00:1:1::/64", "<unknown>"}},
|
||||
{Cells: []interface{}{"ccc2", "10.2.0.0/16,fd00:2:1::/64", "<unknown>"}},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user