diff --git a/test/envtest/dynamic_env_test.go b/test/envtest/dynamic_env_test.go index 83b7b10e..c91b1382 100644 --- a/test/envtest/dynamic_env_test.go +++ b/test/envtest/dynamic_env_test.go @@ -25,7 +25,7 @@ var _ = Describe("dynamic environment variables", Ordered, func() { testSupport.SetMockOperandMetricsReportReady(true) ns := &core.Namespace{ ObjectMeta: meta.ObjectMeta{ - Name: "test2-namespace", + Name: "dynamic-env-test-namespace", }, } Expect(s.k8sClient.Create(context.TODO(), ns)).To(Succeed()) diff --git a/test/envtest/https_test.go b/test/envtest/https_test.go new file mode 100644 index 00000000..e7a5ee72 --- /dev/null +++ b/test/envtest/https_test.go @@ -0,0 +1,89 @@ +package envtest + +import ( + "context" + ar "github.com/Apicurio/apicurio-registry-operator/api/v1" + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" + core "k8s.io/api/core/v1" + meta "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/types" + "k8s.io/apimachinery/pkg/util/intstr" + "time" +) + +var _ = Describe("operator configuring https", Ordered, func() { + + var registry *ar.ApicurioRegistry + //var registryKey types.NamespacedName + var secretKey types.NamespacedName + var serviceKey types.NamespacedName + + BeforeAll(func() { + const registryName = "test" + // Consistency in case the specs are reordered + testSupport.SetMockCanMakeHTTPRequestToOperand(false) + testSupport.SetMockOperandMetricsReportReady(false) + ns := &core.Namespace{ + ObjectMeta: meta.ObjectMeta{ + Name: "https-test-namespace", + }, + } + Expect(s.k8sClient.Create(context.TODO(), ns)).To(Succeed()) + secretKey = types.NamespacedName{Namespace: ns.ObjectMeta.Name, Name: registryName + "-https-secret"} + secret := &core.Secret{ + ObjectMeta: meta.ObjectMeta{ + Name: secretKey.Name, + Namespace: secretKey.Namespace, + }, + Data: map[string][]byte{ + "tls.crt": []byte("LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSURaVENDQWsyZ0F3SUJBZ0lVQktQYTZzcTRTN0NnWHY0QWxnNDVpS205cTV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npxZFdvZ3I5b2NBL0R1aWNKWTBTc0pGd0tkdCtJZWtEdEF3UWx4eUgxdTBJUnI0ZTd2dWcKZkFQOXZCdEJyclZzbEJTL2JDMDZjNHJSdXJPK05zSDhWN2NqeUZNNUFkSXNtMlJjcDZpYndveFJBb0dCQU1iKwpTdjFXdlpTZDNTNFNtQmt5R1VuN1lBSHZ2aDQ3YmhKdVB6QU5UUkx1Y2J6SkhHdXoxVkc1MVBvMkh5UnNmQ1IxCkoxODFCenJjdnVMT1dGV0RMYjNucDRrOC9waVJ5ODd3cVBsekcyTGsxTi9qZWFxb2Z3bmZNejlXMStqTHJvMG8Kdnl6VGJoTmlsdG9EOTlZZEZWdkdNNTRZeHBmN0pjTHF4d1pQWmloOUFvR0JBTkFJZTJQSXdGVklCV3dFaVhHdgo2N2FPTXVpOTUxelF4MER0ZkI1QXRJRXl2SThGOSt3LzJqdWNhcnZBS2xmN2k1b0Y3ak1mZ2cxeEwzWlZmOTl1ClF4NlcxY04wQUJkYTdMWUhYVElpUlZvd0VEZ2J1T0FzNU1YSk05WHRsdWYxcFVkemlTWjVPYUtkQkpySFNUWHIKS05PMFBKUTJ5Rjc0bXFCYTNkeHMzKy9tCi0tLS0tRU5EIFBSSVZBVEUgS0VZLS0tLS0K"), + }, + } + Expect(s.k8sClient.Create(context.TODO(), secret)).To(Succeed()) + registry = &ar.ApicurioRegistry{ + ObjectMeta: meta.ObjectMeta{ + Name: registryName, + Namespace: ns.ObjectMeta.Name, + }, + Spec: ar.ApicurioRegistrySpec{ + Configuration: ar.ApicurioRegistrySpecConfiguration{ + Security: ar.ApicurioRegistrySpecConfigurationSecurity{ + Https: ar.ApicurioRegistrySpecConfigurationSecurityHttps{ + SecretName: secretKey.Name, + }, + }, + }, + }, + } + Expect(s.k8sClient.Create(s.ctx, registry)).To(Succeed()) + //registryKey = types.NamespacedName{Namespace: registry.Namespace, Name: registry.Name} + }) + + // TODO Add tests for other resources. This specifically tests issue #149. + It("should create a service", func() { + service := &core.Service{} + serviceKey = types.NamespacedName{Namespace: registry.Namespace, Name: registry.Name + "-service"} + Eventually(func() []core.ServicePort { + if err := s.k8sClient.Get(s.ctx, serviceKey, service); err == nil { + return service.Spec.Ports + } else { + return []core.ServicePort{} + } + }, 10*time.Second*T_SCALE, EVENTUALLY_CHECK_PERIOD).Should(ConsistOf( + core.ServicePort{ + Name: "https", + Protocol: core.ProtocolTCP, + Port: 8443, + TargetPort: intstr.FromInt(8443), + }, + core.ServicePort{ + Name: "http", + Protocol: core.ProtocolTCP, + Port: 8080, + TargetPort: intstr.FromInt(8080), + }, + )) + }) +}) diff --git a/test/envtest/simple_deploy_test.go b/test/envtest/simple_deploy_test.go index a2db69c5..9519c82e 100644 --- a/test/envtest/simple_deploy_test.go +++ b/test/envtest/simple_deploy_test.go @@ -15,6 +15,7 @@ import ( "k8s.io/apimachinery/pkg/api/errors" meta "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" + "k8s.io/apimachinery/pkg/util/intstr" "time" ) @@ -34,7 +35,7 @@ var _ = Describe("operator processing a simple spec", Ordered, func() { testSupport.SetMockOperandMetricsReportReady(false) ns := &core.Namespace{ ObjectMeta: meta.ObjectMeta{ - Name: "test-namespace", + Name: "simple-deploy-test-namespace", }, } Expect(s.k8sClient.Create(context.TODO(), ns)).To(Succeed()) @@ -81,6 +82,15 @@ var _ = Describe("operator processing a simple spec", Ordered, func() { Eventually(func() error { return s.k8sClient.Get(s.ctx, serviceKey, service) }, 10*time.Second*T_SCALE, EVENTUALLY_CHECK_PERIOD).Should(Succeed()) + // Issue #149 + Expect(service.Spec.Ports).Should(ConsistOf( + core.ServicePort{ + Name: "http", + Protocol: core.ProtocolTCP, + Port: 8080, + TargetPort: intstr.FromInt(8080), + }, + )) }) It("should create an ingress", func() {