Skip to content
Merged
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
29 changes: 25 additions & 4 deletions docs/architecture/process-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,31 @@ Push JWT signing is optional: `gateway.push.signingPrivateKeyFile` names an
unencrypted PKCS#8 Ed25519 PEM key when enabled. Helm projects the operator-managed
Secret selected by `controller.push.signing.secretName`.

Durations use protobuf JSON notation: `60s`, `0.5s`, or `0s`. Unknown fields,
duplicate keys, nulls, YAML aliases/merges, and multiple documents are rejected.
Defaults preserve explicit false and zero values. Zero disables session idle
expiration and leaves share TTL unbounded; nonzero intervals must be positive.
Config files use `sigs.k8s.io/yaml.YAMLToJSONStrict` followed by Go's
`protojson.Unmarshal`. Protovalidate checks the schema after command-line overrides
and application defaults are applied. Parsing follows those libraries:

- Duplicate keys and unknown protobuf fields are rejected. Supplying both the
camelCase and snake_case names of the same protobuf field is also rejected.
- YAML 1.1 scalar rules apply: unquoted `yes`, `no`, `on`, and `off` are booleans;
quote them when a string is intended. YAML numeric forms such as `0x10` are
converted to numbers, and numeric mapping keys become strings.
- YAML anchors, aliases, and merge keys are resolved by the YAML library. Strict
mode rejects duplicate keys, including an explicit override of a merged key.
- Only the first YAML document is read; subsequent documents are ignored.
- ProtoJSON accepts quoted integers for integer fields, but a quoted boolean is
a string and fails boolean decoding. Durations use `60s`, `0.5s`, or `0s`.
- Field `null` means unset; it does not disable a setting. Null list elements are
rejected. An explicitly empty string is validated against the field's schema.

Defaults follow protobuf presence. Ordinary scalars use their protobuf zero value;
for example, omitted and explicit zero `database.pool.minConns` both mean zero.
Optional scalars and message fields distinguish omission from an explicit value:
`kubernetes.leaderElection` defaults to true but accepts false, `sessions.idleTtl`
defaults to seven days but `0s` disables expiration, and omitted
`runtimeDefaults.maxContentLength` selects the runtime limit while zero disables
that limit. Session shares have no TTL bound by default; nonzero intervals must
be positive.

Helm's top-level `config` block mirrors the schema and includes both controller
settings and managed runtime defaults. The chart writes one config file,
Expand Down
20 changes: 9 additions & 11 deletions go/api/gen/kagent/api/v1alpha1/config.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions go/core/internal/controller/collections.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"istio.io/istio/pkg/kube/krt"
corev1 "k8s.io/api/core/v1"

