Skip to content

Commit

Permalink
kubectl describe
Browse files Browse the repository at this point in the history
Change-Id: I0664e11a3a5549e1cc9602b22dcaf294200792a4

Kubernetes-commit: 7e77e8b21d1e26b0ee2e4f54684ddd80e4d29983
  • Loading branch information
aojea authored and k8s-publishing-bot committed Aug 15, 2022
1 parent cebf241 commit 17964a8
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 0 deletions.
56 changes: 56 additions & 0 deletions pkg/describe/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ func describerMap(clientConfig *rest.Config) (map[schema.GroupKind]ResourceDescr
{Group: networkingv1beta1.GroupName, Kind: "IngressClass"}: &IngressClassDescriber{c},
{Group: networkingv1.GroupName, Kind: "Ingress"}: &IngressDescriber{c},
{Group: networkingv1.GroupName, Kind: "IngressClass"}: &IngressClassDescriber{c},
{Group: networkingv1alpha1.GroupName, Kind: "ServiceCIDR"}: &ServiceCIDRDescriber{c},
{Group: networkingv1alpha1.GroupName, Kind: "IPAddress"}: &IPAddressDescriber{c},
{Group: batchv1.GroupName, Kind: "Job"}: &JobDescriber{c},
{Group: batchv1.GroupName, Kind: "CronJob"}: &CronJobDescriber{c},
Expand Down Expand Up @@ -2844,6 +2845,61 @@ func (i *IngressClassDescriber) describeIngressClassV1(ic *networkingv1.IngressC
})
}

// ServiceCIDRDescriber generates information about a ServiceCIDR.
type ServiceCIDRDescriber struct {
client clientset.Interface
}

func (c *ServiceCIDRDescriber) Describe(namespace, name string, describerSettings DescriberSettings) (string, error) {
var events *corev1.EventList

svcV1alpha1, err := c.client.NetworkingV1alpha1().ServiceCIDRs().Get(context.TODO(), name, metav1.GetOptions{})
if err == nil {
if describerSettings.ShowEvents {
events, _ = searchEvents(c.client.CoreV1(), svcV1alpha1, describerSettings.ChunkSize)
}
return c.describeServiceCIDRV1alpha1(svcV1alpha1, events)
}
return "", err
}

func (c *ServiceCIDRDescriber) describeServiceCIDRV1alpha1(svc *networkingv1alpha1.ServiceCIDR, events *corev1.EventList) (string, error) {
return tabbedString(func(out io.Writer) error {
w := NewPrefixWriter(out)
w.Write(LEVEL_0, "Name:\t%v\n", svc.Name)
printLabelsMultiline(w, "Labels", svc.Labels)
printAnnotationsMultiline(w, "Annotations", svc.Annotations)

if svc.Spec.IPv4 != "" {
w.Write(LEVEL_0, "IPv4:\t%s\n", svc.Spec.IPv4)
}

if svc.Spec.IPv6 != "" {
w.Write(LEVEL_0, "IPv6:\t%s\n", svc.Spec.IPv6)
}

if len(svc.Status.Conditions) > 0 {
w.Write(LEVEL_0, "Status:\n")
w.Write(LEVEL_0, "Conditions:\n")
w.Write(LEVEL_1, "Type\tStatus\tLastTransitionTime\tReason\tMessage\n")
w.Write(LEVEL_1, "----\t------\t------------------\t------\t-------\n")
for _, c := range svc.Status.Conditions {
w.Write(LEVEL_1, "%v\t%v\t%s\t%v\t%v\n",
c.Type,
c.Status,
c.LastTransitionTime.Time.Format(time.RFC1123Z),
c.Reason,
c.Message)
}
}

if events != nil {
DescribeEvents(events, w)
}
return nil
})
}

// IPAddressDescriber generates information about an IPAddress.
type IPAddressDescriber struct {
client clientset.Interface
Expand Down
41 changes: 41 additions & 0 deletions pkg/describe/describe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5932,6 +5932,47 @@ Events: <none>` + "\n",
}
}

func TestDescribeServiceCIDR(t *testing.T) {

testcases := map[string]struct {
input *fake.Clientset
output string
}{
"ServiceCIDR v1alpha1": {
input: fake.NewSimpleClientset(&networkingv1alpha1.ServiceCIDR{
ObjectMeta: metav1.ObjectMeta{
Name: "foo.123",
},
Spec: networkingv1alpha1.ServiceCIDRSpec{
IPv4: "10.1.0.0/16",
IPv6: "fd00:1:1::/64",
},
}),

output: `Name: foo.123
Labels: <none>
Annotations: <none>
IPv4: 10.1.0.0/16
IPv6: fd00:1:1::/64
Events: <none>` + "\n",
},
}

for name, tc := range testcases {
t.Run(name, func(t *testing.T) {
c := &describeClient{T: t, Namespace: "foo", Interface: tc.input}
d := ServiceCIDRDescriber{c}
out, err := d.Describe("bar", "foo.123", DescriberSettings{ShowEvents: true})
if err != nil {
t.Errorf("unexpected error: %v", err)
}
if out != tc.output {
t.Errorf("expected :\n%s\nbut got output:\n%s diff:\n%s", tc.output, out, cmp.Diff(tc.output, out))
}
})
}
}

func TestDescribeIPAddress(t *testing.T) {

testcases := map[string]struct {
Expand Down

0 comments on commit 17964a8

Please sign in to comment.