diff --git a/pkg/yurtmanager/webhook/util/writer/certwriter.go b/pkg/yurtmanager/webhook/util/writer/certwriter.go index b52e7d6a4b8..b5e2cbb0b7f 100644 --- a/pkg/yurtmanager/webhook/util/writer/certwriter.go +++ b/pkg/yurtmanager/webhook/util/writer/certwriter.go @@ -77,7 +77,11 @@ func updateIfNotExists(ch certReadWriter) (*generator.Artifacts, bool, error) { certs, err := ch.read() if isNotExist(err) { // Create if not exists - certs, err = ch.overwrite(certs.ResourceVersion) + var resourceVersion string + if certs != nil { + resourceVersion = certs.ResourceVersion + } + certs, err = ch.overwrite(resourceVersion) return certs, true, err } return certs, false, err diff --git a/pkg/yurtmanager/webhook/util/writer/error.go b/pkg/yurtmanager/webhook/util/writer/error.go index de432d2f666..057646780e1 100644 --- a/pkg/yurtmanager/webhook/util/writer/error.go +++ b/pkg/yurtmanager/webhook/util/writer/error.go @@ -16,14 +16,6 @@ limitations under the License. package writer -type notFoundError struct { - err error -} - -func (e notFoundError) Error() string { - return e.err.Error() -} - type alreadyExistError struct { err error } diff --git a/pkg/yurtmanager/webhook/util/writer/fs.go b/pkg/yurtmanager/webhook/util/writer/fs.go index c5a9f23c5d7..5b0370dec08 100644 --- a/pkg/yurtmanager/webhook/util/writer/fs.go +++ b/pkg/yurtmanager/webhook/util/writer/fs.go @@ -188,7 +188,7 @@ func ensureExist(dir string) error { case err == nil: continue case os.IsNotExist(err): - return notFoundError{err} + return notExistError{err} default: return err }