Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
52 changes: 52 additions & 0 deletions pkg/deployer/agentgateway_values.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package deployer

import (
corev1 "k8s.io/api/core/v1"

"github.com/kgateway-dev/kgateway/v2/api/v1alpha1/kgateway"
)

// AgentgatewayHelmConfig stores the top-level helm values used by the deployer
// for agentgateway deployments.
type AgentgatewayHelmConfig struct {
Gateway *AgentgatewayHelmGateway `json:"gateway,omitempty"`
}

// AgentgatewayHelmGateway contains helm values specific to agentgateway deployments.
type AgentgatewayHelmGateway struct {
// naming
Name *string `json:"name,omitempty"`
GatewayName *string `json:"gatewayName,omitempty"`
GatewayNamespace *string `json:"gatewayNamespace,omitempty"`
GatewayClassName *string `json:"gatewayClassName,omitempty"`
GatewayAnnotations map[string]string `json:"gatewayAnnotations,omitempty"`
GatewayLabels map[string]string `json:"gatewayLabels,omitempty"`

// deployment values
Ports []HelmPort `json:"ports,omitempty"`

// pod template values
PodSecurityContext *corev1.PodSecurityContext `json:"podSecurityContext,omitempty"`
StartupProbe *corev1.Probe `json:"startupProbe,omitempty"`
ReadinessProbe *corev1.Probe `json:"readinessProbe,omitempty"`
GracefulShutdown *kgateway.GracefulShutdownSpec `json:"gracefulShutdown,omitempty"`
TerminationGracePeriodSeconds *int64 `json:"terminationGracePeriodSeconds,omitempty"`

// agentgateway container values
Image *HelmImage `json:"image,omitempty"`
Resources *corev1.ResourceRequirements `json:"resources,omitempty"`
SecurityContext *corev1.SecurityContext `json:"securityContext,omitempty"`
Env []corev1.EnvVar `json:"env,omitempty"`

// agentgateway xds values
// Note: agentgateway uses agwXds for its xds connection, but the helm template
// also references xds.host for constructing the XDS_ADDRESS
Xds *HelmXds `json:"xds,omitempty"`
AgwXds *HelmXds `json:"agwXds,omitempty"`

// agentgateway-specific config
// LogFormat specifies the logging format for agentgateway (Json or Text)
LogFormat *string `json:"logFormat,omitempty"`
// RawConfig provides opaque config to be merged into config.yaml
RawConfig map[string]any `json:"rawConfig,omitempty"`
}
55 changes: 10 additions & 45 deletions pkg/deployer/deployer.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ type Deployer struct {
agwControllerName string
agwGatewayClassName string
chart *chart.Chart
agentgatewayChart *chart.Chart
scheme *runtime.Scheme
client apiclient.Client
helmValues HelmValuesGenerator
Expand All @@ -82,7 +81,7 @@ func WithGVKToGVRMapper(m map[schema.GroupVersionKind]schema.GroupVersionResourc
}
}

// NewDeployer creates a new gateway/inference pool/etc
// NewDeployer creates a new gateway/inference pool/etc deployer with a single chart.
// TODO [danehans]: Reloading the chart for every reconciliation is inefficient.
// See https://github.com/kgateway-dev/kgateway/issues/10672 for details.
func NewDeployer(
Expand All @@ -101,36 +100,6 @@ func NewDeployer(
scheme: scheme,
client: client,
chart: chart,
agentgatewayChart: nil,
helmValues: hvg,
helmReleaseNameAndNamespaceGenerator: helmReleaseNameAndNamespaceGenerator,
patcher: applyPatch,
}
for _, o := range opts {
o(d)
}
return d
}

// NewDeployerWithMultipleCharts creates a new gateway deployer that supports both envoy and agentgateway charts
func NewDeployerWithMultipleCharts(
controllerName, agwControllerName, agwGatewayClassName string,
scheme *runtime.Scheme,
client apiclient.Client,
envoyChart *chart.Chart,
agentgatewayChart *chart.Chart,
hvg HelmValuesGenerator,
helmReleaseNameAndNamespaceGenerator func(obj client.Object) (string, string),
opts ...Option,
) *Deployer {
d := &Deployer{
controllerName: controllerName,
agwControllerName: agwControllerName,
agwGatewayClassName: agwGatewayClassName,
scheme: scheme,
client: client,
chart: envoyChart,
agentgatewayChart: agentgatewayChart,
helmValues: hvg,
helmReleaseNameAndNamespaceGenerator: helmReleaseNameAndNamespaceGenerator,
patcher: applyPatch,
Expand Down Expand Up @@ -158,6 +127,14 @@ func JsonConvert(in *HelmConfig, out any) error {
return json.Unmarshal(b, out)
}

func AgentgatewayJsonConvert(in *AgentgatewayHelmConfig, out any) error {
b, err := json.Marshal(in)
if err != nil {
return err
}
return json.Unmarshal(b, out)
}

func (d *Deployer) RenderChartToObjects(ns, name string, vals map[string]any) ([]client.Object, error) {
objs, err := d.RenderToObjects(ns, name, vals)
if err != nil {
Expand Down Expand Up @@ -203,19 +180,7 @@ func (d *Deployer) RenderManifest(ns, name string, vals map[string]any) ([]byte,
install.ClientOnly = true
installCtx := context.Background()

// Select the appropriate chart based on whether agentgateway is enabled
chartToUse := d.chart
if d.agentgatewayChart != nil {
if gateway, ok := vals["gateway"].(map[string]any); ok {
if dataPlaneType, ok := gateway["dataPlaneType"].(string); ok {
if dataPlaneType == string(DataPlaneAgentgateway) {
chartToUse = d.agentgatewayChart
}
}
}
}

release, err := install.RunWithContext(installCtx, chartToUse, vals)
release, err := install.RunWithContext(installCtx, d.chart, vals)
if err != nil {
return nil, fmt.Errorf("failed to render helm chart for %s.%s: %w", ns, name, err)
}
Expand Down
Loading
Loading