Skip to content

Commit bbc886e

Browse files
committed
Splitting HelmConfig into AgentgatewayHelmConfig
A follow-up for 13018 Signed-off-by: David L. Chandler <[email protected]>
1 parent 9de6aa2 commit bbc886e

File tree

8 files changed

+196
-109
lines changed

8 files changed

+196
-109
lines changed
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
package deployer
2+
3+
import (
4+
appsv1 "k8s.io/api/apps/v1"
5+
corev1 "k8s.io/api/core/v1"
6+
7+
"github.com/kgateway-dev/kgateway/v2/api/v1alpha1/kgateway"
8+
)
9+
10+
// AgentgatewayHelmConfig stores the top-level helm values used by the deployer
11+
// for agentgateway deployments.
12+
type AgentgatewayHelmConfig struct {
13+
Gateway *AgentgatewayHelmGateway `json:"gateway,omitempty"`
14+
}
15+
16+
// AgentgatewayHelmGateway contains helm values specific to agentgateway deployments.
17+
type AgentgatewayHelmGateway struct {
18+
// naming
19+
Name *string `json:"name,omitempty"`
20+
GatewayName *string `json:"gatewayName,omitempty"`
21+
GatewayNamespace *string `json:"gatewayNamespace,omitempty"`
22+
GatewayClassName *string `json:"gatewayClassName,omitempty"`
23+
GatewayAnnotations map[string]string `json:"gatewayAnnotations,omitempty"`
24+
GatewayLabels map[string]string `json:"gatewayLabels,omitempty"`
25+
NameOverride *string `json:"nameOverride,omitempty"`
26+
FullnameOverride *string `json:"fullnameOverride,omitempty"`
27+
28+
// deployment/service values
29+
ReplicaCount *uint32 `json:"replicaCount,omitempty"`
30+
Ports []HelmPort `json:"ports,omitempty"`
31+
Service *HelmService `json:"service,omitempty"`
32+
Strategy *appsv1.DeploymentStrategy `json:"strategy,omitempty"`
33+
34+
// serviceaccount values
35+
ServiceAccount *HelmServiceAccount `json:"serviceAccount,omitempty"`
36+
37+
// pod template values
38+
ExtraPodAnnotations map[string]string `json:"extraPodAnnotations,omitempty"`
39+
ExtraPodLabels map[string]string `json:"extraPodLabels,omitempty"`
40+
ImagePullSecrets []corev1.LocalObjectReference `json:"imagePullSecrets,omitempty"`
41+
PodSecurityContext *corev1.PodSecurityContext `json:"podSecurityContext,omitempty"`
42+
NodeSelector map[string]string `json:"nodeSelector,omitempty"`
43+
Affinity *corev1.Affinity `json:"affinity,omitempty"`
44+
Tolerations []corev1.Toleration `json:"tolerations,omitempty"`
45+
StartupProbe *corev1.Probe `json:"startupProbe,omitempty"`
46+
ReadinessProbe *corev1.Probe `json:"readinessProbe,omitempty"`
47+
LivenessProbe *corev1.Probe `json:"livenessProbe,omitempty"`
48+
ExtraVolumes []corev1.Volume `json:"extraVolumes,omitempty"`
49+
GracefulShutdown *kgateway.GracefulShutdownSpec `json:"gracefulShutdown,omitempty"`
50+
TerminationGracePeriodSeconds *int64 `json:"terminationGracePeriodSeconds,omitempty"`
51+
TopologySpreadConstraints []corev1.TopologySpreadConstraint `json:"topologySpreadConstraints,omitempty"`
52+
PriorityClassName *string `json:"priorityClassName,omitempty"`
53+
54+
// agentgateway container values
55+
LogLevel *string `json:"logLevel,omitempty"`
56+
Image *HelmImage `json:"image,omitempty"`
57+
Resources *corev1.ResourceRequirements `json:"resources,omitempty"`
58+
SecurityContext *corev1.SecurityContext `json:"securityContext,omitempty"`
59+
Env []corev1.EnvVar `json:"env,omitempty"`
60+
ExtraVolumeMounts []corev1.VolumeMount `json:"extraVolumeMounts,omitempty"`
61+
62+
// agentgateway xds values
63+
// Note: agentgateway uses agwXds for its xds connection, but the helm template
64+
// also references xds.host for constructing the XDS_ADDRESS
65+
Xds *HelmXds `json:"xds,omitempty"`
66+
AgwXds *HelmXds `json:"agwXds,omitempty"`
67+
68+
// agentgateway-specific config
69+
CustomConfigMapName *string `json:"customConfigMapName,omitempty"`
70+
// LogFormat specifies the logging format for agentgateway (Json or Text)
71+
LogFormat *string `json:"logFormat,omitempty"`
72+
// RawConfig provides opaque config to be merged into config.yaml
73+
RawConfig map[string]any `json:"rawConfig,omitempty"`
74+
}

