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

Commit

Permalink
feat: Remove ocm dependency from policy controller
Browse files Browse the repository at this point in the history
Remove all dependencies related to OCM from the policy controller and
associated code.

Instead of labeling the OCM ManagedCluster resources with weight and geo
metadata, the labels are now added to the gateway itself with the
cluster name embedded.

```
"kuadrant.io/kind-mgc-control-plane_lb-attribute-weight":   "TSTATTR",
"kuadrant.io/kind-mgc-control-plane_lb-attribute-geo-code": "EU"
```
  • Loading branch information
mikenairn committed Dec 7, 2023
1 parent ee86457 commit 179d72f
Show file tree
Hide file tree
Showing 16 changed files with 611 additions and 602 deletions.
7 changes: 1 addition & 6 deletions cmd/policy_controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,11 @@ func main() {
var metricsAddr string
var enableLeaderElection bool
var probeAddr string
var ocmHub bool
flag.StringVar(&metricsAddr, "metrics-bind-address", ":8080", "The address the metric endpoint binds to.")
flag.StringVar(&probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.")
flag.BoolVar(&enableLeaderElection, "leader-elect", false,
"Enable leader election for controller manager. "+
"Enabling this will ensure there is only one active controller manager.")

flag.BoolVar(&ocmHub, "ocm-hub", true,
"tells the controller if it is in an ocm hub"+
"setting this to false will cause the controller to stop watching for managedcluster resources")
opts := zap.Options{
Development: true,
}
Expand Down Expand Up @@ -130,7 +125,7 @@ func main() {
BaseReconciler: dnsPolicyBaseReconciler,
},
DNSProvider: provider.DNSProviderFactory,
}).SetupWithManager(mgr, ocmHub); err != nil {
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "DNSPolicy")
os.Exit(1)
}
Expand Down
3 changes: 1 addition & 2 deletions hack/make/policy_controller.make
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ run-policy-controller: manifests generate fmt vet install
go run ./cmd/policy_controller/main.go \
--metrics-bind-address=:8090 \
--health-probe-bind-address=:8091 \
--zap-log-level=$(LOG_LEVEL) \
--ocm-hub=$(OCM)
--zap-log-level=$(LOG_LEVEL)

.PHONY: docker-build-policy-controller
docker-build-policy-controller: ## Build docker image with the controller.
Expand Down
4 changes: 2 additions & 2 deletions pkg/controllers/dnspolicy/dns_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ func (dh *dnsHelper) getSimpleEndpoints(mcgTarget *dns.MultiClusterGatewayTarget
)