apiv1 "github.com/kagent-dev/kagent/go/api/gen/kagent/api/v1alpha1"
kagentv1alpha3 "github.com/kagent-dev/kagent/go/api/v1alpha3"
"github.com/kagent-dev/kagent/go/core/internal/translator"
)
Expand Down Expand Up @@ -61,7 +62,7 @@ func (p AgentRuntimeObservation) Equals(other AgentRuntimeObservation) bool {

// NewCollections creates the complete read-only input graph. An empty
// watchNamespaces list watches all namespaces.
func NewCollections(client kube.Client, watchNamespaces []string, opts krt.OptionsBuilder, settings translator.CompilerSettings) Collections {
func NewCollections(client kube.Client, watchNamespaces []string, opts krt.OptionsBuilder, settings *apiv1.RuntimeDefaultsConfig, images *apiv1.HarnessImagesConfig) Collections {
sandboxTemplates := typedCollection[*kagentv1alpha3.SandboxTemplate](client, watchNamespaces, "SandboxTemplates", opts)
agents := typedCollection[*kagentv1alpha3.Agent](client, watchNamespaces, "Agents", opts)
agentTemplates := typedCollection[*kagentv1alpha3.AgentTemplate](client, watchNamespaces, "AgentTemplates", opts)
Expand All @@ -77,7 +78,7 @@ func NewCollections(client kube.Client, watchNamespaces []string, opts krt.Optio
Harnesses: harnesses, AgentTemplates: agentTemplates, ResolvedModelConfigs: resolvedModelConfigs, RemoteMCPServers: remoteMCPServers,
ConfigMaps: configMaps, Secrets: secrets, WorkerPools: workerPools,
}
reconciliations := newAgentReconciliations(agents, compilerCollections, agentRuntimeObservations, opts, settings)
reconciliations := newAgentReconciliations(agents, compilerCollections, agentRuntimeObservations, opts, settings, images)
statuses := newAgentStatuses(agents, reconciliations, opts)

return Collections{
Expand Down
22 changes: 11 additions & 11 deletions go/core/internal/controller/collections_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
apimeta "k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/kagent-dev/kagent/go/api/adk"
apiv1 "github.com/kagent-dev/kagent/go/api/gen/kagent/api/v1alpha1"
kagentv1alpha3 "github.com/kagent-dev/kagent/go/api/v1alpha3"
"github.com/kagent-dev/kagent/go/core/internal/translator"
)
Expand Down Expand Up @@ -64,7 +64,7 @@ func TestReconciliationCollectionsCompileAndObserveRevision(t *testing.T) {
Harnesses: collections.Harnesses, AgentTemplates: collections.AgentTemplates, ResolvedModelConfigs: collections.ResolvedModelConfigs,
RemoteMCPServers: collections.RemoteMCPServers, ConfigMaps: collections.ConfigMaps,
Secrets: collections.Secrets, WorkerPools: collections.WorkerPools,
}, collections.AgentRuntimeObservations, opts, testCompilerSettings(),
}, collections.AgentRuntimeObservations, opts, testRuntimeDefaults(), nil,
)
collections.AgentStatuses = newAgentStatuses(collections.Agents, collections.Reconciliations, opts)

Expand Down Expand Up @@ -152,15 +152,15 @@ func TestReconciliationReportsRuntimeValidationAsUnsupported(t *testing.T) {
})
configMaps, secrets := krttest.GetMockCollection[*corev1.ConfigMap](mock), krttest.GetMockCollection[*corev1.Secret](mock)
_, resolvedModels := newModelConfigReconciliations(krttest.GetMockCollection[*kagentv1alpha3.ModelConfig](mock), configMaps, secrets, opts)
settings := testCompilerSettings()
settings.Process = &adk.RuntimeConfig{MaxContentLength: new(int64(-1))}
settings := testRuntimeDefaults()
settings.MaxContentLength = new(int64(-1))
states := newAgentReconciliations(
krt.NewStaticCollection(nil, []*kagentv1alpha3.Agent{testAgent(template, runtimeHarness)}, opts.WithName("Agents")...),
translator.Collections{
Harnesses: krttest.GetMockCollection[*kagentv1alpha3.Harness](mock), AgentTemplates: krttest.GetMockCollection[*kagentv1alpha3.AgentTemplate](mock),
ResolvedModelConfigs: resolvedModels, ConfigMaps: configMaps, Secrets: secrets,
RemoteMCPServers: krttest.GetMockCollection[*kagentv1alpha3.RemoteMCPServer](mock), WorkerPools: krttest.GetMockCollection[*atev1alpha1.WorkerPool](mock),
}, krt.NewStaticCollection[AgentRuntimeObservation](nil, nil, opts.WithName("Observations")...), opts, settings,
}, krt.NewStaticCollection[AgentRuntimeObservation](nil, nil, opts.WithName("Observations")...), opts, settings, nil,
)
waitFor(t, func() bool { return states.GetKey("team-a/assistant") != nil })
state := states.GetKey("team-a/assistant")
Expand Down Expand Up @@ -230,7 +230,7 @@ func TestReconciliationWorkerPoolSandboxClass(t *testing.T) {
Harnesses: krttest.GetMockCollection[*kagentv1alpha3.Harness](mock), AgentTemplates: templates, ResolvedModelConfigs: resolvedModels,
RemoteMCPServers: krttest.GetMockCollection[*kagentv1alpha3.RemoteMCPServer](mock),
ConfigMaps: configMaps, Secrets: secrets, WorkerPools: workerPools,
}, observations, opts, testCompilerSettings())
}, observations, opts, testRuntimeDefaults(), nil)
key := "team-a/assistant"
waitFor(t, func() bool {
state := reconciliations.GetKey(key)
Expand Down Expand Up @@ -371,7 +371,7 @@ func TestClaudeReconciliationCompilesActorTemplate(t *testing.T) {
RemoteMCPServers: krttest.GetMockCollection[*kagentv1alpha3.RemoteMCPServer](mock),
ConfigMaps: configMaps, Secrets: secrets,
WorkerPools: krttest.GetMockCollection[*atev1alpha1.WorkerPool](mock),
}, krttest.GetMockCollection[AgentRuntimeObservation](mock), opts, testCompilerSettings(),
}, krttest.GetMockCollection[AgentRuntimeObservation](mock), opts, testRuntimeDefaults(), nil,
)
waitFor(t, func() bool {
states := reconciliations.List()
Expand Down Expand Up @@ -427,7 +427,7 @@ func TestCodexReconciliationCompilesActorTemplate(t *testing.T) {
RemoteMCPServers: krttest.GetMockCollection[*kagentv1alpha3.RemoteMCPServer](mock),
ConfigMaps: configMaps, Secrets: secrets,
WorkerPools: krttest.GetMockCollection[*atev1alpha1.WorkerPool](mock),
}, krttest.GetMockCollection[AgentRuntimeObservation](mock), opts, testCompilerSettings(),
}, krttest.GetMockCollection[AgentRuntimeObservation](mock), opts, testRuntimeDefaults(), nil,
)
waitFor(t, func() bool {
states := reconciliations.List()
Expand Down Expand Up @@ -480,7 +480,7 @@ func TestReconciliationTracksSharedAgentTemplate(t *testing.T) {
RemoteMCPServers: krttest.GetMockCollection[*kagentv1alpha3.RemoteMCPServer](mock),
ConfigMaps: configMaps, Secrets: secrets,
WorkerPools: krttest.GetMockCollection[*atev1alpha1.WorkerPool](mock),
}, krttest.GetMockCollection[AgentRuntimeObservation](mock), opts, testCompilerSettings(),
}, krttest.GetMockCollection[AgentRuntimeObservation](mock), opts, testRuntimeDefaults(), nil,
)
var initial string
waitFor(t, func() bool {
Expand Down Expand Up @@ -531,6 +531,6 @@ func testAgent(template *kagentv1alpha3.AgentTemplate, harness *kagentv1alpha3.H
}}
}

