From 0503a3aa08af0b57e681fa2527b116a525ca716e Mon Sep 17 00:00:00 2001 From: Michael Nairn Date: Wed, 7 Feb 2024 20:10:42 +0000 Subject: [PATCH] update kuadrant-operator version --- go.mod | 7 +- go.sum | 11 +- pkg/controllers/gateway/gateway_controller.go | 38 +---- test/util/helper.go | 44 ++---- test/util/test_dnspolicy_types.go | 131 ------------------ test/util/test_types.go | 61 -------- 6 files changed, 26 insertions(+), 266 deletions(-) delete mode 100644 test/util/test_dnspolicy_types.go diff --git a/go.mod b/go.mod index 05e51515..12c23555 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( github.com/goombaio/namegenerator v0.0.0-20181006234301-989e774b106e github.com/jetstack/cert-manager v1.7.1 github.com/kuadrant/kuadrant-dns-operator v0.0.0-20240202223525-b889335b228f - github.com/kuadrant/kuadrant-operator v0.1.1-0.20231114121136-3136ed961c70 + github.com/kuadrant/kuadrant-operator v0.1.1-0.20240207215948-fd569587ff6f github.com/onsi/ginkgo/v2 v2.13.2 github.com/onsi/gomega v1.30.0 github.com/operator-framework/api v0.17.5 @@ -59,6 +59,7 @@ require ( github.com/kuadrant/authorino-operator v0.9.0 // indirect github.com/kuadrant/limitador-operator v0.7.0 // indirect github.com/mailru/easyjson v0.7.7 // indirect + github.com/martinlindhe/base36 v1.1.1 // indirect github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 // indirect github.com/mitchellh/copystructure v1.2.0 // indirect github.com/mitchellh/reflectwalk v1.0.2 // indirect @@ -66,10 +67,12 @@ require ( github.com/modern-go/reflect2 v1.0.2 // indirect github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect github.com/pkg/errors v0.9.1 // indirect + github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect github.com/prometheus/client_golang v1.17.0 // indirect github.com/prometheus/client_model v0.5.0 // indirect github.com/prometheus/common v0.45.0 // indirect github.com/prometheus/procfs v0.12.0 // indirect + github.com/rogpeppe/go-internal v1.11.0 // indirect github.com/shopspring/decimal v1.3.1 // indirect github.com/sirupsen/logrus v1.9.3 // indirect github.com/spf13/cast v1.6.0 // indirect @@ -116,4 +119,4 @@ replace maistra.io/istio-operator => github.com/maistra/istio-operator v0.0.0-20 replace github.com/imdario/mergo => dario.cat/mergo v0.3.5 -replace github.com/kuadrant/kuadrant-operator => /home/mnairn/go/src/github.com/kuadrant/kuadrant-operator +//replace github.com/kuadrant/kuadrant-operator => /home/mnairn/go/src/github.com/kuadrant/kuadrant-operator diff --git a/go.sum b/go.sum index 1bc57ca1..600a6b69 100644 --- a/go.sum +++ b/go.sum @@ -103,10 +103,14 @@ github.com/kuadrant/authorino-operator v0.9.0 h1:EV7zrYBNcd53HPQMivvTwe/+DIATTK7 github.com/kuadrant/authorino-operator v0.9.0/go.mod h1:VkUqS4CHNiaHMrjSFQ5V71DN829kPnqT3FQxqlOntEI= github.com/kuadrant/kuadrant-dns-operator v0.0.0-20240202223525-b889335b228f h1:kRhKt1sW8ZqZlEasTGb1aX6xrEutBU1Ef+P4stf3bhY= github.com/kuadrant/kuadrant-dns-operator v0.0.0-20240202223525-b889335b228f/go.mod h1:OyP8aXe7uOCP8PKMhd6JXPSUyzcNkztriNDeyearp4M= +github.com/kuadrant/kuadrant-operator v0.1.1-0.20240207215948-fd569587ff6f h1:90NpS2LHPiwuQdn3GecDXQ5/FD+hd6XJn/5ilp2vKqQ= +github.com/kuadrant/kuadrant-operator v0.1.1-0.20240207215948-fd569587ff6f/go.mod h1:TzNfN5kVB2XLIHvDu7Pk2f2/WImTYEd7CBdkfB47yMQ= github.com/kuadrant/limitador-operator v0.7.0 h1:pLIpM6vUxAY/Jn6ny61IGpqS7Oti786duBzJ67DJOuA= github.com/kuadrant/limitador-operator v0.7.0/go.mod h1:tg+G+3eTzUUfvUmdbiqH3FnScEPSWZ3DmorD1ZAx1bo= github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0= github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc= +github.com/martinlindhe/base36 v1.1.1 h1:1F1MZ5MGghBXDZ2KJ3QfxmiydlWOGB8HCEtkap5NkVg= +github.com/martinlindhe/base36 v1.1.1/go.mod h1:vMS8PaZ5e/jV9LwFKlm0YLnXl/hpOihiBxKkIoc3g08= github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 h1:jWpvCLoY8Z/e3VKvlsiIGKtc+UG6U5vzxaoagmhXfyg= github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0/go.mod h1:QUyp042oQthUoa9bqDv0ER0wrtXnBruoNd7aNjkbP+k= github.com/mitchellh/copystructure v1.0.0/go.mod h1:SNtv71yrdKgLRyLFxmLdkAbkKEFWgYaq1OVrnRcwhnw= @@ -137,8 +141,9 @@ github.com/operator-framework/api v0.17.5/go.mod h1:l/cuwtPxkVUY7fzYgdust2m9tlmb github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= -github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U= +github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/prometheus/client_golang v1.17.0 h1:rl2sfwZMtSthVU752MqfjQozy7blglC+1SOtjMAMh+Q= github.com/prometheus/client_golang v1.17.0/go.mod h1:VeL+gMmOAxkS2IqfCq0ZmHSL+LjWfWDUmp1mBz9JgUY= github.com/prometheus/client_model v0.5.0 h1:VQw1hfvPvk3Uv6Qf29VrPF32JB6rtbgI6cYPYQjL0Qw= @@ -147,8 +152,8 @@ github.com/prometheus/common v0.45.0 h1:2BGz0eBc2hdMDLnO/8n0jeB3oPrt2D08CekT0lne github.com/prometheus/common v0.45.0/go.mod h1:YJmSTw9BoKxJplESWWxlbyttQR4uaEcGyv9MZjVOJsY= github.com/prometheus/procfs v0.12.0 h1:jluTpSng7V9hY0O2R9DzzJHYb2xULk9VTR1V1R/k6Bo= github.com/prometheus/procfs v0.12.0/go.mod h1:pcuDEFsWDnvcgNzo4EEweacyhjeA9Zk3cnaOZAZEfOo= -github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ= -github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog= +github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M= +github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA= github.com/shopspring/decimal v1.2.0/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o= github.com/shopspring/decimal v1.3.1 h1:2Usl1nmF/WZucqkFZhnfFYxxxu8LG21F6nPQBE5gKV8= github.com/shopspring/decimal v1.3.1/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o= diff --git a/pkg/controllers/gateway/gateway_controller.go b/pkg/controllers/gateway/gateway_controller.go index df570c30..002a5216 100644 --- a/pkg/controllers/gateway/gateway_controller.go +++ b/pkg/controllers/gateway/gateway_controller.go @@ -48,6 +48,8 @@ import ( "sigs.k8s.io/controller-runtime/pkg/reconcile" gatewayapiv1 "sigs.k8s.io/gateway-api/apis/v1" + "github.com/kuadrant/kuadrant-operator/pkg/multicluster" + "github.com/Kuadrant/multicluster-gateway-controller/pkg/_internal/gracePeriod" "github.com/Kuadrant/multicluster-gateway-controller/pkg/_internal/metadata" "github.com/Kuadrant/multicluster-gateway-controller/pkg/_internal/slice" @@ -219,7 +221,7 @@ func (r *GatewayReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct } for _, address := range addresses { log.V(3).Info("checking address type for mapping", "address.Type", address.Type) - addressType, supported := AddressTypeToMultiCluster(address) + addressType, supported := multicluster.AddressTypeToMultiCluster(address) if !supported { continue // ignore address type gatewayapiv1.NamedAddressType. Unsupported for multi cluster gateway } @@ -276,7 +278,7 @@ func (r *GatewayReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct func (r *GatewayReconciler) reconcileClusterLabels(ctx context.Context, gateway *gatewayapiv1.Gateway, clusters []string) error { //Remove all existing clusters.kuadrant.io labels for key := range gateway.Labels { - if strings.HasPrefix(key, ClustersLabelPrefix) { + if strings.HasPrefix(key, multicluster.ClustersLabelPrefix) { delete(gateway.Labels, key) } } @@ -293,7 +295,7 @@ func (r *GatewayReconciler) reconcileClusterLabels(ctx context.Context, gateway if !found { continue } - gateway.Labels[ClustersLabelPrefix+cluster+"_"+attribute] = value + gateway.Labels[multicluster.ClustersLabelPrefix+cluster+"_"+attribute] = value } } return nil @@ -567,33 +569,3 @@ func (r *GatewayReconciler) SetupWithManager(mgr ctrl.Manager, ctx context.Conte })). Complete(r) } - -//ToDo These need to be exposed by the kuadrant operator DNSPolicy APIs - -const ( - ClustersLabelPrefix = "clusters." + LabelPrefix - MultiClusterIPAddressType gatewayapiv1.AddressType = LabelPrefix + "MultiClusterIPAddress" - MultiClusterHostnameAddressType gatewayapiv1.AddressType = LabelPrefix + "MultiClusterHostnameAddress" -) - -// AddressTypeToMultiCluster returns a multi cluster version of the address type -// and a bool to indicate that provided address type was converted. If not - original type is returned -func AddressTypeToMultiCluster(address gatewayapiv1.GatewayAddress) (gatewayapiv1.AddressType, bool) { - if *address.Type == gatewayapiv1.IPAddressType { - return MultiClusterIPAddressType, true - } else if *address.Type == gatewayapiv1.HostnameAddressType { - return MultiClusterHostnameAddressType, true - } - return *address.Type, false -} - -// AddressTypeToSingleCluster converts provided multicluster address to single cluster version -// the bool indicates a successful conversion -func AddressTypeToSingleCluster(address gatewayapiv1.GatewayAddress) (gatewayapiv1.AddressType, bool) { - if *address.Type == MultiClusterIPAddressType { - return gatewayapiv1.IPAddressType, true - } else if *address.Type == MultiClusterHostnameAddressType { - return gatewayapiv1.HostnameAddressType, true - } - return *address.Type, false -} diff --git a/test/util/helper.go b/test/util/helper.go index 0dcb801a..c278865e 100644 --- a/test/util/helper.go +++ b/test/util/helper.go @@ -19,20 +19,14 @@ import ( ) const ( - Domain = "thecat.com" - ValidTestHostname = "boop." + Domain - ValidTestWildcard = "*." + Domain - FailFetchDANSSubdomain = "failfetch" - FailCreateDNSSubdomain = "failcreate" - FailEnsureCertHost = "failCreateCert" + "." + Domain - FailGetCertSecretName = "fail-fail" - FailEndpointsHostname = "failEndpoints" + "." + Domain - FailPlacementHostname = "failPlacement" + "." + Domain - Cluster = "test_cluster_one" - Namespace = "boop-namespace" - DummyCRName = "boop" - Placement = "placement" - TLSSecretName = "test-tls-cert" + Domain = "thecat.com" + ValidTestHostname = "boop." + Domain + FailPlacementHostname = "failPlacement" + "." + Domain + Cluster = "test_cluster_one" + Namespace = "boop-namespace" + DummyCRName = "boop" + Placement = "placement" + TLSSecretName = "test-tls-cert" ) func BuildValidTestRequest(name, ns string) ctrl.Request { @@ -87,28 +81,6 @@ func AssertNoErrorReconciliation() func(res ctrl.Result, err error, t *testing.T } } -func AssertErrorReconciliation(expectedError string) func(res ctrl.Result, err error, t *testing.T) { - return func(res ctrl.Result, err error, t *testing.T) { - if (expectedError == "") != (err == nil) { - t.Errorf("expected error %s but got %s", expectedError, err) - } - if err != nil && !strings.Contains(err.Error(), expectedError) { - t.Errorf("expected error to be %s but got %s", expectedError, err) - } - } -} - -func AssertError(expectedError string) func(t *testing.T, err error) { - return func(t *testing.T, err error) { - if (expectedError == "") != (err == nil) { - t.Errorf("expected error %s but got %s", expectedError, err) - } - if err != nil && !strings.Contains(err.Error(), expectedError) { - t.Errorf("expected error to be %s but got %s", expectedError, err) - } - } -} - func GetValidTestClient(initLists ...client.ObjectList) client.WithWatch { return fake.NewClientBuilder(). WithStatusSubresource(&gatewayapiv1.Gateway{}, &gatewayapiv1.GatewayClass{}). diff --git a/test/util/test_dnspolicy_types.go b/test/util/test_dnspolicy_types.go deleted file mode 100644 index df0d0745..00000000 --- a/test/util/test_dnspolicy_types.go +++ /dev/null @@ -1,131 +0,0 @@ -//go:build unit || integration || e2e - -package testutil - -import ( - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - gatewayapiv1 "sigs.k8s.io/gateway-api/apis/v1" - gatewayapiv1alpha2 "sigs.k8s.io/gateway-api/apis/v1alpha2" - - kuadrantdnsv1alpha1 "github.com/kuadrant/kuadrant-dns-operator/api/v1alpha1" - kuadrantv1alpha1 "github.com/kuadrant/kuadrant-operator/api/v1alpha1" -) - -// DNSPolicyBuilder wrapper for DNSPolicy builder helper -type DNSPolicyBuilder struct { - *kuadrantv1alpha1.DNSPolicy -} - -func NewDNSPolicyBuilder(name, ns string) *DNSPolicyBuilder { - return &DNSPolicyBuilder{ - &kuadrantv1alpha1.DNSPolicy{ - ObjectMeta: metav1.ObjectMeta{ - Name: name, - Namespace: ns, - }, - Spec: kuadrantv1alpha1.DNSPolicySpec{}, - }, - } -} - -func (t *DNSPolicyBuilder) WithTargetRef(targetRef gatewayapiv1alpha2.PolicyTargetReference) *DNSPolicyBuilder { - t.Spec.TargetRef = targetRef - return t -} - -func (t *DNSPolicyBuilder) WithHealthCheck(healthCheck kuadrantv1alpha1.HealthCheckSpec) *DNSPolicyBuilder { - t.Spec.HealthCheck = &healthCheck - return t -} - -func (t *DNSPolicyBuilder) WithLoadBalancing(loadBalancing kuadrantv1alpha1.LoadBalancingSpec) *DNSPolicyBuilder { - t.Spec.LoadBalancing = &loadBalancing - return t -} - -func (t *DNSPolicyBuilder) WithRoutingStrategy(strategy kuadrantv1alpha1.RoutingStrategy) *DNSPolicyBuilder { - t.Spec.RoutingStrategy = strategy - return t -} - -//TargetRef - -func (t *DNSPolicyBuilder) WithTargetGateway(gwName string) *DNSPolicyBuilder { - typedNamespace := gatewayapiv1.Namespace(t.GetNamespace()) - return t.WithTargetRef(gatewayapiv1alpha2.PolicyTargetReference{ - Group: "gateway.networking.k8s.io", - Kind: "Gateway", - Name: gatewayapiv1.ObjectName(gwName), - Namespace: &typedNamespace, - }) -} - -//HealthCheck - -func (t *DNSPolicyBuilder) WithHealthCheckFor(endpoint string, port *int, protocol kuadrantdnsv1alpha1.HealthProtocol, failureThreshold *int) *DNSPolicyBuilder { - return t.WithHealthCheck(kuadrantv1alpha1.HealthCheckSpec{ - Endpoint: endpoint, - Port: port, - Protocol: &protocol, - FailureThreshold: failureThreshold, - AdditionalHeadersRef: nil, - ExpectedResponses: nil, - AllowInsecureCertificates: false, - Interval: nil, - }) -} - -//LoadBalancing - -func (t *DNSPolicyBuilder) WithLoadBalancingWeighted(lbWeighted kuadrantv1alpha1.LoadBalancingWeighted) *DNSPolicyBuilder { - if t.Spec.LoadBalancing == nil { - t.Spec.LoadBalancing = &kuadrantv1alpha1.LoadBalancingSpec{} - } - t.Spec.LoadBalancing.Weighted = &lbWeighted - return t -} - -func (t *DNSPolicyBuilder) WithLoadBalancingGeo(lbGeo kuadrantv1alpha1.LoadBalancingGeo) *DNSPolicyBuilder { - if t.Spec.LoadBalancing == nil { - t.Spec.LoadBalancing = &kuadrantv1alpha1.LoadBalancingSpec{} - } - t.Spec.LoadBalancing.Geo = &lbGeo - return t -} - -func (t *DNSPolicyBuilder) WithLoadBalancingWeightedFor(defaultWeight kuadrantv1alpha1.Weight, custom []*kuadrantv1alpha1.CustomWeight) *DNSPolicyBuilder { - return t.WithLoadBalancingWeighted(kuadrantv1alpha1.LoadBalancingWeighted{ - DefaultWeight: defaultWeight, - Custom: custom, - }) -} - -func (t *DNSPolicyBuilder) WithLoadBalancingGeoFor(defaultGeo string) *DNSPolicyBuilder { - return t.WithLoadBalancingGeo(kuadrantv1alpha1.LoadBalancingGeo{ - DefaultGeo: defaultGeo, - }) -} - -// ManagedZoneBuilder wrapper for ManagedZone builder helper -type ManagedZoneBuilder struct { - *kuadrantdnsv1alpha1.ManagedZone -} - -func NewManagedZoneBuilder(name, ns, domainName string) *ManagedZoneBuilder { - return &ManagedZoneBuilder{ - &kuadrantdnsv1alpha1.ManagedZone{ - ObjectMeta: metav1.ObjectMeta{ - Name: name, - Namespace: ns, - }, - Spec: kuadrantdnsv1alpha1.ManagedZoneSpec{ - ID: "1234", - DomainName: domainName, - Description: domainName, - SecretRef: kuadrantdnsv1alpha1.ProviderRef{ - Name: "secretname", - }, - }, - }, - } -} diff --git a/test/util/test_types.go b/test/util/test_types.go index 1b35e5a9..3ebb078f 100644 --- a/test/util/test_types.go +++ b/test/util/test_types.go @@ -8,9 +8,6 @@ import ( certmanv1 "github.com/jetstack/cert-manager/pkg/apis/certmanager/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/runtime/schema" - "sigs.k8s.io/controller-runtime/pkg/client" gatewayapiv1 "sigs.k8s.io/gateway-api/apis/v1" gatewayapiv1alpha2 "sigs.k8s.io/gateway-api/apis/v1alpha2" ) @@ -134,61 +131,3 @@ func AddListener(name string, hostname gatewayapiv1alpha2.Hostname, secretName g gw.Spec.Listeners = append(gw.Spec.Listeners, listener) } - -// -//// TLSPolicyBuilder wrapper for TLSPolicy builder helper -//type TLSPolicyBuilder struct { -// *v1alpha1.TLSPolicy -//} -// -//func NewTLSPolicyBuilder(policyName, ns string) *TLSPolicyBuilder { -// return &TLSPolicyBuilder{ -// &v1alpha1.TLSPolicy{ -// ObjectMeta: metav1.ObjectMeta{ -// Name: policyName, -// Namespace: ns, -// }, -// Spec: v1alpha1.TLSPolicySpec{}, -// }, -// } -//} -// -//func (t *TLSPolicyBuilder) Build() *v1alpha1.TLSPolicy { -// return t.TLSPolicy -//} -// -//func (t *TLSPolicyBuilder) WithTargetGateway(gwName string) *TLSPolicyBuilder { -// typedNamespace := gatewayapiv1.Namespace(t.GetNamespace()) -// t.Spec.TargetRef = gatewayapiv1alpha2.PolicyTargetReference{ -// Group: "gateway.networking.k8s.io", -// Kind: "Gateway", -// Name: gatewayapiv1.ObjectName(gwName), -// Namespace: &typedNamespace, -// } -// return t -//} -// -//func (t *TLSPolicyBuilder) WithIssuerRef(issuerRef certmanmetav1.ObjectReference) *TLSPolicyBuilder { -// t.Spec.IssuerRef = issuerRef -// return t -//} -// -//func (t *TLSPolicyBuilder) WithIssuer(name, kind, group string) *TLSPolicyBuilder { -// t.WithIssuerRef(certmanmetav1.ObjectReference{ -// Name: name, -// Kind: kind, -// Group: group, -// }) -// return t -//} - -var _ client.Object = &TestResource{} - -// TestResource dummy client.Object that can be used in place of a real k8s resource for testing -type TestResource struct { - metav1.TypeMeta - metav1.ObjectMeta -} - -func (*TestResource) GetObjectKind() schema.ObjectKind { return nil } -func (*TestResource) DeepCopyObject() runtime.Object { return nil }