mirror of
https://github.com/dsx-ai-factory/nvke.git
synced 2026-12-07 04:35:58 +08:00
* feat(controller): move a pending control-plane node out of a full failure domain When CAPNICo reports FailureDomainUnavailable for a control-plane node's requested domain past a grace period, patch the Machine's failure domain to the least-used eligible domain the node has not tried, cycling once every domain has been tried. Gated by controlPlaneFailureDomainFallback in nvke-controller-config, off by default. Failure-domain discovery and the allocator move to internal/failuredomains so the provisioning activity can reuse them. nico-sim gains a configurable failure-domain layout, and a nico-containers e2e spec covers the move. Signed-off-by: Eric Staples <estaples@nvidia.com> * feat(controller): keep the failure-domain fallback and stuck-pending re-placement from overlapping With the fallback enabled, the stuck-pending reconciler leaves domain-pinned pending control-plane nodes to the provisioning activity, which moves them in place. Both acted on the same FailureDomainUnavailable signal on different clocks, so a moved node could be deleted after one CAPNICo retry. The rotation now stamps the domain it leaves in the cluster's UnplaceableFailureDomains, so scale-up, remediation, rollout and rebalance stop choosing the emptied, still-full domain for the next 3 hours. When picking the next domain it tries marked domains only after every unmarked one. The rotation skips rebalance surges. A surge is placed in the domain of the node it replaces; moving it can leave two members in one domain after the shed, and rebalance already abandons a surge that cannot get capacity. The unplaceable-domain helpers move to the failuredomains package so the reconciler and the activity share them. Signed-off-by: Eric Staples <estaples@nvidia.com> * feat(controller): replace stuck-pending delete with the failure-domain move Moving a pending control-plane node to another failure domain is now the only way the controller handles a domain CAPNICo reports out of capacity. The stuck-pending reconciler, which deleted such a node after 15 minutes and recreated it elsewhere, is removed along with the controlPlaneFailureDomainFallback.enabled setting that chose between them. The move now also leaves a node with a delete in flight alone. controlPlaneFailureDomainFallback.gracePeriod stays; unset, it defaults to 10 minutes, and a non-positive value is refused at startup and by the chart. FailureDomainUnavailable leaves the MachineMaterialization interface, since only the stuck-pending path called it. The e2e spec gains a scale-up case: with every domain but one out of capacity, scaling the control plane to three moves the stuck Machine in place and fails if any control-plane Machine is deleted. Signed-off-by: Eric Staples <estaples@nvidia.com> * feat(controller): Surge releases the domain of the first rollout target without a delete in flight Signed-off-by: Eric Staples <estaples@nvidia.com> * feat(controller): mark the domain unavailable and update the node in the same transaction Signed-off-by: Eric Staples <estaples@nvidia.com> * feat(controller): make the failure domain check more readable Signed-off-by: Eric Staples <estaples@nvidia.com> * fix(controller): retry a failure-domain move on Machine patch conflict A conflict on the optimistic-lock Machine patch now waits for the next poll instead of failing the activity. Cover the surge-domain release by driving reconcileNodesNeedingRollout, and document the gracePeriod positivity constraint in the chart README. Signed-off-by: Eric Staples <estaples@nvidia.com> * fix(controller): finish an interrupted failure-domain move once the node has an IP When the Machine patch of a failure-domain move succeeds and the row update fails, the next poll records the move. That repair ran only from the rotation path, which waitForCAPIMachineReady reaches only while the Machine has no IP, so a node that got an address in the new domain kept the old domain in its row. The repair now runs on every poll, before the IP check. A repaired wrap-around move rebuilt the tried list by appending the departed domain to the old history instead of restarting it. When the Machine's domain is already in the tried list the move was a restart, so only the departed domain is kept. Signed-off-by: Eric Staples <estaples@nvidia.com> --------- Signed-off-by: Eric Staples <estaples@nvidia.com>
170 lines
7.7 KiB
Go
170 lines
7.7 KiB
Go
// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package controllerconfig
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"os"
|
|
"slices"
|
|
|
|
"github.com/dsx-ai-factory/nvke/controller/internal/config"
|
|
)
|
|
|
|
// LoadStartupConfig returns the configuration the controller runs on: the
|
|
// environment, then the nvke-controller-config file CONTROLLER_CONFIG_PATH names,
|
|
// validated together. It also returns the file, for the settings config.Config
|
|
// does not carry, such as oidc.providers and apiAuth.
|
|
func LoadStartupConfig() (config.Config, *Config, error) {
|
|
if err := refuseRetiredAuthConfigPath(); err != nil {
|
|
return config.Config{}, nil, err
|
|
}
|
|
cfg, err := config.ParseConfigFromEnv()
|
|
if err != nil {
|
|
return config.Config{}, nil, err
|
|
}
|
|
file, err := Load(cfg.ControllerConfigPath)
|
|
if err != nil {
|
|
return config.Config{}, nil, err
|
|
}
|
|
file.ApplyTo(&cfg)
|
|
if err := cfg.Validate(); err != nil {
|
|
return config.Config{}, nil, fmt.Errorf("config validation failed: %w", err)
|
|
}
|
|
if err := file.CheckAuthzNeedsAuthn(); err != nil {
|
|
return config.Config{}, nil, err
|
|
}
|
|
return cfg, file, nil
|
|
}
|
|
|
|
// CheckAuthzNeedsAuthn refuses API authorization with API authentication off,
|
|
// which leaves no caller to authorize. It also refuses enforcing authorization
|
|
// behind permissive authentication, which refuses with 403 every request
|
|
// authentication would have rejected.
|
|
func (c *Config) CheckAuthzNeedsAuthn() error {
|
|
switch {
|
|
case !c.APIAuthz.Enabled:
|
|
return nil
|
|
case !c.APIAuth.Enabled:
|
|
return errors.New("apiAuthz.enabled is true but API authentication is off; enable apiAuth, or set apiAuthz.enabled to false")
|
|
case c.APIAuth.Permissive && !c.APIAuthz.Permissive:
|
|
return errors.New("apiAuthz.permissive is false but apiAuth.permissive is true; set apiAuthz.permissive to true, or apiAuth.permissive to false")
|
|
}
|
|
return nil
|
|
}
|
|
|
|
const (
|
|
// retiredAuthConfigPath named a file holding the API authentication
|
|
// configuration, which apiAuth in nvke-controller-config replaced.
|
|
retiredAuthConfigPath = "AUTH_CONFIG_PATH"
|
|
)
|
|
|
|
// refuseRetiredAuthConfigPath fails startup when AUTH_CONFIG_PATH is set. The
|
|
// controller no longer reads that file, and ignoring the variable would start
|
|
// a deployment that asked for authentication without any.
|
|
func refuseRetiredAuthConfigPath() error {
|
|
if path := os.Getenv(retiredAuthConfigPath); path != "" {
|
|
return fmt.Errorf("%s is set to %q, but the controller no longer reads an authentication file. Move its audiences and issuers to apiAuth in nvke-controller-config (the chart's apiAuth.config), set apiAuth.enabled, and remove the variable", retiredAuthConfigPath, path)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// ApplyTo copies the file into every field of cfg that has a controllerconfig
|
|
// tag, and leaves the fields that come from the environment alone.
|
|
func (c *Config) ApplyTo(cfg *config.Config) {
|
|
cfg.AgentReadiness = c.AgentReadiness.runtimeConfig()
|
|
cfg.FieldManagerName = c.FieldManager.Name
|
|
cfg.FieldManagerRebootMachineName = c.FieldManager.RebootMachineName
|
|
cfg.FieldManagerMachineHealthIssueName = c.FieldManager.MachineHealthIssueName
|
|
cfg.ManagedByLabelValue = c.ManagedByLabelValue
|
|
cfg.ManagementNamespace = c.ManagementNamespace
|
|
cfg.RBACConfigMapName = c.RBACConfigMapName
|
|
cfg.MetricsListenAddress = c.MetricsListenAddress
|
|
cfg.SupportedInfraProviders = slices.Clone(c.SupportedInfraProviders)
|
|
cfg.NodeMetadataAllowlistedLabelKeys = slices.Clone(c.NodeMetadataAllowlistedLabelKeys)
|
|
cfg.MachineMetadataAllowlistedLabelKeys = slices.Clone(c.MachineMetadataAllowlistedLabelKeys)
|
|
cfg.MachineMetadataAllowlistedAnnotationKeys = slices.Clone(c.MachineMetadataAllowlistedAnnotationKeys)
|
|
cfg.Tracing.Enabled = c.Tracing.Enabled
|
|
cfg.Tracing.Endpoint = c.Tracing.Endpoint
|
|
cfg.Tracing.Insecure = c.Tracing.Insecure
|
|
cfg.Tracing.ServiceName = c.Tracing.ServiceName
|
|
|
|
cfg.CertRenewalControllerEnabled = c.CertRenewal.ControllerEnabled
|
|
cfg.CertRenewalInterval = c.CertRenewal.Interval.Duration
|
|
cfg.CertRenewalThresholdDays = c.CertRenewal.ThresholdDays
|
|
|
|
cfg.CredentialMonitoringEnabled = c.CredentialMonitoring.Enabled
|
|
cfg.CertificateInspectionInterval = c.CredentialMonitoring.InspectionInterval.Duration
|
|
cfg.CertificateObservationMaxAge = c.CredentialMonitoring.ObservationMaxAge.Duration
|
|
cfg.CertificateWarningDays = c.CredentialMonitoring.WarningDays
|
|
|
|
if c.ControlPlaneFailureDomainFallback.GracePeriod != nil {
|
|
cfg.ControlPlaneFailureDomainFallbackGracePeriod = c.ControlPlaneFailureDomainFallback.GracePeriod.Duration
|
|
}
|
|
|
|
cfg.KubeadmImageRepository = c.KubeadmImageRepository
|
|
cfg.CNIImageRegistry = c.CNIImageRegistry
|
|
cfg.InstallCNIAfterInit = c.InstallCNIAfterInit
|
|
cfg.NicoControllersEnabled = c.NicoControllersEnabled
|
|
cfg.BootstrapControllersEnabled = c.BootstrapControllersEnabled
|
|
cfg.ProfilesDir = c.ProfilesDir
|
|
cfg.RunbooksDir = c.RunbooksDir
|
|
cfg.TenantAccessEnabled = c.TenantAccessEnabled
|
|
|
|
cfg.NodeAgent.UpdateMethod = c.NodeAgent.UpdateMethod
|
|
cfg.NodeAgent.SpireAttestationMethod = config.SpireAttestationMethod(c.NodeAgent.SpireAttestationMethod)
|
|
cfg.NodeAgent.DSXImds.Endpoint = c.NodeAgent.DSXImds.Endpoint
|
|
cfg.NodeAgent.DSXImds.PluginChecksum = c.NodeAgent.DSXImds.PluginChecksum
|
|
cfg.NodeAgent.DSXImds.OperatorTenant = c.NodeAgent.DSXImds.OperatorTenant
|
|
cfg.NodeAgent.TLSJWT.Enabled = c.NodeAgent.TLSJWT.Enabled
|
|
cfg.NodeAgent.TLSJWT.Issuer = c.NodeAgent.TLSJWT.Issuer
|
|
cfg.NodeAgent.TLSJWT.JWKSURI = c.NodeAgent.TLSJWT.JWKSURI
|
|
cfg.NodeAgent.TLSJWT.Algorithms = slices.Clone(c.NodeAgent.TLSJWT.Algorithms)
|
|
cfg.NodeAgent.TLSJWT.SubjectTrustDomain = c.NodeAgent.TLSJWT.SubjectTrustDomain
|
|
cfg.NodeAgent.TLSJWT.DSXIdentityExchangeURL = c.NodeAgent.TLSJWT.DSXIdentityExchangeURL
|
|
cfg.NodeAgent.TLSJWT.SubjectTenant = c.NodeAgent.TLSJWT.SubjectTenant
|
|
cfg.NodeAgent.TLSJWT.SubjectService = c.NodeAgent.TLSJWT.SubjectService
|
|
cfg.NodeAgentExternalMTLSEnabled = c.NodeAgent.ExternalMTLSEnabled
|
|
|
|
shared := c.OIDC.ManagementOIDCAuth
|
|
cfg.NvkeOIDCAuth.Enabled = shared.Enabled
|
|
cfg.NvkeOIDCAuth.IssuerURL = shared.IssuerURL
|
|
cfg.NvkeOIDCAuth.DiscoveryURL = shared.DiscoveryURL
|
|
cfg.NvkeOIDCAuth.CABundleSecret.Namespace = shared.CABundleSecretRef.Namespace
|
|
cfg.NvkeOIDCAuth.CABundleSecret.Name = shared.CABundleSecretRef.Name
|
|
cfg.NvkeOIDCAuth.CABundleSecret.Key = shared.CABundleSecretRef.Key
|
|
|
|
cfg.TemporalHostPort = c.Temporal.HostPort
|
|
cfg.TemporalNamespace = c.Temporal.Namespace
|
|
cfg.TemporalTaskQueue = c.Temporal.TaskQueue
|
|
cfg.TemporalTLS.CaCert = c.Temporal.TLS.CACert
|
|
cfg.TemporalTLS.ClientCert = c.Temporal.TLS.ClientCert
|
|
cfg.TemporalTLS.ClientKey = c.Temporal.TLS.ClientKey
|
|
cfg.TemporalTLS.ServerName = c.Temporal.TLS.ServerName
|
|
|
|
cfg.SpiffeEnabled = c.Spire.SpiffeEnabled
|
|
cfg.SpiffeEndpointSocket = c.Spire.SpiffeEndpointSocket
|
|
cfg.SpiffeJWTExchangeEndpoint = c.Spire.SpiffeJWTExchangeEndpoint
|
|
cfg.SpireServerNamespace = c.Spire.ServerNamespace
|
|
cfg.SpireClassName = c.Spire.ClassName
|
|
cfg.SpireTPMPubhashesConfigMapName = c.Spire.TPMPubhashesConfigMapName
|
|
cfg.SpireServerPort = c.Spire.ServerPort
|
|
cfg.SpireJoinTokenTTL = c.Spire.JoinTokenTTL.Duration
|
|
|
|
cfg.Teleport.Enabled = c.Teleport.Enabled
|
|
cfg.Teleport.IdentityFile = c.Teleport.IdentityFile
|
|
cfg.Teleport.ProxyAddress = c.Teleport.ProxyAddress
|
|
cfg.Teleport.Environment = c.Teleport.Environment
|
|
cfg.Teleport.ManagedByLabelValue = c.Teleport.ManagedByLabelValue
|
|
cfg.Teleport.AcceptedManagedByLabelValues = c.Teleport.AcceptedManagedByLabelValues
|
|
cfg.Teleport.TokenNamePrefix = c.Teleport.TokenNamePrefix
|
|
cfg.Teleport.ResourceGroupLabelValue = c.Teleport.ResourceGroupLabelValue
|
|
|
|
cfg.PermissiveMode = c.APIAuth.Permissive
|
|
cfg.AllowControlPlaneWithoutVIP = c.AllowControlPlaneWithoutVIP
|
|
cfg.ClusterSelfAdoptionEnabled = c.ClusterSelfAdoptionEnabled
|
|
cfg.KubeVip.LocalASN = c.KubeVip.LocalASN
|
|
cfg.KubeVip.StaticPeerASN = c.KubeVip.StaticPeerASN
|
|
}
|