From 3ef7371e9049c127ec3041aa4fca6682c0260d1a Mon Sep 17 00:00:00 2001 From: Konrad Kaim Date: Mon, 27 Oct 2025 16:44:05 +0000 Subject: [PATCH] remove deprecated EndpointSlice api from describe Kubernetes-commit: bda0e6a83c5e8f5bd6ffdc22c8034498ed38fecc --- pkg/describe/describe.go | 90 +-------------------- pkg/describe/describe_test.go | 148 +++++++++------------------------- 2 files changed, 40 insertions(+), 198 deletions(-) diff --git a/pkg/describe/describe.go b/pkg/describe/describe.go index 59807006c..587890e11 100644 --- a/pkg/describe/describe.go +++ b/pkg/describe/describe.go @@ -46,7 +46,6 @@ import ( coordinationv1 "k8s.io/api/coordination/v1" corev1 "k8s.io/api/core/v1" discoveryv1 "k8s.io/api/discovery/v1" - discoveryv1beta1 "k8s.io/api/discovery/v1beta1" extensionsv1beta1 "k8s.io/api/extensions/v1beta1" networkingv1 "k8s.io/api/networking/v1" networkingv1beta1 "k8s.io/api/networking/v1beta1" @@ -209,7 +208,6 @@ func describerMap(clientConfig *rest.Config) (map[schema.GroupKind]ResourceDescr {Group: corev1.GroupName, Kind: "Endpoints"}: &EndpointsDescriber{c}, {Group: corev1.GroupName, Kind: "ConfigMap"}: &ConfigMapDescriber{c}, {Group: corev1.GroupName, Kind: "PriorityClass"}: &PriorityClassDescriber{c}, - {Group: discoveryv1beta1.GroupName, Kind: "EndpointSlice"}: &EndpointSliceDescriber{c}, {Group: discoveryv1.GroupName, Kind: "EndpointSlice"}: &EndpointSliceDescriber{c}, {Group: autoscalingv2.GroupName, Kind: "HorizontalPodAutoscaler"}: &HorizontalPodAutoscalerDescriber{c}, {Group: extensionsv1beta1.GroupName, Kind: "Ingress"}: &IngressDescriber{c}, @@ -392,7 +390,6 @@ func init() { describeDeployment, describeEndpoints, describeEndpointSliceV1, - describeEndpointSliceV1beta1, describeHorizontalPodAutoscalerV1, describeHorizontalPodAutoscalerV2, describeJob, @@ -3255,26 +3252,15 @@ type EndpointSliceDescriber struct { func (d *EndpointSliceDescriber) Describe(namespace, name string, describerSettings DescriberSettings) (string, error) { var events *corev1.EventList - // try endpointslice/v1 first (v1.21) and fallback to v1beta1 if error occurs epsV1, err := d.DiscoveryV1().EndpointSlices(namespace).Get(context.TODO(), name, metav1.GetOptions{}) - if err == nil { - if describerSettings.ShowEvents { - events, _ = searchEvents(d.CoreV1(), epsV1, describerSettings.ChunkSize) - } - return describeEndpointSliceV1(epsV1, events) - } - - epsV1beta1, err := d.DiscoveryV1beta1().EndpointSlices(namespace).Get(context.TODO(), name, metav1.GetOptions{}) if err != nil { return "", err } - if describerSettings.ShowEvents { - events, _ = searchEvents(d.CoreV1(), epsV1beta1, describerSettings.ChunkSize) + events, _ = searchEvents(d.CoreV1(), epsV1, describerSettings.ChunkSize) } - - return describeEndpointSliceV1beta1(epsV1beta1, events) + return describeEndpointSliceV1(epsV1, events) } func describeEndpointSliceV1(eps *discoveryv1.EndpointSlice, events *corev1.EventList) (string, error) { @@ -3359,78 +3345,6 @@ func describeEndpointSliceV1(eps *discoveryv1.EndpointSlice, events *corev1.Even }) } -func describeEndpointSliceV1beta1(eps *discoveryv1beta1.EndpointSlice, events *corev1.EventList) (string, error) { - return tabbedString(func(out io.Writer) error { - w := NewPrefixWriter(out) - w.Write(LEVEL_0, "Name:\t%s\n", eps.Name) - w.Write(LEVEL_0, "Namespace:\t%s\n", eps.Namespace) - printLabelsMultiline(w, "Labels", eps.Labels) - printAnnotationsMultiline(w, "Annotations", eps.Annotations) - - w.Write(LEVEL_0, "AddressType:\t%s\n", string(eps.AddressType)) - - if len(eps.Ports) == 0 { - w.Write(LEVEL_0, "Ports: \n") - } else { - w.Write(LEVEL_0, "Ports:\n") - w.Write(LEVEL_1, "Name\tPort\tProtocol\n") - w.Write(LEVEL_1, "----\t----\t--------\n") - for _, port := range eps.Ports { - portName := "" - if port.Name != nil && len(*port.Name) > 0 { - portName = *port.Name - } - - portNum := "" - if port.Port != nil { - portNum = strconv.Itoa(int(*port.Port)) - } - - w.Write(LEVEL_1, "%s\t%s\t%s\n", portName, portNum, *port.Protocol) - } - } - - if len(eps.Endpoints) == 0 { - w.Write(LEVEL_0, "Endpoints: \n") - } else { - w.Write(LEVEL_0, "Endpoints:\n") - for i := range eps.Endpoints { - endpoint := &eps.Endpoints[i] - - addressesString := strings.Join(endpoint.Addresses, ",") - if len(addressesString) == 0 { - addressesString = "" - } - w.Write(LEVEL_1, "- Addresses:\t%s\n", addressesString) - - w.Write(LEVEL_2, "Conditions:\n") - readyText := "" - if endpoint.Conditions.Ready != nil { - readyText = strconv.FormatBool(*endpoint.Conditions.Ready) - } - w.Write(LEVEL_3, "Ready:\t%s\n", readyText) - - hostnameText := "" - if endpoint.Hostname != nil { - hostnameText = *endpoint.Hostname - } - w.Write(LEVEL_2, "Hostname:\t%s\n", hostnameText) - - if endpoint.TargetRef != nil { - w.Write(LEVEL_2, "TargetRef:\t%s/%s\n", endpoint.TargetRef.Kind, endpoint.TargetRef.Name) - } - - printLabelsMultilineWithIndent(w, " ", "Topology", "\t", endpoint.Topology, sets.New[string]()) - } - } - - if events != nil { - DescribeEvents(events, w) - } - return nil - }) -} - // ServiceAccountDescriber generates information about a service. type ServiceAccountDescriber struct { clientset.Interface diff --git a/pkg/describe/describe_test.go b/pkg/describe/describe_test.go index 5583726da..fbee084d4 100644 --- a/pkg/describe/describe_test.go +++ b/pkg/describe/describe_test.go @@ -36,7 +36,6 @@ import ( coordinationv1 "k8s.io/api/coordination/v1" corev1 "k8s.io/api/core/v1" discoveryv1 "k8s.io/api/discovery/v1" - discoveryv1beta1 "k8s.io/api/discovery/v1beta1" networkingv1 "k8s.io/api/networking/v1" networkingv1beta1 "k8s.io/api/networking/v1beta1" policyv1 "k8s.io/api/policy/v1" @@ -5158,7 +5157,7 @@ func TestDescribeEvents(t *testing.T) { }, events), }, "EndpointSliceDescriber": &EndpointSliceDescriber{ - fake.NewClientset(&discoveryv1beta1.EndpointSlice{ + fake.NewClientset(&discoveryv1.EndpointSlice{ ObjectMeta: metav1.ObjectMeta{ Name: "bar", Namespace: "foo", @@ -6600,100 +6599,35 @@ func TestDescribeEndpointSlice(t *testing.T) { protocolTCP := corev1.ProtocolTCP port80 := int32(80) - testcases := map[string]struct { - input *fake.Clientset - output string - }{ - "EndpointSlices v1beta1": { - input: fake.NewClientset(&discoveryv1beta1.EndpointSlice{ - ObjectMeta: metav1.ObjectMeta{ - Name: "foo.123", - Namespace: "bar", - }, - AddressType: discoveryv1beta1.AddressTypeIPv4, - Endpoints: []discoveryv1beta1.Endpoint{ - { - Addresses: []string{"1.2.3.4", "1.2.3.5"}, - Conditions: discoveryv1beta1.EndpointConditions{Ready: ptr.To(true)}, - TargetRef: &corev1.ObjectReference{Kind: "Pod", Name: "test-123"}, - Topology: map[string]string{ - "topology.kubernetes.io/zone": "us-central1-a", - "topology.kubernetes.io/region": "us-central1", - }, - }, { - Addresses: []string{"1.2.3.6", "1.2.3.7"}, - Conditions: discoveryv1beta1.EndpointConditions{Ready: ptr.To(true)}, - TargetRef: &corev1.ObjectReference{Kind: "Pod", Name: "test-124"}, - Topology: map[string]string{ - "topology.kubernetes.io/zone": "us-central1-b", - "topology.kubernetes.io/region": "us-central1", - }, - }, - }, - Ports: []discoveryv1beta1.EndpointPort{ - { - Protocol: &protocolTCP, - Port: &port80, - }, - }, - }), - - output: `Name: foo.123 -Namespace: bar -Labels: -Annotations: -AddressType: IPv4 -Ports: - Name Port Protocol - ---- ---- -------- - 80 TCP -Endpoints: - - Addresses: 1.2.3.4,1.2.3.5 - Conditions: - Ready: true - Hostname: - TargetRef: Pod/test-123 - Topology: topology.kubernetes.io/region=us-central1 - topology.kubernetes.io/zone=us-central1-a - - Addresses: 1.2.3.6,1.2.3.7 - Conditions: - Ready: true - Hostname: - TargetRef: Pod/test-124 - Topology: topology.kubernetes.io/region=us-central1 - topology.kubernetes.io/zone=us-central1-b -Events: ` + "\n", + input := fake.NewClientset(&discoveryv1.EndpointSlice{ + ObjectMeta: metav1.ObjectMeta{ + Name: "foo.123", + Namespace: "bar", }, - "EndpointSlices v1": { - input: fake.NewClientset(&discoveryv1.EndpointSlice{ - ObjectMeta: metav1.ObjectMeta{ - Name: "foo.123", - Namespace: "bar", - }, - AddressType: discoveryv1.AddressTypeIPv4, - Endpoints: []discoveryv1.Endpoint{ - { - Addresses: []string{"1.2.3.4", "1.2.3.5"}, - Conditions: discoveryv1.EndpointConditions{Ready: ptr.To(true)}, - TargetRef: &corev1.ObjectReference{Kind: "Pod", Name: "test-123"}, - Zone: ptr.To("us-central1-a"), - NodeName: ptr.To("node-1"), - }, { - Addresses: []string{"1.2.3.6", "1.2.3.7"}, - Conditions: discoveryv1.EndpointConditions{Ready: ptr.To(true)}, - TargetRef: &corev1.ObjectReference{Kind: "Pod", Name: "test-124"}, - NodeName: ptr.To("node-2"), - }, - }, - Ports: []discoveryv1.EndpointPort{ - { - Protocol: &protocolTCP, - Port: &port80, - }, - }, - }), + AddressType: discoveryv1.AddressTypeIPv4, + Endpoints: []discoveryv1.Endpoint{ + { + Addresses: []string{"1.2.3.4", "1.2.3.5"}, + Conditions: discoveryv1.EndpointConditions{Ready: ptr.To(true)}, + TargetRef: &corev1.ObjectReference{Kind: "Pod", Name: "test-123"}, + Zone: ptr.To("us-central1-a"), + NodeName: ptr.To("node-1"), + }, { + Addresses: []string{"1.2.3.6", "1.2.3.7"}, + Conditions: discoveryv1.EndpointConditions{Ready: ptr.To(true)}, + TargetRef: &corev1.ObjectReference{Kind: "Pod", Name: "test-124"}, + NodeName: ptr.To("node-2"), + }, + }, + Ports: []discoveryv1.EndpointPort{ + { + Protocol: &protocolTCP, + Port: &port80, + }, + }, + }) - output: `Name: foo.123 + output := `Name: foo.123 Namespace: bar Labels: Annotations: @@ -6717,23 +6651,17 @@ Endpoints: TargetRef: Pod/test-124 NodeName: node-2 Zone: -Events: ` + "\n", - }, - } +Events: ` + "\n" - for name, tc := range testcases { - t.Run(name, func(t *testing.T) { - c := &describeClient{T: t, Namespace: "foo", Interface: tc.input} - d := EndpointSliceDescriber{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.Log(out) - t.Errorf("expected :\n%s\nbut got output:\n%s", tc.output, out) - } - }) + c := &describeClient{T: t, Namespace: "foo", Interface: input} + d := EndpointSliceDescriber{c} + out, err := d.Describe("bar", "foo.123", DescriberSettings{ShowEvents: true}) + if err != nil { + t.Errorf("unexpected error: %v", err) + } + if out != output { + t.Log(out) + t.Errorf("expected :\n%s\nbut got output:\n%s", output, out) } }