Skip to content

Commit 27925a1

Browse files
Update licences and fix lint errors
Signed-off-by: Danil Grigorev <[email protected]>
1 parent a7b3b2f commit 27925a1

File tree

17 files changed

+41
-38
lines changed

17 files changed

+41
-38
lines changed

bootstrap/internal/cloudinit/controlplane_init.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ runcmd:
3535
- '/opt/rke2-cis-script.sh'{{ end }}
3636
- 'systemctl enable rke2-server.service'
3737
- 'systemctl start rke2-server.service'
38-
- 'kubectl create secret tls cluster-etcd -o yaml --dry-run=client -n kube-system --cert=/var/lib/rancher/rke2/server/tls/etcd/server-client.crt --key=/var/lib/rancher/rke2/server/tls/etcd/server-client.key --kubeconfig /var/lib/rancher/rke2/server/cred/api-server.kubeconfig | kubectl apply -f- --kubeconfig /var/lib/rancher/rke2/server/cred/api-server.kubeconfig'
38+
- 'kubectl create secret tls cluster-etcd -o yaml --dry-run=client -n kube-system --cert=/var/lib/rancher/rke2/server/tls/etcd/server.crt --key=/var/lib/rancher/rke2/server/tls/etcd/server.key --kubeconfig /var/lib/rancher/rke2/server/cred/api-server.kubeconfig | kubectl apply -f- --kubeconfig /var/lib/rancher/rke2/server/cred/api-server.kubeconfig'
3939
- 'mkdir /run/cluster-api'
4040
- '{{ .SentinelFileCommand }}'
4141
{{- template "commands" .PostRKE2Commands }}

