Skip to content

Commit ab0219e

Browse files
committed
review: centralize install defaults, derive atelet namespace from POD_NAMESPACE
Addresses review comments on agent-substrate#350: - New internal/installdefaults package owns SystemNamespace, RouterServiceName, DNSServiceName. dns, router, and controlapi/informer drop their duplicate Default* constants and reference installdefaults via the matching flag declarations and tests. - Drop the --atelet-namespace flag on ateapi. The namespace is now resolved at startup from the POD_NAMESPACE env var (Kubernetes' downward API), falling back to installdefaults.SystemNamespace for non-k8s invocations (tests, local dev). atelet and ateapi share a namespace in every supported deployment topology, so a separate knob was dead weight.
1 parent 23bc7ac commit ab0219e

11 files changed

Lines changed: 64 additions & 52 deletions

File tree

charts/substrate/templates/ate-api-server.yaml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,6 @@ spec:
110110
- "--session-id-ca-pool=/run/session-id-ca-pool/pool.json"
111111
- "--client-jwt-ca-cert=/var/run/secrets/kubernetes.io/serviceaccount/ca.crt"
112112
{{- end }}
113-
# Pass the chart-resolved namespace so the atelet pod informer
114-
# watches the correct namespace when substrate is installed as a
115-
# subchart (the binary default is "ate-system").
116-
- "--atelet-namespace={{ .Release.Namespace }}"
117113
env:
118114
- name: POD_NAME
119115
valueFrom:

