Skip to content

Commit 9603e49

Browse files
committed
review: derive atenet's system namespace from POD_NAMESPACE
Same rationale as the prior atelet-namespace change: atenet, atenet-router, and substrate's CoreDNS live in a single namespace in every supported deployment topology, so a separate --system-namespace flag was dead weight. Resolve from the POD_NAMESPACE env var (Kubernetes' downward API) with installdefaults.SystemNamespace as the fallback for non-k8s runs. --router-service-name and --dns-service-name stay as flags because a subchart deployment renames those Services with a release prefix, and the binary can't derive that from pod metadata.
1 parent 0817dfc commit 9603e49

3 files changed

Lines changed: 27 additions & 9 deletions

File tree

charts/substrate/templates/atenet-dns.yaml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,16 @@ spec:
150150
- "--log-level=debug"
151151
- "--interval=10s"
152152
- "--corefile-path=/etc/coredns/Corefile"
153-
# Pass the chart-resolved names/namespace so the controller looks up
154-
# the correct Services when substrate is installed as a subchart.
155-
- "--system-namespace={{ .Release.Namespace }}"
153+
# Pass the chart-resolved Service names so the controller looks up the
154+
# correct objects when substrate is installed as a subchart. The
155+
# system namespace is read from POD_NAMESPACE below.
156156
- "--router-service-name={{ include "substrate.fullname" (list "atenet-router" .) }}"
157157
- "--dns-service-name={{ include "substrate.fullname" (list "dns" .) }}"
158+
env:
159+
- name: POD_NAMESPACE
160+
valueFrom:
161+
fieldRef:
162+
fieldPath: metadata.namespace
158163
volumeMounts:
159164
- name: dns-config-volume
160165
mountPath: /etc/coredns

cmd/atenet/internal/dns.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ type DnsConfig struct {
3838
Kubeconfig string
3939
ReconcileInterval time.Duration
4040
CorefilePath string
41-
SystemNamespace string
4241
RouterServiceName string
4342
DNSServiceName string
4443
}
@@ -90,12 +89,22 @@ func NewDnsCmd() *cobra.Command {
9089
return fmt.Errorf("failed to initialize cluster client: %w", err)
9190
}
9291

92+
// atenet shares the system namespace with atenet-router and
93+
// substrate's CoreDNS in every supported deployment topology.
94+
// POD_NAMESPACE comes from Kubernetes' downward API; the install
95+
// fallback keeps non-k8s invocations (tests, local dev) working.
96+
systemNamespace := os.Getenv("POD_NAMESPACE")
97+
if systemNamespace == "" {
98+
systemNamespace = installdefaults.SystemNamespace
99+
}
100+
slog.InfoContext(ctx, "Resolved system namespace", slog.String("system-namespace", systemNamespace))
101+
93102
dnsController := &dns.Controller{
94103
Client: k8sClient,
95104
Interval: cfg.ReconcileInterval,
96105
CorefilePath: cfg.CorefilePath,
97106
Reloader: dns.NewConfigReloader(),
98-
SystemNamespace: cfg.SystemNamespace,
107+
SystemNamespace: systemNamespace,
99108
RouterServiceName: cfg.RouterServiceName,
100109
DNSServiceName: cfg.DNSServiceName,
101110
}
@@ -109,7 +118,6 @@ func NewDnsCmd() *cobra.Command {
109118
cmd.Flags().StringVar(&cfg.Kubeconfig, "kubeconfig", "", "Absolute path to the kubeconfig configuration file")
110119
cmd.Flags().DurationVar(&cfg.ReconcileInterval, "interval", 10*time.Second, "Interval for reconciling DNS configurations")
111120
cmd.Flags().StringVar(&cfg.CorefilePath, "corefile-path", "/etc/coredns/Corefile", "Path to the local Corefile configuration on shared volume")
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.")
113121
cmd.Flags().StringVar(&cfg.RouterServiceName, "router-service-name", installdefaults.RouterServiceName, "Service name of the atenet-router. Override when the deployment renames the Service.")
114122
cmd.Flags().StringVar(&cfg.DNSServiceName, "dns-service-name", installdefaults.DNSServiceName, "Service name of substrate's CoreDNS. Override when the deployment renames the Service.")
115123

manifests/ate-install/atenet-dns.yaml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,11 +170,16 @@ spec:
170170
- "--log-level=debug"
171171
- "--interval=10s"
172172
- "--corefile-path=/etc/coredns/Corefile"
173-
# Pass the chart-resolved names/namespace so the controller looks up
174-
# the correct Services when substrate is installed as a subchart.
175-
- "--system-namespace=ate-system"
173+
# Pass the chart-resolved Service names so the controller looks up the
174+
# correct objects when substrate is installed as a subchart. The
175+
# system namespace is read from POD_NAMESPACE below.
176176
- "--router-service-name=atenet-router"
177177
- "--dns-service-name=dns"
178+
env:
179+
- name: POD_NAMESPACE
180+
valueFrom:
181+
fieldRef:
182+
fieldPath: metadata.namespace
178183
volumeMounts:
179184
- name: dns-config-volume
180185
mountPath: /etc/coredns

0 commit comments

Comments
 (0)