Remove dependency of https://grpcb.in

This commit is contained in:
Manuel Alejandro de Brito Fontes 2020-02-13 11:49:00 -03:00
parent acd5b4c852
commit b4dba519fc
5 changed files with 121 additions and 10 deletions

View file

@ -39,9 +39,11 @@ import (
var _ = framework.IngressNginxDescribe("Annotations - GRPC", func() {
f := framework.NewDefaultFramework("grpc")
It("should use grpc_pass in the configuration file", func() {
BeforeEach(func() {
f.NewGRPCFortuneTellerDeployment()
})
It("should use grpc_pass in the configuration file", func() {
host := "grpc"
annotations := map[string]string{
@ -65,15 +67,19 @@ var _ = framework.IngressNginxDescribe("Annotations - GRPC", func() {
})
It("should return OK for service with backend protocol GRPC", func() {
Skip("GRPC test temporarily disabled")
f.NewGRPCBinDeployment()
host := "echo"
svc := &core.Service{
ObjectMeta: metav1.ObjectMeta{
Name: "grpcbin",
Name: "grpcbin-test",
Namespace: f.Namespace,
},
Spec: corev1.ServiceSpec{
ExternalName: "grpcb.in",
ExternalName: fmt.Sprintf("grpcbin.%v.svc.cluster.local", f.Namespace),
Type: corev1.ServiceTypeExternalName,
Ports: []corev1.ServicePort{
{
@ -91,7 +97,7 @@ var _ = framework.IngressNginxDescribe("Annotations - GRPC", func() {
"nginx.ingress.kubernetes.io/backend-protocol": "GRPC",
}
ing := framework.NewSingleIngressWithTLS(host, "/", host, []string{host}, f.Namespace, "grpcbin", 9000, annotations)
ing := framework.NewSingleIngressWithTLS(host, "/", host, []string{host}, f.Namespace, "grpcbin-test", 9000, annotations)
f.EnsureIngress(ing)
@ -121,15 +127,19 @@ var _ = framework.IngressNginxDescribe("Annotations - GRPC", func() {
})
It("should return OK for service with backend protocol GRPCS", func() {
Skip("GRPC test temporarily disabled")
f.NewGRPCBinDeployment()
host := "echo"
svc := &core.Service{
ObjectMeta: metav1.ObjectMeta{
Name: "grpcbin",
Name: "grpcbin-test",
Namespace: f.Namespace,
},
Spec: corev1.ServiceSpec{
ExternalName: "grpcb.in",
ExternalName: fmt.Sprintf("grpcbin.%v.svc.cluster.local", f.Namespace),
Type: corev1.ServiceTypeExternalName,
Ports: []corev1.ServicePort{
{
@ -153,7 +163,7 @@ var _ = framework.IngressNginxDescribe("Annotations - GRPC", func() {
`,
}
ing := framework.NewSingleIngressWithTLS(host, "/", host, []string{host}, f.Namespace, "grpcbin", 9001, annotations)
ing := framework.NewSingleIngressWithTLS(host, "/", host, []string{host}, f.Namespace, "grpcbin-test", 9001, annotations)
f.EnsureIngress(ing)
f.WaitForNginxServer(host,

View file

@ -174,6 +174,102 @@ server {
Expect(err).NotTo(HaveOccurred(), "failed to wait for endpoints to become ready")
}
// NewGRPCBinDeployment creates a new deployment of the
// moul/grpcbin image for GRPC tests
func (f *Framework) NewGRPCBinDeployment() {
name := "grpcbin"
probe := &corev1.Probe{
InitialDelaySeconds: 5,
PeriodSeconds: 10,
SuccessThreshold: 2,
TimeoutSeconds: 1,
Handler: corev1.Handler{
TCPSocket: &corev1.TCPSocketAction{
Port: intstr.FromInt(9000),
},
},
}
deployment := &appsv1.Deployment{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: f.Namespace,
},
Spec: appsv1.DeploymentSpec{
Replicas: NewInt32(1),
Selector: &metav1.LabelSelector{
MatchLabels: map[string]string{
"app": name,
},
},
Template: corev1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Labels: map[string]string{
"app": name,
},
},
Spec: corev1.PodSpec{
TerminationGracePeriodSeconds: NewInt64(0),
Containers: []corev1.Container{
{
Name: name,
Image: "moul/grpcbin",
Ports: []corev1.ContainerPort{
{
Name: "insecure",
ContainerPort: 9000,
},
{
Name: "secure",
ContainerPort: 9001,
},
},
ReadinessProbe: probe,
LivenessProbe: probe,
},
},
},
},
},
}
d := f.EnsureDeployment(deployment)
Expect(d).NotTo(BeNil(), "expected a deployment but none returned")
service := &corev1.Service{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: f.Namespace,
},
Spec: corev1.ServiceSpec{
Ports: []corev1.ServicePort{
{
Name: "insecure",
Port: 9000,
TargetPort: intstr.FromInt(9000),
Protocol: corev1.ProtocolTCP,
},
{
Name: "secure",
Port: 9001,
TargetPort: intstr.FromInt(9000),
Protocol: corev1.ProtocolTCP,
},
},
Selector: map[string]string{
"app": name,
},
},
}
s := f.EnsureService(service)
Expect(s).NotTo(BeNil(), "expected a service but none returned")
err := WaitForEndpoints(f.KubeClientSet, DefaultTimeout, name, f.Namespace, 1)
Expect(err).NotTo(HaveOccurred(), "failed to wait for endpoints to become ready")
}
func newDeployment(name, namespace, image string, port int32, replicas int32, command []string,
volumeMounts []corev1.VolumeMount, volumes []corev1.Volume) *appsv1.Deployment {
probe := &corev1.Probe{

View file

@ -104,7 +104,7 @@ func (f *Framework) BeforeEach() {
// AfterEach deletes the namespace, after reading its events.
func (f *Framework) AfterEach() {
err := DeleteKubeNamespace(f.KubeClientSet, f.Namespace)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
gomega.Expect(err).NotTo(gomega.HaveOccurred(), "unexpected error deleting namespace %v", f.Namespace)
if ginkgo.CurrentGinkgoTestDescription().Failed {
log, err := f.NginxLogs()

View file

@ -117,7 +117,12 @@ func CreateKubeNamespace(baseName string, c kubernetes.Interface) (string, error
// DeleteKubeNamespace deletes a namespace and all the objects inside
func DeleteKubeNamespace(c kubernetes.Interface, namespace string) error {
return c.CoreV1().Namespaces().Delete(namespace, metav1.NewDeleteOptions(0))
grace := int64(0)
pb := metav1.DeletePropagationBackground
return c.CoreV1().Namespaces().Delete(namespace, &metav1.DeleteOptions{
GracePeriodSeconds: &grace,
PropagationPolicy: &pb,
})
}
// ExpectNoError tests whether an error occurred.

View file

@ -115,7 +115,7 @@ var _ = framework.IngressNginxDescribe("Shutdown ingress controller", func() {
case res := <-result:
Expect(res.errs).Should(BeEmpty())
Expect(res.status).To(Equal(http.StatusOK), "expecting a valid response from HTTP request")
Expect(time.Since(startTime).Seconds()).To(BeNumerically(">", 70), "waiting shutdown")
Expect(time.Since(startTime).Seconds()).To(BeNumerically(">", 60), "waiting shutdown")
ticker.Stop()
return
case <-ticker.C: