Skip to content

Commit

Permalink
check file path
Browse files Browse the repository at this point in the history
Signed-off-by: xin.li <xin.li@daocloud.io>
  • Loading branch information
my-git9 committed Jul 17, 2022
1 parent ab00a50 commit d778ca1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pkg/karmadactl/cmdinit/karmada/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ func InitKarmadaResources(dir, caBase64, systemNamespace string) error {
}

// Initialize crd
if err = utils.PathExists(dir + "/crds/bases"); err != nil {
klog.Exitln(err)
}
basesCRDsFiles := utils.ListFiles(dir + "/crds/bases")
klog.Infof("Initialize karmada bases crd resource `%s/crds/bases`", dir)
for _, v := range basesCRDsFiles {
Expand All @@ -70,6 +73,9 @@ func InitKarmadaResources(dir, caBase64, systemNamespace string) error {
}
}

if err = utils.PathExists(dir + "/crds/patches"); err != nil {
klog.Exitln(err)
}
patchesCRDsFiles := utils.ListFiles(dir + "/crds/patches")
klog.Infof("Initialize karmada patches crd resource `%s/crds/patches`", dir)
for _, v := range patchesCRDsFiles {
Expand Down
12 changes: 12 additions & 0 deletions pkg/karmadactl/cmdinit/utils/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,18 @@ func ioCopyN(outFile *os.File, tr *tar.Reader) error {
return nil
}

// PathExists check if the file path exists
func PathExists(path string) error {
_, err := os.Stat(path)
if err == nil {
return nil
}
if os.IsNotExist(err) {
return err
}
return nil
}

// ListFiles traverse directory files
func ListFiles(path string) []string {
var files []string
Expand Down

0 comments on commit d778ca1

Please sign in to comment.