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.

Enable aws, google and inmemory providers in local deployment of dns
operator.
  • Loading branch information
mikenairn committed Jun 4, 2024
1 parent 6823ed0 commit ef9b749
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 7 deletions.
4 changes: 4 additions & 0 deletions config/dependencies/dns/deployment_patch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@
- op: replace
path: /spec/template/metadata/labels/control-plane
value: dns-operator-controller-manager

- op: add
path: /spec/template/spec/containers/0/args/-
value: --provider=aws,google,inmemory
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 @@ -28,6 +30,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 @@ -46,8 +49,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 @@ -120,6 +136,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 @@ -28,6 +30,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 @@ -46,8 +49,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 @@ -114,6 +130,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 @@ -29,6 +30,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 @@ -43,8 +45,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 @@ -60,6 +76,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 @@ -136,23 +136,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 @@ -521,11 +523,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 ef9b749

Please sign in to comment.