cmd/ateapi/internal/controlapi/functional_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929
"github.com/agent-substrate/substrate/cmd/ateapi/internal/workercache"
3030
"github.com/agent-substrate/substrate/internal/ateinterceptors"
3131
"github.com/agent-substrate/substrate/internal/envtestbins"
32+
"github.com/agent-substrate/substrate/internal/installdefaults"
3233
"github.com/agent-substrate/substrate/internal/proto/ateletpb"
3334
atev1alpha1 "github.com/agent-substrate/substrate/pkg/api/v1alpha1"
3435
"github.com/agent-substrate/substrate/pkg/client/clientset/versioned"
@@ -270,7 +271,7 @@ func setupTest(t *testing.T, ns string) *testContext {
270271

271272
// 3. Initialize Informers
272273
workerFactory, workerInformer := WorkerPodInformer(k8sClient)
273-
ateletFactory, ateletInformer := AteletInformer(k8sClient, DefaultAteletNamespace)
274+
ateletFactory, ateletInformer := AteletInformer(k8sClient, installdefaults.SystemNamespace)
274275

275276
substrateInformerFactory := externalversions.NewSharedInformerFactory(substrateClient, 0)
276277
actorTemplateLister := substrateInformerFactory.Api().V1alpha1().ActorTemplates().Lister()

cmd/ateapi/internal/controlapi/informer.go

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,10 @@ import (
2525
)
2626

2727
const (
28-
// DefaultAteletNamespace matches the atelet DaemonSet's namespace in
29-
// the canonical install manifests under manifests/ate-install/.
30-
// Deployments that run atelet elsewhere must override this via the
31-
// --atelet-namespace flag on ateapi.
32-
DefaultAteletNamespace = "ate-system"
33-
byNamespaceAndName = "by-namespace-and-name"
34-
byWorkerPool = "by-worker-pool"
35-
byNode = "by-node"
36-
workerPodLabel = "ate.dev/worker-pool"
28+
byNamespaceAndName = "by-namespace-and-name"
29+
byWorkerPool = "by-worker-pool"
30+
byNode = "by-node"
31+
workerPodLabel = "ate.dev/worker-pool"
3732
)
3833

3934
// AteletInformer creates a SharedInformerFactory and SharedIndexInformer for

cmd/ateapi/main.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import (
3333
"github.com/agent-substrate/substrate/cmd/ateapi/internal/workercache"
3434
"github.com/agent-substrate/substrate/internal/ateapiauth"
3535
"github.com/agent-substrate/substrate/internal/ateinterceptors"
36+
"github.com/agent-substrate/substrate/internal/installdefaults"
3637
"github.com/agent-substrate/substrate/internal/serverboot"
3738
"github.com/agent-substrate/substrate/internal/version"
3839
"github.com/agent-substrate/substrate/pkg/client/clientset/versioned"
@@ -72,8 +73,6 @@ var (
7273
showVersion = pflag.Bool("version", false, "Print version and exit.")
7374
authMode = pflag.String("auth-mode", "mtls", "Auth mode for incoming gRPC: mtls|jwt. 'mtls' (default) relies on transport-level mTLS for client identity. 'jwt' additionally requires a Kubernetes ServiceAccount Bearer token on every RPC.")
7475
clientJWTCAFile = pflag.String("client-jwt-ca-cert", "/var/run/secrets/kubernetes.io/serviceaccount/ca.crt", "CA cert file used to verify TLS when fetching the OIDC discovery document and JWKS for JWT authentication. Defaults to the in-cluster service account CA.")
75-
76-
ateletNamespace = pflag.String("atelet-namespace", controlapi.DefaultAteletNamespace, "Namespace where atelet pods run. Override when the deployment runs atelet in a namespace other than the default.")
7776
)
7877

7978
func main() {
@@ -135,8 +134,17 @@ func main() {
135134
workerPoolLister := ateFactory.Api().V1alpha1().WorkerPools().Lister()
136135
sandboxConfigLister := ateFactory.Api().V1alpha1().SandboxConfigs().Lister()
137136

137+
// atelet shares ateapi's namespace in every supported deployment topology.
138+
// POD_NAMESPACE comes from Kubernetes' downward API; the install fallback
139+
// keeps non-k8s invocations (tests, local dev) working.
140+
ateletNamespace := os.Getenv("POD_NAMESPACE")
141+
if ateletNamespace == "" {
142+
ateletNamespace = installdefaults.SystemNamespace
143+
}
144+
slog.InfoContext(ctx, "Resolved atelet namespace", slog.String("atelet-namespace", ateletNamespace))
145+
138146
workerPodInformerFactory, workerPodInformer := controlapi.WorkerPodInformer(clientset)
139-
ateletPodInformerFactory, ateletPodInformer := controlapi.AteletInformer(clientset, *ateletNamespace)
147+
ateletPodInformerFactory, ateletPodInformer := controlapi.AteletInformer(clientset, ateletNamespace)
140148

141149
syncer := controlapi.NewWorkerPoolSyncer(redisPersistence, workerPodInformer)
142150
syncer.Start(ctx)

cmd/atenet/internal/dns.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030
"sigs.k8s.io/controller-runtime/pkg/client/config"
3131

3232
"github.com/agent-substrate/substrate/cmd/atenet/internal/dns"
33+
"github.com/agent-substrate/substrate/internal/installdefaults"
3334
)
3435

3536
type DnsConfig struct {
@@ -108,9 +109,9 @@ func NewDnsCmd() *cobra.Command {
108109
cmd.Flags().StringVar(&cfg.Kubeconfig, "kubeconfig", "", "Absolute path to the kubeconfig configuration file")
109110
cmd.Flags().DurationVar(&cfg.ReconcileInterval, "interval", 10*time.Second, "Interval for reconciling DNS configurations")
110111
cmd.Flags().StringVar(&cfg.CorefilePath, "corefile-path", "/etc/coredns/Corefile", "Path to the local Corefile configuration on shared volume")
111-
cmd.Flags().StringVar(&cfg.SystemNamespace, "system-namespace", dns.DefaultSystemNamespace, "Namespace where atenet-router and substrate's CoreDNS Service live. Override when the deployment uses a different namespace.")
112-
cmd.Flags().StringVar(&cfg.RouterServiceName, "router-service-name", dns.DefaultRouterServiceName, "Service name of the atenet-router. Override when the deployment renames the Service.")
113-
cmd.Flags().StringVar(&cfg.DNSServiceName, "dns-service-name", dns.DefaultDNSServiceName, "Service name of substrate's CoreDNS. Override when the deployment renames the Service.")
112+
cmd.Flags().StringVar(&cfg.SystemNamespace, "system-namespace", installdefaults.SystemNamespace, "Namespace where atenet-router and substrate's CoreDNS Service live. Override when the deployment uses a different namespace.")
113+
cmd.Flags().StringVar(&cfg.RouterServiceName, "router-service-name", installdefaults.RouterServiceName, "Service name of the atenet-router. Override when the deployment renames the Service.")
114+
cmd.Flags().StringVar(&cfg.DNSServiceName, "dns-service-name", installdefaults.DNSServiceName, "Service name of substrate's CoreDNS. Override when the deployment renames the Service.")
114115

115116
return cmd
116117
}

cmd/atenet/internal/dns/dns.go

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,6 @@ import (
3333
"sigs.k8s.io/controller-runtime/pkg/client"
3434
)
3535

36-
// Default resource names match the canonical install manifests in
37-
// manifests/ate-install/ (atenet-router and dns Services in the
38-
// ate-system namespace). Deployments that use a different namespace or
39-
// rename these Services must pass the actual values via the matching
40-
// flags on the dns command.
41-
const (
42-
DefaultSystemNamespace = "ate-system"
43-
DefaultRouterServiceName = "atenet-router"
44-
DefaultDNSServiceName = "dns"
45-
)
46-
4736
// Controller manages the DNS configuration for the ATE.
4837
type Controller struct {
4938
Client client.Client
@@ -52,14 +41,14 @@ type Controller struct {
5241
Reloader ConfigReloader
5342

5443
// SystemNamespace is the namespace where atenet-router and the substrate
55-
// CoreDNS Service live. Defaults to DefaultSystemNamespace.
44+
// CoreDNS Service live. Defaults to installdefaults.SystemNamespace.
5645
SystemNamespace string
5746
// RouterServiceName is the Service name of the atenet-router that the
5847
// CoreDNS Corefile forwards actor traffic to. Defaults to
59-
// DefaultRouterServiceName.
48+
// installdefaults.RouterServiceName.
6049
RouterServiceName string
6150
// DNSServiceName is the Service name of substrate's CoreDNS. Defaults to
62-
// DefaultDNSServiceName.
51+
// installdefaults.DNSServiceName.
6352
DNSServiceName string
6453
}
6554

cmd/atenet/internal/dns/dns_test.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ import (
2828
"k8s.io/apimachinery/pkg/runtime"
2929
"k8s.io/apimachinery/pkg/types"
3030
"sigs.k8s.io/controller-runtime/pkg/client/fake"
31+
32+
"github.com/agent-substrate/substrate/internal/installdefaults"
3133
)
3234

3335
type mockConfigReloader struct {
@@ -98,9 +100,9 @@ func TestReconcile(t *testing.T) {
98100
Interval: 1 * time.Second,
99101
CorefilePath: corefilePath,
100102
Reloader: reloader,
101-
SystemNamespace: DefaultSystemNamespace,
102-
RouterServiceName: DefaultRouterServiceName,
103-
DNSServiceName: DefaultDNSServiceName,
103+
SystemNamespace: installdefaults.SystemNamespace,
104+
RouterServiceName: installdefaults.RouterServiceName,
105+
DNSServiceName: installdefaults.DNSServiceName,
104106
}
105107

106108
// Run one reconciliation loop
@@ -192,9 +194,9 @@ func TestReconcileKubeDNSNotFound(t *testing.T) {
192194
Interval: 1 * time.Second,
193195
CorefilePath: corefilePath,
194196
Reloader: &mockConfigReloader{},
195-
SystemNamespace: DefaultSystemNamespace,
196-
RouterServiceName: DefaultRouterServiceName,
197-
DNSServiceName: DefaultDNSServiceName,
197+
SystemNamespace: installdefaults.SystemNamespace,
198+
RouterServiceName: installdefaults.RouterServiceName,
199+
DNSServiceName: installdefaults.DNSServiceName,
198200
}
199201

200202
ctx := context.Background()

cmd/atenet/internal/router.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"github.com/spf13/cobra"
2222

2323
"github.com/agent-substrate/substrate/cmd/atenet/internal/router"
24+
"github.com/agent-substrate/substrate/internal/installdefaults"
2425
)
2526

2627
func NewRouterCmd() *cobra.Command {
@@ -44,7 +45,7 @@ func NewRouterCmd() *cobra.Command {
4445
cmd.Flags().StringVar(&cfg.MetricsAddr, "metrics-listen-addr", ":9090", "Address and port the prometheus metrics server should listen on.")
4546
cmd.Flags().BoolVar(&cfg.Standalone, "standalone", false, "Run in standalone mode, bypassing creation of managed deployment and services in Kubernetes cluster")
4647
cmd.Flags().StringVar(&cfg.Namespace, "namespace", "default", "Target operations namespace")
47-
cmd.Flags().StringVar(&cfg.RouterServiceName, "router-service-name", router.DefaultRouterServiceName, "Service name of this atenet-router in the operations namespace. Override when the deployment renames the Service.")
48+
cmd.Flags().StringVar(&cfg.RouterServiceName, "router-service-name", installdefaults.RouterServiceName, "Service name of this atenet-router in the operations namespace. Override when the deployment renames the Service.")
4849
cmd.Flags().StringVar(&cfg.Kubeconfig, "kubeconfig", "", "Absolute path to the kubeconfig configuration file")
4950
cmd.Flags().StringVar(&cfg.AteapiAddr, "ateapi-address", "api.ate-system.svc:443", "gRPC host address of the cluster ateapi Control instance")
5051
cmd.Flags().IntVar(&cfg.HttpPort, "port-http", 8080, "TCP port for workload traffic entering through the Envoy Router")

cmd/atenet/internal/router/router.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,19 +62,13 @@ func init() {
6262
utilruntime.Must(v1alpha1.AddToScheme(scheme))
6363
}
6464

65-
// DefaultRouterServiceName matches the atenet-router Service name in the
66-
// canonical install manifests under manifests/ate-install/. Deployments
67-
// that rename the Service must pass the actual name via
68-
// --router-service-name.
69-
const DefaultRouterServiceName = "atenet-router"
70-
7165
// RouterConfig holds deployment setup and endpoint options for the router node instance.
7266
type RouterConfig struct {
7367
Standalone bool
7468
Namespace string
7569
// RouterServiceName is the Service name of this atenet-router in the
7670
// operations namespace, used by /statusz to look up its own ClusterIP.
77-
// Defaults to DefaultRouterServiceName.
71+
// Defaults to installdefaults.RouterServiceName.
7872
RouterServiceName string
7973
Kubeconfig string
8074
AteapiAddr string
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright 2026 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
// Package installdefaults holds the default namespace and Service names
16+
// that match the canonical install layout in manifests/ate-install/.
17+
// Binaries use these as flag defaults; deployments that diverge from
18+
// the canonical layout pass actual values via the corresponding flags.
19+
package installdefaults
20+
21+
const (
22+
// SystemNamespace is the namespace where substrate's control-plane
23+
// components and the atelet DaemonSet run.
24+
SystemNamespace = "ate-system"
25+
// RouterServiceName is the Service name of atenet-router.
26+
RouterServiceName = "atenet-router"
27+
// DNSServiceName is the Service name of substrate's CoreDNS.
28+
DNSServiceName = "dns"
29+
)

0 commit comments

Comments
 (0)