mirror of
https://github.com/siderolabs/talos.git
synced 2025-10-23 13:31:12 +02:00
This changes the way Kubernetes nodename is computed: it is set by the controller based on the hostname and machine configuration, and pulled from the resource when needed. Kubelet client now also uses nodename to fix the certifcate mismatch issue on AWS. Signed-off-by: Andrey Smirnov <smirnov.andrey@gmail.com>
62 lines
1.7 KiB
Go
62 lines
1.7 KiB
Go
// This Source Code Form is subject to the terms of the Mozilla Public
|
|
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
// +build linux
|
|
|
|
package k8s
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/cosi-project/runtime/pkg/resource"
|
|
"github.com/cosi-project/runtime/pkg/state"
|
|
|
|
"github.com/talos-systems/talos/pkg/resources/network"
|
|
)
|
|
|
|
// NodenameReadyCondition implements condition which waits for the nodename to be ready.
|
|
type NodenameReadyCondition struct {
|
|
state state.State
|
|
}
|
|
|
|
// NewNodenameReadyCondition builds a coondition which waits for the network to be ready.
|
|
func NewNodenameReadyCondition(state state.State) *NodenameReadyCondition {
|
|
return &NodenameReadyCondition{
|
|
state: state,
|
|
}
|
|
}
|
|
|
|
func (condition *NodenameReadyCondition) String() string {
|
|
return "nodename"
|
|
}
|
|
|
|
// Wait implements condition interface.
|
|
func (condition *NodenameReadyCondition) Wait(ctx context.Context) error {
|
|
_, err := condition.state.WatchFor(
|
|
ctx,
|
|
resource.NewMetadata(ControlPlaneNamespaceName, NodenameType, NodenameID, resource.VersionUndefined),
|
|
state.WithCondition(func(r resource.Resource) (bool, error) {
|
|
if resource.IsTombstone(r) {
|
|
return false, nil
|
|
}
|
|
|
|
nodename := r.(*Nodename).TypedSpec()
|
|
|
|
// check that hostname status version matches one recorded in the nodename
|
|
hostnameStatus, err := condition.state.Get(ctx, resource.NewMetadata(network.NamespaceName, network.HostnameStatusType, network.HostnameID, resource.VersionUndefined))
|
|
if err != nil {
|
|
return false, err
|
|
}
|
|
|
|
if hostnameStatus.Metadata().Version().String() != nodename.HostnameVersion {
|
|
return false, nil
|
|
}
|
|
|
|
return true, nil
|
|
}),
|
|
)
|
|
|
|
return err
|
|
}
|