Andrey Smirnov 0c7ce1cd81 feat: remove remnants of bootkube support
Fixes #3951

Bootkube support was removed in Talos 0.9. Talos versions 0.9-0.11
support conversion of self-hosted bootkube-based control plane to the
new style control plane running as static pods managed by Talos.

This commit removes all backwards compatibility and removes conversion
code.

For the k8s controllers, `BootstrapStatus` is removed and a dependency
on `etcd` service status is added (as it was implicitly there via
`BootstrapStatus`).

Remove control plane conversion code.

In k8s upgrade code, remove self-hosted part.

Signed-off-by: Andrey Smirnov <smirnov.andrey@gmail.com>
2021-08-03 07:55:42 -07:00

80 lines
2.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/.
package kubernetes
import (
"context"
"fmt"
"gopkg.in/yaml.v3"
"github.com/talos-systems/talos/pkg/machinery/api/machine"
"github.com/talos-systems/talos/pkg/machinery/client"
"github.com/talos-systems/talos/pkg/machinery/config/configloader"
v1alpha1config "github.com/talos-systems/talos/pkg/machinery/config/types/v1alpha1"
"github.com/talos-systems/talos/pkg/resources/config"
)
// patchNodeConfig updates node configuration by means of patch function.
//
//nolint:gocyclo
func patchNodeConfig(ctx context.Context, cluster UpgradeProvider, node string, patchFunc func(config *v1alpha1config.Config) error) error {
c, err := cluster.Client()
if err != nil {
return fmt.Errorf("error building Talos API client: %w", err)
}
ctx = client.WithNodes(ctx, node)
resources, err := c.Resources.Get(ctx, config.NamespaceName, config.MachineConfigType, config.V1Alpha1ID)
if err != nil {
return fmt.Errorf("error fetching config resource: %w", err)
}
if len(resources) != 1 {
return fmt.Errorf("expected 1 instance of config resource, got %d", len(resources))
}
r := resources[0]
yamlConfig, err := yaml.Marshal(r.Resource.Spec())
if err != nil {
return fmt.Errorf("error getting YAML config: %w", err)
}
config, err := configloader.NewFromBytes(yamlConfig)
if err != nil {
return fmt.Errorf("error loading config: %w", err)
}
cfg, ok := config.(*v1alpha1config.Config)
if !ok {
return fmt.Errorf("config is not v1alpha1 config")
}
if !cfg.Persist() {
return fmt.Errorf("config persistence is disabled, patching is not supported")
}
if err = patchFunc(cfg); err != nil {
return fmt.Errorf("error patching config: %w", err)
}
cfgBytes, err := cfg.Bytes()
if err != nil {
return fmt.Errorf("error serializing config: %w", err)
}
_, err = c.ApplyConfiguration(ctx, &machine.ApplyConfigurationRequest{
Data: cfgBytes,
Immediate: true,
})
if err != nil {
return fmt.Errorf("error applying config: %w", err)
}
return nil
}