bootstrap/internal/ignition/ignition.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ var (
3737
"systemctl enable rke2-server.service",
3838
"systemctl start rke2-server.service",
3939
"kubectl create secret tls cluster-etcd -o yaml --dry-run=client -n kube-system " +
40-
"--cert=/var/lib/rancher/rke2/server/tls/etcd/server-client.crt --key=/var/lib/rancher/rke2/server/tls/etcd/server-client.key " +
40+
"--cert=/var/lib/rancher/rke2/server/tls/etcd/server.crt --key=/var/lib/rancher/rke2/server/tls/etcd/server.key " +
4141
"--kubeconfig /var/lib/rancher/rke2/server/cred/api-server.kubeconfig |" +
4242
" kubectl apply -f- --kubeconfig /var/lib/rancher/rke2/server/cred/api-server.kubeconfig",
4343
"restorecon /etc/systemd/system/rke2-server.service",

controlplane/internal/controllers/rke2controlplane_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,7 @@ func (r *RKE2ControlPlaneReconciler) GetWorkloadCluster(ctx context.Context, con
573573
func (r *RKE2ControlPlaneReconciler) reconcileEtcdMembers(ctx context.Context, controlPlane *rke2.ControlPlane) error {
574574
log := ctrl.LoggerFrom(ctx)
575575

576-
// If there is no KCP-owned control-plane machines, then control-plane has not been initialized yet.
576+
// If there is no RKE-owned control-plane machines, then control-plane has not been initialized yet.
577577
if controlPlane.Machines.Len() == 0 {
578578
return nil
579579
}

pkg/etcd/client_generator.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright 2020 The Kubernetes Authors.
2+
Copyright 2024 SUSE.
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.

pkg/etcd/client_generator_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright 2020 The Kubernetes Authors.
2+
Copyright 2024 SUSE.
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.

pkg/etcd/etcd.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright 2020 The Kubernetes Authors.
2+
Copyright 2024 SUSE.
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.

pkg/etcd/etcd_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright 2020 The Kubernetes Authors.
2+
Copyright 2024 SUSE.
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.

pkg/etcd/fake/client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright 2020 The Kubernetes Authors.
2+
Copyright 2024 SUSE.
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.

pkg/etcd/util/util.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright 2020 The Kubernetes Authors.
2+
Copyright 2024 SUSE.
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.

pkg/proxy/addr.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright 2020 The Kubernetes Authors.
2+
Copyright 2024 SUSE.
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
// Package proxy implements kubeadm proxy functionality.
17+
// Package proxy implements proxy functionality.
1818
package proxy
1919

2020
import (

pkg/proxy/conn.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright 2020 The Kubernetes Authors.
2+
Copyright 2024 SUSE.
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.

pkg/proxy/dial.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright 2020 The Kubernetes Authors.
2+
Copyright 2024 SUSE.
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.

pkg/proxy/proxy.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright 2020 The Kubernetes Authors.
2+
Copyright 2024 SUSE.
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.

pkg/rke2/management_cluster.go

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -133,25 +133,27 @@ func (m *Management) getEtcdCAKeyPair(ctx context.Context, clusterKey ctrlclient
133133
certificates := secret.Certificates{&secret.ManagedCertificate{
134134
Purpose: secret.EtcdServerCA,
135135
}}
136+
secretName := secret.Name(clusterKey.Name, secret.EtcdServerCA)
136137

137138
// Try to get the certificate via the cached ctrlclient.
138-
err := certificates.Lookup(ctx, m.SecretCachingClient, clusterKey)
139-
if err != nil {
139+
if err := certificates.Lookup(ctx, m.SecretCachingClient, clusterKey); err != nil {
140140
// Return error if we got an errors which is not a NotFound error.
141-
return nil, errors.Wrapf(err, "failed to get secret CA bungle; etcd CA bundle %s/%s", clusterKey.Namespace, secret.Name(clusterKey.Name, secret.EtcdServerCA))
141+
return nil, errors.Wrapf(err, "failed to get secret CA bungle; etcd CA bundle %s/%s", clusterKey.Namespace, secretName)
142142
}
143143

144-
s := certificates[0].AsSecret(clusterKey, metav1.OwnerReference{})
145-
if err := m.SecretCachingClient.Get(ctx, ctrlclient.ObjectKeyFromObject(s), s); err != nil {
146-
return nil, errors.Wrapf(err, "failed to get secret; etcd CA bundle %s/%s", clusterKey.Namespace, secret.Name(clusterKey.Name, secret.EtcdServerCA))
147-
}
144+
var keypair *certs.KeyPair
148145

149-
// External certificate needs to be fetched, to sync the content
150-
if s.Labels == nil || s.Labels[secret.ExternalSecretPurposeLabel] != string(secret.EtcdServerCA) {
151-
return nil, nil
146+
if s, err := certificates[0].Lookup(ctx, m.SecretCachingClient, clusterKey); err != nil {
147+
return nil, errors.Wrapf(err, "failed to get secret; etcd CA bundle %s/%s", clusterKey.Namespace, secretName)
148+
} else if s == nil {
149+
return keypair, nil
150+
} else if s.Labels != nil && s.Labels[secret.ExternalPurposeLabel] == string(secret.EtcdServerCA) {
151+
keypair = certificates[0].GetKeyPair()
152152
}
153153

154-
return certificates[0].GetKeyPair(), nil
154+
// External certificate needs to be fetched otherwise, to sync the content
155+
156+
return keypair, nil
155157
}
156158

157159
func (m *Management) getRemoteKeyPair(ctx context.Context, remoteClient ctrlclient.Client, clusterKey ctrlclient.ObjectKey) (*certs.KeyPair, error) {

pkg/rke2/workload_cluster.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -103,40 +103,40 @@ func (m *Management) NewWorkload(
103103
restConfig.Timeout = remoteEtcdTimeout
104104

105105
// Retrieves the etcd CA key Pair
106-
keyPair, err := m.getEtcdCAKeyPair(ctx, clusterKey)
106+
etcdKeyPair, err := m.getEtcdCAKeyPair(ctx, clusterKey)
107107
if ctrlclient.IgnoreNotFound(err) != nil {
108108
return nil, err
109-
} else if apierrors.IsNotFound(err) || keyPair == nil {
110-
keyPair, err = m.getRemoteKeyPair(ctx, cl, clusterKey)
109+
} else if apierrors.IsNotFound(err) || etcdKeyPair == nil {
110+
etcdKeyPair, err = m.getRemoteKeyPair(ctx, cl, clusterKey)
111111
if ctrlclient.IgnoreNotFound(err) != nil {
112112
return nil, err
113-
} else if keyPair == nil {
113+
} else if etcdKeyPair == nil {
114114
log.FromContext(ctx).Info("Cluster does not provide etcd certificates for creating child etcd ctrlclient." +
115115
"Please scale up the CP nodes by one to bootstrap the etcd secret content.")
116116

117117
return workload, nil
118118
}
119119
}
120120

121-
clientCert, err := tls.X509KeyPair(keyPair.Cert, keyPair.Key)
121+
clientCert, err := tls.X509KeyPair(etcdKeyPair.Cert, etcdKeyPair.Key)
122122
if err != nil {
123123
return nil, err
124124
}
125125

126-
if _, err := certs.DecodePrivateKeyPEM(keyPair.Key); err == nil {
126+
if _, err := certs.DecodePrivateKeyPEM(etcdKeyPair.Key); err == nil {
127127
clientKey, err := m.Tracker.GetEtcdClientCertificateKey(ctx, clusterKey)
128128
if err != nil {
129129
return nil, err
130130
}
131131

132-
clientCert, err = generateClientCert(keyPair.Cert, keyPair.Key, clientKey)
132+
clientCert, err = generateClientCert(etcdKeyPair.Cert, etcdKeyPair.Key, clientKey)
133133
if err != nil {
134134
return nil, err
135135
}
136136
}
137137

138138
caPool := x509.NewCertPool()
139-
caPool.AppendCertsFromPEM(keyPair.Cert)
139+
caPool.AppendCertsFromPEM(etcdKeyPair.Cert)
140140
tlsConfig := &tls.Config{
141141
RootCAs: caPool,
142142
Certificates: []tls.Certificate{clientCert},

pkg/secret/certificates.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,9 @@ const (
8383
// TenYears is the duration of one year.
8484
TenYears = time.Hour * 24 * 365 * 10
8585

86-
// ExternalSecretPurposeLabel is a label set on external secrets, uniquely identifying their belonging
87-
// to external source and used for a specified purpose
88-
ExternalSecretPurposeLabel = "cluster.x-k8s.io/purpose"
86+
// ExternalPurposeLabel is a label set on external secrets, uniquely identifying their belonging
87+
// to external source and used for a specified purpose.
88+
ExternalPurposeLabel = "cluster.x-k8s.io/purpose"
8989
)
9090

9191
// Purpose is the name to append to the secret generated for a cluster.
@@ -600,7 +600,8 @@ func generateServiceAccountKeys() (*certs.KeyPair, error) {
600600

601601
func asExternalSecret(data map[string][]byte, purpose Purpose, clusterName types.NamespacedName, owner metav1.OwnerReference) *corev1.Secret {
602602
secret := asSecret(data, purpose, clusterName, owner)
603-
secret.Labels[ExternalSecretPurposeLabel] = string(purpose)
603+
secret.Labels[ExternalPurposeLabel] = string(purpose)
604+
604605
return secret
605606
}
606607

test/e2e/e2e_upgrade_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// +build e2e
33

44
/*
5-
Copyright 2023 SUSE.
5+
Copyright 2024 SUSE.
66
77
Licensed under the Apache License, Version 2.0 (the "License");
88
you may not use this file except in compliance with the License.

0 commit comments

Comments
 (0)