Skip to content

Commit 03b3d4e

Browse files
committed
feat: define BodyBasedRoutingConfig API types for BBR pluggability
1 parent 2a1fca3 commit 03b3d4e

3 files changed

Lines changed: 155 additions & 0 deletions

File tree

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/*
2+
Copyright 2025 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package v1alpha1
18+
19+
import (
20+
"encoding/json"
21+
"fmt"
22+
"strings"
23+
24+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
25+
)
26+
27+
// +kubebuilder:object:root=true
28+
29+
// BodyBasedRoutingConfig is the Schema for the bodybasedroutingconfigs API.
30+
// It defines the plugins and request/response pipelines for the BBR component.
31+
type BodyBasedRoutingConfig struct {
32+
metav1.TypeMeta `json:",inline"`
33+
34+
// +required
35+
// +kubebuilder:validation:Required
36+
// Plugins is the list of plugins that will be instantiated.
37+
Plugins []PluginSpec `json:"plugins"`
38+
39+
// +optional
40+
// Request is the ordered list of plugins to execute on the request path.
41+
// Plugins are executed in the order they appear in this list.
42+
// Each referenced plugin must implement the RequestProcessor interface.
43+
Request []BBRPluginRef `json:"request,omitempty"`
44+
45+
// +optional
46+
// Response is the ordered list of plugins to execute on the response path.
47+
// Plugins are executed in the order they appear in this list.
48+
// Each referenced plugin must implement the ResponseProcessor interface.
49+
Response []BBRPluginRef `json:"response,omitempty"`
50+
}
51+
52+
func (cfg BodyBasedRoutingConfig) String() string {
53+
var parts []string
54+
if len(cfg.Plugins) > 0 {
55+
parts = append(parts, fmt.Sprintf("Plugins: %v", cfg.Plugins))
56+
}
57+
if len(cfg.Request) > 0 {
58+
parts = append(parts, fmt.Sprintf("Request: %v", cfg.Request))
59+
}
60+
if len(cfg.Response) > 0 {
61+
parts = append(parts, fmt.Sprintf("Response: %v", cfg.Response))
62+
}
63+
return "{" + strings.Join(parts, ", ") + "}"
64+
}
65+
66+
// BBRPluginRef references a plugin defined in the Plugins section
67+
// for use in request or response pipelines.
68+
type BBRPluginRef struct {
69+
// +required
70+
// +kubebuilder:validation:Required
71+
// PluginRef specifies a particular Plugin instance to be used in this
72+
// pipeline step. The reference is to the name of an entry of the Plugins
73+
// defined in the configuration's Plugins section.
74+
PluginRef string `json:"pluginRef"`
75+
76+
// +optional
77+
// Parameters are optional runtime parameters for this pipeline step.
78+
// The plugin is responsible for parsing these parameters.
79+
Parameters json.RawMessage `json:"parameters,omitempty"`
80+
}
81+
82+
func (ref BBRPluginRef) String() string {
83+
var parts []string
84+
parts = append(parts, "PluginRef: "+ref.PluginRef)
85+
if len(ref.Parameters) > 0 {
86+
parts = append(parts, "Parameters: "+string(ref.Parameters))
87+
}
88+
return "{" + strings.Join(parts, ", ") + "}"
89+
}

apix/config/v1alpha1/zz_generated.deepcopy.go

Lines changed: 65 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apix/config/v1alpha1/zz_generated.register.go

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)