mirror of
https://github.com/siderolabs/talos.git
synced 2025-11-02 17:31:11 +01:00
There should be no functional change with this PR.
The primary driver is supporting strategic merge configuration patches.
For such type of patches machine config should be loaded from incomplete
fragments, so it becomes critically important to distinguish between a
field having zero value vs. field being set in YAML.
E.g. with following struct:
```go
struct { AEnabled *bool `yaml:"a"` }
```
It's possible to distinguish between:
```yaml
a: false
```
and no metion of `a` in YAML.
Merging process trewats zero values as "not set" (skips them when
merging), so it's important to allow overriding value to explicit
`false`.
Signed-off-by: Andrey Smirnov <andrey.smirnov@talos-systems.com>
194 lines
6.1 KiB
Go
194 lines
6.1 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/.
|
|
|
|
//nolint:dupl
|
|
package cluster_test
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/cosi-project/runtime/pkg/resource"
|
|
"github.com/siderolabs/go-pointer"
|
|
"github.com/stretchr/testify/suite"
|
|
"github.com/talos-systems/go-retry/retry"
|
|
|
|
clusterctrl "github.com/talos-systems/talos/internal/app/machined/pkg/controllers/cluster"
|
|
"github.com/talos-systems/talos/pkg/machinery/config/types/v1alpha1"
|
|
"github.com/talos-systems/talos/pkg/machinery/resources/cluster"
|
|
"github.com/talos-systems/talos/pkg/machinery/resources/config"
|
|
)
|
|
|
|
type ConfigSuite struct {
|
|
ClusterSuite
|
|
}
|
|
|
|
func (suite *ConfigSuite) TestReconcileConfig() {
|
|
suite.Require().NoError(suite.runtime.RegisterController(&clusterctrl.ConfigController{}))
|
|
|
|
suite.startRuntime()
|
|
|
|
cfg := config.NewMachineConfig(&v1alpha1.Config{
|
|
ConfigVersion: "v1alpha1",
|
|
ClusterConfig: &v1alpha1.ClusterConfig{
|
|
ClusterID: "cluster1",
|
|
ClusterSecret: "kCQsKr4B28VUl7qw1sVkTDNF9fFH++ViIuKsss+C6kc=",
|
|
ClusterDiscoveryConfig: &v1alpha1.ClusterDiscoveryConfig{
|
|
DiscoveryEnabled: pointer.To(true),
|
|
},
|
|
},
|
|
})
|
|
|
|
suite.Require().NoError(suite.state.Create(suite.ctx, cfg))
|
|
|
|
specMD := resource.NewMetadata(config.NamespaceName, cluster.ConfigType, cluster.ConfigID, resource.VersionUndefined)
|
|
|
|
suite.Assert().NoError(retry.Constant(3*time.Second, retry.WithUnits(100*time.Millisecond)).Retry(
|
|
suite.assertResource(
|
|
specMD,
|
|
func(res resource.Resource) error {
|
|
spec := res.(*cluster.Config).TypedSpec()
|
|
|
|
suite.Assert().True(spec.DiscoveryEnabled)
|
|
suite.Assert().True(spec.RegistryKubernetesEnabled)
|
|
suite.Assert().True(spec.RegistryServiceEnabled)
|
|
suite.Assert().Equal("discovery.talos.dev:443", spec.ServiceEndpoint)
|
|
suite.Assert().False(spec.ServiceEndpointInsecure)
|
|
suite.Assert().Equal("cluster1", spec.ServiceClusterID)
|
|
suite.Assert().Equal(
|
|
[]byte("\x90\x24\x2c\x2a\xbe\x01\xdb\xc5\x54\x97\xba\xb0\xd6\xc5\x64\x4c\x33\x45\xf5\xf1\x47\xfb\xe5\x62\x22\xe2\xac\xb2\xcf\x82\xea\x47"),
|
|
spec.ServiceEncryptionKey)
|
|
|
|
return nil
|
|
},
|
|
),
|
|
))
|
|
}
|
|
|
|
func (suite *ConfigSuite) TestReconcileConfigCustom() {
|
|
suite.Require().NoError(suite.runtime.RegisterController(&clusterctrl.ConfigController{}))
|
|
|
|
suite.startRuntime()
|
|
|
|
cfg := config.NewMachineConfig(&v1alpha1.Config{
|
|
ConfigVersion: "v1alpha1",
|
|
ClusterConfig: &v1alpha1.ClusterConfig{
|
|
ClusterID: "cluster1",
|
|
ClusterSecret: "kCQsKr4B28VUl7qw1sVkTDNF9fFH++ViIuKsss+C6kc=",
|
|
ClusterDiscoveryConfig: &v1alpha1.ClusterDiscoveryConfig{
|
|
DiscoveryEnabled: pointer.To(true),
|
|
DiscoveryRegistries: v1alpha1.DiscoveryRegistriesConfig{
|
|
RegistryKubernetes: v1alpha1.RegistryKubernetesConfig{
|
|
RegistryDisabled: pointer.To(true),
|
|
},
|
|
RegistryService: v1alpha1.RegistryServiceConfig{
|
|
RegistryEndpoint: "https://[2001:470:6d:30e:565d:e162:e2a0:cf5a]:3456/",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
})
|
|
|
|
suite.Require().NoError(suite.state.Create(suite.ctx, cfg))
|
|
|
|
specMD := resource.NewMetadata(config.NamespaceName, cluster.ConfigType, cluster.ConfigID, resource.VersionUndefined)
|
|
|
|
suite.Assert().NoError(retry.Constant(3*time.Second, retry.WithUnits(100*time.Millisecond)).Retry(
|
|
suite.assertResource(
|
|
specMD,
|
|
func(res resource.Resource) error {
|
|
spec := res.(*cluster.Config).TypedSpec()
|
|
|
|
suite.Assert().True(spec.DiscoveryEnabled)
|
|
suite.Assert().False(spec.RegistryKubernetesEnabled)
|
|
suite.Assert().True(spec.RegistryServiceEnabled)
|
|
suite.Assert().Equal("[2001:470:6d:30e:565d:e162:e2a0:cf5a]:3456", spec.ServiceEndpoint)
|
|
suite.Assert().False(spec.ServiceEndpointInsecure)
|
|
|
|
return nil
|
|
},
|
|
),
|
|
))
|
|
}
|
|
|
|
func (suite *ConfigSuite) TestReconcileConfigCustomInsecure() {
|
|
suite.Require().NoError(suite.runtime.RegisterController(&clusterctrl.ConfigController{}))
|
|
|
|
suite.startRuntime()
|
|
|
|
cfg := config.NewMachineConfig(&v1alpha1.Config{
|
|
ConfigVersion: "v1alpha1",
|
|
ClusterConfig: &v1alpha1.ClusterConfig{
|
|
ClusterID: "cluster1",
|
|
ClusterSecret: "kCQsKr4B28VUl7qw1sVkTDNF9fFH++ViIuKsss+C6kc=",
|
|
ClusterDiscoveryConfig: &v1alpha1.ClusterDiscoveryConfig{
|
|
DiscoveryEnabled: pointer.To(true),
|
|
DiscoveryRegistries: v1alpha1.DiscoveryRegistriesConfig{
|
|
RegistryKubernetes: v1alpha1.RegistryKubernetesConfig{
|
|
RegistryDisabled: pointer.To(true),
|
|
},
|
|
RegistryService: v1alpha1.RegistryServiceConfig{
|
|
RegistryEndpoint: "http://localhost:3000",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
})
|
|
|
|
suite.Require().NoError(suite.state.Create(suite.ctx, cfg))
|
|
|
|
specMD := resource.NewMetadata(config.NamespaceName, cluster.ConfigType, cluster.ConfigID, resource.VersionUndefined)
|
|
|
|
suite.Assert().NoError(retry.Constant(3*time.Second, retry.WithUnits(100*time.Millisecond)).Retry(
|
|
suite.assertResource(
|
|
specMD,
|
|
func(res resource.Resource) error {
|
|
spec := res.(*cluster.Config).TypedSpec()
|
|
|
|
suite.Assert().True(spec.DiscoveryEnabled)
|
|
suite.Assert().False(spec.RegistryKubernetesEnabled)
|
|
suite.Assert().True(spec.RegistryServiceEnabled)
|
|
suite.Assert().Equal("localhost:3000", spec.ServiceEndpoint)
|
|
suite.Assert().True(spec.ServiceEndpointInsecure)
|
|
|
|
return nil
|
|
},
|
|
),
|
|
))
|
|
}
|
|
|
|
func (suite *ConfigSuite) TestReconcileDisabled() {
|
|
suite.Require().NoError(suite.runtime.RegisterController(&clusterctrl.ConfigController{}))
|
|
|
|
suite.startRuntime()
|
|
|
|
cfg := config.NewMachineConfig(&v1alpha1.Config{
|
|
ConfigVersion: "v1alpha1",
|
|
MachineConfig: &v1alpha1.MachineConfig{},
|
|
ClusterConfig: &v1alpha1.ClusterConfig{},
|
|
})
|
|
|
|
suite.Require().NoError(suite.state.Create(suite.ctx, cfg))
|
|
|
|
specMD := resource.NewMetadata(config.NamespaceName, cluster.ConfigType, cluster.ConfigID, resource.VersionUndefined)
|
|
|
|
suite.Assert().NoError(retry.Constant(3*time.Second, retry.WithUnits(100*time.Millisecond)).Retry(
|
|
suite.assertResource(
|
|
specMD,
|
|
func(res resource.Resource) error {
|
|
spec := res.(*cluster.Config).TypedSpec()
|
|
|
|
suite.Assert().False(spec.DiscoveryEnabled)
|
|
suite.Assert().False(spec.RegistryKubernetesEnabled)
|
|
|
|
return nil
|
|
},
|
|
),
|
|
))
|
|
}
|
|
|
|
func TestConfigSuite(t *testing.T) {
|
|
suite.Run(t, new(ConfigSuite))
|
|
}
|