talos/pkg/resources/network/hostname_status.go
Andrey Smirnov cb83edd7fc fix: wait for the network to be ready in mainteancne mode
This got "broken" as part of the change to the new networking
implementation, so that maintenance service is launched before the
network is ready.

Fetch DNS names and IPs for the certificate from the resources.

Signed-off-by: Andrey Smirnov <smirnov.andrey@gmail.com>
2021-06-16 10:56:47 -07:00

106 lines
2.6 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 network
import (
"fmt"
"github.com/cosi-project/runtime/pkg/resource"
"github.com/cosi-project/runtime/pkg/resource/meta"
)
// HostnameStatusType is type of HostnameStatus resource.
const HostnameStatusType = resource.Type("HostnameStatuses.net.talos.dev")
// HostnameStatus resource holds node hostname.
type HostnameStatus struct {
md resource.Metadata
spec HostnameStatusSpec
}
// HostnameStatusSpec describes node nostname.
type HostnameStatusSpec struct {
Hostname string `yaml:"hostname"`
Domainname string `yaml:"domainname"`
}
// FQDN returns the fully-qualified domain name.
func (spec *HostnameStatusSpec) FQDN() string {
if spec.Domainname == "" {
return spec.Hostname
}
return spec.Hostname + "." + spec.Domainname
}
// DNSNames returns DNS names to be added to the certificate based on the hostname and fqdn.
func (spec *HostnameStatusSpec) DNSNames() []string {
result := []string{spec.Hostname}
if spec.Domainname != "" {
result = append(result, spec.FQDN())
}
return result
}
// NewHostnameStatus initializes a HostnameStatus resource.
func NewHostnameStatus(namespace resource.Namespace, id resource.ID) *HostnameStatus {
r := &HostnameStatus{
md: resource.NewMetadata(namespace, HostnameStatusType, id, resource.VersionUndefined),
spec: HostnameStatusSpec{},
}
r.md.BumpVersion()
return r
}
// Metadata implements resource.Resource.
func (r *HostnameStatus) Metadata() *resource.Metadata {
return &r.md
}
// Spec implements resource.Resource.
func (r *HostnameStatus) Spec() interface{} {
return r.spec
}
func (r *HostnameStatus) String() string {
return fmt.Sprintf("network.HostnameStatus(%q)", r.md.ID())
}
// DeepCopy implements resource.Resource.
func (r *HostnameStatus) DeepCopy() resource.Resource {
return &HostnameStatus{
md: r.md,
spec: r.spec,
}
}
// ResourceDefinition implements meta.ResourceDefinitionProvider interface.
func (r *HostnameStatus) ResourceDefinition() meta.ResourceDefinitionSpec {
return meta.ResourceDefinitionSpec{
Type: HostnameStatusType,
Aliases: []resource.Type{"hostname"},
DefaultNamespace: NamespaceName,
PrintColumns: []meta.PrintColumn{
{
Name: "Hostname",
JSONPath: "{.hostname}",
},
{
Name: "Domainname",
JSONPath: "{.domainname}",
},
},
}
}
// TypedSpec allows to access the Spec with the proper type.
func (r *HostnameStatus) TypedSpec() *HostnameStatusSpec {
return &r.spec
}