Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into release-1.30
Browse files Browse the repository at this point in the history
  • Loading branch information
k8s-release-robot committed Apr 1, 2024
2 parents dd54a63 + 79c61d5 commit 1dc72d7
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 14 deletions.
4 changes: 2 additions & 2 deletions cmd/kubeadm/app/phases/certs/renewal/manager.go
Expand Up @@ -322,7 +322,7 @@ func (rm *Manager) CertificateExists(name string) (bool, error) {
return false, errors.Errorf("%s is not a known certificate", name)
}

return handler.readwriter.Exists(), nil
return handler.readwriter.Exists()
}

// GetCertificateExpirationInfo returns certificate expiration info.
Expand Down Expand Up @@ -358,7 +358,7 @@ func (rm *Manager) CAExists(name string) (bool, error) {
return false, errors.Errorf("%s is not a known certificate", name)
}

return handler.readwriter.Exists(), nil
return handler.readwriter.Exists()
}

// GetCAExpirationInfo returns CA expiration info.
Expand Down
4 changes: 2 additions & 2 deletions cmd/kubeadm/app/phases/certs/renewal/manager_test.go
Expand Up @@ -54,8 +54,8 @@ type fakecertificateReadWriter struct {
cert *x509.Certificate
}

func (cr fakecertificateReadWriter) Exists() bool {
return cr.exist
func (cr fakecertificateReadWriter) Exists() (bool, error) {
return cr.exist, nil
}

func (cr fakecertificateReadWriter) Read() (*x509.Certificate, error) {
Expand Down
17 changes: 10 additions & 7 deletions cmd/kubeadm/app/phases/certs/renewal/readwriter.go
Expand Up @@ -36,7 +36,7 @@ import (
// read or write a certificate stored/embedded in a file
type certificateReadWriter interface {
//Exists return true if the certificate exists
Exists() bool
Exists() (bool, error)

// Read a certificate stored/embedded in a file
Read() (*x509.Certificate, error)
Expand All @@ -61,17 +61,20 @@ func newPKICertificateReadWriter(certificateDir string, baseName string) *pkiCer
}

// Exists checks if a certificate exist
func (rw *pkiCertificateReadWriter) Exists() bool {
func (rw *pkiCertificateReadWriter) Exists() (bool, error) {
certificatePath, _ := pkiutil.PathsForCertAndKey(rw.certificateDir, rw.baseName)
return fileExists(certificatePath)
}

func fileExists(filename string) bool {
func fileExists(filename string) (bool, error) {
info, err := os.Stat(filename)
if os.IsNotExist(err) {
return false
if err != nil {
if os.IsNotExist(err) {
return false, nil
}
return false, err
}
return !info.IsDir()
return !info.IsDir(), nil
}

// Read a certificate from a file the K8s pki managed by kubeadm
Expand Down Expand Up @@ -120,7 +123,7 @@ func newKubeconfigReadWriter(kubernetesDir string, kubeConfigFileName string, ce
}

// Exists checks if a certificate embedded in kubeConfig file exists
func (rw *kubeConfigReadWriter) Exists() bool {
func (rw *kubeConfigReadWriter) Exists() (bool, error) {
return fileExists(rw.kubeConfigFilePath)
}

Expand Down
6 changes: 3 additions & 3 deletions cmd/kubeadm/app/phases/certs/renewal/readwriter_test.go
Expand Up @@ -239,7 +239,7 @@ func TestFileExists(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := fileExists(tt.filename); got != tt.want {
if got, _ := fileExists(tt.filename); got != tt.want {
t.Errorf("fileExists() = %v, want %v", got, tt.want)
}
})
Expand Down Expand Up @@ -295,7 +295,7 @@ func TestPKICertificateReadWriterExists(t *testing.T) {
baseName: tt.fields.baseName,
certificateDir: tt.fields.certificateDir,
}
if got := rw.Exists(); got != tt.want {
if got, _ := rw.Exists(); got != tt.want {
t.Errorf("pkiCertificateReadWriter.Exists() = %v, want %v", got, tt.want)
}
})
Expand Down Expand Up @@ -338,7 +338,7 @@ func TestKubeConfigReadWriterExists(t *testing.T) {
rw := &kubeConfigReadWriter{
kubeConfigFilePath: tt.kubeConfigFilePath,
}
if got := rw.Exists(); got != tt.want {
if got, _ := rw.Exists(); got != tt.want {
t.Errorf("kubeConfigReadWriter.Exists() = %v, want %v", got, tt.want)
}
})
Expand Down

0 comments on commit 1dc72d7

Please sign in to comment.