Skip to content

Commit

Permalink
tests: Use inmemory provider backed managed zones
Browse files Browse the repository at this point in the history
Update all DNSPolicy integration tests to use the inmemory provider. If
the dns operator is running on the target cluster managedzones and
dnsrecords should work as if they are targeting a real DNS Provider.
  • Loading branch information
mikenairn committed May 29, 2024
1 parent 0e2a9d6 commit 73d4654
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 7 deletions.
22 changes: 21 additions & 1 deletion controllers/dnspolicy_controller_multi_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ package controllers
import (
"context"
"fmt"
"time"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
. "github.com/onsi/gomega/gstruct"
externaldns "sigs.k8s.io/external-dns/endpoint"

v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/utils/ptr"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand All @@ -27,6 +29,7 @@ import (
var _ = Describe("DNSPolicy Multi Cluster", func() {

var gatewayClass *gatewayapiv1.GatewayClass
var dnsProviderSecret *v1.Secret
var managedZone *kuadrantdnsv1alpha1.ManagedZone
var testNamespace string
var gateway *gatewayapiv1.Gateway
Expand All @@ -45,8 +48,21 @@ var _ = Describe("DNSPolicy Multi Cluster", func() {
gatewayClass = testBuildGatewayClass("gwc-"+testNamespace, "default", "kuadrant.io/bar")
Expect(k8sClient.Create(ctx, gatewayClass)).To(Succeed())

managedZone = testBuildManagedZone("mz-example-com", testNamespace, "example.com")
dnsProviderSecret = testBuildInMemoryCredentialsSecret("inmemory-credentials", testNamespace)
managedZone = testBuildManagedZone("mz-example-com", testNamespace, "example.com", dnsProviderSecret.Name)
Expect(k8sClient.Create(ctx, dnsProviderSecret)).To(Succeed())
Expect(k8sClient.Create(ctx, managedZone)).To(Succeed())
Eventually(func(g Gomega) {
err := k8sClient.Get(ctx, client.ObjectKeyFromObject(managedZone), managedZone)
g.Expect(err).NotTo(HaveOccurred())
g.Expect(managedZone.Status.Conditions).To(
ContainElement(MatchFields(IgnoreExtras, Fields{
"Type": Equal(string(kuadrantdnsv1alpha1.ConditionTypeReady)),
"Status": Equal(metav1.ConditionTrue),
"ObservedGeneration": Equal(managedZone.Generation),
})),
)
}, TestTimeoutMedium, time.Second).Should(Succeed())

gateway = NewGatewayBuilder(TestGatewayName, gatewayClass.Name, testNamespace).
WithHTTPListener(TestListenerNameOne, TestHostOne).
Expand Down Expand Up @@ -119,6 +135,10 @@ var _ = Describe("DNSPolicy Multi Cluster", func() {
err := k8sClient.Delete(ctx, managedZone)
Expect(client.IgnoreNotFound(err)).ToNot(HaveOccurred())
}
if dnsProviderSecret != nil {
err := k8sClient.Delete(ctx, dnsProviderSecret)
Expect(client.IgnoreNotFound(err)).ToNot(HaveOccurred())
}
if gatewayClass != nil {
err := k8sClient.Delete(ctx, gatewayClass)
Expect(client.IgnoreNotFound(err)).ToNot(HaveOccurred())
Expand Down
22 changes: 21 additions & 1 deletion controllers/dnspolicy_controller_single_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ package controllers
import (
"context"
"fmt"
"time"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
. "github.com/onsi/gomega/gstruct"
externaldns "sigs.k8s.io/external-dns/endpoint"

v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/utils/ptr"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand All @@ -27,6 +29,7 @@ import (
var _ = Describe("DNSPolicy Single Cluster", func() {

var gatewayClass *gatewayapiv1.GatewayClass
var dnsProviderSecret *v1.Secret
var managedZone *kuadrantdnsv1alpha1.ManagedZone
var testNamespace string
var gateway *gatewayapiv1.Gateway
Expand All @@ -45,8 +48,21 @@ var _ = Describe("DNSPolicy Single Cluster", func() {
gatewayClass = testBuildGatewayClass("gwc-"+testNamespace, "default", "kuadrant.io/bar")
Expect(k8sClient.Create(ctx, gatewayClass)).To(Succeed())

managedZone = testBuildManagedZone("mz-example-com", testNamespace, "example.com")
dnsProviderSecret = testBuildInMemoryCredentialsSecret("inmemory-credentials", testNamespace)
managedZone = testBuildManagedZone("mz-example-com", testNamespace, "example.com", dnsProviderSecret.Name)
Expect(k8sClient.Create(ctx, dnsProviderSecret)).To(Succeed())
Expect(k8sClient.Create(ctx, managedZone)).To(Succeed())
Eventually(func(g Gomega) {
err := k8sClient.Get(ctx, client.ObjectKeyFromObject(managedZone), managedZone)
g.Expect(err).NotTo(HaveOccurred())
g.Expect(managedZone.Status.Conditions).To(
ContainElement(MatchFields(IgnoreExtras, Fields{
"Type": Equal(string(kuadrantdnsv1alpha1.ConditionTypeReady)),
"Status": Equal(metav1.ConditionTrue),
"ObservedGeneration": Equal(managedZone.Generation),
})),
)
}, TestTimeoutMedium, time.Second).Should(Succeed())

gateway = NewGatewayBuilder(TestGatewayName, gatewayClass.Name, testNamespace).
WithHTTPListener("foo", "foo.example.com").
Expand Down Expand Up @@ -113,6 +129,10 @@ var _ = Describe("DNSPolicy Single Cluster", func() {
err := k8sClient.Delete(ctx, managedZone)
Expect(client.IgnoreNotFound(err)).ToNot(HaveOccurred())
}
if dnsProviderSecret != nil {
err := k8sClient.Delete(ctx, dnsProviderSecret)
Expect(client.IgnoreNotFound(err)).ToNot(HaveOccurred())
}
if gatewayClass != nil {
err := k8sClient.Delete(ctx, gatewayClass)
Expect(client.IgnoreNotFound(err)).ToNot(HaveOccurred())
Expand Down
22 changes: 21 additions & 1 deletion controllers/dnspolicy_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
. "github.com/onsi/gomega/gstruct"

kuadrantdnsv1alpha1 "github.com/kuadrant/dns-operator/api/v1alpha1"
v1 "k8s.io/api/core/v1"
k8serrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/utils/ptr"
Expand All @@ -28,6 +29,7 @@ import (
var _ = Describe("DNSPolicy controller", func() {

var gatewayClass *gatewayapiv1.GatewayClass
var dnsProviderSecret *v1.Secret
var managedZone *kuadrantdnsv1alpha1.ManagedZone
var testNamespace string
var gateway *gatewayapiv1.Gateway
Expand All @@ -42,8 +44,22 @@ var _ = Describe("DNSPolicy controller", func() {
gatewayClass = testBuildGatewayClass("gwc-"+testNamespace, "default", "kuadrant.io/bar")
Expect(k8sClient.Create(ctx, gatewayClass)).To(Succeed())

managedZone = testBuildManagedZone("mz-example-com", testNamespace, "example.com")
dnsProviderSecret = testBuildInMemoryCredentialsSecret("inmemory-credentials", testNamespace)
managedZone = testBuildManagedZone("mz-example-com", testNamespace, "example.com", dnsProviderSecret.Name)
Expect(k8sClient.Create(ctx, dnsProviderSecret)).To(Succeed())
Expect(k8sClient.Create(ctx, managedZone)).To(Succeed())

Eventually(func(g Gomega) {
err := k8sClient.Get(ctx, client.ObjectKeyFromObject(managedZone), managedZone)
g.Expect(err).NotTo(HaveOccurred())
g.Expect(managedZone.Status.Conditions).To(
ContainElement(MatchFields(IgnoreExtras, Fields{
"Type": Equal(string(kuadrantdnsv1alpha1.ConditionTypeReady)),
"Status": Equal(metav1.ConditionTrue),
"ObservedGeneration": Equal(managedZone.Generation),
})),
)
}, TestTimeoutMedium, time.Second).Should(Succeed())
})

AfterEach(func() {
Expand All @@ -59,6 +75,10 @@ var _ = Describe("DNSPolicy controller", func() {
err := k8sClient.Delete(ctx, managedZone)
Expect(client.IgnoreNotFound(err)).ToNot(HaveOccurred())
}
if dnsProviderSecret != nil {
err := k8sClient.Delete(ctx, dnsProviderSecret)
Expect(client.IgnoreNotFound(err)).ToNot(HaveOccurred())
}
if gatewayClass != nil {
err := k8sClient.Delete(ctx, gatewayClass)
Expect(client.IgnoreNotFound(err)).ToNot(HaveOccurred())
Expand Down
16 changes: 13 additions & 3 deletions controllers/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -522,23 +522,33 @@ func testObjectDoesNotExist(obj client.Object) func() bool {

// DNS

func testBuildManagedZone(name, ns, domainName string) *kuadrantdnsv1alpha1.ManagedZone {
func testBuildManagedZone(name, ns, domainName, secretName string) *kuadrantdnsv1alpha1.ManagedZone {
return &kuadrantdnsv1alpha1.ManagedZone{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: ns,
},
Spec: kuadrantdnsv1alpha1.ManagedZoneSpec{
ID: "1234",
DomainName: domainName,
Description: domainName,
SecretRef: kuadrantdnsv1alpha1.ProviderRef{
Name: "secretname",
Name: secretName,
},
},
}
}

func testBuildInMemoryCredentialsSecret(name, ns string) *v1.Secret {
return &v1.Secret{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: ns,
},
Data: map[string][]byte{},
Type: "kuadrant.io/inmemory",
}
}

//Gateway

func testBuildGatewayClass(name, ns, controllerName string) *gatewayapiv1.GatewayClass {
Expand Down
18 changes: 17 additions & 1 deletion controllers/target_status_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ import (

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
. "github.com/onsi/gomega/gstruct"

certmanv1 "github.com/cert-manager/cert-manager/pkg/apis/certmanager/v1"
certmanmetav1 "github.com/cert-manager/cert-manager/pkg/apis/meta/v1"
authorinoapi "github.com/kuadrant/authorino/api/v1beta2"
kuadrantdnsv1alpha1 "github.com/kuadrant/dns-operator/api/v1alpha1"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/utils/ptr"
Expand Down Expand Up @@ -517,11 +519,25 @@ var _ = Describe("Target status reconciler", Ordered, func() {
}
}

var dnsProviderSecret *v1.Secret
var managedZone *kuadrantdnsv1alpha1.ManagedZone

BeforeEach(func(ctx SpecContext) {
managedZone = testBuildManagedZone("mz-toystore-com", testNamespace, "toystore.com")
dnsProviderSecret = testBuildInMemoryCredentialsSecret("inmemory-credentials", testNamespace)
managedZone = testBuildManagedZone("mz-toystore-com", testNamespace, "toystore.com", dnsProviderSecret.Name)
Expect(k8sClient.Create(ctx, dnsProviderSecret)).To(Succeed())
Expect(k8sClient.Create(ctx, managedZone)).To(Succeed())
Eventually(func(g Gomega) {
err := k8sClient.Get(ctx, client.ObjectKeyFromObject(managedZone), managedZone)
g.Expect(err).NotTo(HaveOccurred())
g.Expect(managedZone.Status.Conditions).To(
ContainElement(MatchFields(IgnoreExtras, Fields{
"Type": Equal(string(kuadrantdnsv1alpha1.ConditionTypeReady)),
"Status": Equal(metav1.ConditionTrue),
"ObservedGeneration": Equal(managedZone.Generation),
})),
)
}, TestTimeoutMedium, time.Second).Should(Succeed())
})

AfterEach(func(ctx SpecContext) {
Expand Down

0 comments on commit 73d4654

Please sign in to comment.