mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 05:27:21 +00:00
Merge pull request #55166 from kad/kubeadm-issue-522
Automatic merge from submit-queue (batch tested with PRs 55214, 55166). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. kubeadm: don't create duplicate volume/mount **What this PR does / why we need it**: If certificates for etcd are located in the same directory or subdirectories of kubernetes pki directory, don't create separate volumes and mounts in manifests. **Which issue(s) this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close the issue(s) when PR gets merged)*: Fixes kubernetes/kubeadm#522 **Special notes for your reviewer**: /sig cluster-lifecycle /area kubeadm **Release note**: ```release-note NONE ```
This commit is contained in:
commit
dd70d3c28b
@ -57,7 +57,7 @@ func getHostPathVolumesForTheControlPlane(cfg *kubeadmapi.MasterConfiguration) c
|
|||||||
|
|
||||||
// If external etcd is specified, mount the directories needed for accessing the CA/serving certs and the private key
|
// If external etcd is specified, mount the directories needed for accessing the CA/serving certs and the private key
|
||||||
if len(cfg.Etcd.Endpoints) != 0 {
|
if len(cfg.Etcd.Endpoints) != 0 {
|
||||||
etcdVols, etcdVolMounts := getEtcdCertVolumes(cfg.Etcd)
|
etcdVols, etcdVolMounts := getEtcdCertVolumes(cfg.Etcd, cfg.CertificatesDir)
|
||||||
mounts.AddHostPathMounts(kubeadmconstants.KubeAPIServer, etcdVols, etcdVolMounts)
|
mounts.AddHostPathMounts(kubeadmconstants.KubeAPIServer, etcdVols, etcdVolMounts)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -166,14 +166,15 @@ func (c *controlPlaneHostPathMounts) addComponentVolumeMount(component string, v
|
|||||||
}
|
}
|
||||||
|
|
||||||
// getEtcdCertVolumes returns the volumes/volumemounts needed for talking to an external etcd cluster
|
// getEtcdCertVolumes returns the volumes/volumemounts needed for talking to an external etcd cluster
|
||||||
func getEtcdCertVolumes(etcdCfg kubeadmapi.Etcd) ([]v1.Volume, []v1.VolumeMount) {
|
func getEtcdCertVolumes(etcdCfg kubeadmapi.Etcd, k8sCertificatesDir string) ([]v1.Volume, []v1.VolumeMount) {
|
||||||
certPaths := []string{etcdCfg.CAFile, etcdCfg.CertFile, etcdCfg.KeyFile}
|
certPaths := []string{etcdCfg.CAFile, etcdCfg.CertFile, etcdCfg.KeyFile}
|
||||||
certDirs := sets.NewString()
|
certDirs := sets.NewString()
|
||||||
for _, certPath := range certPaths {
|
for _, certPath := range certPaths {
|
||||||
certDir := filepath.Dir(certPath)
|
certDir := filepath.Dir(certPath)
|
||||||
// Ignore ".", which is the result of passing an empty path.
|
// Ignore ".", which is the result of passing an empty path.
|
||||||
// Also ignore the cert directories that already may be mounted; /etc/ssl/certs and /etc/pki. If the etcd certs are in there, it's okay, we don't have to do anything
|
// Also ignore the cert directories that already may be mounted; /etc/ssl/certs, /etc/pki or Kubernetes CertificatesDir
|
||||||
if certDir == "." || strings.HasPrefix(certDir, caCertsVolumePath) || strings.HasPrefix(certDir, caCertsPkiVolumePath) {
|
// If the etcd certs are in there, it's okay, we don't have to do anything
|
||||||
|
if certDir == "." || strings.HasPrefix(certDir, caCertsVolumePath) || strings.HasPrefix(certDir, caCertsPkiVolumePath) || strings.HasPrefix(certDir, k8sCertificatesDir) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
// Filter out any existing hostpath mounts in the list that contains a subset of the path
|
// Filter out any existing hostpath mounts in the list that contains a subset of the path
|
||||||
|
@ -30,6 +30,7 @@ import (
|
|||||||
|
|
||||||
func TestGetEtcdCertVolumes(t *testing.T) {
|
func TestGetEtcdCertVolumes(t *testing.T) {
|
||||||
hostPathDirectoryOrCreate := v1.HostPathDirectoryOrCreate
|
hostPathDirectoryOrCreate := v1.HostPathDirectoryOrCreate
|
||||||
|
k8sCertifcatesDir := "/etc/kubernetes/pki"
|
||||||
var tests = []struct {
|
var tests = []struct {
|
||||||
ca, cert, key string
|
ca, cert, key string
|
||||||
vol []v1.Volume
|
vol []v1.Volume
|
||||||
@ -59,6 +60,14 @@ func TestGetEtcdCertVolumes(t *testing.T) {
|
|||||||
vol: []v1.Volume{},
|
vol: []v1.Volume{},
|
||||||
volMount: []v1.VolumeMount{},
|
volMount: []v1.VolumeMount{},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
// Should ignore files in Kubernetes PKI directory (and subdirs)
|
||||||
|
ca: k8sCertifcatesDir + "/ca/my-etcd-ca.crt",
|
||||||
|
cert: k8sCertifcatesDir + "/my-etcd.crt",
|
||||||
|
key: k8sCertifcatesDir + "/my-etcd.key",
|
||||||
|
vol: []v1.Volume{},
|
||||||
|
volMount: []v1.VolumeMount{},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
// All in the same dir
|
// All in the same dir
|
||||||
ca: "/var/lib/certs/etcd/my-etcd-ca.crt",
|
ca: "/var/lib/certs/etcd/my-etcd-ca.crt",
|
||||||
@ -228,7 +237,7 @@ func TestGetEtcdCertVolumes(t *testing.T) {
|
|||||||
CAFile: rt.ca,
|
CAFile: rt.ca,
|
||||||
CertFile: rt.cert,
|
CertFile: rt.cert,
|
||||||
KeyFile: rt.key,
|
KeyFile: rt.key,
|
||||||
})
|
}, k8sCertifcatesDir)
|
||||||
if !reflect.DeepEqual(actualVol, rt.vol) {
|
if !reflect.DeepEqual(actualVol, rt.vol) {
|
||||||
t.Errorf(
|
t.Errorf(
|
||||||
"failed getEtcdCertVolumes:\n\texpected: %v\n\t actual: %v",
|
"failed getEtcdCertVolumes:\n\texpected: %v\n\t actual: %v",
|
||||||
@ -389,7 +398,7 @@ func TestGetHostPathVolumesForTheControlPlane(t *testing.T) {
|
|||||||
Name: "etcd-certs-1",
|
Name: "etcd-certs-1",
|
||||||
VolumeSource: v1.VolumeSource{
|
VolumeSource: v1.VolumeSource{
|
||||||
HostPath: &v1.HostPathVolumeSource{
|
HostPath: &v1.HostPathVolumeSource{
|
||||||
Path: "/var/lib/certs/etcd",
|
Path: "/var/lib/etcd/certs",
|
||||||
Type: &hostPathDirectoryOrCreate,
|
Type: &hostPathDirectoryOrCreate,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -460,7 +469,7 @@ func TestGetHostPathVolumesForTheControlPlane(t *testing.T) {
|
|||||||
}
|
}
|
||||||
volMountMap2[kubeadmconstants.KubeAPIServer]["etcd-certs-1"] = v1.VolumeMount{
|
volMountMap2[kubeadmconstants.KubeAPIServer]["etcd-certs-1"] = v1.VolumeMount{
|
||||||
Name: "etcd-certs-1",
|
Name: "etcd-certs-1",
|
||||||
MountPath: "/var/lib/certs/etcd",
|
MountPath: "/var/lib/etcd/certs",
|
||||||
ReadOnly: true,
|
ReadOnly: true,
|
||||||
}
|
}
|
||||||
volMountMap2[kubeadmconstants.KubeControllerManager] = map[string]v1.VolumeMount{}
|
volMountMap2[kubeadmconstants.KubeControllerManager] = map[string]v1.VolumeMount{}
|
||||||
@ -505,14 +514,14 @@ func TestGetHostPathVolumesForTheControlPlane(t *testing.T) {
|
|||||||
volMount: volMountMap,
|
volMount: volMountMap,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
// Should ignore files in /etc/ssl/certs
|
// Should ignore files in /etc/ssl/certs and in CertificatesDir
|
||||||
cfg: &kubeadmapi.MasterConfiguration{
|
cfg: &kubeadmapi.MasterConfiguration{
|
||||||
CertificatesDir: testCertsDir,
|
CertificatesDir: testCertsDir,
|
||||||
Etcd: kubeadmapi.Etcd{
|
Etcd: kubeadmapi.Etcd{
|
||||||
Endpoints: []string{"foo"},
|
Endpoints: []string{"foo"},
|
||||||
CAFile: "/etc/certs/etcd/my-etcd-ca.crt",
|
CAFile: "/etc/certs/etcd/my-etcd-ca.crt",
|
||||||
CertFile: "/var/lib/certs/etcd/my-etcd.crt",
|
CertFile: testCertsDir + "/etcd/my-etcd.crt",
|
||||||
KeyFile: "/var/lib/certs/etcd/my-etcd.key",
|
KeyFile: "/var/lib/etcd/certs/my-etcd.key",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
vol: volMap2,
|
vol: volMap2,
|
||||||
|
Loading…
Reference in New Issue
Block a user