Skip to content

Commit

Permalink
Merge pull request #16 from xyz-li/master
Browse files Browse the repository at this point in the history
Fix: check configmap when initialization
  • Loading branch information
zheng1 committed Jun 28, 2021
2 parents 0796add + ee5ecf3 commit 29f28bf
Showing 1 changed file with 26 additions and 11 deletions.
37 changes: 26 additions & 11 deletions cmd/import-app/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
"kubesphere.io/openpitrix-jobs/pkg/s3"
"kubesphere.io/openpitrix-jobs/pkg/types"
"kubesphere.io/openpitrix-jobs/pkg/utils"
"os"
"time"
)

var kubeconfig string
Expand All @@ -27,19 +29,32 @@ func newRootCmd(out io.Writer, args []string) (*cobra.Command, error) {
}

cobra.OnInitialize(func() {
utils.DumpConfig()
var ksConfig *types.Config
var err error

ksConfig, err := types.TryLoadFromDisk()
if err != nil {
klog.Fatalf("load config failed, error: %s", err)
}

if ksConfig.OpenPitrixOptions == nil {
klog.Fatalf("openpitrix config is empty, please wait a minute")
}
// https://kubernetes.io/docs/tasks/configure-pod-container/configure-pod-configmap/#mounted-configmaps-are-updated-automatically
// Mounted ConfigMaps are updated automatically
retry := 100
for i := 0; ; i++ {
if i == retry {
klog.Errorf("load openpitrix config failed")
os.Exit(1)
}
utils.DumpConfig()
ksConfig, err = types.TryLoadFromDisk()
if err != nil {
klog.Errorf("load config failed, error: %s", err)
} else {
if ksConfig.OpenPitrixOptions == nil {
klog.Errorf("openpitrix config is empty, please wait a minute")
} else if ksConfig.OpenPitrixOptions.S3Options == nil {
klog.Errorf("openpitrix s3 config is empty, please wait a minute")
} else {
break
}
}

if ksConfig.OpenPitrixOptions.S3Options == nil {
klog.Fatalf("s3 config is empty, please wait a minute")
time.Sleep(5 * time.Second)
}

s3Options = ksConfig.OpenPitrixOptions.S3Options
Expand Down

0 comments on commit 29f28bf

Please sign in to comment.