mirror of
https://github.com/projectcapsule/capsule.git
synced 2026-02-14 18:09:58 +00:00
test(e2e): aligning tests to new v1beta1 structure and ExternalName case
This commit is contained in:
108
e2e/disable_externalname_test.go
Normal file
108
e2e/disable_externalname_test.go
Normal file
@@ -0,0 +1,108 @@
|
||||
//+build e2e
|
||||
|
||||
// Copyright 2020-2021 Clastix Labs
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package e2e
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/util/intstr"
|
||||
"k8s.io/utils/pointer"
|
||||
|
||||
capsulev1beta1 "github.com/clastix/capsule/api/v1beta1"
|
||||
)
|
||||
|
||||
var _ = Describe("creating an ExternalName service when it is disabled for Tenant", func() {
|
||||
tnt := &capsulev1beta1.Tenant{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "disable-external-service",
|
||||
},
|
||||
Spec: capsulev1beta1.TenantSpec{
|
||||
Owners: capsulev1beta1.OwnerListSpec{
|
||||
{
|
||||
Name: "google",
|
||||
Kind: "User",
|
||||
},
|
||||
},
|
||||
ServiceOptions: &capsulev1beta1.ServiceOptions{
|
||||
AllowedServices: &capsulev1beta1.AllowedServices{
|
||||
ExternalName: pointer.BoolPtr(false),
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
JustBeforeEach(func() {
|
||||
EventuallyCreation(func() error {
|
||||
tnt.ResourceVersion = ""
|
||||
return k8sClient.Create(context.TODO(), tnt)
|
||||
}).Should(Succeed())
|
||||
})
|
||||
|
||||
JustAfterEach(func() {
|
||||
Expect(k8sClient.Delete(context.TODO(), tnt)).Should(Succeed())
|
||||
})
|
||||
|
||||
It("should fail creating a service with ExternalService type", func() {
|
||||
ns := NewNamespace("disable-external-service")
|
||||
NamespaceCreation(ns, tnt.Spec.Owners[0], defaultTimeoutInterval).Should(Succeed())
|
||||
|
||||
EventuallyCreation(func() error {
|
||||
svc := &corev1.Service{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "cluster-ip",
|
||||
Namespace: ns.GetName(),
|
||||
},
|
||||
Spec: corev1.ServiceSpec{
|
||||
Type: corev1.ServiceTypeClusterIP,
|
||||
Ports: []corev1.ServicePort{
|
||||
{
|
||||
Port: 8888,
|
||||
TargetPort: intstr.IntOrString{
|
||||
Type: intstr.Int,
|
||||
IntVal: 8888,
|
||||
},
|
||||
Protocol: corev1.ProtocolTCP,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
cs := ownerClient(tnt.Spec.Owners[0])
|
||||
_, err := cs.CoreV1().Services(ns.Name).Create(context.Background(), svc, metav1.CreateOptions{})
|
||||
return err
|
||||
}).Should(Succeed())
|
||||
|
||||
EventuallyCreation(func() error {
|
||||
svc := &corev1.Service{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "disable-external-service",
|
||||
Namespace: ns.GetName(),
|
||||
},
|
||||
Spec: corev1.ServiceSpec{
|
||||
Type: corev1.ServiceTypeExternalName,
|
||||
Ports: []corev1.ServicePort{
|
||||
{
|
||||
Port: 9999,
|
||||
TargetPort: intstr.IntOrString{
|
||||
Type: intstr.Int,
|
||||
IntVal: 9999,
|
||||
},
|
||||
Protocol: corev1.ProtocolTCP,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
cs := ownerClient(tnt.Spec.Owners[0])
|
||||
_, err := cs.CoreV1().Services(ns.Name).Create(context.Background(), svc, metav1.CreateOptions{})
|
||||
return err
|
||||
}).ShouldNot(Succeed())
|
||||
})
|
||||
})
|
||||
@@ -30,7 +30,11 @@ var _ = Describe("creating a nodePort service when it is disabled for Tenant", f
|
||||
Kind: "User",
|
||||
},
|
||||
},
|
||||
EnableNodePorts: pointer.BoolPtr(false),
|
||||
ServiceOptions: &capsulev1beta1.ServiceOptions{
|
||||
AllowedServices: &capsulev1beta1.AllowedServices{
|
||||
NodePort: pointer.BoolPtr(false),
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@@ -33,14 +33,16 @@ var _ = Describe("adding metadata to Service objects", func() {
|
||||
Kind: "User",
|
||||
},
|
||||
},
|
||||
ServicesMetadata: &capsulev1beta1.AdditionalMetadataSpec{
|
||||
AdditionalLabels: map[string]string{
|
||||
"k8s.io/custom-label": "foo",
|
||||
"clastix.io/custom-label": "bar",
|
||||
},
|
||||
AdditionalAnnotations: map[string]string{
|
||||
"k8s.io/custom-annotation": "bizz",
|
||||
"clastix.io/custom-annotation": "buzz",
|
||||
ServiceOptions: &capsulev1beta1.ServiceOptions{
|
||||
AdditionalMetadata: &capsulev1beta1.AdditionalMetadataSpec{
|
||||
AdditionalLabels: map[string]string{
|
||||
"k8s.io/custom-label": "foo",
|
||||
"clastix.io/custom-label": "bar",
|
||||
},
|
||||
AdditionalAnnotations: map[string]string{
|
||||
"k8s.io/custom-annotation": "bizz",
|
||||
"clastix.io/custom-annotation": "buzz",
|
||||
},
|
||||
},
|
||||
},
|
||||
AdditionalRoleBindings: []capsulev1beta1.AdditionalRoleBindingsSpec{
|
||||
@@ -98,7 +100,7 @@ var _ = Describe("adding metadata to Service objects", func() {
|
||||
By("checking additional labels", func() {
|
||||
Eventually(func() (ok bool) {
|
||||
Expect(k8sClient.Get(context.TODO(), types.NamespacedName{Name: svc.GetName(), Namespace: ns.GetName()}, svc)).Should(Succeed())
|
||||
for k, v := range tnt.Spec.ServicesMetadata.AdditionalLabels {
|
||||
for k, v := range tnt.Spec.ServiceOptions.AdditionalMetadata.AdditionalLabels {
|
||||
ok, _ = HaveKeyWithValue(k, v).Match(svc.Labels)
|
||||
if !ok {
|
||||
return false
|
||||
@@ -110,7 +112,7 @@ var _ = Describe("adding metadata to Service objects", func() {
|
||||
By("checking additional annotations", func() {
|
||||
Eventually(func() (ok bool) {
|
||||
Expect(k8sClient.Get(context.TODO(), types.NamespacedName{Name: svc.GetName(), Namespace: ns.GetName()}, svc)).Should(Succeed())
|
||||
for k, v := range tnt.Spec.ServicesMetadata.AdditionalAnnotations {
|
||||
for k, v := range tnt.Spec.ServiceOptions.AdditionalMetadata.AdditionalAnnotations {
|
||||
ok, _ = HaveKeyWithValue(k, v).Match(svc.Annotations)
|
||||
if !ok {
|
||||
return false
|
||||
@@ -153,7 +155,7 @@ var _ = Describe("adding metadata to Service objects", func() {
|
||||
By("checking additional labels", func() {
|
||||
Eventually(func() (ok bool) {
|
||||
Expect(k8sClient.Get(context.TODO(), types.NamespacedName{Name: ep.GetName(), Namespace: ns.GetName()}, ep)).Should(Succeed())
|
||||
for k, v := range tnt.Spec.ServicesMetadata.AdditionalLabels {
|
||||
for k, v := range tnt.Spec.ServiceOptions.AdditionalMetadata.AdditionalLabels {
|
||||
ok, _ = HaveKeyWithValue(k, v).Match(ep.Labels)
|
||||
if !ok {
|
||||
return false
|
||||
@@ -165,7 +167,7 @@ var _ = Describe("adding metadata to Service objects", func() {
|
||||
By("checking additional annotations", func() {
|
||||
Eventually(func() (ok bool) {
|
||||
Expect(k8sClient.Get(context.TODO(), types.NamespacedName{Name: ep.GetName(), Namespace: ns.GetName()}, ep)).Should(Succeed())
|
||||
for k, v := range tnt.Spec.ServicesMetadata.AdditionalAnnotations {
|
||||
for k, v := range tnt.Spec.ServiceOptions.AdditionalMetadata.AdditionalAnnotations {
|
||||
ok, _ = HaveKeyWithValue(k, v).Match(ep.Annotations)
|
||||
if !ok {
|
||||
return false
|
||||
@@ -212,7 +214,7 @@ var _ = Describe("adding metadata to Service objects", func() {
|
||||
By("checking additional annotations EndpointSlice", 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.ServicesMetadata.AdditionalAnnotations {
|
||||
for k, v := range tnt.Spec.ServiceOptions.AdditionalMetadata.AdditionalAnnotations {
|
||||
ok, _ = HaveKeyWithValue(k, v).Match(eps.Annotations)
|
||||
if !ok {
|
||||
return false
|
||||
@@ -224,7 +226,7 @@ var _ = Describe("adding metadata to Service objects", func() {
|
||||
By("checking additional labels on EndpointSlice", 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.ServicesMetadata.AdditionalLabels {
|
||||
for k, v := range tnt.Spec.ServiceOptions.AdditionalMetadata.AdditionalLabels {
|
||||
ok, _ = HaveKeyWithValue(k, v).Match(eps.Labels)
|
||||
if !ok {
|
||||
return false
|
||||
|
||||
Reference in New Issue
Block a user