for _, cgwTarget := range mcgTarget.ClusterGatewayTargets {
for _, gwa := range cgwTarget.GatewayAddresses {
for _, gwa := range cgwTarget.Status.Addresses {
if *gwa.Type == gatewayapiv1.IPAddressType {
ipValues = append(ipValues, gwa.Value)
} else {
Expand Down Expand Up @@ -273,7 +273,7 @@ func (dh *dnsHelper) getLoadBalancedEndpoints(mcgTarget *dns.MultiClusterGateway

var ipValues []string
var hostValues []string
for _, gwa := range cgwTarget.GatewayAddresses {
for _, gwa := range cgwTarget.Status.Addresses {
if *gwa.Type == gatewayapiv1.IPAddressType {
ipValues = append(ipValues, gwa.Value)
} else {
Expand Down
224 changes: 117 additions & 107 deletions pkg/controllers/dnspolicy/dns_helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (

"github.com/Kuadrant/multicluster-gateway-controller/pkg/apis/v1alpha1"
"github.com/Kuadrant/multicluster-gateway-controller/pkg/dns"
"github.com/Kuadrant/multicluster-gateway-controller/pkg/utils"
testutil "github.com/Kuadrant/multicluster-gateway-controller/test/util"
)

Expand Down Expand Up @@ -421,40 +422,42 @@ func Test_dnsHelper_setEndpoints(t *testing.T) {
},
ClusterGatewayTargets: []dns.ClusterGatewayTarget{
{
ClusterGateway: &dns.ClusterGateway{
Cluster: &testutil.TestResource{
ObjectMeta: v1.ObjectMeta{
Name: "test-cluster-1",
},
},
GatewayAddresses: []gatewayapiv1.GatewayAddress{
{
Type: testutil.Pointer(gatewayapiv1.IPAddressType),
Value: "1.1.1.1",
},
{
Type: testutil.Pointer(gatewayapiv1.IPAddressType),
Value: "2.2.2.2",
ClusterGateway: &utils.ClusterGateway{
Gateway: gatewayapiv1.Gateway{
ObjectMeta: v1.ObjectMeta{Name: "testgw"},
Status: gatewayapiv1.GatewayStatus{
Addresses: []gatewayapiv1.GatewayStatusAddress{
{
Type: testutil.Pointer(gatewayapiv1.IPAddressType),
Value: "1.1.1.1",
},
{
Type: testutil.Pointer(gatewayapiv1.IPAddressType),
Value: "2.2.2.2",
},
},
},
},
ClusterName: "test-cluster-1",
},
Geo: testutil.Pointer(dns.GeoCode("default")),
Weight: testutil.Pointer(120),
},
{

ClusterGateway: &dns.ClusterGateway{
Cluster: &testutil.TestResource{
ObjectMeta: v1.ObjectMeta{
Name: "test-cluster-2",
},
},
GatewayAddresses: []gatewayapiv1.GatewayAddress{
{
Type: testutil.Pointer(gatewayapiv1.HostnameAddressType),
Value: "mylb.example.com",
ClusterGateway: &utils.ClusterGateway{
Gateway: gatewayapiv1.Gateway{
ObjectMeta: v1.ObjectMeta{Name: "testgw"},
Status: gatewayapiv1.GatewayStatus{
Addresses: []gatewayapiv1.GatewayStatusAddress{
{
Type: testutil.Pointer(gatewayapiv1.HostnameAddressType),
Value: "mylb.example.com",
},
},
},
},
ClusterName: "test-cluster-2",
},
Geo: testutil.Pointer(dns.GeoCode("default")),
Weight: testutil.Pointer(120),
Expand Down Expand Up @@ -531,41 +534,42 @@ func Test_dnsHelper_setEndpoints(t *testing.T) {
},
ClusterGatewayTargets: []dns.ClusterGatewayTarget{
{

ClusterGateway: &dns.ClusterGateway{
Cluster: &testutil.TestResource{
ObjectMeta: v1.ObjectMeta{
Name: "test-cluster-1",
},
},
GatewayAddresses: []gatewayapiv1.GatewayAddress{
{
Type: testutil.Pointer(gatewayapiv1.IPAddressType),
Value: "1.1.1.1",
},
{
Type: testutil.Pointer(gatewayapiv1.IPAddressType),
Value: "2.2.2.2",
ClusterGateway: &utils.ClusterGateway{
Gateway: gatewayapiv1.Gateway{
ObjectMeta: v1.ObjectMeta{Name: "testgw"},
Status: gatewayapiv1.GatewayStatus{
Addresses: []gatewayapiv1.GatewayStatusAddress{
{
Type: testutil.Pointer(gatewayapiv1.IPAddressType),
Value: "1.1.1.1",
},
{
Type: testutil.Pointer(gatewayapiv1.IPAddressType),
Value: "2.2.2.2",
},
},
},
},
ClusterName: "test-cluster-1",
},
Geo: testutil.Pointer(dns.GeoCode("NA")),
Weight: testutil.Pointer(120),
},
{

ClusterGateway: &dns.ClusterGateway{
Cluster: &testutil.TestResource{
ObjectMeta: v1.ObjectMeta{
Name: "test-cluster-2",
},
},
GatewayAddresses: []gatewayapiv1.GatewayAddress{
{
Type: testutil.Pointer(gatewayapiv1.HostnameAddressType),
Value: "mylb.example.com",
ClusterGateway: &utils.ClusterGateway{
Gateway: gatewayapiv1.Gateway{
ObjectMeta: v1.ObjectMeta{Name: "testgw"},
Status: gatewayapiv1.GatewayStatus{
Addresses: []gatewayapiv1.GatewayStatusAddress{
{
Type: testutil.Pointer(gatewayapiv1.HostnameAddressType),
Value: "mylb.example.com",
},
},
},
},
ClusterName: "test-cluster-2",
},
Geo: testutil.Pointer(dns.GeoCode("IE")),
Weight: testutil.Pointer(120),
Expand Down Expand Up @@ -677,40 +681,42 @@ func Test_dnsHelper_setEndpoints(t *testing.T) {
ClusterGatewayTargets: []dns.ClusterGatewayTarget{
{

ClusterGateway: &dns.ClusterGateway{
Cluster: &testutil.TestResource{
ObjectMeta: v1.ObjectMeta{
Name: "test-cluster-1",
},
},
GatewayAddresses: []gatewayapiv1.GatewayAddress{
{
Type: testutil.Pointer(gatewayapiv1.IPAddressType),
Value: "1.1.1.1",
},
{
Type: testutil.Pointer(gatewayapiv1.IPAddressType),
Value: "2.2.2.2",
ClusterGateway: &utils.ClusterGateway{
Gateway: gatewayapiv1.Gateway{
ObjectMeta: v1.ObjectMeta{Name: "testgw"},
Status: gatewayapiv1.GatewayStatus{
Addresses: []gatewayapiv1.GatewayStatusAddress{
{
Type: testutil.Pointer(gatewayapiv1.IPAddressType),
Value: "1.1.1.1",
},
{
Type: testutil.Pointer(gatewayapiv1.IPAddressType),
Value: "2.2.2.2",
},
},
},
},
ClusterName: "test-cluster-1",
},
Geo: testutil.Pointer(dns.GeoCode("default")),
Weight: testutil.Pointer(120),
},
{

ClusterGateway: &dns.ClusterGateway{
Cluster: &testutil.TestResource{
ObjectMeta: v1.ObjectMeta{
Name: "test-cluster-2",
},
},
GatewayAddresses: []gatewayapiv1.GatewayAddress{
{
Type: testutil.Pointer(gatewayapiv1.HostnameAddressType),
Value: "mylb.example.com",
ClusterGateway: &utils.ClusterGateway{
Gateway: gatewayapiv1.Gateway{
ObjectMeta: v1.ObjectMeta{Name: "testgw"},
Status: gatewayapiv1.GatewayStatus{
Addresses: []gatewayapiv1.GatewayStatusAddress{
{
Type: testutil.Pointer(gatewayapiv1.HostnameAddressType),
Value: "mylb.example.com",
},
},
},
},
ClusterName: "test-cluster-2",
},
Geo: testutil.Pointer(dns.GeoCode("default")),
Weight: testutil.Pointer(120),
Expand Down Expand Up @@ -788,40 +794,42 @@ func Test_dnsHelper_setEndpoints(t *testing.T) {
ClusterGatewayTargets: []dns.ClusterGatewayTarget{
{

ClusterGateway: &dns.ClusterGateway{
Cluster: &testutil.TestResource{
ObjectMeta: v1.ObjectMeta{
Name: "test-cluster-1",
},
},
GatewayAddresses: []gatewayapiv1.GatewayAddress{
{
Type: testutil.Pointer(gatewayapiv1.IPAddressType),
Value: "1.1.1.1",
},
{
Type: testutil.Pointer(gatewayapiv1.IPAddressType),
Value: "2.2.2.2",
ClusterGateway: &utils.ClusterGateway{
Gateway: gatewayapiv1.Gateway{
ObjectMeta: v1.ObjectMeta{Name: "testgw"},
Status: gatewayapiv1.GatewayStatus{
Addresses: []gatewayapiv1.GatewayStatusAddress{
{
Type: testutil.Pointer(gatewayapiv1.IPAddressType),
Value: "1.1.1.1",
},
{
Type: testutil.Pointer(gatewayapiv1.IPAddressType),
Value: "2.2.2.2",
},
},
},
},
ClusterName: "test-cluster-1",
},
Geo: testutil.Pointer(dns.GeoCode("NA")),
Weight: testutil.Pointer(120),
},
{

ClusterGateway: &dns.ClusterGateway{
Cluster: &testutil.TestResource{
ObjectMeta: v1.ObjectMeta{
Name: "test-cluster-2",
},
},
GatewayAddresses: []gatewayapiv1.GatewayAddress{
{
Type: testutil.Pointer(gatewayapiv1.HostnameAddressType),
Value: "mylb.example.com",
ClusterGateway: &utils.ClusterGateway{
Gateway: gatewayapiv1.Gateway{
ObjectMeta: v1.ObjectMeta{Name: "testgw"},
Status: gatewayapiv1.GatewayStatus{
Addresses: []gatewayapiv1.GatewayStatusAddress{
{
Type: testutil.Pointer(gatewayapiv1.HostnameAddressType),
Value: "mylb.example.com",
},
},
},
},
ClusterName: "test-cluster-2",
},
Geo: testutil.Pointer(dns.GeoCode("IE")),
Weight: testutil.Pointer(120),
Expand Down Expand Up @@ -930,26 +938,28 @@ func Test_dnsHelper_setEndpoints(t *testing.T) {
ClusterGatewayTargets: []dns.ClusterGatewayTarget{
{

ClusterGateway: &dns.ClusterGateway{
Cluster: &testutil.TestResource{
ObjectMeta: v1.ObjectMeta{
Name: "test-cluster-1",
ClusterGateway: &utils.ClusterGateway{
Gateway: gatewayapiv1.Gateway{
ObjectMeta: v1.ObjectMeta{Name: "testgw"},
Status: gatewayapiv1.GatewayStatus{
Addresses: []gatewayapiv1.GatewayStatusAddress{},
},
},
GatewayAddresses: []gatewayapiv1.GatewayAddress{},
ClusterName: "test-cluster-1",
},
Geo: testutil.Pointer(dns.GeoCode("NA")),
Weight: testutil.Pointer(120),
},
{

ClusterGateway: &dns.ClusterGateway{
Cluster: &testutil.TestResource{
ObjectMeta: v1.ObjectMeta{
Name: "test-cluster-2",
ClusterGateway: &utils.ClusterGateway{
Gateway: gatewayapiv1.Gateway{
ObjectMeta: v1.ObjectMeta{Name: "testgw"},
Status: gatewayapiv1.GatewayStatus{
Addresses: []gatewayapiv1.GatewayStatusAddress{},
},
},
GatewayAddresses: []gatewayapiv1.GatewayAddress{},
ClusterName: "test-cluster-2",
},
Geo: testutil.Pointer(dns.GeoCode("IE")),
Weight: testutil.Pointer(120),
Expand Down
Loading

0 comments on commit 179d72f

Please sign in to comment.