mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-10-31 18:28:13 +00:00 
			
		
		
		
	describe servicecidr and ipaddress v1
This commit is contained in:
		| @@ -217,6 +217,8 @@ func describerMap(clientConfig *rest.Config) (map[schema.GroupKind]ResourceDescr | ||||
| 		{Group: networkingv1.GroupName, Kind: "IngressClass"}:                     &IngressClassDescriber{c}, | ||||
| 		{Group: networkingv1beta1.GroupName, Kind: "ServiceCIDR"}:                 &ServiceCIDRDescriber{c}, | ||||
| 		{Group: networkingv1beta1.GroupName, Kind: "IPAddress"}:                   &IPAddressDescriber{c}, | ||||
| 		{Group: networkingv1.GroupName, Kind: "ServiceCIDR"}:                      &ServiceCIDRDescriber{c}, | ||||
| 		{Group: networkingv1.GroupName, Kind: "IPAddress"}:                        &IPAddressDescriber{c}, | ||||
| 		{Group: batchv1.GroupName, Kind: "Job"}:                                   &JobDescriber{c}, | ||||
| 		{Group: batchv1.GroupName, Kind: "CronJob"}:                               &CronJobDescriber{c}, | ||||
| 		{Group: batchv1beta1.GroupName, Kind: "CronJob"}:                          &CronJobDescriber{c}, | ||||
| @@ -2889,6 +2891,14 @@ type ServiceCIDRDescriber struct { | ||||
| func (c *ServiceCIDRDescriber) Describe(namespace, name string, describerSettings DescriberSettings) (string, error) { | ||||
| 	var events *corev1.EventList | ||||
|  | ||||
| 	svcV1, err := c.client.NetworkingV1().ServiceCIDRs().Get(context.TODO(), name, metav1.GetOptions{}) | ||||
| 	if err == nil { | ||||
| 		if describerSettings.ShowEvents { | ||||
| 			events, _ = searchEvents(c.client.CoreV1(), svcV1, describerSettings.ChunkSize) | ||||
| 		} | ||||
| 		return c.describeServiceCIDRV1(svcV1, events) | ||||
| 	} | ||||
|  | ||||
| 	svcV1beta1, err := c.client.NetworkingV1beta1().ServiceCIDRs().Get(context.TODO(), name, metav1.GetOptions{}) | ||||
| 	if err == nil { | ||||
| 		if describerSettings.ShowEvents { | ||||
| @@ -2899,6 +2909,37 @@ func (c *ServiceCIDRDescriber) Describe(namespace, name string, describerSetting | ||||
| 	return "", err | ||||
| } | ||||
|  | ||||
| func (c *ServiceCIDRDescriber) describeServiceCIDRV1(svc *networkingv1.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) | ||||
|  | ||||
| 		w.Write(LEVEL_0, "CIDRs:\t%v\n", strings.Join(svc.Spec.CIDRs, ", ")) | ||||
|  | ||||
| 		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 | ||||
| 	}) | ||||
| } | ||||
|  | ||||
| func (c *ServiceCIDRDescriber) describeServiceCIDRV1beta1(svc *networkingv1beta1.ServiceCIDR, events *corev1.EventList) (string, error) { | ||||
| 	return tabbedString(func(out io.Writer) error { | ||||
| 		w := NewPrefixWriter(out) | ||||
| @@ -2938,6 +2979,14 @@ type IPAddressDescriber struct { | ||||
| func (c *IPAddressDescriber) Describe(namespace, name string, describerSettings DescriberSettings) (string, error) { | ||||
| 	var events *corev1.EventList | ||||
|  | ||||
| 	ipV1, err := c.client.NetworkingV1().IPAddresses().Get(context.TODO(), name, metav1.GetOptions{}) | ||||
| 	if err == nil { | ||||
| 		if describerSettings.ShowEvents { | ||||
| 			events, _ = searchEvents(c.client.CoreV1(), ipV1, describerSettings.ChunkSize) | ||||
| 		} | ||||
| 		return c.describeIPAddressV1(ipV1, events) | ||||
| 	} | ||||
|  | ||||
| 	ipV1beta1, err := c.client.NetworkingV1beta1().IPAddresses().Get(context.TODO(), name, metav1.GetOptions{}) | ||||
| 	if err == nil { | ||||
| 		if describerSettings.ShowEvents { | ||||
| @@ -2948,6 +2997,28 @@ func (c *IPAddressDescriber) Describe(namespace, name string, describerSettings | ||||
| 	return "", err | ||||
| } | ||||
|  | ||||
| func (c *IPAddressDescriber) describeIPAddressV1(ip *networkingv1.IPAddress, events *corev1.EventList) (string, error) { | ||||
| 	return tabbedString(func(out io.Writer) error { | ||||
| 		w := NewPrefixWriter(out) | ||||
| 		w.Write(LEVEL_0, "Name:\t%v\n", ip.Name) | ||||
| 		printLabelsMultiline(w, "Labels", ip.Labels) | ||||
| 		printAnnotationsMultiline(w, "Annotations", ip.Annotations) | ||||
|  | ||||
| 		if ip.Spec.ParentRef != nil { | ||||
| 			w.Write(LEVEL_0, "Parent Reference:\n") | ||||
| 			w.Write(LEVEL_1, "Group:\t%v\n", ip.Spec.ParentRef.Group) | ||||
| 			w.Write(LEVEL_1, "Resource:\t%v\n", ip.Spec.ParentRef.Resource) | ||||
| 			w.Write(LEVEL_1, "Namespace:\t%v\n", ip.Spec.ParentRef.Namespace) | ||||
| 			w.Write(LEVEL_1, "Name:\t%v\n", ip.Spec.ParentRef.Name) | ||||
| 		} | ||||
|  | ||||
| 		if events != nil { | ||||
| 			DescribeEvents(events, w) | ||||
| 		} | ||||
| 		return nil | ||||
| 	}) | ||||
| } | ||||
|  | ||||
| func (c *IPAddressDescriber) describeIPAddressV1beta1(ip *networkingv1beta1.IPAddress, events *corev1.EventList) (string, error) { | ||||
| 	return tabbedString(func(out io.Writer) error { | ||||
| 		w := NewPrefixWriter(out) | ||||
|   | ||||
| @@ -6590,6 +6590,54 @@ Events:       <none>` + "\n", | ||||
| Labels:       <none> | ||||
| Annotations:  <none> | ||||
| CIDRs:        fd00:1:1::/64 | ||||
| Events:       <none>` + "\n", | ||||
| 		}, | ||||
| 		"ServiceCIDR v1": { | ||||
| 			input: fake.NewSimpleClientset(&networkingv1.ServiceCIDR{ | ||||
| 				ObjectMeta: metav1.ObjectMeta{ | ||||
| 					Name: "foo.123", | ||||
| 				}, | ||||
| 				Spec: networkingv1.ServiceCIDRSpec{ | ||||
| 					CIDRs: []string{"10.1.0.0/16", "fd00:1:1::/64"}, | ||||
| 				}, | ||||
| 			}), | ||||
|  | ||||
| 			output: `Name:         foo.123 | ||||
| Labels:       <none> | ||||
| Annotations:  <none> | ||||
| CIDRs:        10.1.0.0/16, fd00:1:1::/64 | ||||
| Events:       <none>` + "\n", | ||||
| 		}, | ||||
| 		"ServiceCIDR v1 IPv4": { | ||||
| 			input: fake.NewSimpleClientset(&networkingv1.ServiceCIDR{ | ||||
| 				ObjectMeta: metav1.ObjectMeta{ | ||||
| 					Name: "foo.123", | ||||
| 				}, | ||||
| 				Spec: networkingv1.ServiceCIDRSpec{ | ||||
| 					CIDRs: []string{"10.1.0.0/16"}, | ||||
| 				}, | ||||
| 			}), | ||||
|  | ||||
| 			output: `Name:         foo.123 | ||||
| Labels:       <none> | ||||
| Annotations:  <none> | ||||
| CIDRs:        10.1.0.0/16 | ||||
| Events:       <none>` + "\n", | ||||
| 		}, | ||||
| 		"ServiceCIDR v1 IPv6": { | ||||
| 			input: fake.NewSimpleClientset(&networkingv1.ServiceCIDR{ | ||||
| 				ObjectMeta: metav1.ObjectMeta{ | ||||
| 					Name: "foo.123", | ||||
| 				}, | ||||
| 				Spec: networkingv1.ServiceCIDRSpec{ | ||||
| 					CIDRs: []string{"fd00:1:1::/64"}, | ||||
| 				}, | ||||
| 			}), | ||||
|  | ||||
| 			output: `Name:         foo.123 | ||||
| Labels:       <none> | ||||
| Annotations:  <none> | ||||
| CIDRs:        fd00:1:1::/64 | ||||
| Events:       <none>` + "\n", | ||||
| 		}, | ||||
| 	} | ||||
| @@ -6633,6 +6681,31 @@ func TestDescribeIPAddress(t *testing.T) { | ||||
| 			output: `Name:         foo.123 | ||||
| Labels:       <none> | ||||
| Annotations:  <none> | ||||
| Parent Reference: | ||||
|   Group:      mygroup | ||||
|   Resource:   myresource | ||||
|   Namespace:  mynamespace | ||||
|   Name:       myname | ||||
| Events:       <none>` + "\n", | ||||
| 		}, | ||||
| 		"IPAddress v1": { | ||||
| 			input: fake.NewSimpleClientset(&networkingv1.IPAddress{ | ||||
| 				ObjectMeta: metav1.ObjectMeta{ | ||||
| 					Name: "foo.123", | ||||
| 				}, | ||||
| 				Spec: networkingv1.IPAddressSpec{ | ||||
| 					ParentRef: &networkingv1.ParentReference{ | ||||
| 						Group:     "mygroup", | ||||
| 						Resource:  "myresource", | ||||
| 						Namespace: "mynamespace", | ||||
| 						Name:      "myname", | ||||
| 					}, | ||||
| 				}, | ||||
| 			}), | ||||
|  | ||||
| 			output: `Name:         foo.123 | ||||
| Labels:       <none> | ||||
| Annotations:  <none> | ||||
| Parent Reference: | ||||
|   Group:      mygroup | ||||
|   Resource:   myresource | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Antonio Ojea
					Antonio Ojea