Skip to content

Commit fc12b7f

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 8f38eb9 commit fc12b7f

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"
@@ -273,7 +274,7 @@ func setupTest(t *testing.T, ns string) *testContext {
273274

274275
// 3. Initialize Informers
275276
workerFactory, workerInformer := WorkerPodInformer(k8sClient)
276-
ateletFactory, ateletInformer := AteletInformer(k8sClient, DefaultAteletNamespace)
277+
ateletFactory, ateletInformer := AteletInformer(k8sClient, installdefaults.SystemNamespace)
277278

278279
substrateInformerFactory := externalversions.NewSharedInformerFactory(substrateClient, 0)
279280
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
@@ -34,6 +34,7 @@ import (
3434
"github.com/agent-substrate/substrate/cmd/ateapi/internal/workercache"
3535
"github.com/agent-substrate/substrate/internal/ateapiauth"
3636
"github.com/agent-substrate/substrate/internal/ateinterceptors"
37+
"github.com/agent-substrate/substrate/internal/installdefaults"
3738
"github.com/agent-substrate/substrate/internal/k8sjwt"
3839
"github.com/agent-substrate/substrate/internal/serverboot"
3940
"github.com/agent-substrate/substrate/internal/version"
@@ -74,8 +75,6 @@ var (
7475
showVersion = pflag.Bool("version", false, "Print version and exit.")
7576
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. Substrate will drop support for JWT auth mode once the Pod Certificates feature is enabled by default in the minimum supported Kubernetes version.")
7677
clientJWTCAFile = pflag.String("client-jwt-ca-cert", ateapiauth.DefaultServiceAccountCAFile, "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.")
77-
78-
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.")
7978
)
8079

8180
func main() {
@@ -137,8 +136,17 @@ func main() {
137136
workerPoolLister := ateFactory.Api().V1alpha1().WorkerPools().Lister()
138137
sandboxConfigLister := ateFactory.Api().V1alpha1().SandboxConfigs().Lister()
139138

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

143151
syncer := controlapi.NewWorkerPoolSyncer(redisPersistence, workerPodInformer)
144152
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
@@ -22,6 +22,7 @@ import (
2222

2323
"github.com/agent-substrate/substrate/cmd/atenet/internal/router"
2424
"github.com/agent-substrate/substrate/internal/ateapiauth"
25+
"github.com/agent-substrate/substrate/internal/installdefaults"
2526
)
2627

2728
func NewRouterCmd() *cobra.Command {
@@ -45,7 +46,7 @@ func NewRouterCmd() *cobra.Command {
4546
cmd.Flags().StringVar(&cfg.MetricsAddr, "metrics-listen-addr", ":9090", "Address and port the prometheus metrics server should listen on.")
4647
cmd.Flags().BoolVar(&cfg.Standalone, "standalone", false, "Run in standalone mode, bypassing creation of managed deployment and services in Kubernetes cluster")
4748
cmd.Flags().StringVar(&cfg.Namespace, "namespace", "default", "Target operations namespace")
48-
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.")
49+
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.")
4950
cmd.Flags().StringVar(&cfg.Kubeconfig, "kubeconfig", "", "Absolute path to the kubeconfig configuration file")
5051
cmd.Flags().StringVar(&cfg.AteapiAddr, "ateapi-address", "api.ate-system.svc:443", "gRPC host address of the cluster ateapi Control instance")
5152
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)