Skip to content

Commit

Permalink
update envtest
Browse files Browse the repository at this point in the history
  • Loading branch information
randmonkey committed Aug 23, 2024
1 parent 41fd3a1 commit c0dd220
Showing 1 changed file with 2 additions and 51 deletions.
53 changes: 2 additions & 51 deletions test/envtest/kongupstreampolicy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -455,16 +455,12 @@ func TestKongUpstreamPolicyNotReferencedInReconciledIngress(t *testing.T) {
logger := zapr.NewLogger(zap.NewNop())
ctrl.SetLogger(logger)

diagPort := helpers.GetFreePort(t)
ns := CreateNamespace(ctx, t, ctrlClient)
RunManager(ctx, t, envcfg,
AdminAPIOptFns(),
WithPublishService(ns.Name),
WithIngressClass(ingressClassName),
WithGatewayFeatureEnabled,
WithGatewayAPIControllers(),
WithProxySyncSeconds(0.10),
WithDiagnosticsServer(diagPort),
)

t.Log("creating a KongUpstreamPolicy")
Expand All @@ -481,63 +477,18 @@ func TestKongUpstreamPolicyNotReferencedInReconciledIngress(t *testing.T) {
}
require.NoError(t, ctrlClient.Create(ctx, kup))

t.Log("deploying a minimal HTTP container deployment to test Ingress routes")
container := generators.NewContainer("httpbin", test.HTTPBinImage, test.HTTPBinPort)
deployment := generators.NewDeploymentForContainer(container)
deployment.Spec.Template.Spec.Containers[0].Ports[0].Name = "http"
deployment.Namespace = ns.Name
require.NoError(t, ctrlClient.Create(ctx, deployment))

service := generators.NewServiceForDeployment(deployment, corev1.ServiceTypeLoadBalancer)
service := generators.NewServiceForDeployment(deployment, corev1.ServiceTypeClusterIP)
service.Namespace = ns.Name
service.Annotations = map[string]string{
kongv1beta1.KongUpstreamPolicyAnnotationKey: KongUpstreamPolicyName,
}
t.Logf("exposing deployment %s via service %s", deployment.Name, service.Name)
t.Logf("Creating a Service %s with the KongUpstreamPolicy and used as backend of Ingress", service.Name)
require.NoError(t, ctrlClient.Create(ctx, service))

pod := corev1.Pod{
ObjectMeta: metav1.ObjectMeta{
Name: "pod-1",
Namespace: ns.Name,
Labels: map[string]string{
"app": "httpbin",
},
},
Spec: corev1.PodSpec{
Containers: []corev1.Container{
func() corev1.Container {
c := generators.NewContainer("httpbin", test.HTTPBinImage, test.HTTPBinPort)
c.Ports[0].Name = "http"
return c
}(),
},
},
}
require.NoError(t, ctrlClient.Create(ctx, &pod))

es := discoveryv1.EndpointSlice{
ObjectMeta: metav1.ObjectMeta{
Name: uuid.NewString(),
Namespace: ns.Name,
Labels: map[string]string{
"kubernetes.io/service-name": service.Name,
},
},
AddressType: discoveryv1.AddressTypeIPv4,
Endpoints: []discoveryv1.Endpoint{
{
Addresses: []string{"10.0.0.1"},
Conditions: discoveryv1.EndpointConditions{
Ready: lo.ToPtr(true),
Terminating: lo.ToPtr(false),
},
TargetRef: testPodReference("pod-1", ns.Name),
},
},
Ports: builder.NewEndpointPort(80).WithName("http").IntoSlice(),
}
require.NoError(t, ctrlClient.Create(ctx, &es))
// KongUpstreamPolicy should not be reconciled when no reconciled Ingresses/HTTPRoutes reference it.
alterIngress := &netv1.Ingress{
ObjectMeta: metav1.ObjectMeta{
Expand Down

0 comments on commit c0dd220

Please sign in to comment.