116 lines
2.8 KiB
Go
116 lines
2.8 KiB
Go
package templates
|
|
|
|
import (
|
|
"strings"
|
|
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
types "undecided.project/monok8s/pkg/apis/monok8s/v1alpha1"
|
|
)
|
|
|
|
func DefaultMonoKSConfig(v TemplateValues) types.MonoKSConfig {
|
|
return types.MonoKSConfig{
|
|
TypeMeta: metav1.TypeMeta{
|
|
APIVersion: "monok8s.io/v1alpha1",
|
|
Kind: "MonoKSConfig",
|
|
},
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
Name: "example",
|
|
Namespace: "kube-system",
|
|
},
|
|
Spec: types.MonoKSConfigSpec{
|
|
KubernetesVersion: v.KubernetesVersion,
|
|
NodeName: firstNonEmpty(v.NodeName, v.Hostname),
|
|
|
|
ClusterRole: v.ClusterRole,
|
|
InitControlPlane: v.InitControlPlane,
|
|
EnableControlAgent: v.EnableControlAgent,
|
|
|
|
ClusterName: v.ClusterName,
|
|
ClusterDomain: v.ClusterDomain,
|
|
|
|
PodSubnet: v.PodSubnet,
|
|
ServiceSubnet: v.ServiceSubnet,
|
|
|
|
APIServerAdvertiseAddress: v.APIServerAdvertiseAddress,
|
|
APIServerEndpoint: v.APIServerEndpoint,
|
|
|
|
BootstrapToken: v.BootstrapToken,
|
|
DiscoveryTokenCACertHash: v.DiscoveryTokenCACertHash,
|
|
|
|
ContainerRuntimeEndpoint: v.ContainerRuntimeEndpoint,
|
|
CNIPlugin: v.CNIPlugin,
|
|
|
|
AllowSchedulingOnControlPlane: v.AllowSchedulingOnControlPlane,
|
|
SkipImageCheck: v.SkipImageCheck,
|
|
|
|
KubeProxyNodePortAddresses: []string{
|
|
"primary",
|
|
},
|
|
|
|
SubjectAltNames: copyStringSlice(v.SubjectAltNames),
|
|
NodeLabels: copyStringMap(v.NodeLabels),
|
|
NodeAnnotations: copyStringMap(v.NodeAnnotations),
|
|
|
|
Network: types.NetworkSpec{
|
|
Hostname: firstNonEmpty(v.Hostname, v.NodeName),
|
|
ManagementIface: v.MgmtIface,
|
|
ManagementCIDR: v.MgmtAddress,
|
|
ManagementGW: v.MgmtGateway,
|
|
DNSNameservers: copyStringSlice(v.DNSNameservers),
|
|
DNSSearchDomains: copyStringSlice(v.DNSSearchDomains),
|
|
},
|
|
},
|
|
}
|
|
}
|
|
|
|
func DefaultOSUpgrade(v TemplateValues) types.OSUpgrade {
|
|
return types.OSUpgrade{
|
|
TypeMeta: metav1.TypeMeta{
|
|
APIVersion: "monok8s.io/v1alpha1",
|
|
Kind: "OSUpgrade",
|
|
},
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
Name: "example",
|
|
Namespace: "kube-system",
|
|
},
|
|
Spec: types.OSUpgradeSpec{
|
|
Version: "v0.0.1",
|
|
ImageURL: "https://example.invalid/images/monok8s-v0.0.1.img.zst",
|
|
TargetPartition: "B",
|
|
NodeSelector: []string{
|
|
firstNonEmpty(v.NodeName, v.Hostname),
|
|
},
|
|
Force: false,
|
|
},
|
|
}
|
|
}
|
|
|
|
func firstNonEmpty(xs ...string) string {
|
|
for _, x := range xs {
|
|
if strings.TrimSpace(x) != "" {
|
|
return strings.TrimSpace(x)
|
|
}
|
|
}
|
|
return ""
|
|
}
|
|
|
|
func copyStringSlice(in []string) []string {
|
|
if len(in) == 0 {
|
|
return nil
|
|
}
|
|
out := make([]string, len(in))
|
|
copy(out, in)
|
|
return out
|
|
}
|
|
|
|
func copyStringMap(in map[string]string) map[string]string {
|
|
if len(in) == 0 {
|
|
return nil
|
|
}
|
|
out := make(map[string]string, len(in))
|
|
for k, v := range in {
|
|
out[k] = v
|
|
}
|
|
return out
|
|
}
|