Skip to content

Commit

Permalink
Merge pull request #4060 from LiilyZhang/zhangl/Issue4058
Browse files Browse the repository at this point in the history
Issue #4058 - Bug: k8s mms doesn't work after auto upgrad…
  • Loading branch information
LiilyZhang authored May 15, 2024
2 parents d0c247e + bf2eda7 commit 509fea5
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions resource/certificate.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const (
daysValidFor = 500
)

// Create ESS Cert file and key file if not exist
func CreateCertificate(org string, keyPath string, certPath string) error {

// get message printer, this function is called by CLI
Expand All @@ -33,6 +34,11 @@ func CreateCertificate(org string, keyPath string, certPath string) error {
common.Configuration.ServerCertificate = path.Join(certPath, config.HZN_FSS_CERT_FILE)
common.Configuration.ServerKey = path.Join(keyPath, config.HZN_FSS_CERT_KEY_FILE)

if fileExists(common.Configuration.ServerCertificate) && fileExists(common.Configuration.ServerKey) {
glog.V(3).Infof(reslog(fmt.Sprintf("ESS self signed cert and key already exist in %v, %v, skip creating...", common.Configuration.ServerCertificate, common.Configuration.ServerKey)))
return nil
}

glog.V(5).Infof(reslog(fmt.Sprintf("creating self signed cert in %v", common.Configuration.ServerCertificate)))

if err := os.MkdirAll(certPath, 0755); err != nil {
Expand Down Expand Up @@ -111,3 +117,16 @@ func CreateCertificate(org string, keyPath string, certPath string) error {

return nil
}

// This function checks if file exits or not
func fileExists(filename string) bool {
fileinfo, err := os.Stat(filename)
if os.IsNotExist(err) {
return false
}
if fileinfo.IsDir() {
return false
}

return true
}

0 comments on commit 509fea5

Please sign in to comment.