Skip to content

Commit

Permalink
fixup: use group kinds from machinery package where possible
Browse files Browse the repository at this point in the history
Signed-off-by: KevFan <[email protected]>
  • Loading branch information
KevFan committed Aug 19, 2024
1 parent d7d3d30 commit 619af82
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 52 deletions.
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
4 changes: 2 additions & 2 deletions machinery/core_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
)

var (
ServiceGroupKind = schema.GroupKind{Kind: "Service"}
ServicePortGroupKind = schema.GroupKind{Kind: "ServicePort"}
ServiceGroupKind = core.SchemeGroupVersion.WithKind("Service").GroupKind()
ServicePortGroupKind = core.SchemeGroupVersion.WithKind("ServicePort").GroupKind()
)

// These are wrappers for Core API types so instances can be used as targetables in the topology.
Expand Down
6 changes: 3 additions & 3 deletions machinery/gateway_api_test_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func BuildBackendRef(f ...func(*gwapiv1.BackendObjectReference)) gwapiv1.Backend
func BuildTCPRoute(f ...func(route *gwapiv1alpha2.TCPRoute)) *gwapiv1alpha2.TCPRoute {
r := &gwapiv1alpha2.TCPRoute{
TypeMeta: metav1.TypeMeta{
APIVersion: gwapiv1.GroupVersion.String(),
APIVersion: gwapiv1alpha2.GroupVersion.String(),
Kind: "TCPRoute",
},
ObjectMeta: metav1.ObjectMeta{
Expand Down Expand Up @@ -206,7 +206,7 @@ func BuildTCPRoute(f ...func(route *gwapiv1alpha2.TCPRoute)) *gwapiv1alpha2.TCPR
func BuildTLSRoute(f ...func(route *gwapiv1alpha2.TLSRoute)) *gwapiv1alpha2.TLSRoute {
r := &gwapiv1alpha2.TLSRoute{
TypeMeta: metav1.TypeMeta{
APIVersion: gwapiv1.GroupVersion.String(),
APIVersion: gwapiv1alpha2.GroupVersion.String(),
Kind: "TLSRoute",
},
ObjectMeta: metav1.ObjectMeta{
Expand Down Expand Up @@ -238,7 +238,7 @@ func BuildTLSRoute(f ...func(route *gwapiv1alpha2.TLSRoute)) *gwapiv1alpha2.TLSR
func BuildUDPRoute(f ...func(route *gwapiv1alpha2.UDPRoute)) *gwapiv1alpha2.UDPRoute {
r := &gwapiv1alpha2.UDPRoute{
TypeMeta: metav1.TypeMeta{
APIVersion: gwapiv1.GroupVersion.String(),
APIVersion: gwapiv1alpha2.GroupVersion.String(),
Kind: "UDPRoute",
},
ObjectMeta: metav1.ObjectMeta{
Expand Down
26 changes: 13 additions & 13 deletions machinery/gateway_api_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@ import (
)

var (
GatewayClassGroupKind = schema.GroupKind{Group: gwapiv1.GroupVersion.Group, Kind: "GatewayClass"}
GatewayGroupKind = schema.GroupKind{Group: gwapiv1.GroupVersion.Group, Kind: "Gateway"}
ListenerGroupKind = schema.GroupKind{Group: gwapiv1.GroupVersion.Group, Kind: "Listener"}
HTTPRouteGroupKind = schema.GroupKind{Group: gwapiv1.GroupVersion.Group, Kind: "HTTPRoute"}
HTTPRouteRuleGroupKind = schema.GroupKind{Group: gwapiv1.GroupVersion.Group, Kind: "HTTPRouteRule"}
GRPCRouteGroupKind = schema.GroupKind{Group: gwapiv1.GroupVersion.Group, Kind: "GRPCRoute"}
GRPCRouteRuleGroupKind = schema.GroupKind{Group: gwapiv1.GroupVersion.Group, Kind: "GRPCRouteRule"}
TCPRouteGroupKind = schema.GroupKind{Group: gwapiv1alpha2.GroupVersion.Group, Kind: "TCPRoute"}
TCPRouteRuleGroupKind = schema.GroupKind{Group: gwapiv1alpha2.GroupVersion.Group, Kind: "TCPRouteRule"}
TLSRouteGroupKind = schema.GroupKind{Group: gwapiv1alpha2.GroupVersion.Group, Kind: "TLSRoute"}
TLSRouteRuleGroupKind = schema.GroupKind{Group: gwapiv1alpha2.GroupVersion.Group, Kind: "TLSRouteRule"}
UDPRouteGroupKind = schema.GroupKind{Group: gwapiv1alpha2.GroupVersion.Group, Kind: "UDPRoute"}
UDPRouteRuleGroupKind = schema.GroupKind{Group: gwapiv1alpha2.GroupVersion.Group, Kind: "UDPRouteRule"}
GatewayClassGroupKind = gwapiv1.SchemeGroupVersion.WithKind("GatewayClass").GroupKind()
GatewayGroupKind = gwapiv1.SchemeGroupVersion.WithKind("Gateway").GroupKind()
ListenerGroupKind = gwapiv1.SchemeGroupVersion.WithKind("Listener").GroupKind()
HTTPRouteGroupKind = gwapiv1.SchemeGroupVersion.WithKind("HTTPRoute").GroupKind()
HTTPRouteRuleGroupKind = gwapiv1.SchemeGroupVersion.WithKind("HTTPRouteRule").GroupKind()
GRPCRouteGroupKind = gwapiv1.SchemeGroupVersion.WithKind("GRPCRoute").GroupKind()
GRPCRouteRuleGroupKind = gwapiv1.SchemeGroupVersion.WithKind("GRPCRouteRule").GroupKind()
TCPRouteGroupKind = gwapiv1alpha2.SchemeGroupVersion.WithKind("TCPRoute").GroupKind()
TCPRouteRuleGroupKind = gwapiv1alpha2.SchemeGroupVersion.WithKind("TCPRouteRule").GroupKind()
TLSRouteGroupKind = gwapiv1alpha2.SchemeGroupVersion.WithKind("TLSRoute").GroupKind()
TLSRouteRuleGroupKind = gwapiv1alpha2.SchemeGroupVersion.WithKind("TLSRouteRule").GroupKind()
UDPRouteGroupKind = gwapiv1alpha2.SchemeGroupVersion.WithKind("UDPRoute").GroupKind()
UDPRouteRuleGroupKind = gwapiv1alpha2.SchemeGroupVersion.WithKind("UDPRouteRule").GroupKind()
)

const nameSectionNameURLSeparator = '#'
Expand Down

0 comments on commit 619af82

Please sign in to comment.