Skip to content

Commit

Permalink
restore ssl/tls
Browse files Browse the repository at this point in the history
Signed-off-by: Thiago Pagotto <pagottoo@gmail.com>
  • Loading branch information
pagottoo committed Jul 19, 2022
1 parent 9967f33 commit 0386711
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion internal/ssl/ssl.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ import (
"k8s.io/client-go/tools/clientcmd"
)

var namespaces []string

func init() {
namespaces = []string{"argo", "atlantis", "chartmuseum", "gitlab", "vault"}
}

func getItemsToBackup(apiGroup string, apiVersion string, resourceType string, namespaces []string, jqQuery string) ([]string, error) {
config := configs.ReadConfig()

Expand Down Expand Up @@ -85,7 +91,6 @@ func GetBackupCertificates() (string, error) {
aws.CreateBucket(false, bucketName)

log.Println("getting certificates")
namespaces := []string{"argo", "atlantis", "chartmuseum", "gitlab", "vault"}
certificates, err := getItemsToBackup("cert-manager.io", "v1", "certificates", namespaces, "")
if err != nil {
log.Panic(err)
Expand Down Expand Up @@ -122,3 +127,25 @@ func GetBackupCertificates() (string, error) {

return "Backuped Cert-Manager resources finished successfully!", nil
}

func RestoreSSL() {
config := configs.ReadConfig()

for _, ns := range namespaces {
_, _, err := pkg.ExecShellReturnStrings(config.KubectlClientPath, "--kubeconfig", config.KubeConfigPath, "create", "ns", ns)
if err != nil {
log.Print("failed to create ns: %s, assuming that exists...", err)
}
}
aws.DownloadBucket("k1-kube1st.com", config.CertsPath)
//! We need apply secrets firstly than other resources, accordingly with cert-manager docs
pathsRestored := []string{"secrets", "certs", "clusterissuers"}
for _, path := range pathsRestored {
log.Printf("applying the folder: %s", path)
_, _, err := pkg.ExecShellReturnStrings(config.KubectlClientPath, "--kubeconfig", config.KubeConfigPath, "apply", "-f", filepath.Join(config.CertsPath, path))
if err != nil {
log.Printf("failed to apply %s: %s, assuming that exists...", path, err)
}
}

}

0 comments on commit 0386711

Please sign in to comment.