Skip to content

Commit

Permalink
wip: notes
Browse files Browse the repository at this point in the history
  • Loading branch information
npolshakova committed Feb 13, 2025
1 parent b5b25d9 commit 3f932af
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 2 deletions.
15 changes: 15 additions & 0 deletions internal/kgateway/extensions2/plugins/routepolicy/ai.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,20 @@ func processAIRoutePolicy(ctx context.Context, aiConfig *v1alpha1.AIRoutePolicy,
outputRoute.TypedPerFilterConfig = make(map[string]*anypb.Any)
}



upstreams := getAiUpstreams(pCtx.In.Backends)
if len(upstreams) != 0 {

}

return nil
}

func getAiUpstreams(backends []ir.HttpBackend) []*ir.Upstream {
var upstreams []*ir.Upstream
for _, backend := range backends {
if backend.Backend.Upstream.ObjIr
}
return upstreams
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ func NewPlugin(ctx context.Context, commoncol *common.CommonCollections) extensi
commoncol.KrtOpts.ToOptions("RoutePolicy")...,
)
gk := v1alpha1.RoutePolicyGVK.GroupKind()
// RoutePolicy IR will have TypedConfig -> implement backendroute method to add prompt guard, etc.
policyCol := krt.NewCollection(col, func(krtctx krt.HandlerContext, policyCR *v1alpha1.RoutePolicy) *ir.PolicyWrapper {
var pol = &ir.PolicyWrapper{
ObjectSource: ir.ObjectSource{
Expand All @@ -57,8 +58,11 @@ func NewPlugin(ctx context.Context, commoncol *common.CommonCollections) extensi
Namespace: policyCR.Namespace,
Name: policyCR.Name,
},
Policy: policyCR,
PolicyIR: &routeOptsPlugin{ct: policyCR.CreationTimestamp.Time, spec: policyCR.Spec},
Policy: policyCR,
PolicyIR: &routeOptsPlugin{
ct: policyCR.CreationTimestamp.Time,
spec: policyCR.Spec,
},
TargetRefs: convert(policyCR.Spec.TargetRef),
}
return pol
Expand Down
8 changes: 8 additions & 0 deletions internal/kgateway/extensions2/plugins/upstream/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,10 +293,18 @@ func (p *plugin2) ApplyVhostPlugin(ctx context.Context, pCtx *ir.VirtualHostCont

// called 0 or more times
func (p *plugin2) ApplyForRoute(ctx context.Context, pCtx *ir.RouteContext, outputRoute *envoy_config_route_v3.Route) error {
// TODO: apply llm headers here

return nil
}

// Run on upstream, regardless of policy (based on upstream gvk)
// share route proto message
//func ApplyForBackend()

// Only called if policy attatched (extension ref)
// Can implement in route policy for ai (prompt guard, etc.)
// Alt. apply regardless if policy is present...?
func (p *plugin2) ApplyForRouteBackend(
ctx context.Context, policy ir.PolicyIR,
pCtx *ir.RouteBackendContext,
Expand Down
1 change: 1 addition & 0 deletions internal/kgateway/ir/iface.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type RouteBackendContext struct {
FilterChainName string
Upstream *Upstream
// todo: make this not public
// TODO: or change this to be proto.mesage (do the any conversion -> get the extproc)
TypedFiledConfig *map[string]*anypb.Any
}

Expand Down
3 changes: 3 additions & 0 deletions internal/kgateway/ir/upstream.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ type Upstream struct {
// i think so, assuming obj -> objir is a 1:1 mapping.
ObjIr interface{ Equals(any) bool }

// AI config
LLM string

AttachedPolicies AttachedPolicies
}

Expand Down

0 comments on commit 3f932af

Please sign in to comment.