Fix issue with etcd node name missing hostname

* Set ServerNodeName in snapshot CLI setup
* Raise errer if ServerNodeName ends up empty some other way
* Fix status controller to use etcd node name annotation instead of prefix checking

Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
(cherry picked from commit 82432a2df7)
Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
pull/9707/head
Brad Davidson 10 months ago committed by Brad Davidson
parent 853473c180
commit 45d36a0886

@ -80,10 +80,11 @@ func commandSetup(app *cli.Context, cfg *cmds.Server, config *server.Config) (*e
// command uses the same endpoint selection logic as it does when starting up the full server. Specifically,
// we need to set an IPv6 service CIDR on IPv6-only or IPv6-first nodes, as the etcd default endpoints check
// the service CIDR primary addresss family to determine what loopback address to use.
_, nodeIPs, err := util.GetHostnameAndIPs(cmds.AgentConfig.NodeName, cmds.AgentConfig.NodeIP)
nodeName, nodeIPs, err := util.GetHostnameAndIPs(cmds.AgentConfig.NodeName, cmds.AgentConfig.NodeIP)
if err != nil {
return nil, err
}
config.ControlConfig.ServerNodeName = nodeName
// configure ClusterIPRanges. Use default 10.42.0.0/16 or fd00:42::/56 if user did not set it
_, defaultClusterCIDR, defaultServiceCIDR, _ := util.GetDefaultAddresses(nodeIPs[0])

@ -623,6 +623,9 @@ func (e *ETCD) setName(force bool) error {
fileName := nameFile(e.config)
data, err := os.ReadFile(fileName)
if os.IsNotExist(err) || force {
if e.config.ServerNodeName == "" {
return errors.New("server node name not set")
}
e.name = e.config.ServerNodeName + "-" + uuid.New().String()[:8]
if err := os.MkdirAll(filepath.Dir(fileName), 0700); err != nil {
return err
@ -1106,7 +1109,7 @@ func (e *ETCD) manageLearners(ctx context.Context) {
var node *v1.Node
for _, n := range nodes {
if strings.HasPrefix(member.Name, n.Name+"-") {
if member.Name == n.Annotations[NodeNameAnnotation] {
node = n
nodeIsMember[n.Name] = true
break

@ -27,6 +27,7 @@ func mustGetAddress() string {
}
func generateTestConfig() *config.Control {
hostname, _ := os.Hostname()
containerRuntimeReady := make(chan struct{})
close(containerRuntimeReady)
criticalControlArgs := config.CriticalControlArgs{
@ -37,6 +38,7 @@ func generateTestConfig() *config.Control {
ServiceIPRange: testutil.ServiceIPNet(),
}
return &config.Control{
ServerNodeName: hostname,
Runtime: config.NewRuntime(containerRuntimeReady),
HTTPSPort: 6443,
SupervisorPort: 6443,

Loading…
Cancel
Save