diff --git a/api/v1/dnspolicy_types.go b/api/v1/dnspolicy_types.go index fe85d8546..84a300350 100644 --- a/api/v1/dnspolicy_types.go +++ b/api/v1/dnspolicy_types.go @@ -24,10 +24,13 @@ import ( dnsv1alpha1 "github.com/kuadrant/dns-operator/api/v1alpha1" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/utils/ptr" gatewayapiv1 "sigs.k8s.io/gateway-api/apis/v1" gatewayapiv1alpha2 "sigs.k8s.io/gateway-api/apis/v1alpha2" + "github.com/kuadrant/policy-machinery/machinery" + kuadrantgatewayapi "github.com/kuadrant/kuadrant-operator/pkg/library/gatewayapi" "github.com/kuadrant/kuadrant-operator/pkg/library/kuadrant" "github.com/kuadrant/kuadrant-operator/pkg/library/utils" @@ -38,6 +41,11 @@ const ( WildcardGeo GeoCode = "*" ) +var ( + DNSPoliciesResource = GroupVersion.WithResource("dnspolicies") + DNSPolicyGroupKind = schema.GroupKind{Group: GroupVersion.Group, Kind: "DNSPolicy"} +) + // DNSPolicySpec defines the desired state of DNSPolicy type DNSPolicySpec struct { // targetRef identifies an API object to apply policy to. @@ -161,6 +169,31 @@ type DNSPolicy struct { Status DNSPolicyStatus `json:"status,omitempty"` } +var _ machinery.Policy = &DNSPolicy{} + +func (p *DNSPolicy) GetTargetRefs() []machinery.PolicyTargetReference { + return []machinery.PolicyTargetReference{ + machinery.LocalPolicyTargetReferenceWithSectionName{ + LocalPolicyTargetReferenceWithSectionName: p.Spec.TargetRef, + PolicyNamespace: p.Namespace, + }, + } +} + +func (p *DNSPolicy) GetMergeStrategy() machinery.MergeStrategy { + return func(policy machinery.Policy, _ machinery.Policy) machinery.Policy { + return policy + } +} + +func (p *DNSPolicy) Merge(other machinery.Policy) machinery.Policy { + return other +} + +func (p *DNSPolicy) GetLocator() string { + return machinery.LocatorFromObject(p) +} + func (p *DNSPolicy) Validate() error { return p.Spec.ExcludeAddresses.Validate() } diff --git a/api/v1/tlspolicy_types.go b/api/v1/tlspolicy_types.go index f8d7f522c..e98bf8ad2 100644 --- a/api/v1/tlspolicy_types.go +++ b/api/v1/tlspolicy_types.go @@ -19,15 +19,24 @@ package v1 import ( certmanv1 "github.com/cert-manager/cert-manager/pkg/apis/certmanager/v1" certmanmetav1 "github.com/cert-manager/cert-manager/pkg/apis/meta/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime/schema" gatewayapiv1 "sigs.k8s.io/gateway-api/apis/v1" gatewayapiv1alpha2 "sigs.k8s.io/gateway-api/apis/v1alpha2" + "github.com/kuadrant/policy-machinery/machinery" + kuadrantgatewayapi "github.com/kuadrant/kuadrant-operator/pkg/library/gatewayapi" "github.com/kuadrant/kuadrant-operator/pkg/library/kuadrant" "github.com/kuadrant/kuadrant-operator/pkg/library/utils" ) +var ( + TLSPoliciesResource = GroupVersion.WithResource("tlspolicies") + TLSPolicyGroupKind = schema.GroupKind{Group: GroupVersion.Group, Kind: "TLSPolicy"} +) + // TLSPolicySpec defines the desired state of TLSPolicy type TLSPolicySpec struct { // TargetRef identifies an API object to apply policy to. @@ -136,6 +145,31 @@ type TLSPolicy struct { Status TLSPolicyStatus `json:"status,omitempty"` } +var _ machinery.Policy = &TLSPolicy{} + +func (p *TLSPolicy) GetTargetRefs() []machinery.PolicyTargetReference { + return []machinery.PolicyTargetReference{ + machinery.LocalPolicyTargetReference{ + LocalPolicyTargetReference: p.Spec.TargetRef, + PolicyNamespace: p.Namespace, + }, + } +} + +func (p *TLSPolicy) GetMergeStrategy() machinery.MergeStrategy { + return func(policy machinery.Policy, _ machinery.Policy) machinery.Policy { + return policy + } +} + +func (p *TLSPolicy) Merge(other machinery.Policy) machinery.Policy { + return other +} + +func (p *TLSPolicy) GetLocator() string { + return machinery.LocatorFromObject(p) +} + // Deprecated: kuadrant.Policy. func (p *TLSPolicy) Kind() string { return TLSPolicyGroupKind.Kind diff --git a/api/v1/topology.go b/api/v1/topology.go deleted file mode 100644 index eed60703e..000000000 --- a/api/v1/topology.go +++ /dev/null @@ -1,65 +0,0 @@ -package v1 - -// Contains of this file allow the DNSPolicy and TLSPolicy to adhere to the machinery.Policy interface - -import ( - "github.com/kuadrant/policy-machinery/machinery" - "k8s.io/apimachinery/pkg/runtime/schema" -) - -var ( - DNSPoliciesResource = GroupVersion.WithResource("dnspolicies") - DNSPolicyGroupKind = schema.GroupKind{Group: GroupVersion.Group, Kind: "DNSPolicy"} - TLSPoliciesResource = GroupVersion.WithResource("tlspolicies") - TLSPolicyGroupKind = schema.GroupKind{Group: GroupVersion.Group, Kind: "TLSPolicy"} -) - -var _ machinery.Policy = &DNSPolicy{} - -func (p *DNSPolicy) GetTargetRefs() []machinery.PolicyTargetReference { - return []machinery.PolicyTargetReference{ - machinery.LocalPolicyTargetReferenceWithSectionName{ - LocalPolicyTargetReferenceWithSectionName: p.Spec.TargetRef, - PolicyNamespace: p.Namespace, - }, - } -} - -func (p *DNSPolicy) GetMergeStrategy() machinery.MergeStrategy { - return func(policy machinery.Policy, _ machinery.Policy) machinery.Policy { - return policy - } -} - -func (p *DNSPolicy) Merge(other machinery.Policy) machinery.Policy { - return other -} - -func (p *DNSPolicy) GetLocator() string { - return machinery.LocatorFromObject(p) -} - -var _ machinery.Policy = &TLSPolicy{} - -func (p *TLSPolicy) GetTargetRefs() []machinery.PolicyTargetReference { - return []machinery.PolicyTargetReference{ - machinery.LocalPolicyTargetReference{ - LocalPolicyTargetReference: p.Spec.TargetRef, - PolicyNamespace: p.Namespace, - }, - } -} - -func (p *TLSPolicy) GetMergeStrategy() machinery.MergeStrategy { - return func(policy machinery.Policy, _ machinery.Policy) machinery.Policy { - return policy - } -} - -func (p *TLSPolicy) Merge(other machinery.Policy) machinery.Policy { - return other -} - -func (p *TLSPolicy) GetLocator() string { - return machinery.LocatorFromObject(p) -}