Andrey Smirnov d2fd7c2170
feat: make kubelet service apply changes immediately
The gist is that `kubelet` service code only manages the container
lifecycle, while `kubelet` configuration is managed now in the
controllers and resources.

New resources:

* `secrets.Kubelet` contains Kubelet PKI derived directly from the
machine configuration
* `k8s.KubeletConfig` contains Kubelet non-secret config derived
directly from the machine configuration
* `k8s.NodeIPConfig` contains configuration on picking up Node IP for
the kubelet (from machine configuration)
* `k8s.NodeIP` contains actual Node IPs picked from the node addresses
based on `NodeIPConfig`
* `k8s.KubeletSpec` contains final `kubelet` container configuration,
including merged arguments, KubeletConfig, etc. It is derived from
`KubeletConfig`, `Nodename` and `NodeIP`.

Final controller `KubeletServiceController` writes down configuration
and PKI to disk, and manages restart/start of the `kubelet` service
which is a pure wrapper around container lifecycle.

Signed-off-by: Andrey Smirnov <andrey.smirnov@talos-systems.com>
2021-12-03 23:02:49 +03:00

85 lines
2.0 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 k8s
import (
"fmt"
"github.com/cosi-project/runtime/pkg/resource"
"github.com/cosi-project/runtime/pkg/resource/meta"
)
// NodenameType is type of Nodename resource.
const NodenameType = resource.Type("Nodenames.kubernetes.talos.dev")
// NodenameID is a singleton resource ID for Nodename.
const NodenameID = resource.ID("nodename")
// Nodename resource holds Kubernetes nodename.
type Nodename struct {
md resource.Metadata
spec NodenameSpec
}
// NodenameSpec describes Kubernetes nodename.
type NodenameSpec struct {
Nodename string `yaml:"nodename"`
HostnameVersion string `yaml:"hostnameVersion"`
}
// NewNodename initializes a Nodename resource.
func NewNodename(namespace resource.Namespace, id resource.ID) *Nodename {
r := &Nodename{
md: resource.NewMetadata(namespace, NodenameType, id, resource.VersionUndefined),
spec: NodenameSpec{},
}
r.md.BumpVersion()
return r
}
// Metadata implements resource.Resource.
func (r *Nodename) Metadata() *resource.Metadata {
return &r.md
}
// Spec implements resource.Resource.
func (r *Nodename) Spec() interface{} {
return r.spec
}
func (r *Nodename) String() string {
return fmt.Sprintf("k8s.Nodename(%q)", r.md.ID())
}
// DeepCopy implements resource.Resource.
func (r *Nodename) DeepCopy() resource.Resource {
return &Nodename{
md: r.md,
spec: r.spec,
}
}
// ResourceDefinition implements meta.ResourceDefinitionProvider interface.
func (r *Nodename) ResourceDefinition() meta.ResourceDefinitionSpec {
return meta.ResourceDefinitionSpec{
Type: NodenameType,
Aliases: []resource.Type{},
DefaultNamespace: NamespaceName,
PrintColumns: []meta.PrintColumn{
{
Name: "Nodename",
JSONPath: "{.nodename}",
},
},
}
}
// TypedSpec allows to access the Spec with the proper type.
func (r *Nodename) TypedSpec() *NodenameSpec {
return &r.spec
}