Skip to content

Commit

Permalink
Merge pull request #215 from kubefirst/fix_missing_error
Browse files Browse the repository at this point in the history
fix: improve error handling for certificate upload
  • Loading branch information
João Paulo Vanzuita authored Aug 11, 2022
2 parents a299216 + 65cbf93 commit b5efa67
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion cmd/restoreSSL.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ to quickly create a Cobra application.`,
fmt.Println("restoreSSL called")
err := ssl.RestoreSSL()
if err != nil {
fmt.Println("Bucket not found, missing SSL backup, assuming first installation")
fmt.Printf("Bucket not found, missing SSL backup, assuming first installation, error is: %v", err)
}
},
}
Expand Down
4 changes: 2 additions & 2 deletions internal/aws/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package aws

import (
"context"
"errors"
"fmt"
"log"
"net"
Expand Down Expand Up @@ -476,8 +477,7 @@ func DownloadBucket(bucket string, destFolder string) error {
})

if err != nil {
log.Printf("Couldn't list bucket contents")
return fmt.Errorf("Couldn't list bucket contents")
return errors.New("couldn't list bucket contents")
}

for _, object := range listObjsResponse.Contents {
Expand Down
11 changes: 9 additions & 2 deletions internal/ssl/ssl.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,11 @@ func GetBackupCertificates() (string, error) {
for _, cert := range certificates {
fullPath := strings.Replace(cert, config.CertsPath, "/certs", 1)
log.Println(fullPath)
aws.UploadFile(bucketName, fullPath, cert)
err = aws.UploadFile(bucketName, fullPath, cert)
if err != nil {
log.Println("there is an issue to uploaded your certificate to the S3 bucket")
log.Panic(err)
}
}

log.Println("getting secrets")
Expand Down Expand Up @@ -138,7 +142,10 @@ func RestoreSSL() error {
}
}
bucketName := fmt.Sprintf("k1-%s", viper.GetString("aws.hostedzonename"))
aws.DownloadBucket(bucketName, config.CertsPath)
err := aws.DownloadBucket(bucketName, config.CertsPath)
if err != nil {
return err
}
//! We need apply secrets firstly than other resources, accordingly with cert-manager docs
//pathsRestored := []string{"secrets", "certs", "clusterissuers"}
//! At this moment, we dont have the crds certs/clusterissuers installed on cluster
Expand Down

0 comments on commit b5efa67

Please sign in to comment.