Skip to content
This repository has been archived by the owner on Dec 16, 2024. It is now read-only.

Commit

Permalink
GH-311 gateway status instead of ocm api calls
Browse files Browse the repository at this point in the history
  • Loading branch information
maksymvavilov committed Sep 1, 2023
1 parent 2db61d7 commit dc9e23d
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 12 deletions.
19 changes: 13 additions & 6 deletions pkg/controllers/dnspolicy/dnspolicy_dnsrecords.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package dnspolicy
import (
"context"
"fmt"
"strings"

k8serrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/labels"
Expand Down Expand Up @@ -46,13 +47,9 @@ func (r *DNSPolicyReconciler) reconcileGatewayDNSRecords(ctx context.Context, ga
return err
}

placed, err := r.Placement.GetPlacedClusters(ctx, gateway)
if err != nil {
return err
}
clusters := placed.UnsortedList()
clusters := getPlacedClusters(gateway)

log.V(3).Info("checking gateway for attached routes ", "gateway", gateway.Name, "clusters", placed)
log.V(3).Info("checking gateway for attached routes ", "gateway", gateway.Name, "clusters", clusters)

for _, listener := range gateway.Spec.Listeners {
var clusterGateways []dns.ClusterGateway
Expand Down Expand Up @@ -135,3 +132,13 @@ func (r *DNSPolicyReconciler) deleteGatewayDNSRecords(ctx context.Context, gatew
}
return nil
}

func getPlacedClusters(gateway *gatewayv1beta1.Gateway) []string {
var clusters []string

for _, address := range gateway.Status.Addresses {
clusters = append(clusters, strings.Split(address.Value, "/")[0])
}

return clusters
}
38 changes: 32 additions & 6 deletions test/integration/dnspolicy_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/Kuadrant/multicluster-gateway-controller/pkg/apis/v1alpha1"
. "github.com/Kuadrant/multicluster-gateway-controller/pkg/controllers/dnspolicy"
"github.com/Kuadrant/multicluster-gateway-controller/pkg/dns"
testutil "github.com/Kuadrant/multicluster-gateway-controller/test/util"
)

func testBuildManagedZone(domainName, ns string) *v1alpha1.ManagedZone {
Expand Down Expand Up @@ -84,6 +85,15 @@ func testBuildGateway(gwName, gwClassName, hostname, ns string) *gatewayv1beta1.
}
}

func testBuildGatewayAddresses() []gatewayv1beta1.GatewayAddress {
return []gatewayv1beta1.GatewayAddress{
{
Type: testutil.Pointer(gatewayv1beta1.IPAddressType),
Value: TestPlacedClusterName,
},
}
}

func testBuildDNSPolicyWithHealthCheck(policyName, gwName, ns string) *v1alpha1.DNSPolicy {
typedNamespace := gatewayv1beta1.Namespace(ns)
protocol := v1alpha1.HttpProtocol
Expand Down Expand Up @@ -195,10 +205,12 @@ var _ = Describe("DNSPolicy", Ordered, func() {

Context("gateway placed", func() {
var gateway *gatewayv1beta1.Gateway
var lbHash, dnsRecordName, wildcardDNSRecordName string
var lbHash string
var dnsRecordName string
var wildcardDNSRecordName string

BeforeEach(func() {
gateway = testBuildGateway(TestPlacedGatewayName, gatewayClass.Name, TestAttachedRouteName, testNamespace)
gateway = testBuildGateway(TestPlacedGatewayName, testutil.DummyCRName, TestAttachedRouteName, testNamespace)
lbHash = dns.ToBase36hash(fmt.Sprintf("%s-%s", gateway.Name, gateway.Namespace))
dnsRecordName = fmt.Sprintf("%s-%s", TestPlacedGatewayName, TestAttachedRouteName)
wildcardDNSRecordName = fmt.Sprintf("%s-%s", TestPlacedGatewayName, TestWildCardListenerName)
Expand All @@ -207,6 +219,14 @@ var _ = Describe("DNSPolicy", Ordered, func() {
if err := k8sClient.Get(ctx, client.ObjectKey{Name: gateway.Name, Namespace: gateway.Namespace}, gateway); err != nil {
return false
}

// TODO remove the workaround during https://github.com/Kuadrant/multicluster-gateway-controller/issues/330
// also use a proper gateway class
gateway.Status.Addresses = testBuildGatewayAddresses()
if err := k8sClient.Status().Update(ctx, gateway); err != nil {
return false
}

return true
}, TestTimeoutMedium, TestRetryIntervalMedium).Should(BeTrue())
})
Expand Down Expand Up @@ -278,7 +298,6 @@ var _ = Describe("DNSPolicy", Ordered, func() {
},
}
Eventually(func() bool { // DNS record exists

if err := k8sClient.Get(ctx, client.ObjectKey{Name: dnsRecordName, Namespace: testNamespace}, createdDNSRecord); err != nil {
return false
}
Expand Down Expand Up @@ -665,11 +684,10 @@ var _ = Describe("DNSPolicy", Ordered, func() {
Context("gateway not placed", func() {
var gateway *gatewayv1beta1.Gateway
var dnsPolicy *v1alpha1.DNSPolicy
testGatewayName := "test-not-placed-gateway"

BeforeEach(func() {
gateway = testBuildGateway(testGatewayName, gatewayClass.Name, TestAttachedRouteName, testNamespace)
dnsPolicy = testBuildDNSPolicyWithHealthCheck("test-dns-policy", testGatewayName, testNamespace)
gateway = testBuildGateway("test-not-placed-gateway", testutil.DummyCRName, TestAttachedRouteName, testNamespace)
dnsPolicy = testBuildDNSPolicyWithHealthCheck("test-dns-policy", "test-not-placed-gateway", testNamespace)

Expect(k8sClient.Create(ctx, gateway)).To(BeNil())
Expect(k8sClient.Create(ctx, dnsPolicy)).To(BeNil())
Expand All @@ -685,6 +703,14 @@ var _ = Describe("DNSPolicy", Ordered, func() {
if err := k8sClient.Get(ctx, client.ObjectKey{Name: gateway.Name, Namespace: gateway.Namespace}, gateway); err != nil {
return false
}

// TODO remove the workaround during https://github.com/Kuadrant/multicluster-gateway-controller/issues/330
// also use a proper gateway class
gateway.Status.Addresses = testBuildGatewayAddresses()
if err := k8sClient.Status().Update(ctx, gateway); err != nil {
return false
}

return true
}, TestTimeoutMedium, TestRetryIntervalMedium).Should(BeTrue())

Expand Down

0 comments on commit dc9e23d

Please sign in to comment.