mirror of
https://github.com/siderolabs/talos.git
synced 2025-09-15 02:41:10 +02:00
Fixes #4231 This allows much faster worker join on `apid` level without waiting for Kubernetes control plane to be up (and even if the Kubernetes control plane doesn't go up or the kubelet isn't up). Signed-off-by: Andrey Smirnov <andrey.smirnov@talos-systems.com>
78 lines
2.9 KiB
Go
78 lines
2.9 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/.
|
|
|
|
package cluster_test
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/cosi-project/runtime/pkg/resource"
|
|
"github.com/stretchr/testify/suite"
|
|
"github.com/talos-systems/go-retry/retry"
|
|
"inet.af/netaddr"
|
|
|
|
clusterctrl "github.com/talos-systems/talos/internal/app/machined/pkg/controllers/cluster"
|
|
"github.com/talos-systems/talos/pkg/machinery/config/types/v1alpha1/machine"
|
|
"github.com/talos-systems/talos/pkg/resources/cluster"
|
|
"github.com/talos-systems/talos/pkg/resources/k8s"
|
|
)
|
|
|
|
type EndpointSuite struct {
|
|
ClusterSuite
|
|
}
|
|
|
|
func (suite *EndpointSuite) TestReconcileDefault() {
|
|
suite.startRuntime()
|
|
|
|
suite.Require().NoError(suite.runtime.RegisterController(&clusterctrl.EndpointController{}))
|
|
|
|
member1 := cluster.NewMember(cluster.NamespaceName, "talos-default-master-1")
|
|
*member1.TypedSpec() = cluster.MemberSpec{
|
|
NodeID: "7x1SuC8Ege5BGXdAfTEff5iQnlWZLfv9h1LGMxA2pYkC",
|
|
Addresses: []netaddr.IP{netaddr.MustParseIP("172.20.0.2"), netaddr.MustParseIP("fd50:8d60:4238:6302:f857:23ff:fe21:d1e0")},
|
|
Hostname: "talos-default-master-1",
|
|
MachineType: machine.TypeControlPlane,
|
|
OperatingSystem: "Talos (v1.0.0)",
|
|
}
|
|
|
|
member2 := cluster.NewMember(cluster.NamespaceName, "talos-default-master-2")
|
|
*member2.TypedSpec() = cluster.MemberSpec{
|
|
NodeID: "9dwHNUViZlPlIervqX9Qo256RUhrfhgO0xBBnKcKl4F",
|
|
Addresses: []netaddr.IP{netaddr.MustParseIP("172.20.0.3"), netaddr.MustParseIP("fd50:8d60:4238:6302:f857:23ff:fe21:d1e1")},
|
|
Hostname: "talos-default-master-2",
|
|
MachineType: machine.TypeControlPlane,
|
|
OperatingSystem: "Talos (v1.0.0)",
|
|
}
|
|
|
|
member3 := cluster.NewMember(cluster.NamespaceName, "talos-default-worker-1")
|
|
*member3.TypedSpec() = cluster.MemberSpec{
|
|
NodeID: "xCnFFfxylOf9i5ynhAkt6ZbfcqaLDGKfIa3gwpuaxe7F",
|
|
Addresses: []netaddr.IP{netaddr.MustParseIP("172.20.0.4")},
|
|
Hostname: "talos-default-worker-1",
|
|
MachineType: machine.TypeWorker,
|
|
OperatingSystem: "Talos (v1.0.0)",
|
|
}
|
|
|
|
for _, r := range []resource.Resource{member1, member2, member3} {
|
|
suite.Require().NoError(suite.state.Create(suite.ctx, r))
|
|
}
|
|
|
|
// control plane members should be translated to Endpoints
|
|
suite.Assert().NoError(retry.Constant(3*time.Second, retry.WithUnits(100*time.Millisecond)).Retry(
|
|
suite.assertResource(*k8s.NewEndpoint(k8s.ControlPlaneNamespaceName, k8s.ControlPlaneDiscoveredEndpointsID).Metadata(), func(r resource.Resource) error {
|
|
spec := r.(*k8s.Endpoint).TypedSpec()
|
|
|
|
suite.Assert().Equal(`["172.20.0.2" "172.20.0.3" "fd50:8d60:4238:6302:f857:23ff:fe21:d1e0" "fd50:8d60:4238:6302:f857:23ff:fe21:d1e1"]`, fmt.Sprintf("%q", spec.Addresses))
|
|
|
|
return nil
|
|
}),
|
|
))
|
|
}
|
|
|
|
func TestEndpointSuite(t *testing.T) {
|
|
suite.Run(t, new(EndpointSuite))
|
|
}
|