func testCompilerSettings() translator.CompilerSettings {
return translator.CompilerSettings{APIURL: "http://kagent-controller.kagent:8083", GatewayURL: "http://kagent-controller.kagent:8083", LogLevel: "info"}
func testRuntimeDefaults() *apiv1.RuntimeDefaultsConfig {
return &apiv1.RuntimeDefaultsConfig{ControlPlaneUrl: new("http://kagent-controller.kagent:8083"), GatewayUrl: new("http://kagent-controller.kagent:8083"), Logging: &apiv1.LoggingConfig{Level: new("info")}}
}
2 changes: 1 addition & 1 deletion go/core/internal/controller/preparation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ func newPreparationTestCollections(t *testing.T, workerPool string) (Collections
Harnesses: collections.Harnesses, AgentTemplates: collections.AgentTemplates, ResolvedModelConfigs: collections.ResolvedModelConfigs,
RemoteMCPServers: collections.RemoteMCPServers, ConfigMaps: collections.ConfigMaps,
Secrets: collections.Secrets, WorkerPools: collections.WorkerPools,
}, collections.AgentRuntimeObservations, opts, testCompilerSettings())
}, collections.AgentRuntimeObservations, opts, testRuntimeDefaults(), nil)
collections.AgentStatuses = newAgentStatuses(collections.Agents, collections.Reconciliations, opts)
waitFor(t, func() bool {
states := collections.Reconciliations.List()
Expand Down
6 changes: 4 additions & 2 deletions go/core/internal/controller/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"k8s.io/client-go/util/workqueue"

kagentclient "github.com/kagent-dev/kagent/go/api/clientset/versioned/typed/api/v1alpha3"
apiv1 "github.com/kagent-dev/kagent/go/api/gen/kagent/api/v1alpha1"
kagentv1alpha3 "github.com/kagent-dev/kagent/go/api/v1alpha3"
"github.com/kagent-dev/kagent/go/core/internal/database"
"github.com/kagent-dev/kagent/go/core/internal/substrate"
Expand Down Expand Up @@ -96,7 +97,8 @@ func newAgentReconciliations(
collections translator.Collections,
agentRuntimeObservations krt.Collection[AgentRuntimeObservation],
opts krt.OptionsBuilder,
settings translator.CompilerSettings,
settings *apiv1.RuntimeDefaultsConfig,
images *apiv1.HarnessImagesConfig,
) krt.Collection[AgentReconciliation] {
return krt.NewCollection(agents, func(ctx krt.HandlerContext, agent *kagentv1alpha3.Agent) *AgentReconciliation {
state := &AgentReconciliation{Agent: agent}
Expand All @@ -105,7 +107,7 @@ func newAgentReconciliations(
translator.HarnessTypeCodex: codextranslator.NewCompiler(ctx, collections, settings),
translator.HarnessTypeClaude: claudetranslator.NewCompiler(ctx, collections, settings),
translator.HarnessTypeBYO: byotranslator.NewCompiler(ctx, collections, settings),
}, settings.Images).CompileAgent(context.Background(), agent)
}, images).CompileAgent(context.Background(), agent)
if err != nil {
condition, reason := kagentv1alpha3.AgentConditionResolvedRefs, "ReferenceResolutionFailed"
var validation *translator.ValidationError
Expand Down
6 changes: 3 additions & 3 deletions go/core/internal/controller/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
"istio.io/istio/pkg/kube/krt"
"k8s.io/client-go/rest"

apiv1 "github.com/kagent-dev/kagent/go/api/gen/kagent/api/v1alpha1"
"github.com/kagent-dev/kagent/go/core/internal/controller/apiclient"
"github.com/kagent-dev/kagent/go/core/internal/translator"
)

// Runtime owns the Kubernetes client and common options shared by the KRT
Expand All @@ -23,13 +23,13 @@ type Runtime struct {

// NewRuntime creates the shared KRT client and collection graph. Handlers are
// deliberately registered separately at the eventual application boundary.
func NewRuntime(config *rest.Config, watchNamespaces []string, stop <-chan struct{}, settings translator.CompilerSettings) (*Runtime, error) {
func NewRuntime(config *rest.Config, watchNamespaces []string, stop <-chan struct{}, settings *apiv1.RuntimeDefaultsConfig, images *apiv1.HarnessImagesConfig) (*Runtime, error) {
client, err := apiclient.New(config)
if err != nil {
return nil, fmt.Errorf("create KRT Kubernetes client: %w", err)
}
options := krt.NewOptionsBuilder(stop, "kagent", krt.GlobalDebugHandler)
collections := NewCollections(client, watchNamespaces, options, settings)
collections := NewCollections(client, watchNamespaces, options, settings, images)
return &Runtime{Client: client, Options: options, Collections: collections}, nil
}

Expand Down
14 changes: 9 additions & 5 deletions go/core/internal/translator/byo/compiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
corev1 "k8s.io/api/core/v1"

"github.com/kagent-dev/kagent/go/api/adk"
apiv1 "github.com/kagent-dev/kagent/go/api/gen/kagent/api/v1alpha1"
"github.com/kagent-dev/kagent/go/core/internal/translator"
"github.com/kagent-dev/kagent/go/core/internal/translator/adkconfig"
"github.com/kagent-dev/kagent/go/pkg/tracing"
Expand All @@ -22,12 +23,12 @@ import (
// Compiler translates resolved inputs into a BYO A2A runtime revision.
type Compiler struct {
config *adkconfig.Builder
settings translator.CompilerSettings
settings *apiv1.RuntimeDefaultsConfig
}

var _ translator.HarnessCompiler = (*Compiler)(nil)

func NewCompiler(ctx krt.HandlerContext, collections translator.Collections, settings translator.CompilerSettings) *Compiler {
func NewCompiler(ctx krt.HandlerContext, collections translator.Collections, settings *apiv1.RuntimeDefaultsConfig) *Compiler {
return &Compiler{settings: settings, config: adkconfig.NewBuilder(ctx, collections)}
}

Expand All @@ -38,7 +39,7 @@ func (c *Compiler) Compile(ctx context.Context, input *translator.HarnessInput)
}
template, harness := input.Root.Template, input.Harness
configJSON, err := adk.Marshal(&adk.Config{
Runtime: c.settings.RuntimeConfig(input.AgentName, template.Namespace),
Runtime: translator.RuntimeConfig(c.settings, input.AgentName, template.Namespace),
Agent: compiled.Config,
})
if err != nil {
Expand All @@ -53,7 +54,10 @@ func (c *Compiler) Compile(ctx context.Context, input *translator.HarnessInput)
return nil, fmt.Errorf("convert agent card: %w", err)
}
// An opaque image may export to its own backend, so its own values win.
telemetryConfig := c.settings.Telemetry
telemetryConfig, err := translator.TelemetryConfigFromSettings(c.settings.GetTelemetry())
if err != nil {
return nil, err
}
environment := append([]corev1.EnvVar(nil), compiled.Environment...)
environment = append(environment, adkconfig.HarnessEnvironment(harness)...)
environment = adkconfig.DedupeEnv(environment)
Expand All @@ -71,7 +75,7 @@ func (c *Compiler) Compile(ctx context.Context, input *translator.HarnessInput)
return nil, err
}
compiled.Egress = append(compiled.Egress, telemetryConfig.Destinations(environment)...)
compiled.Egress = append(compiled.Egress, c.settings.APIURL)
compiled.Egress = append(compiled.Egress, c.settings.GetControlPlaneUrl())
slices.Sort(compiled.Egress)

return &translator.CompileResult{Revision: translator.Revision{
Expand Down
Loading
Loading