kubectl describe
Change-Id: I0664e11a3a5549e1cc9602b22dcaf294200792a4
This commit is contained in:
		
				
					committed by
					
						
						Antonio Ojea
					
				
			
			
				
	
			
			
			
						parent
						
							2feb1503e2
						
					
				
				
					commit
					7e77e8b21d
				
			@@ -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},
 | 
			
		||||
@@ -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
 | 
			
		||||
 
 | 
			
		||||
@@ -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 {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user