Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: more Gateway API kind wrappers #16

Merged
merged 21 commits into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
53e0f16
targetable: GCRPRoute Gateway API kind wrapper
KevFan Jul 30, 2024
79e1fb7
targetable: GCRPRouteRule Gateway API kind wrapper
KevFan Jul 30, 2024
c5517ed
object: ReferenceGrant Gateway API kind wrapper
KevFan Jul 30, 2024
12d082c
policy: BackendTLSPolicy Gateway API kind wrapper
KevFan Jul 30, 2024
4c39dae
targetable: TCPRoute Gateway API kind wrapper
KevFan Jul 30, 2024
bd1e8c3
targetable: TCPRouteRule Gateway API kind wrapper
KevFan Jul 30, 2024
1d17482
targetable: TLSRoute Gateway API kind wrapper
KevFan Jul 30, 2024
bd41ce5
targetable: TLSRouteRule Gateway API kind wrapper
KevFan Jul 30, 2024
2c5b14f
targetable: UCPRoute Gateway API kind wrapper
KevFan Jul 30, 2024
4ac33aa
targetable: UDPRouteRule Gateway API kind wrapper
KevFan Jul 30, 2024
1f2e779
policy: BackendLBPolicy Gateway API kind wrapper
KevFan Jul 30, 2024
d9d03d4
targetable: Namespace Core API kind wrapper
KevFan Jul 30, 2024
c94410c
machinary: add GRPCRoute & GRPCRouteRules to topology
KevFan Jul 30, 2024
c72f74e
refactor: Gateway API GroupKind vars
KevFan Jul 31, 2024
3a85136
machinary: add TCPRoute & TCPRouteRules to topology
KevFan Jul 31, 2024
34a873f
machinary: add TLSRoute & TLSRouteRules to topology
KevFan Jul 31, 2024
dcd153b
machinary: add UDPRoute & UDPRouteRules to topology
KevFan Aug 1, 2024
64ccd19
fixup: address comments
KevFan Aug 15, 2024
d7d3d30
fixup: expand service ports as targetables only once
KevFan Aug 16, 2024
619af82
fixup: use group kinds from machinery package where possible
KevFan Aug 19, 2024
0613f74
fixup: add missing group kinds
KevFan Aug 21, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions controller/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,6 @@ import (
gwapiv1 "sigs.k8s.io/gateway-api/apis/v1"
)

// GroupKinds
var (
// core
ServiceKind = core.SchemeGroupVersion.WithKind("Service").GroupKind()

// gateway api
GatewayClassKind = gwapiv1.SchemeGroupVersion.WithKind("GatewayClass").GroupKind()
GatewayKind = gwapiv1.SchemeGroupVersion.WithKind("Gateway").GroupKind()
HTTPRouteKind = gwapiv1.SchemeGroupVersion.WithKind("HTTPRoute").GroupKind()
)

