Skip to content

Commit

Permalink
common moved to utils
Browse files Browse the repository at this point in the history
  • Loading branch information
philbrookes committed Apr 16, 2024
1 parent 835aabf commit e773993
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 9 deletions.
9 changes: 5 additions & 4 deletions controllers/dnspolicy_controller_multi_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (

"github.com/kuadrant/kuadrant-operator/api/v1alpha1"
"github.com/kuadrant/kuadrant-operator/pkg/common"
"github.com/kuadrant/kuadrant-operator/pkg/library/utils"
"github.com/kuadrant/kuadrant-operator/pkg/multicluster"
)

Expand All @@ -38,10 +39,10 @@ var _ = Describe("DNSPolicy Multi Cluster", func() {
CreateNamespace(&testNamespace)

var err error
err, clusterID = common.GetClusterUID(ctx, k8sClient)
err, clusterID = utils.GetClusterUID(ctx, k8sClient)
Expect(err).To(BeNil())

clusterID = common.ToBase36HashLen(clusterID, common.ClusterIDLength)
clusterID = common.ToBase36HashLen(clusterID, utils.ClusterIDLength)

gatewayClass = testBuildGatewayClass("foo", "default", "kuadrant.io/bar")
Expect(k8sClient.Create(ctx, gatewayClass)).To(Succeed())
Expand All @@ -55,8 +56,8 @@ var _ = Describe("DNSPolicy Multi Cluster", func() {
Gateway
Expect(k8sClient.Create(ctx, gateway)).To(Succeed())

clusterOneIDHash = common.ToBase36HashLen(TestClusterNameOne, common.ClusterIDLength)
clusterTwoIDHash = common.ToBase36HashLen(TestClusterNameTwo, common.ClusterIDLength)
clusterOneIDHash = common.ToBase36HashLen(TestClusterNameOne, utils.ClusterIDLength)
clusterTwoIDHash = common.ToBase36HashLen(TestClusterNameTwo, utils.ClusterIDLength)
gwHash = common.ToBase36HashLen(gateway.Name+"-"+gateway.Namespace, 6)

//Set multi cluster gateway status
Expand Down
5 changes: 3 additions & 2 deletions controllers/dnspolicy_controller_single_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (

"github.com/kuadrant/kuadrant-operator/api/v1alpha1"
"github.com/kuadrant/kuadrant-operator/pkg/common"
"github.com/kuadrant/kuadrant-operator/pkg/library/utils"
)

var _ = Describe("DNSPolicy Single Cluster", func() {
Expand All @@ -37,10 +38,10 @@ var _ = Describe("DNSPolicy Single Cluster", func() {
CreateNamespace(&testNamespace)

var err error
err, clusterUID := common.GetClusterUID(ctx, k8sClient)
err, clusterUID := utils.GetClusterUID(ctx, k8sClient)
Expect(err).To(BeNil())

clusterID = common.ToBase36HashLen(clusterUID, common.ClusterIDLength)
clusterID = common.ToBase36HashLen(clusterUID, utils.ClusterIDLength)

gatewayClass = testBuildGatewayClass("foo", "default", "kuadrant.io/bar")
Expect(k8sClient.Create(ctx, gatewayClass)).To(Succeed())
Expand Down
2 changes: 1 addition & 1 deletion controllers/dnspolicy_dnsrecords.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (r *DNSPolicyReconciler) reconcileDNSRecords(ctx context.Context, dnsPolicy

func (r *DNSPolicyReconciler) reconcileGatewayDNSRecords(ctx context.Context, gw *gatewayapiv1.Gateway, dnsPolicy *v1alpha1.DNSPolicy) error {
log := crlog.FromContext(ctx)
err, clusterID := common.GetClusterUID(ctx, r.Client())
err, clusterID := utils.GetClusterUID(ctx, r.Client())
if err != nil {
return fmt.Errorf("failed to generate cluster ID: %w", err)
}
Expand Down
5 changes: 3 additions & 2 deletions pkg/multicluster/target.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/kuadrant/kuadrant-operator/api/v1alpha1"
"github.com/kuadrant/kuadrant-operator/pkg/common"
"github.com/kuadrant/kuadrant-operator/pkg/library/utils"
)

const (
Expand All @@ -33,7 +34,7 @@ func (t *GatewayTarget) GetName() string {
}

func (t *GatewayTarget) GetShortCode() string {
return common.ToBase36HashLen(t.GetName(), common.ClusterIDLength)
return common.ToBase36HashLen(t.GetName(), utils.ClusterIDLength)
}

// GroupTargetsByGeo groups targets based on Geo Code.
Expand Down Expand Up @@ -108,7 +109,7 @@ func (t *ClusterGatewayTarget) GetName() string {
}

func (t *ClusterGatewayTarget) GetShortCode() string {
return common.ToBase36HashLen(t.GetName(), common.ClusterIDLength)
return common.ToBase36HashLen(t.GetName(), utils.ClusterIDLength)
}

func (t *ClusterGatewayTarget) setGeo(defaultGeo v1alpha1.GeoCode) {
Expand Down

0 comments on commit e773993

Please sign in to comment.