Skip to content

Commit

Permalink
remove v1/topology.go for consistency with other apis
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Nairn <[email protected]>
  • Loading branch information
mikenairn committed Nov 5, 2024
1 parent ac2e38e commit 6fcae1b
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 65 deletions.
33 changes: 33 additions & 0 deletions api/v1/dnspolicy_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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.
Expand Down Expand Up @@ -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
}

Check warning on line 186 in api/v1/dnspolicy_types.go

View check run for this annotation

Codecov / codecov/patch

api/v1/dnspolicy_types.go#L183-L186

Added lines #L183 - L186 were not covered by tests
}

func (p *DNSPolicy) Merge(other machinery.Policy) machinery.Policy {
return other

Check warning on line 190 in api/v1/dnspolicy_types.go

View check run for this annotation

Codecov / codecov/patch

api/v1/dnspolicy_types.go#L189-L190

Added lines #L189 - L190 were not covered by tests
}

func (p *DNSPolicy) GetLocator() string {
return machinery.LocatorFromObject(p)
}

func (p *DNSPolicy) Validate() error {
return p.Spec.ExcludeAddresses.Validate()
}
Expand Down
34 changes: 34 additions & 0 deletions api/v1/tlspolicy_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
}

Check warning on line 162 in api/v1/tlspolicy_types.go

View check run for this annotation

Codecov / codecov/patch

api/v1/tlspolicy_types.go#L159-L162

Added lines #L159 - L162 were not covered by tests
}

func (p *TLSPolicy) Merge(other machinery.Policy) machinery.Policy {
return other

Check warning on line 166 in api/v1/tlspolicy_types.go

View check run for this annotation

Codecov / codecov/patch

api/v1/tlspolicy_types.go#L165-L166

Added lines #L165 - L166 were not covered by tests
}

func (p *TLSPolicy) GetLocator() string {
return machinery.LocatorFromObject(p)
}

// Deprecated: kuadrant.Policy.
func (p *TLSPolicy) Kind() string {
return TLSPolicyGroupKind.Kind
Expand Down
65 changes: 0 additions & 65 deletions api/v1/topology.go

This file was deleted.

0 comments on commit 6fcae1b

Please sign in to comment.