mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-22 11:21:47 +00:00
Merge pull request #81002 from zgfh/patch-10
kubeadm: fix name of CA spell error
This commit is contained in:
commit
34db8e08c1
@ -36,7 +36,7 @@ func TestKubeConfigSubCommandsThatWritesToOut(t *testing.T) {
|
|||||||
defer os.RemoveAll(tmpdir)
|
defer os.RemoveAll(tmpdir)
|
||||||
|
|
||||||
// Adds a pki folder with a ca cert to the temp folder
|
// Adds a pki folder with a ca cert to the temp folder
|
||||||
pkidir := testutil.SetupPkiDirWithCertificateAuthorithy(t, tmpdir)
|
pkidir := testutil.SetupPkiDirWithCertificateAuthority(t, tmpdir)
|
||||||
|
|
||||||
// Retrieves ca cert for assertions
|
// Retrieves ca cert for assertions
|
||||||
caCert, _, err := pkiutil.TryLoadCertAndKeyFromDisk(pkidir, kubeadmconstants.CACertAndKeyBaseName)
|
caCert, _, err := pkiutil.TryLoadCertAndKeyFromDisk(pkidir, kubeadmconstants.CACertAndKeyBaseName)
|
||||||
|
@ -90,7 +90,7 @@ func (k *KubeadmCert) CreateAsCA(ic *kubeadmapi.InitConfiguration) (*x509.Certif
|
|||||||
return nil, nil, errors.Wrapf(err, "couldn't generate %q CA certificate", k.Name)
|
return nil, nil, errors.Wrapf(err, "couldn't generate %q CA certificate", k.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = writeCertificateAuthorithyFilesIfNotExist(
|
err = writeCertificateAuthorityFilesIfNotExist(
|
||||||
ic.CertificatesDir,
|
ic.CertificatesDir,
|
||||||
k.BaseName,
|
k.BaseName,
|
||||||
caCert,
|
caCert,
|
||||||
@ -146,7 +146,7 @@ func (t CertificateTree) CreateTree(ic *kubeadmapi.InitConfiguration) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = writeCertificateAuthorithyFilesIfNotExist(
|
err = writeCertificateAuthorityFilesIfNotExist(
|
||||||
ic.CertificatesDir,
|
ic.CertificatesDir,
|
||||||
ca.BaseName,
|
ca.BaseName,
|
||||||
caCert,
|
caCert,
|
||||||
|
@ -113,7 +113,7 @@ func CreateCACertAndKeyFiles(certSpec *KubeadmCert, cfg *kubeadmapi.InitConfigur
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return writeCertificateAuthorithyFilesIfNotExist(
|
return writeCertificateAuthorityFilesIfNotExist(
|
||||||
cfg.CertificatesDir,
|
cfg.CertificatesDir,
|
||||||
certSpec.BaseName,
|
certSpec.BaseName,
|
||||||
caCert,
|
caCert,
|
||||||
@ -176,11 +176,11 @@ func LoadCertificateAuthority(pkiDir string, baseName string) (*x509.Certificate
|
|||||||
return caCert, caKey, nil
|
return caCert, caKey, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// writeCertificateAuthorithyFilesIfNotExist write a new certificate Authority to the given path.
|
// writeCertificateAuthorityFilesIfNotExist write a new certificate Authority to the given path.
|
||||||
// If there already is a certificate file at the given path; kubeadm tries to load it and check if the values in the
|
// If there already is a certificate file at the given path; kubeadm tries to load it and check if the values in the
|
||||||
// existing and the expected certificate equals. If they do; kubeadm will just skip writing the file as it's up-to-date,
|
// existing and the expected certificate equals. If they do; kubeadm will just skip writing the file as it's up-to-date,
|
||||||
// otherwise this function returns an error.
|
// otherwise this function returns an error.
|
||||||
func writeCertificateAuthorithyFilesIfNotExist(pkiDir string, baseName string, caCert *x509.Certificate, caKey crypto.Signer) error {
|
func writeCertificateAuthorityFilesIfNotExist(pkiDir string, baseName string, caCert *x509.Certificate, caKey crypto.Signer) error {
|
||||||
|
|
||||||
// If cert or key exists, we should try to load them
|
// If cert or key exists, we should try to load them
|
||||||
if pkiutil.CertOrKeyExist(pkiDir, baseName) {
|
if pkiutil.CertOrKeyExist(pkiDir, baseName) {
|
||||||
|
@ -52,7 +52,7 @@ func createTestCSR(t *testing.T) (*x509.CertificateRequest, crypto.Signer) {
|
|||||||
return csr, key
|
return csr, key
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestWriteCertificateAuthorithyFilesIfNotExist(t *testing.T) {
|
func TestWriteCertificateAuthorityFilesIfNotExist(t *testing.T) {
|
||||||
setupCert, setupKey := certstestutil.CreateCACert(t)
|
setupCert, setupKey := certstestutil.CreateCACert(t)
|
||||||
caCert, caKey := certstestutil.CreateCACert(t)
|
caCert, caKey := certstestutil.CreateCACert(t)
|
||||||
|
|
||||||
@ -66,7 +66,7 @@ func TestWriteCertificateAuthorithyFilesIfNotExist(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{ // ca cert exists, is ca > existing ca used
|
{ // ca cert exists, is ca > existing ca used
|
||||||
setupFunc: func(pkiDir string) error {
|
setupFunc: func(pkiDir string) error {
|
||||||
return writeCertificateAuthorithyFilesIfNotExist(pkiDir, "dummy", setupCert, setupKey)
|
return writeCertificateAuthorityFilesIfNotExist(pkiDir, "dummy", setupCert, setupKey)
|
||||||
},
|
},
|
||||||
expectedCa: setupCert,
|
expectedCa: setupCert,
|
||||||
},
|
},
|
||||||
@ -100,13 +100,13 @@ func TestWriteCertificateAuthorithyFilesIfNotExist(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// executes create func
|
// executes create func
|
||||||
err := writeCertificateAuthorithyFilesIfNotExist(tmpdir, "dummy", caCert, caKey)
|
err := writeCertificateAuthorityFilesIfNotExist(tmpdir, "dummy", caCert, caKey)
|
||||||
|
|
||||||
if !test.expectedError && err != nil {
|
if !test.expectedError && err != nil {
|
||||||
t.Errorf("error writeCertificateAuthorithyFilesIfNotExist failed when not expected to fail: %v", err)
|
t.Errorf("error writeCertificateAuthorityFilesIfNotExist failed when not expected to fail: %v", err)
|
||||||
continue
|
continue
|
||||||
} else if test.expectedError && err == nil {
|
} else if test.expectedError && err == nil {
|
||||||
t.Error("error writeCertificateAuthorithyFilesIfNotExist didn't failed when expected")
|
t.Error("error writeCertificateAuthorityFilesIfNotExist didn't failed when expected")
|
||||||
continue
|
continue
|
||||||
} else if test.expectedError {
|
} else if test.expectedError {
|
||||||
continue
|
continue
|
||||||
|
@ -64,7 +64,7 @@ func TestGetKubeConfigSpecs(t *testing.T) {
|
|||||||
defer os.RemoveAll(tmpdir)
|
defer os.RemoveAll(tmpdir)
|
||||||
|
|
||||||
// Adds a pki folder with a ca certs to the temp folder
|
// Adds a pki folder with a ca certs to the temp folder
|
||||||
pkidir := testutil.SetupPkiDirWithCertificateAuthorithy(t, tmpdir)
|
pkidir := testutil.SetupPkiDirWithCertificateAuthority(t, tmpdir)
|
||||||
|
|
||||||
// Creates InitConfigurations pointing to the pkidir folder
|
// Creates InitConfigurations pointing to the pkidir folder
|
||||||
cfgs := []*kubeadmapi.InitConfiguration{
|
cfgs := []*kubeadmapi.InitConfiguration{
|
||||||
@ -185,7 +185,7 @@ func TestGetKubeConfigSpecs(t *testing.T) {
|
|||||||
|
|
||||||
func TestBuildKubeConfigFromSpecWithClientAuth(t *testing.T) {
|
func TestBuildKubeConfigFromSpecWithClientAuth(t *testing.T) {
|
||||||
// Creates a CA
|
// Creates a CA
|
||||||
caCert, caKey := certstestutil.SetupCertificateAuthorithy(t)
|
caCert, caKey := certstestutil.SetupCertificateAuthority(t)
|
||||||
|
|
||||||
// Executes buildKubeConfigFromSpec passing a KubeConfigSpec with a ClientAuth
|
// Executes buildKubeConfigFromSpec passing a KubeConfigSpec with a ClientAuth
|
||||||
config := setupdKubeConfigWithClientAuth(t, caCert, caKey, "https://1.2.3.4:1234", "myClientName", "test-cluster", "myOrg1", "myOrg2")
|
config := setupdKubeConfigWithClientAuth(t, caCert, caKey, "https://1.2.3.4:1234", "myClientName", "test-cluster", "myOrg1", "myOrg2")
|
||||||
@ -197,7 +197,7 @@ func TestBuildKubeConfigFromSpecWithClientAuth(t *testing.T) {
|
|||||||
|
|
||||||
func TestBuildKubeConfigFromSpecWithTokenAuth(t *testing.T) {
|
func TestBuildKubeConfigFromSpecWithTokenAuth(t *testing.T) {
|
||||||
// Creates a CA
|
// Creates a CA
|
||||||
caCert, _ := certstestutil.SetupCertificateAuthorithy(t)
|
caCert, _ := certstestutil.SetupCertificateAuthority(t)
|
||||||
|
|
||||||
// Executes buildKubeConfigFromSpec passing a KubeConfigSpec with a Token
|
// Executes buildKubeConfigFromSpec passing a KubeConfigSpec with a Token
|
||||||
config := setupdKubeConfigWithTokenAuth(t, caCert, "https://1.2.3.4:1234", "myClientName", "123456", "test-cluster")
|
config := setupdKubeConfigWithTokenAuth(t, caCert, "https://1.2.3.4:1234", "myClientName", "123456", "test-cluster")
|
||||||
@ -210,8 +210,8 @@ func TestBuildKubeConfigFromSpecWithTokenAuth(t *testing.T) {
|
|||||||
func TestCreateKubeConfigFileIfNotExists(t *testing.T) {
|
func TestCreateKubeConfigFileIfNotExists(t *testing.T) {
|
||||||
|
|
||||||
// Creates a CAs
|
// Creates a CAs
|
||||||
caCert, caKey := certstestutil.SetupCertificateAuthorithy(t)
|
caCert, caKey := certstestutil.SetupCertificateAuthority(t)
|
||||||
anotherCaCert, anotherCaKey := certstestutil.SetupCertificateAuthorithy(t)
|
anotherCaCert, anotherCaKey := certstestutil.SetupCertificateAuthority(t)
|
||||||
|
|
||||||
// build kubeconfigs (to be used to test kubeconfigs equality/not equality)
|
// build kubeconfigs (to be used to test kubeconfigs equality/not equality)
|
||||||
config := setupdKubeConfigWithClientAuth(t, caCert, caKey, "https://1.2.3.4:1234", "test-cluster", "myOrg1", "myOrg2")
|
config := setupdKubeConfigWithClientAuth(t, caCert, caKey, "https://1.2.3.4:1234", "test-cluster", "myOrg1", "myOrg2")
|
||||||
@ -307,7 +307,7 @@ func TestCreateKubeconfigFilesAndWrappers(t *testing.T) {
|
|||||||
defer os.RemoveAll(tmpdir)
|
defer os.RemoveAll(tmpdir)
|
||||||
|
|
||||||
// Adds a pki folder with a ca certs to the temp folder
|
// Adds a pki folder with a ca certs to the temp folder
|
||||||
pkidir := testutil.SetupPkiDirWithCertificateAuthorithy(t, tmpdir)
|
pkidir := testutil.SetupPkiDirWithCertificateAuthority(t, tmpdir)
|
||||||
|
|
||||||
// Creates an InitConfiguration pointing to the pkidir folder
|
// Creates an InitConfiguration pointing to the pkidir folder
|
||||||
cfg := &kubeadmapi.InitConfiguration{
|
cfg := &kubeadmapi.InitConfiguration{
|
||||||
@ -382,7 +382,7 @@ func TestWriteKubeConfig(t *testing.T) {
|
|||||||
defer os.RemoveAll(tmpdir)
|
defer os.RemoveAll(tmpdir)
|
||||||
|
|
||||||
// Adds a pki folder with a ca cert to the temp folder
|
// Adds a pki folder with a ca cert to the temp folder
|
||||||
pkidir := testutil.SetupPkiDirWithCertificateAuthorithy(t, tmpdir)
|
pkidir := testutil.SetupPkiDirWithCertificateAuthority(t, tmpdir)
|
||||||
|
|
||||||
// Retrieves ca cert for assertions
|
// Retrieves ca cert for assertions
|
||||||
caCert, _, err := pkiutil.TryLoadCertAndKeyFromDisk(pkidir, kubeadmconstants.CACertAndKeyBaseName)
|
caCert, _, err := pkiutil.TryLoadCertAndKeyFromDisk(pkidir, kubeadmconstants.CACertAndKeyBaseName)
|
||||||
@ -454,8 +454,8 @@ func TestWriteKubeConfig(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestValidateKubeConfig(t *testing.T) {
|
func TestValidateKubeConfig(t *testing.T) {
|
||||||
caCert, caKey := certstestutil.SetupCertificateAuthorithy(t)
|
caCert, caKey := certstestutil.SetupCertificateAuthority(t)
|
||||||
anotherCaCert, anotherCaKey := certstestutil.SetupCertificateAuthorithy(t)
|
anotherCaCert, anotherCaKey := certstestutil.SetupCertificateAuthority(t)
|
||||||
|
|
||||||
config := setupdKubeConfigWithClientAuth(t, caCert, caKey, "https://1.2.3.4:1234", "test-cluster", "myOrg1")
|
config := setupdKubeConfigWithClientAuth(t, caCert, caKey, "https://1.2.3.4:1234", "test-cluster", "myOrg1")
|
||||||
configWithAnotherClusterCa := setupdKubeConfigWithClientAuth(t, anotherCaCert, anotherCaKey, "https://1.2.3.4:1234", "test-cluster", "myOrg1")
|
configWithAnotherClusterCa := setupdKubeConfigWithClientAuth(t, anotherCaCert, anotherCaKey, "https://1.2.3.4:1234", "test-cluster", "myOrg1")
|
||||||
@ -528,7 +528,7 @@ func TestValidateKubeconfigsForExternalCA(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// creates CA, write to pkiDir and remove ca.key to get into external CA condition
|
// creates CA, write to pkiDir and remove ca.key to get into external CA condition
|
||||||
caCert, caKey := certstestutil.SetupCertificateAuthorithy(t)
|
caCert, caKey := certstestutil.SetupCertificateAuthority(t)
|
||||||
if err := pkiutil.WriteCertAndKey(pkiDir, kubeadmconstants.CACertAndKeyBaseName, caCert, caKey); err != nil {
|
if err := pkiutil.WriteCertAndKey(pkiDir, kubeadmconstants.CACertAndKeyBaseName, caCert, caKey); err != nil {
|
||||||
t.Fatalf("failure while saving CA certificate and key: %v", err)
|
t.Fatalf("failure while saving CA certificate and key: %v", err)
|
||||||
}
|
}
|
||||||
@ -540,7 +540,7 @@ func TestValidateKubeconfigsForExternalCA(t *testing.T) {
|
|||||||
config := setupdKubeConfigWithClientAuth(t, caCert, caKey, "https://1.2.3.4:1234", "test-cluster", "myOrg1")
|
config := setupdKubeConfigWithClientAuth(t, caCert, caKey, "https://1.2.3.4:1234", "test-cluster", "myOrg1")
|
||||||
|
|
||||||
// create a config with another CA
|
// create a config with another CA
|
||||||
anotherCaCert, anotherCaKey := certstestutil.SetupCertificateAuthorithy(t)
|
anotherCaCert, anotherCaKey := certstestutil.SetupCertificateAuthority(t)
|
||||||
configWithAnotherClusterCa := setupdKubeConfigWithClientAuth(t, anotherCaCert, anotherCaKey, "https://1.2.3.4:1234", "test-cluster", "myOrg1")
|
configWithAnotherClusterCa := setupdKubeConfigWithClientAuth(t, anotherCaCert, anotherCaKey, "https://1.2.3.4:1234", "test-cluster", "myOrg1")
|
||||||
|
|
||||||
// create a config with another server URL
|
// create a config with another server URL
|
||||||
|
@ -687,7 +687,7 @@ func TestCleanupDirs(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestRenewCertsByComponent(t *testing.T) {
|
func TestRenewCertsByComponent(t *testing.T) {
|
||||||
caCert, caKey := certstestutil.SetupCertificateAuthorithy(t)
|
caCert, caKey := certstestutil.SetupCertificateAuthority(t)
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
|
@ -29,9 +29,9 @@ import (
|
|||||||
pkiutil "k8s.io/kubernetes/cmd/kubeadm/app/util/pkiutil"
|
pkiutil "k8s.io/kubernetes/cmd/kubeadm/app/util/pkiutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
// SetupCertificateAuthorithy is a utility function for kubeadm testing that creates a
|
// SetupCertificateAuthority is a utility function for kubeadm testing that creates a
|
||||||
// CertificateAuthorithy cert/key pair
|
// CertificateAuthority cert/key pair
|
||||||
func SetupCertificateAuthorithy(t *testing.T) (*x509.Certificate, crypto.Signer) {
|
func SetupCertificateAuthority(t *testing.T) (*x509.Certificate, crypto.Signer) {
|
||||||
caCert, caKey, err := pkiutil.NewCertificateAuthority(&certutil.Config{CommonName: "kubernetes"})
|
caCert, caKey, err := pkiutil.NewCertificateAuthority(&certutil.Config{CommonName: "kubernetes"})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failure while generating CA certificate and key: %v", err)
|
t.Fatalf("failure while generating CA certificate and key: %v", err)
|
||||||
|
@ -95,11 +95,11 @@ func SetupEmptyFiles(t *testing.T, tmpdir string, fileNames ...string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetupPkiDirWithCertificateAuthorithy is a utility function for kubeadm testing that creates a
|
// SetupPkiDirWithCertificateAuthority is a utility function for kubeadm testing that creates a
|
||||||
// CertificateAuthorithy cert/key pair into /pki subfolder of a given temporary directory.
|
// CertificateAuthority cert/key pair into /pki subfolder of a given temporary directory.
|
||||||
// The function returns the path of the created pki.
|
// The function returns the path of the created pki.
|
||||||
func SetupPkiDirWithCertificateAuthorithy(t *testing.T, tmpdir string) string {
|
func SetupPkiDirWithCertificateAuthority(t *testing.T, tmpdir string) string {
|
||||||
caCert, caKey := certtestutil.SetupCertificateAuthorithy(t)
|
caCert, caKey := certtestutil.SetupCertificateAuthority(t)
|
||||||
|
|
||||||
certDir := filepath.Join(tmpdir, "pki")
|
certDir := filepath.Join(tmpdir, "pki")
|
||||||
if err := pkiutil.WriteCertAndKey(certDir, kubeadmconstants.CACertAndKeyBaseName, caCert, caKey); err != nil {
|
if err := pkiutil.WriteCertAndKey(certDir, kubeadmconstants.CACertAndKeyBaseName, caCert, caKey); err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user