From 71d3f9e249e8c6602c0fd2f2a4fa5e0ee1c127bd Mon Sep 17 00:00:00 2001 From: "xin.li" Date: Sat, 22 Jun 2024 18:47:28 +0800 Subject: [PATCH] Remove unused function in phases/certs Signed-off-by: xin.li --- cmd/kubeadm/app/phases/certs/certs.go | 10 ------- cmd/kubeadm/app/phases/certs/certs_test.go | 33 ---------------------- 2 files changed, 43 deletions(-) diff --git a/cmd/kubeadm/app/phases/certs/certs.go b/cmd/kubeadm/app/phases/certs/certs.go index 71fae77221f..4a63918aa05 100644 --- a/cmd/kubeadm/app/phases/certs/certs.go +++ b/cmd/kubeadm/app/phases/certs/certs.go @@ -129,16 +129,6 @@ func CreateCACertAndKeyFiles(certSpec *KubeadmCert, cfg *kubeadmapi.InitConfigur ) } -// NewCSR will generate a new CSR and accompanying key -func NewCSR(certSpec *KubeadmCert, cfg *kubeadmapi.InitConfiguration) (*x509.CertificateRequest, crypto.Signer, error) { - certConfig, err := certSpec.GetConfig(cfg) - if err != nil { - return nil, nil, errors.Wrap(err, "failed to retrieve cert configuration") - } - - return pkiutil.NewCSRAndKey(certConfig) -} - // CreateCertAndKeyFilesWithCA loads the given certificate authority from disk, then generates and writes out the given certificate and key. // The certSpec and caCertSpec should both be one of the variables from this package. func CreateCertAndKeyFilesWithCA(certSpec *KubeadmCert, caCertSpec *KubeadmCert, cfg *kubeadmapi.InitConfiguration) error { diff --git a/cmd/kubeadm/app/phases/certs/certs_test.go b/cmd/kubeadm/app/phases/certs/certs_test.go index 04559041073..1ecfd9311f7 100644 --- a/cmd/kubeadm/app/phases/certs/certs_test.go +++ b/cmd/kubeadm/app/phases/certs/certs_test.go @@ -25,7 +25,6 @@ import ( "testing" "github.com/pkg/errors" - "github.com/stretchr/testify/assert" utilerrors "k8s.io/apimachinery/pkg/util/errors" certutil "k8s.io/client-go/util/cert" @@ -638,38 +637,6 @@ func TestValidateMethods(t *testing.T) { } } -func TestNewCSR(t *testing.T) { - kubeadmCert := KubeadmCertAPIServer() - cfg := testutil.GetDefaultInternalConfig(t) - - certConfig, err := kubeadmCert.GetConfig(cfg) - if err != nil { - t.Fatalf("couldn't get cert config: %v", err) - } - - csr, _, err := NewCSR(kubeadmCert, cfg) - - if err != nil { - t.Errorf("invalid signature on CSR: %v", err) - } - - assert.ElementsMatch(t, certConfig.Organization, csr.Subject.Organization, "organizations not equal") - - if csr.Subject.CommonName != certConfig.CommonName { - t.Errorf("expected common name %q, got %q", certConfig.CommonName, csr.Subject.CommonName) - } - - assert.ElementsMatch(t, certConfig.AltNames.DNSNames, csr.DNSNames, "dns names not equal") - - assert.Len(t, csr.IPAddresses, len(certConfig.AltNames.IPs)) - - for i, ip := range csr.IPAddresses { - if !ip.Equal(certConfig.AltNames.IPs[i]) { - t.Errorf("[%d]: %v != %v", i, ip, certConfig.AltNames.IPs[i]) - } - } -} - func TestCreateCertificateFilesMethods(t *testing.T) { var tests = []struct {