// API Resources
var (
// core
Expand Down
2 changes: 1 addition & 1 deletion controller/test_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func init() {
myObjects := objs.FilterByGroupKind(schema.GroupKind{Group: "test/v1", Kind: "MyObject"})
return machinery.LinkFunc{
From: schema.GroupKind{Group: "test/v1", Kind: "MyObject"},
To: GatewayKind,
To: machinery.GatewayGroupKind,
Func: func(_ machinery.Object) []machinery.Object { return []machinery.Object{&RuntimeObject{myObjects[0]}} },
}
}
Expand Down
8 changes: 4 additions & 4 deletions controller/topology_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ type gatewayAPITopologyBuilder struct {
}

func (t *gatewayAPITopologyBuilder) Build(objs Store) *machinery.Topology {
gatewayClasses := lo.Map(objs.FilterByGroupKind(GatewayClassKind), ObjectAs[*gwapiv1.GatewayClass])
gateways := lo.Map(objs.FilterByGroupKind(GatewayKind), ObjectAs[*gwapiv1.Gateway])
httpRoutes := lo.Map(objs.FilterByGroupKind(HTTPRouteKind), ObjectAs[*gwapiv1.HTTPRoute])
services := lo.Map(objs.FilterByGroupKind(ServiceKind), ObjectAs[*core.Service])
gatewayClasses := lo.Map(objs.FilterByGroupKind(machinery.GatewayClassGroupKind), ObjectAs[*gwapiv1.GatewayClass])
gateways := lo.Map(objs.FilterByGroupKind(machinery.GatewayGroupKind), ObjectAs[*gwapiv1.Gateway])
httpRoutes := lo.Map(objs.FilterByGroupKind(machinery.HTTPRouteGroupKind), ObjectAs[*gwapiv1.HTTPRoute])
services := lo.Map(objs.FilterByGroupKind(machinery.ServiceGroupKind), ObjectAs[*core.Service])

linkFuncs := lo.Map(t.objectLinks, func(f LinkFunc, _ int) machinery.LinkFunc {
return f(objs)
Expand Down
24 changes: 12 additions & 12 deletions examples/kuadrant/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,18 @@ import (
const (
// reconciliation modes
defaultReconciliationMode = stateReconciliationMode
deltaReconciliationMode = "delta"
stateReconciliationMode = "state"
deltaReconciliationMode = "delta"
stateReconciliationMode = "state"
)

var (
scheme = runtime.NewScheme()

supportedReconciliationModes = []string{stateReconciliationMode, deltaReconciliationMode}
reconciliationMode = defaultReconciliationMode
reconciliationMode = defaultReconciliationMode

supportedGatewayProviders = []string{reconcilers.EnvoyGatewayProviderName, reconcilers.IstioGatewayProviderName}
gatewayProviders []string
gatewayProviders []string
)

func init() {
Expand Down Expand Up @@ -134,13 +134,13 @@ func main() {
controller.WithReconcile(buildReconciler(gatewayProviders, client)),
}

// gateway provider specific controller options
// gateway provider specific controller options
controllerOpts = append(controllerOpts, controllerOptionsFor(gatewayProviders)...)

// managed controller
if reconciliationMode == stateReconciliationMode {
manager, err := ctrlruntime.NewManager(config, ctrlruntime.Options{
Logger: logger,
Logger: logger,
Scheme: scheme,
Metrics: ctrlruntimemetrics.Options{BindAddress: ":8080"},
WebhookServer: ctrlruntimewebhook.NewServer(ctrlruntimewebhook.Options{Port: 9443}),
Expand Down Expand Up @@ -204,10 +204,10 @@ func buildReconciler(gatewayProviders []string, client *dynamic.DynamicClient) c
effectivePolicyReconciler := &reconcilers.EffectivePoliciesReconciler{Client: client}

commonAuthPolicyResourceEventMatchers := []controller.ResourceEventMatcher{
{Kind: ptr.To(controller.GatewayClassKind)},
{Kind: ptr.To(controller.GatewayKind), EventType: ptr.To(controller.CreateEvent)},
{Kind: ptr.To(controller.GatewayKind), EventType: ptr.To(controller.UpdateEvent)},
{Kind: ptr.To(controller.HTTPRouteKind)},
{Kind: ptr.To(machinery.GatewayClassGroupKind)},
{Kind: ptr.To(machinery.GatewayGroupKind), EventType: ptr.To(controller.CreateEvent)},
{Kind: ptr.To(machinery.GatewayGroupKind), EventType: ptr.To(controller.UpdateEvent)},
{Kind: ptr.To(machinery.HTTPRouteGroupKind)},
{Kind: ptr.To(kuadrantv1beta3.AuthPolicyKind)},
}

Expand All @@ -222,7 +222,7 @@ func buildReconciler(gatewayProviders []string, client *dynamic.DynamicClient) c
effectivePolicyReconciler.ReconcileFuncs = append(effectivePolicyReconciler.ReconcileFuncs, (&controller.Subscription{
ReconcileFunc: envoyGatewayProvider.DeleteSecurityPolicy,
Events: []controller.ResourceEventMatcher{
{Kind: ptr.To(controller.GatewayKind), EventType: ptr.To(controller.DeleteEvent)},
{Kind: ptr.To(machinery.GatewayGroupKind), EventType: ptr.To(controller.DeleteEvent)},
},
}).Reconcile)
case reconcilers.IstioGatewayProviderName:
Expand All @@ -234,7 +234,7 @@ func buildReconciler(gatewayProviders []string, client *dynamic.DynamicClient) c
effectivePolicyReconciler.ReconcileFuncs = append(effectivePolicyReconciler.ReconcileFuncs, (&controller.Subscription{
ReconcileFunc: istioGatewayProvider.DeleteAuthorizationPolicy,
Events: []controller.ResourceEventMatcher{
{Kind: ptr.To(controller.GatewayKind), EventType: ptr.To(controller.DeleteEvent)},
{Kind: ptr.To(machinery.GatewayGroupKind), EventType: ptr.To(controller.DeleteEvent)},
},
}).Reconcile)
}
Expand Down
6 changes: 3 additions & 3 deletions examples/kuadrant/reconcilers/envoy_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,10 @@ func (p *EnvoyGatewayProvider) deleteSecurityPolicy(ctx context.Context, topolog
}

func LinkGatewayToEnvoyGatewaySecurityPolicyFunc(objs controller.Store) machinery.LinkFunc {
gateways := lo.Map(objs.FilterByGroupKind(controller.GatewayKind), controller.ObjectAs[*gwapiv1.Gateway])
gateways := lo.Map(objs.FilterByGroupKind(machinery.GatewayGroupKind), controller.ObjectAs[*gwapiv1.Gateway])

return machinery.LinkFunc{
From: controller.GatewayKind,
From: machinery.GatewayGroupKind,
To: EnvoyGatewaySecurityPolicyKind,
Func: func(child machinery.Object) []machinery.Object {
o := child.(*controller.RuntimeObject)
Expand All @@ -168,7 +168,7 @@ func LinkGatewayToEnvoyGatewaySecurityPolicyFunc(objs controller.Store) machiner
refs = append(refs, *ref)
}
refs = lo.Filter(refs, func(ref gwapiv1alpha2.LocalPolicyTargetReferenceWithSectionName, _ int) bool {
return ref.Group == gwapiv1.GroupName && ref.Kind == gwapiv1.Kind(controller.GatewayKind.Kind)
return ref.Group == gwapiv1.GroupName && ref.Kind == gwapiv1.Kind(machinery.GatewayGroupKind.Kind)
})
if len(refs) == 0 {
return nil
Expand Down
6 changes: 3 additions & 3 deletions examples/kuadrant/reconcilers/istio.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,10 +294,10 @@ func hostSubsetOf(superset gwapiv1.Hostname) func(gwapiv1.Hostname, int) bool {
}

func LinkGatewayToIstioAuthorizationPolicyFunc(objs controller.Store) machinery.LinkFunc {
gateways := lo.Map(objs.FilterByGroupKind(controller.GatewayKind), controller.ObjectAs[*gwapiv1.Gateway])
gateways := lo.Map(objs.FilterByGroupKind(machinery.GatewayGroupKind), controller.ObjectAs[*gwapiv1.Gateway])

return machinery.LinkFunc{
From: controller.GatewayKind,
From: machinery.GatewayGroupKind,
To: IstioAuthorizationPolicyKind,
Func: func(child machinery.Object) []machinery.Object {
o := child.(*controller.RuntimeObject)
Expand All @@ -307,7 +307,7 @@ func LinkGatewayToIstioAuthorizationPolicyFunc(objs controller.Store) machinery.
refs = append(refs, ref)
}
refs = lo.Filter(refs, func(ref *istiov1beta1.PolicyTargetReference, _ int) bool {
return ref.Group == gwapiv1.GroupName && ref.Kind == controller.GatewayKind.Kind
return ref.Group == gwapiv1.GroupName && ref.Kind == machinery.GatewayGroupKind.Kind
})
if len(refs) == 0 {
return nil
Expand Down
91 changes: 91 additions & 0 deletions machinery/core_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
package machinery

import (
core "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
gwapiv1 "sigs.k8s.io/gateway-api/apis/v1"
)

var (
ServiceGroupKind = core.SchemeGroupVersion.WithKind("Service").GroupKind()
KevFan marked this conversation as resolved.
Show resolved Hide resolved
ServicePortGroupKind = core.SchemeGroupVersion.WithKind("ServicePort").GroupKind()
)

// These are wrappers for Core API types so instances can be used as targetables in the topology.

type Namespace struct {
*core.Namespace

attachedPolicies []Policy
}

var _ Targetable = &Namespace{}

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

func (n *Namespace) SetPolicies(policies []Policy) {
n.attachedPolicies = policies
}

func (n *Namespace) Policies() []Policy {
return n.attachedPolicies
}
KevFan marked this conversation as resolved.
Show resolved Hide resolved

type Service struct {
*core.Service

attachedPolicies []Policy
}

var _ Targetable = &Service{}

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

func (s *Service) SetPolicies(policies []Policy) {
s.attachedPolicies = policies
}

func (s *Service) Policies() []Policy {
return s.attachedPolicies
}

type ServicePort struct {
*core.ServicePort

Service *Service
attachedPolicies []Policy
}

var _ Targetable = &ServicePort{}

func (p *ServicePort) GroupVersionKind() schema.GroupVersionKind {
return schema.GroupVersionKind{
Kind: "ServicePort",
}
}

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

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

func (p *ServicePort) GetNamespace() string {
return p.Service.GetNamespace()
}

func (p *ServicePort) GetName() string {
return namespacedSectionName(p.Service.Name, gwapiv1.SectionName(p.Name))
}

func (p *ServicePort) SetPolicies(policies []Policy) {
p.attachedPolicies = policies
}

func (p *ServicePort) Policies() []Policy {
return p.attachedPolicies
}
Loading
Loading