Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kubelet Configuration for cp and wn Tinkerbell #8217

Merged
merged 1 commit into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions pkg/clusterapi/workers.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package clusterapi

import (
"context"
"reflect"

"github.com/pkg/errors"
"k8s.io/apimachinery/pkg/api/equality"
Expand Down Expand Up @@ -124,7 +125,10 @@ func GetKubeadmConfigTemplate(ctx context.Context, client kubernetes.Client, nam
func KubeadmConfigTemplateEqual(new, old *kubeadmv1.KubeadmConfigTemplate) bool {
// DeepDerivative treats empty map (length == 0) as unset field. We need to manually compare certain fields
// such as taints, so that setting it to empty will trigger machine recreate
// The file check with deep equal has been added since the introduction of kubelet configuration in case users
// want to get rid of the files with that context.
return kubeadmConfigTemplateTaintsEqual(new, old) && kubeadmConfigTemplateExtraArgsEqual(new, old) &&
reflect.DeepEqual(new.Spec.Template.Spec.Files, old.Spec.Template.Spec.Files) &&
equality.Semantic.DeepDerivative(new.Spec, old.Spec)
}

Expand Down
43 changes: 43 additions & 0 deletions pkg/clusterapi/workers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,49 @@ func TestKubeadmConfigTemplateEqual(t *testing.T) {
},
want: false,
},
{
name: "diff spec files",
new: &kubeadmv1.KubeadmConfigTemplate{
Spec: kubeadmv1.KubeadmConfigTemplateSpec{
Template: kubeadmv1.KubeadmConfigTemplateResource{
Spec: kubeadmv1.KubeadmConfigSpec{
JoinConfiguration: &kubeadmv1.JoinConfiguration{
NodeRegistration: kubeadmv1.NodeRegistrationOptions{
Taints: []corev1.Taint{
{
Key: "key",
},
},
},
},
Files: []kubeadmv1.File{
{
Owner: "me",
},
},
},
},
},
},
old: &kubeadmv1.KubeadmConfigTemplate{
Spec: kubeadmv1.KubeadmConfigTemplateSpec{
Template: kubeadmv1.KubeadmConfigTemplateResource{
Spec: kubeadmv1.KubeadmConfigSpec{
JoinConfiguration: &kubeadmv1.JoinConfiguration{
NodeRegistration: kubeadmv1.NodeRegistrationOptions{
Taints: []corev1.Taint{
{
Key: "key",
},
},
},
},
},
},
},
},
want: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions pkg/crypto/tls.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import (
// This is what we currently support as the default. In the future,
// we can make this customizable and return a wider range of
// supported names.
func secureCipherSuiteNames() []string {
func SecureCipherSuiteNames() []string {
return []string{"TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256"}
}

func SecureCipherSuitesString() string {
return strings.Join(secureCipherSuiteNames(), ",")
return strings.Join(SecureCipherSuiteNames(), ",")
}
25 changes: 25 additions & 0 deletions pkg/providers/tinkerbell/config/template-cp.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -161,14 +161,23 @@ spec:
certificatesDir: /var/lib/kubeadm/pki
{{- end }}
initConfiguration:
{{- if .kubeletConfiguration }}
patches:
directory: /etc/kubernetes/patches
{{- end }}
nodeRegistration:
kubeletExtraArgs:
provider-id: PROVIDER_ID
{{- if not .kubeletConfiguration }}
read-only-port: "0"
anonymous-auth: "false"
{{- if .kubeletExtraArgs }}
{{ .kubeletExtraArgs.ToYaml | indent 10 }}
{{- end }}
{{- end }}
mitalipaygude marked this conversation as resolved.
Show resolved Hide resolved
{{- if .cpNodeLabelArgs }}
{{ .cpNodeLabelArgs.ToYaml | indent 10 }}
{{- end }}
{{- if not .workerNodeGroupConfigurations }}
taints: []
{{- end }}
Expand All @@ -184,6 +193,10 @@ spec:
{{- end }}
{{- end }}
joinConfiguration:
{{- if .kubeletConfiguration }}
patches:
directory: /etc/kubernetes/patches
{{- end }}
{{- if (eq .format "bottlerocket") }}
pause:
imageRepository: {{.pauseRepository}}
Expand Down Expand Up @@ -223,11 +236,16 @@ spec:
- DirAvailable--etc-kubernetes-manifests
kubeletExtraArgs:
provider-id: PROVIDER_ID
{{- if not .kubeletConfiguration }}
read-only-port: "0"
anonymous-auth: "false"
{{- if .kubeletExtraArgs }}
{{ .kubeletExtraArgs.ToYaml | indent 10 }}
{{- end }}
{{- end }}
{{- if .cpNodeLabelArgs }}
{{ .cpNodeLabelArgs.ToYaml | indent 10 }}
{{- end }}
{{- if not .workerNodeGroupConfigurations }}
taints: []
{{- end }}
Expand All @@ -243,6 +261,13 @@ spec:
{{- end }}
{{- end }}
files:
{{- if .kubeletConfiguration }}
- content: |
{{ .kubeletConfiguration | indent 10 }}
owner: root:root
permissions: "0644"
path: /etc/kubernetes/patches/kubeletconfiguration0+strategic.yaml
{{- end }}
{{- if not .cpSkipLoadBalancerDeployment }}
- content: |
apiVersion: v1
Expand Down
18 changes: 17 additions & 1 deletion pkg/providers/tinkerbell/config/template-md.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ spec:
template:
spec:
joinConfiguration:
{{- if .kubeletConfiguration }}
patches:
directory: /etc/kubernetes/patches
{{- end }}
{{- if (eq .format "bottlerocket") }}
pause:
imageRepository: {{.pauseRepository}}
Expand Down Expand Up @@ -123,14 +127,26 @@ spec:
{{- end }}
kubeletExtraArgs:
provider-id: PROVIDER_ID
{{- if not .kubeletConfiguration }}
read-only-port: "0"
anonymous-auth: "false"
{{- if .kubeletExtraArgs }}
{{ .kubeletExtraArgs.ToYaml | indent 12 }}
{{- end }}
{{- if and (ne .format "bottlerocket") (or .proxyConfig .registryMirrorMap) }}
{{- end }}
{{- if .wnNodeLabelArgs }}
{{ .wnNodeLabelArgs.ToYaml | indent 12 }}
{{- end }}
{{- if or (and (ne .format "bottlerocket") (or .proxyConfig .registryMirrorMap)) .kubeletConfiguration }}
files:
{{- end }}
{{- if .kubeletConfiguration }}
- content: |
{{ .kubeletConfiguration | indent 12 }}
owner: root:root
permissions: "0644"
path: /etc/kubernetes/patches/kubeletconfiguration0+strategic.yaml
{{- end }}
{{- if and .proxyConfig (ne .format "bottlerocket") }}
- content: |
[Service]
Expand Down
72 changes: 60 additions & 12 deletions pkg/providers/tinkerbell/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"github.com/pkg/errors"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
yamlutil "k8s.io/apimachinery/pkg/util/yaml"
"sigs.k8s.io/yaml"

"github.com/aws/eks-anywhere/pkg/api/v1alpha1"
"github.com/aws/eks-anywhere/pkg/cluster"
Expand Down Expand Up @@ -66,9 +67,6 @@
func (tb *TemplateBuilder) GenerateCAPISpecControlPlane(clusterSpec *cluster.Spec, buildOptions ...providers.BuildMapOption) (content []byte, err error) {
cpTemplateConfig := clusterSpec.TinkerbellTemplateConfigs[tb.controlPlaneMachineSpec.TemplateRef.Name]
bundle := clusterSpec.RootVersionsBundle()
if err != nil {
return nil, err
}
var OSImageURL string

if tinkerbellIP := clusterSpec.Cluster.HasTinkerbellIPAnnotation(); tinkerbellIP != "" {
Expand Down Expand Up @@ -401,9 +399,6 @@
Append(clusterapi.AwsIamAuthExtraArgs(clusterSpec.AWSIamConfig)).
Append(clusterapi.APIServerExtraArgs(clusterSpec.Cluster.Spec.ControlPlaneConfiguration.APIServerExtraArgs))
clusterapi.SetPodIAMAuthExtraArgs(clusterSpec.Cluster.Spec.PodIAMConfig, apiServerExtraArgs)
kubeletExtraArgs := clusterapi.SecureTlsCipherSuitesExtraArgs().
Append(clusterapi.ResolvConfExtraArgs(clusterSpec.Cluster.Spec.ClusterNetwork.DNS.ResolvConf)).
Append(clusterapi.ControlPlaneNodeLabelsExtraArgs(clusterSpec.Cluster.Spec.ControlPlaneConfiguration))

values := map[string]interface{}{
"auditPolicy": auditPolicy,
Expand All @@ -430,7 +425,6 @@
"etcdImageTag": versionsBundle.KubeDistro.Etcd.Tag,
"externalEtcdVersion": versionsBundle.KubeDistro.EtcdVersion,
"etcdCipherSuites": crypto.SecureCipherSuitesString(),
"kubeletExtraArgs": kubeletExtraArgs.ToPartialYaml(),
"hardwareSelector": controlPlaneMachineSpec.HardwareSelector,
"controlPlaneTaints": clusterSpec.Cluster.Spec.ControlPlaneConfiguration.Taints,
"workerNodeGroupConfigurations": clusterSpec.Cluster.Spec.WorkerNodeGroupConfigurations,
Expand Down Expand Up @@ -510,6 +504,36 @@
values["bottlerocketSettings"] = brSettings
}

if clusterSpec.Cluster.Spec.ControlPlaneConfiguration.KubeletConfiguration != nil {
cpKubeletConfig := clusterSpec.Cluster.Spec.ControlPlaneConfiguration.KubeletConfiguration.Object

if _, ok := cpKubeletConfig["tlsCipherSuites"]; !ok {
cpKubeletConfig["tlsCipherSuites"] = crypto.SecureCipherSuiteNames()
}

if _, ok := cpKubeletConfig["resolvConf"]; !ok {
if clusterSpec.Cluster.Spec.ClusterNetwork.DNS.ResolvConf != nil {
cpKubeletConfig["resolvConf"] = clusterSpec.Cluster.Spec.ClusterNetwork.DNS.ResolvConf.Path
}
}
kcString, err := yaml.Marshal(cpKubeletConfig)
if err != nil {
return nil, fmt.Errorf("marshaling control plane node Kubelet Configuration while building CAPI template %v", err)

Check warning on line 521 in pkg/providers/tinkerbell/template.go

View check run for this annotation

Codecov / codecov/patch

pkg/providers/tinkerbell/template.go#L521

Added line #L521 was not covered by tests
}

values["kubeletConfiguration"] = string(kcString)
} else {
kubeletExtraArgs := clusterapi.SecureTlsCipherSuitesExtraArgs().
Append(clusterapi.ResolvConfExtraArgs(clusterSpec.Cluster.Spec.ClusterNetwork.DNS.ResolvConf))

values["kubeletExtraArgs"] = kubeletExtraArgs.ToPartialYaml()
}

cpNodeLabelArgs := clusterapi.ControlPlaneNodeLabelsExtraArgs(clusterSpec.Cluster.Spec.ControlPlaneConfiguration)
if len(cpNodeLabelArgs) != 0 {
values["cpNodeLabelArgs"] = cpNodeLabelArgs.ToPartialYaml()
}

return values, nil
}

Expand All @@ -523,14 +547,9 @@
versionsBundle := clusterSpec.WorkerNodeGroupVersionsBundle(workerNodeGroupConfiguration)
format := "cloud-config"

kubeletExtraArgs := clusterapi.SecureTlsCipherSuitesExtraArgs().
Append(clusterapi.WorkerNodeLabelsExtraArgs(workerNodeGroupConfiguration)).
Append(clusterapi.ResolvConfExtraArgs(clusterSpec.Cluster.Spec.ClusterNetwork.DNS.ResolvConf))

values := map[string]interface{}{
"clusterName": clusterSpec.Cluster.Name,
"eksaSystemNamespace": constants.EksaSystemNamespace,
"kubeletExtraArgs": kubeletExtraArgs.ToPartialYaml(),
"format": format,
"kubernetesVersion": versionsBundle.KubeDistro.Kubernetes.Tag,
"workerNodeGroupName": workerNodeGroupConfiguration.Name,
Expand Down Expand Up @@ -586,6 +605,35 @@
values["bottlerocketSettings"] = brSettings
}

if workerNodeGroupConfiguration.KubeletConfiguration != nil {
wnKubeletConfig := workerNodeGroupConfiguration.KubeletConfiguration.Object
if _, ok := wnKubeletConfig["tlsCipherSuites"]; !ok {
wnKubeletConfig["tlsCipherSuites"] = crypto.SecureCipherSuiteNames()
}

if _, ok := wnKubeletConfig["resolvConf"]; !ok {
if clusterSpec.Cluster.Spec.ClusterNetwork.DNS.ResolvConf != nil {
wnKubeletConfig["resolvConf"] = clusterSpec.Cluster.Spec.ClusterNetwork.DNS.ResolvConf.Path
}
}

kcString, err := yaml.Marshal(wnKubeletConfig)
if err != nil {
return nil, fmt.Errorf("marshaling Kubelet Configuration for worker node %s: %v", workerNodeGroupConfiguration.Name, err)

Check warning on line 622 in pkg/providers/tinkerbell/template.go

View check run for this annotation

Codecov / codecov/patch

pkg/providers/tinkerbell/template.go#L622

Added line #L622 was not covered by tests
}

values["kubeletConfiguration"] = string(kcString)
} else {
kubeletExtraArgs := clusterapi.SecureTlsCipherSuitesExtraArgs().
Append(clusterapi.ResolvConfExtraArgs(clusterSpec.Cluster.Spec.ClusterNetwork.DNS.ResolvConf))
values["kubeletExtraArgs"] = kubeletExtraArgs.ToPartialYaml()
}

wnNodeLabelArgs := clusterapi.WorkerNodeLabelsExtraArgs(workerNodeGroupConfiguration)
if len(wnNodeLabelArgs) != 0 {
values["wnNodeLabelArgs"] = wnNodeLabelArgs.ToPartialYaml()
}

return values, nil
}

Expand Down
Loading
Loading