Skip to content

Commit

Permalink
test: support for endpointslice/v1 for k8s v1.25
Browse files Browse the repository at this point in the history
  • Loading branch information
prometherion committed Nov 19, 2022
1 parent 4e3a4fa commit 4a7f964
Showing 1 changed file with 54 additions and 23 deletions.
77 changes: 54 additions & 23 deletions e2e/service_metadata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ import (
"context"
"errors"
"fmt"
discoveryv1 "k8s.io/api/discovery/v1"
discoveryv1beta1 "k8s.io/api/discovery/v1beta1"
"sigs.k8s.io/controller-runtime/pkg/client"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
corev1 "k8s.io/api/core/v1"
discoveryv1beta1 "k8s.io/api/discovery/v1beta1"
networkingv1 "k8s.io/api/networking/v1"
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand All @@ -37,7 +39,7 @@ var _ = Describe("adding metadata to Service objects", func() {
Kind: "User",
},
},
ServiceOptions: &capsulev1beta1.ServiceOptions{
ServiceOptions: &api.ServiceOptions{
AdditionalMetadata: &api.AdditionalMetadataSpec{
Labels: map[string]string{
"k8s.io/custom-label": "foo",
Expand Down Expand Up @@ -218,7 +220,7 @@ var _ = Describe("adding metadata to Service objects", func() {
})
})

It("should apply them to EndpointSlice", func() {
It("should apply them to EndpointSlice in v1", func() {
if err := k8sClient.List(context.Background(), &networkingv1.IngressList{}); err != nil {
missingAPIError := &meta.NoKindMatchError{}
if errors.As(err, &missingAPIError) {
Expand All @@ -230,24 +232,6 @@ var _ = Describe("adding metadata to Service objects", func() {
NamespaceCreation(ns, tnt.Spec.Owners[0], defaultTimeoutInterval).Should(Succeed())
TenantNamespaceList(tnt, defaultTimeoutInterval).Should(ContainElement(ns.GetName()))

eps := &discoveryv1beta1.EndpointSlice{
ObjectMeta: metav1.ObjectMeta{
Name: "endpointslice-metadata",
Namespace: ns.GetName(),
},
AddressType: discoveryv1beta1.AddressTypeIPv4,
Endpoints: []discoveryv1beta1.Endpoint{
{
Addresses: []string{"10.10.1.1"},
},
},
Ports: []discoveryv1beta1.EndpointPort{
{
Name: pointer.StringPtr("foo"),
Port: pointer.Int32Ptr(9999),
},
},
}
// Waiting for the reconciliation of required RBAC
EventuallyCreation(func() (err error) {
pod := &corev1.Pod{
Expand All @@ -268,6 +252,53 @@ var _ = Describe("adding metadata to Service objects", func() {
return
}).Should(Succeed())

var eps client.Object

if err := k8sClient.List(context.Background(), &discoveryv1.EndpointSliceList{}); err != nil {
missingAPIError := &meta.NoKindMatchError{}
if errors.As(err, &missingAPIError) {
Skip(fmt.Sprintf("Running test due to unsupported API kind: %s", err.Error()))
}

eps = &discoveryv1beta1.EndpointSlice{
ObjectMeta: metav1.ObjectMeta{
Name: "endpointslice-metadata",
Namespace: ns.GetName(),
},
AddressType: discoveryv1beta1.AddressTypeIPv4,
Endpoints: []discoveryv1beta1.Endpoint{
{
Addresses: []string{"10.10.1.1"},
},
},
Ports: []discoveryv1beta1.EndpointPort{
{
Name: pointer.StringPtr("foo"),
Port: pointer.Int32Ptr(9999),
},
},
}
} else {
eps = &discoveryv1.EndpointSlice{
ObjectMeta: metav1.ObjectMeta{
Name: "endpointslice-metadata",
Namespace: ns.GetName(),
},
AddressType: discoveryv1.AddressTypeIPv4,
Endpoints: []discoveryv1.Endpoint{
{
Addresses: []string{"10.10.1.1"},
},
},
Ports: []discoveryv1.EndpointPort{
{
Name: pointer.StringPtr("foo"),
Port: pointer.Int32Ptr(9999),
},
},
}
}

EventuallyCreation(func() (err error) {
return k8sClient.Create(context.TODO(), eps)
}).Should(Succeed())
Expand All @@ -276,7 +307,7 @@ var _ = Describe("adding metadata to Service objects", func() {
Eventually(func() (ok bool) {
Expect(k8sClient.Get(context.TODO(), types.NamespacedName{Name: eps.GetName(), Namespace: ns.GetName()}, eps)).Should(Succeed())
for k, v := range tnt.Spec.ServiceOptions.AdditionalMetadata.Annotations {
ok, _ = HaveKeyWithValue(k, v).Match(eps.Annotations)
ok, _ = HaveKeyWithValue(k, v).Match(eps.GetAnnotations())
if !ok {
return false
}
Expand All @@ -289,7 +320,7 @@ var _ = Describe("adding metadata to Service objects", func() {
Eventually(func() (ok bool) {
Expect(k8sClient.Get(context.TODO(), types.NamespacedName{Name: eps.GetName(), Namespace: ns.GetName()}, eps)).Should(Succeed())
for k, v := range tnt.Spec.ServiceOptions.AdditionalMetadata.Labels {
ok, _ = HaveKeyWithValue(k, v).Match(eps.Labels)
ok, _ = HaveKeyWithValue(k, v).Match(eps.GetLabels())
if !ok {
return false
}
Expand Down

0 comments on commit 4a7f964

Please sign in to comment.