Skip to content

Commit 6b9e106

Browse files
committed
kubeadm: remove unused function in util/pkiutil
Signed-off-by: xin.li <[email protected]>
1 parent 66df84b commit 6b9e106

File tree

2 files changed

+0
-46
lines changed

2 files changed

+0
-46
lines changed

cmd/kubeadm/app/cmd/certs_test.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -359,18 +359,12 @@ func TestRunGenCSR(t *testing.T) {
359359
for _, name := range expectedCertificates {
360360
_, err = pkiutil.TryLoadKeyFromDisk(certDir, name)
361361
assert.NoErrorf(t, err, "failed to load key file: %s", name)
362-
363-
_, err = pkiutil.TryLoadCSRFromDisk(certDir, name)
364-
assert.NoError(t, err, "failed to load CSR file: %s", name)
365362
}
366363

367364
t.Log("The command generates kubeconfig files in the configured --kubeconfig-dir")
368365
for _, name := range expectedKubeConfigs {
369366
_, err = clientcmd.LoadFromFile(kubeConfigDir + "/" + name + ".conf")
370367
assert.NoErrorf(t, err, "failed to load kubeconfig file: %s", name)
371-
372-
_, err = pkiutil.TryLoadCSRFromDisk(kubeConfigDir, name+".conf")
373-
assert.NoError(t, err, "failed to load kubeconfig CSR file: %s", name)
374368
}
375369
}
376370

cmd/kubeadm/app/util/pkiutil/pki_helpers.go

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -355,18 +355,6 @@ func TryLoadPrivatePublicKeyFromDisk(pkiPath, name string) (crypto.PrivateKey, c
355355
}
356356
}
357357

358-
// TryLoadCSRFromDisk tries to load the CSR from the disk
359-
func TryLoadCSRFromDisk(pkiPath, name string) (*x509.CertificateRequest, error) {
360-
csrPath := pathForCSR(pkiPath, name)
361-
362-
csr, err := CertificateRequestFromFile(csrPath)
363-
if err != nil {
364-
return nil, errors.Wrapf(err, "could not load the CSR %s", csrPath)
365-
}
366-
367-
return csr, nil
368-
}
369-
370358
// PathsForCertAndKey returns the paths for the certificate and key given the path and basename.
371359
func PathsForCertAndKey(pkiPath, name string) (string, string) {
372360
return pathForCert(pkiPath, name), pathForKey(pkiPath, name)
@@ -507,34 +495,6 @@ func EncodeCSRPEM(csr *x509.CertificateRequest) []byte {
507495
return pem.EncodeToMemory(&block)
508496
}
509497

510-
func parseCSRPEM(pemCSR []byte) (*x509.CertificateRequest, error) {
511-
block, _ := pem.Decode(pemCSR)
512-
if block == nil {
513-
return nil, errors.New("data doesn't contain a valid certificate request")
514-
}
515-
516-
if block.Type != certutil.CertificateRequestBlockType {
517-
return nil, errors.Errorf("expected block type %q, but PEM had type %q", certutil.CertificateRequestBlockType, block.Type)
518-
}
519-
520-
return x509.ParseCertificateRequest(block.Bytes)
521-
}
522-
523-
// CertificateRequestFromFile returns the CertificateRequest from a given PEM-encoded file.
524-
// Returns an error if the file could not be read or if the CSR could not be parsed.
525-
func CertificateRequestFromFile(file string) (*x509.CertificateRequest, error) {
526-
pemBlock, err := os.ReadFile(file)
527-
if err != nil {
528-
return nil, errors.Wrap(err, "failed to read file")
529-
}
530-
531-
csr, err := parseCSRPEM(pemBlock)
532-
if err != nil {
533-
return nil, errors.Wrapf(err, "error reading certificate request file %s", file)
534-
}
535-
return csr, nil
536-
}
537-
538498
// NewCSR creates a new CSR
539499
func NewCSR(cfg CertConfig, key crypto.Signer) (*x509.CertificateRequest, error) {
540500
RemoveDuplicateAltNames(&cfg.AltNames)

0 commit comments

Comments
 (0)