pkg/deployer/deployer.go

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,14 @@ func JsonConvert(in *HelmConfig, out any) error {
158158
return json.Unmarshal(b, out)
159159
}
160160

161+
func AgentgatewayJsonConvert(in *AgentgatewayHelmConfig, out any) error {
162+
b, err := json.Marshal(in)
163+
if err != nil {
164+
return err
165+
}
166+
return json.Unmarshal(b, out)
167+
}
168+
161169
func (d *Deployer) RenderChartToObjects(ns, name string, vals map[string]any) ([]client.Object, error) {
162170
objs, err := d.RenderToObjects(ns, name, vals)
163171
if err != nil {
@@ -175,7 +183,12 @@ func (d *Deployer) RenderChartToObjects(ns, name string, vals map[string]any) ([
175183
// It returns the list of Objects that are rendered, and an optional error if rendering failed,
176184
// or converting the rendered manifests to objects failed.
177185
func (d *Deployer) RenderToObjects(ns, name string, vals map[string]any) ([]client.Object, error) {
178-
manifest, err := d.RenderManifest(ns, name, vals)
186+
return d.RenderToObjectsWithChartType(ns, name, vals, ChartTypeEnvoy)
187+
}
188+
189+
// RenderToObjectsWithChartType renders the helm chart with the specified chart type.
190+
func (d *Deployer) RenderToObjectsWithChartType(ns, name string, vals map[string]any, chartType ChartType) ([]client.Object, error) {
191+
manifest, err := d.RenderManifestWithChartType(ns, name, vals, chartType)
179192
if err != nil {
180193
return nil, err
181194
}
@@ -188,6 +201,11 @@ func (d *Deployer) RenderToObjects(ns, name string, vals map[string]any) ([]clie
188201
}
189202

190203
func (d *Deployer) RenderManifest(ns, name string, vals map[string]any) ([]byte, error) {
204+
return d.RenderManifestWithChartType(ns, name, vals, ChartTypeEnvoy)
205+
}
206+
207+
// RenderManifestWithChartType renders the helm chart with the specified chart type.
208+
func (d *Deployer) RenderManifestWithChartType(ns, name string, vals map[string]any, chartType ChartType) ([]byte, error) {
191209
mem := driver.NewMemory()
192210
mem.SetNamespace(ns)
193211
cfg := &action.Configuration{
@@ -203,16 +221,10 @@ func (d *Deployer) RenderManifest(ns, name string, vals map[string]any) ([]byte,
203221
install.ClientOnly = true
204222
installCtx := context.Background()
205223

206-
// Select the appropriate chart based on whether agentgateway is enabled
224+
// Select the appropriate chart based on chart type
207225
chartToUse := d.chart
208-
if d.agentgatewayChart != nil {
209-
if gateway, ok := vals["gateway"].(map[string]any); ok {
210-
if dataPlaneType, ok := gateway["dataPlaneType"].(string); ok {
211-
if dataPlaneType == string(DataPlaneAgentgateway) {
212-
chartToUse = d.agentgatewayChart
213-
}
214-
}
215-
}
226+
if chartType == ChartTypeAgentgateway && d.agentgatewayChart != nil {
227+
chartToUse = d.agentgatewayChart
216228
}
217229

218230
release, err := install.RunWithContext(installCtx, chartToUse, vals)
@@ -250,8 +262,10 @@ func (d *Deployer) GetObjsToDeploy(ctx context.Context, obj client.Object) ([]cl
250262
"values", vals,
251263
)
252264

265+
chartType := d.helmValues.GetChartType(ctx, obj)
266+
253267
rname, rns := d.helmReleaseNameAndNamespaceGenerator(obj)
254-
objs, err := d.RenderToObjects(rns, rname, vals)
268+
objs, err := d.RenderToObjectsWithChartType(rns, rname, vals, chartType)
255269
if err != nil {
256270
return nil, fmt.Errorf("failed to get objects to deploy %s.%s: %w", obj.GetNamespace(), obj.GetName(), err)
257271
}

pkg/deployer/helm_values_generator.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ type HelmValuesGenerator interface {
1717

1818
// GetCacheSyncHandlers returns the cache sync handlers for the HelmValuesGenerator controller
1919
GetCacheSyncHandlers() []cache.InformerSynced
20+
21+
// GetChartType returns the chart type to use for rendering the given object.
22+
GetChartType(ctx context.Context, obj client.Object) ChartType
2023
}
2124

2225
// ObjectPostProcessor is an optional interface that can be implemented by HelmValuesGenerator
@@ -27,3 +30,14 @@ type ObjectPostProcessor interface {
2730
// This is called after helm rendering but before deployment.
2831
PostProcessObjects(ctx context.Context, obj client.Object, rendered []client.Object) error
2932
}
33+
34+
// ChartType indicates which helm chart to use for rendering.
35+
type ChartType int
36+
37+
const (
38+
// ChartTypeEnvoy indicates the Envoy proxy chart should be used.
39+
ChartTypeEnvoy ChartType = iota
40+
// ChartTypeAgentgateway indicates the agentgateway chart should be used.
41+
ChartTypeAgentgateway
42+
)
43+

pkg/deployer/values.go

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,14 @@ import (
77
"github.com/kgateway-dev/kgateway/v2/api/v1alpha1/kgateway"
88
)
99

10-
type DataPlaneType string
11-
12-
const (
13-
DataPlaneAgentgateway DataPlaneType = "agentgateway"
14-
DataPlaneEnvoy DataPlaneType = "envoy"
15-
)
16-
17-
// helmConfig stores the top-level helm values used by the deployer.
10+
// HelmConfig stores the top-level helm values used by the deployer for Envoy deployments.
1811
type HelmConfig struct {
1912
Gateway *HelmGateway `json:"gateway,omitempty"`
2013
InferenceExtension *HelmInferenceExtension `json:"inferenceExtension,omitempty"`
2114
}
2215

16+
// HelmGateway contains helm values specific to Envoy gateway deployments.
2317
type HelmGateway struct {
24-
// not needed by the helm charts, but by the code that select the correct
25-
// helm chart:
26-
DataPlaneType DataPlaneType `json:"dataPlaneType"`
27-
2818
// naming
2919
Name *string `json:"name,omitempty"`
3020
GatewayName *string `json:"gatewayName,omitempty"`
@@ -69,12 +59,8 @@ type HelmGateway struct {
6959
Istio *HelmIstio `json:"istio,omitempty"`
7060

7161
// envoy container values
72-
ComponentLogLevel *string `json:"componentLogLevel,omitempty"`
73-
74-
// envoy or agentgateway container values
75-
// Note: ideally, these should be mapped to container specific values, but right now they
76-
// map to the proxy container
7762
LogLevel *string `json:"logLevel,omitempty"`
63+
ComponentLogLevel *string `json:"componentLogLevel,omitempty"`
7864
Image *HelmImage `json:"image,omitempty"`
7965
Resources *corev1.ResourceRequirements `json:"resources,omitempty"`
8066
SecurityContext *corev1.SecurityContext `json:"securityContext,omitempty"`
@@ -83,18 +69,9 @@ type HelmGateway struct {
8369

8470
// xds values
8571
Xds *HelmXds `json:"xds,omitempty"`
86-
// agentgateway xds values
87-
AgwXds *HelmXds `json:"agwXds,omitempty"`
8872

8973
// stats values
9074
Stats *HelmStatsConfig `json:"stats,omitempty"`
91-
92-
// agentgateway integration values
93-
CustomConfigMapName *string `json:"customConfigMapName,omitempty"`
94-
// LogFormat specifies the logging format for agentgateway (Json or Text)
95-
LogFormat *string `json:"logFormat,omitempty"`
96-
// RawConfig provides opaque config to be merged into config.yaml
97-
RawConfig map[string]any `json:"rawConfig,omitempty"`
9875
}
9976

10077
// helmPort represents a Gateway Listener port

pkg/kgateway/deployer/agentgateway_parameters.go

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ func NewAgentgatewayParametersApplier(params *agentgateway.AgentgatewayParameter
156156
// ApplyToHelmValues applies the AgentgatewayParameters configs to the helm
157157
// values. This is called before rendering the helm chart. (We render a helm
158158
// chart, but we do not use helm beyond that point.)
159-
func (a *AgentgatewayParametersApplier) ApplyToHelmValues(vals *deployer.HelmConfig) {
159+
func (a *AgentgatewayParametersApplier) ApplyToHelmValues(vals *deployer.AgentgatewayHelmConfig) {
160160
if a.params == nil || vals == nil || vals.Gateway == nil {
161161
return
162162
}
@@ -316,13 +316,13 @@ func (g *agentgatewayParametersHelmValuesGenerator) GetValues(ctx context.Contex
316316
}
317317

318318
if g.inputs.ControlPlane.XdsTLS {
319-
if err := injectXdsCACertificate(g.inputs.ControlPlane.XdsTlsCaPath, vals); err != nil {
319+
if err := injectXdsCACertificate(g.inputs.ControlPlane.XdsTlsCaPath, vals.Gateway.Xds, vals.Gateway.AgwXds); err != nil {
320320
return nil, fmt.Errorf("failed to inject xDS CA certificate: %w", err)
321321
}
322322
}
323323

324324
var jsonVals map[string]any
325-
err = deployer.JsonConvert(vals, &jsonVals)
325+
err = deployer.AgentgatewayJsonConvert(vals, &jsonVals)
326326
return jsonVals, err
327327
}
328328

@@ -441,7 +441,7 @@ func (g *agentgatewayParametersHelmValuesGenerator) shouldOmitDefaultSecurityCon
441441
// GatewayParameters to helm values. This provides backward compatibility for
442442
// users who configure agentgateway using GatewayParameters, not
443443
// AgentgatewayParameters.
444-
func (g *agentgatewayParametersHelmValuesGenerator) applyGatewayParametersToHelmValues(gwp *kgateway.GatewayParameters, vals *deployer.HelmConfig) {
444+
func (g *agentgatewayParametersHelmValuesGenerator) applyGatewayParametersToHelmValues(gwp *kgateway.GatewayParameters, vals *deployer.AgentgatewayHelmConfig) {
445445
if gwp == nil || gwp.Spec.Kube == nil || vals.Gateway == nil {
446446
return
447447
}
@@ -516,22 +516,25 @@ func (g *agentgatewayParametersHelmValuesGenerator) GetCacheSyncHandlers() []cac
516516
return append(handlers, g.gwParamClient.HasSynced)
517517
}
518518

519+
func (g *agentgatewayParametersHelmValuesGenerator) GetChartType(ctx context.Context, obj client.Object) deployer.ChartType {
520+
return deployer.ChartTypeAgentgateway
521+
}
522+
519523
// GetResolvedParametersForGateway returns both the GatewayClass-level and Gateway-level
520524
// AgentgatewayParameters for the given Gateway. This allows callers to apply overlays
521525
// in order (GatewayClass first, then Gateway).
522526
func (g *agentgatewayParametersHelmValuesGenerator) GetResolvedParametersForGateway(gw *gwv1.Gateway) (*resolvedParameters, error) {
523527
return g.resolveParameters(gw)
524528
}
525529

526-
func (g *agentgatewayParametersHelmValuesGenerator) getDefaultAgentgatewayHelmValues(gw *gwv1.Gateway, omitDefaultSecurityContext bool) (*deployer.HelmConfig, error) {
530+
func (g *agentgatewayParametersHelmValuesGenerator) getDefaultAgentgatewayHelmValues(gw *gwv1.Gateway, omitDefaultSecurityContext bool) (*deployer.AgentgatewayHelmConfig, error) {
527531
irGW := deployer.GetGatewayIR(gw, g.inputs.CommonCollections)
528532
ports := deployer.GetPortsValues(irGW, nil, true) // true = agentgateway
529533
if len(ports) == 0 {
530534
return nil, ErrNoValidPorts
531535
}
532536

533-
gtw := &deployer.HelmGateway{
534-
DataPlaneType: deployer.DataPlaneAgentgateway,
537+
gtw := &deployer.AgentgatewayHelmGateway{
535538
Name: &gw.Name,
536539
GatewayName: &gw.Name,
537540
GatewayNamespace: &gw.Namespace,
@@ -569,7 +572,6 @@ func (g *agentgatewayParametersHelmValuesGenerator) getDefaultAgentgatewayHelmVa
569572
Tag: ptr.To(deployer.AgentgatewayDefaultTag),
570573
PullPolicy: ptr.To(""),
571574
}
572-
gtw.DataPlaneType = deployer.DataPlaneAgentgateway
573575

574576
gtw.TerminationGracePeriodSeconds = ptr.To(int64(60))
575577
gtw.GracefulShutdown = &kgateway.GracefulShutdownSpec{
@@ -619,5 +621,5 @@ func (g *agentgatewayParametersHelmValuesGenerator) getDefaultAgentgatewayHelmVa
619621
}
620622
}
621623

622-
return &deployer.HelmConfig{Gateway: gtw}, nil
624+
return &deployer.AgentgatewayHelmConfig{Gateway: gtw}, nil
623625
}

pkg/kgateway/deployer/agentgateway_parameters_test.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ import (
1919

2020
func TestAgentgatewayParametersApplier_ApplyToHelmValues_NilParams(t *testing.T) {
2121
applier := NewAgentgatewayParametersApplier(nil)
22-
vals := &deployer.HelmConfig{
23-
Gateway: &deployer.HelmGateway{
22+
vals := &deployer.AgentgatewayHelmConfig{
23+
Gateway: &deployer.AgentgatewayHelmGateway{
2424
LogLevel: ptr.To("info"),
2525
},
2626
}
@@ -45,8 +45,8 @@ func TestAgentgatewayParametersApplier_ApplyToHelmValues_Image(t *testing.T) {
4545
}
4646

4747
applier := NewAgentgatewayParametersApplier(params)
48-
vals := &deployer.HelmConfig{
49-
Gateway: &deployer.HelmGateway{},
48+
vals := &deployer.AgentgatewayHelmConfig{
49+
Gateway: &deployer.AgentgatewayHelmGateway{},
5050
}
5151

5252
applier.ApplyToHelmValues(vals)
@@ -76,8 +76,8 @@ func TestAgentgatewayParametersApplier_ApplyToHelmValues_Resources(t *testing.T)
7676
}
7777

7878
applier := NewAgentgatewayParametersApplier(params)
79-
vals := &deployer.HelmConfig{
80-
Gateway: &deployer.HelmGateway{},
79+
vals := &deployer.AgentgatewayHelmConfig{
80+
Gateway: &deployer.AgentgatewayHelmGateway{},
8181
}
8282

8383
applier.ApplyToHelmValues(vals)
@@ -100,8 +100,8 @@ func TestAgentgatewayParametersApplier_ApplyToHelmValues_Env(t *testing.T) {
100100
}
101101

102102
applier := NewAgentgatewayParametersApplier(params)
103-
vals := &deployer.HelmConfig{
104-
Gateway: &deployer.HelmGateway{
103+
vals := &deployer.AgentgatewayHelmConfig{
104+
Gateway: &deployer.AgentgatewayHelmGateway{
105105
Env: []corev1.EnvVar{
106106
{Name: "EXISTING_VAR", Value: "existing_value"},
107107
},
@@ -128,8 +128,8 @@ func TestAgentgatewayParametersApplier_ApplyToHelmValues_Logging(t *testing.T) {
128128
}
129129

130130
applier := NewAgentgatewayParametersApplier(params)
131-
vals := &deployer.HelmConfig{
132-
Gateway: &deployer.HelmGateway{},
131+
vals := &deployer.AgentgatewayHelmConfig{
132+
Gateway: &deployer.AgentgatewayHelmGateway{},
133133
}
134134

135135
applier.ApplyToHelmValues(vals)
@@ -227,8 +227,8 @@ func TestAgentgatewayParametersApplier_ApplyToHelmValues_RawConfig(t *testing.T)
227227
}
228228

229229
applier := NewAgentgatewayParametersApplier(params)
230-
vals := &deployer.HelmConfig{
231-
Gateway: &deployer.HelmGateway{},
230+
vals := &deployer.AgentgatewayHelmConfig{
231+
Gateway: &deployer.AgentgatewayHelmGateway{},
232232
}
233233

234234
applier.ApplyToHelmValues(vals)
@@ -267,8 +267,8 @@ func TestAgentgatewayParametersApplier_ApplyToHelmValues_RawConfigWithLogging(t
267267
}
268268

269269
applier := NewAgentgatewayParametersApplier(params)
270-
vals := &deployer.HelmConfig{
271-
Gateway: &deployer.HelmGateway{},
270+
vals := &deployer.AgentgatewayHelmConfig{
271+
Gateway: &deployer.AgentgatewayHelmGateway{},
272272
}
273273

274274
applier.ApplyToHelmValues(vals)

0 commit comments

Comments
 (0)