Skip to content

Commit

Permalink
refactor: GetURL() -> GetIdentity()
Browse files Browse the repository at this point in the history
Signed-off-by: KevFan <[email protected]>
  • Loading branch information
KevFan committed Aug 22, 2024
1 parent e963418 commit 3412363
Show file tree
Hide file tree
Showing 18 changed files with 113 additions and 112 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ type MyPolicySpec struct {
TargetRef gwapiv1alpha2.LocalPolicyTargetReference
}

func (p *MyPolicy) GetURL() string {
return machinery.UrlFromObject(p)
func (p *MyPolicy) GetIdentity() string {
return machinery.IdentityFromObject(p)
}

func (p *MyPolicy) GetTargetRefs() []machinery.PolicyTargetReference {
Expand Down
4 changes: 2 additions & 2 deletions controller/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ func (o *RuntimeObject) GetName() string {
return o.Object.GetName()
}

func (o *RuntimeObject) GetURL() string {
return machinery.UrlFromObject(o)
func (o *RuntimeObject) GetIdentity() string {
return machinery.IdentityFromObject(o)
}

// ObjectAs casts an Object generically into any kind
Expand Down
4 changes: 2 additions & 2 deletions examples/color_policy/color_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ type ColorPolicy struct {

var _ machinery.Policy = &ColorPolicy{}

func (p *ColorPolicy) GetURL() string {
return machinery.UrlFromObject(p)
func (p *ColorPolicy) GetIdentity() string {
return machinery.IdentityFromObject(p)
}

func (p *ColorPolicy) GetTargetRefs() []machinery.PolicyTargetReference {
Expand Down
5 changes: 3 additions & 2 deletions examples/json_patch/color_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
gwapi "sigs.k8s.io/gateway-api/apis/v1alpha2"

jsonpatch "github.com/evanphx/json-patch"

"github.com/kuadrant/policy-machinery/machinery"
)

Expand All @@ -19,8 +20,8 @@ type ColorPolicy struct {

var _ machinery.Policy = &ColorPolicy{}

func (p *ColorPolicy) GetURL() string {
return machinery.UrlFromObject(p)
func (p *ColorPolicy) GetIdentity() string {
return machinery.IdentityFromObject(p)
}

func (p *ColorPolicy) GetTargetRefs() []machinery.PolicyTargetReference {
Expand Down
4 changes: 2 additions & 2 deletions examples/kuadrant/apis/v1alpha2/dnspolicy_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ func (p *DNSPolicy) GetName() string {
return p.Name
}

func (p *DNSPolicy) GetURL() string {
return machinery.UrlFromObject(p)
func (p *DNSPolicy) GetIdentity() string {
return machinery.IdentityFromObject(p)
}

func (p *DNSPolicy) GetTargetRefs() []machinery.PolicyTargetReference {
Expand Down
4 changes: 2 additions & 2 deletions examples/kuadrant/apis/v1alpha2/tlspolicy_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ func (p *TLSPolicy) GetName() string {
return p.Name
}

func (p *TLSPolicy) GetURL() string {
return machinery.UrlFromObject(p)
func (p *TLSPolicy) GetIdentity() string {
return machinery.IdentityFromObject(p)
}

func (p *TLSPolicy) GetTargetRefs() []machinery.PolicyTargetReference {
Expand Down
4 changes: 2 additions & 2 deletions examples/kuadrant/apis/v1beta3/authpolicy_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ func (p *AuthPolicy) GetName() string {
return p.Name
}

func (p *AuthPolicy) GetURL() string {
return machinery.UrlFromObject(p)
func (p *AuthPolicy) GetIdentity() string {
return machinery.IdentityFromObject(p)
}

func (p *AuthPolicy) GetTargetRefs() []machinery.PolicyTargetReference {
Expand Down
4 changes: 2 additions & 2 deletions examples/kuadrant/apis/v1beta3/ratelimitpolicy_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ func (p *RateLimitPolicy) GetName() string {
return p.Name
}

func (p *RateLimitPolicy) GetURL() string {
return machinery.UrlFromObject(p)
func (p *RateLimitPolicy) GetIdentity() string {
return machinery.IdentityFromObject(p)
}

func (p *RateLimitPolicy) GetTargetRefs() []machinery.PolicyTargetReference {
Expand Down
2 changes: 1 addition & 1 deletion examples/kuadrant/reconcilers/envoy_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (p *EnvoyGatewayProvider) ReconcileSecurityPolicies(ctx context.Context, _
logger.Error(fmt.Errorf("unexpected topology path length to build Envoy SecurityPolicy"), "path", lo.Map(path, machinery.MapTargetableToURLFunc))
return false
}
return path[0].GetURL() == gateway.GetURL() && lo.ContainsBy(targetables.Parents(path[0]), func(parent machinery.Targetable) bool {
return path[0].GetIdentity() == gateway.GetIdentity() && lo.ContainsBy(targetables.Parents(path[0]), func(parent machinery.Targetable) bool {
gc, ok := parent.(*machinery.GatewayClass)
return ok && gc.Spec.ControllerName == "gateway.envoyproxy.io/gatewayclass-controller"
})
Expand Down
2 changes: 1 addition & 1 deletion examples/kuadrant/reconcilers/istio.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (p *IstioGatewayProvider) ReconcileAuthorizationPolicies(ctx context.Contex
logger.Error(fmt.Errorf("unexpected topology path length to build Istio AuthorizationPolicy"), "path", lo.Map(path, machinery.MapTargetableToURLFunc))
return false
}
return path[0].GetURL() == gateway.GetURL() && lo.ContainsBy(targetables.Parents(path[0]), func(parent machinery.Targetable) bool {
return path[0].GetIdentity() == gateway.GetIdentity() && lo.ContainsBy(targetables.Parents(path[0]), func(parent machinery.Targetable) bool {
gc, ok := parent.(*machinery.GatewayClass)
return ok && gc.Spec.ControllerName == "istio.io/gateway-controller"
})
Expand Down
12 changes: 6 additions & 6 deletions machinery/core_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ type Namespace struct {

var _ Targetable = &Namespace{}

func (n *Namespace) GetURL() string {
return UrlFromObject(n)
func (n *Namespace) GetIdentity() string {
return IdentityFromObject(n)
}

func (n *Namespace) SetPolicies(policies []Policy) {
Expand All @@ -42,8 +42,8 @@ type Service struct {

var _ Targetable = &Service{}

func (s *Service) GetURL() string {
return UrlFromObject(s)
func (s *Service) GetIdentity() string {
return IdentityFromObject(s)
}

func (s *Service) SetPolicies(policies []Policy) {
Expand Down Expand Up @@ -71,8 +71,8 @@ func (p *ServicePort) GroupVersionKind() schema.GroupVersionKind {

func (p *ServicePort) SetGroupVersionKind(schema.GroupVersionKind) {}

func (p *ServicePort) GetURL() string {
return namespacedSectionName(UrlFromObject(p.Service), gwapiv1.SectionName(p.Name))
func (p *ServicePort) GetIdentity() string {
return namespacedSectionName(IdentityFromObject(p.Service), gwapiv1.SectionName(p.Name))
}

func (p *ServicePort) GetNamespace() string {
Expand Down
4 changes: 2 additions & 2 deletions machinery/gateway_api_test_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -539,8 +539,8 @@ type TestPolicySpec struct {

var _ Policy = &TestPolicy{}

func (p *TestPolicy) GetURL() string {
return UrlFromObject(p)
func (p *TestPolicy) GetIdentity() string {
return IdentityFromObject(p)
}

func (p *TestPolicy) GetTargetRefs() []PolicyTargetReference {
Expand Down
4 changes: 2 additions & 2 deletions machinery/gateway_api_topology.go
Original file line number Diff line number Diff line change
Expand Up @@ -638,15 +638,15 @@ func findListenerFromParentRefFunc(gateways []*Gateway, listeners []*Listener, r
}
if parentRef.SectionName != nil {
listener, ok := lo.Find(listeners, func(l *Listener) bool {
return l.Gateway.GetURL() == gateway.GetURL() && l.Name == *parentRef.SectionName
return l.Gateway.GetIdentity() == gateway.GetIdentity() && l.Name == *parentRef.SectionName
})
if !ok {
return nil
}
return []Object{listener}
}
return lo.FilterMap(listeners, func(l *Listener, _ int) (Object, bool) {
return l, l.Gateway.GetURL() == gateway.GetURL()
return l, l.Gateway.GetIdentity() == gateway.GetIdentity()
})
}
}
Expand Down
Loading

0 comments on commit 3412363

Please sign in to comment.