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 Aug 2, 2022
1 parent ab00a50 commit 2b1440e
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 20 deletions.
54 changes: 34 additions & 20 deletions pkg/karmadactl/cmdinit/karmada/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,26 +59,8 @@ func InitKarmadaResources(dir, caBase64, systemNamespace string) error {
}

// Initialize crd
basesCRDsFiles := utils.ListFiles(dir + "/crds/bases")
klog.Infof("Initialize karmada bases crd resource `%s/crds/bases`", dir)
for _, v := range basesCRDsFiles {
if path.Ext(v) != ".yaml" {
continue
}
if err := createCRDs(crdClient, v); err != nil {
return err
}
}

patchesCRDsFiles := utils.ListFiles(dir + "/crds/patches")
klog.Infof("Initialize karmada patches crd resource `%s/crds/patches`", dir)
for _, v := range patchesCRDsFiles {
if path.Ext(v) != ".yaml" {
continue
}
if err := patchCRDs(crdClient, caBase64, v); err != nil {
return err
}
if err = crdInitialize(crdClient, dir, caBase64); err != nil {
klog.Exitln(err)
}

// create webhook configuration
Expand Down Expand Up @@ -106,6 +88,38 @@ func InitKarmadaResources(dir, caBase64, systemNamespace string) error {
return nil
}

// crdInitialize initialize crd
func crdInitialize(crdClient *clientset.Clientset, dir, caBase64 string) error {
if err := utils.PathExists(dir + "/crds/bases"); err != nil {
return err
}
basesCRDsFiles := utils.ListFiles(dir + "/crds/bases")
klog.Infof("Initialize karmada bases crd resource `%s/crds/bases`", dir)
for _, v := range basesCRDsFiles {
if path.Ext(v) != ".yaml" {
continue
}
if err := createCRDs(crdClient, v); err != nil {
return err
}
}

if err := utils.PathExists(dir + "/crds/patches"); err != nil {
return err
}
patchesCRDsFiles := utils.ListFiles(dir + "/crds/patches")
klog.Infof("Initialize karmada patches crd resource `%s/crds/patches`", dir)
for _, v := range patchesCRDsFiles {
if path.Ext(v) != ".yaml" {
continue
}
if err := patchCRDs(crdClient, caBase64, v); err != nil {
return err
}
}
return nil
}

func crdPatchesResources(filename, caBundle string) ([]byte, error) {
data, err := ioutil.ReadFile(filename)
if err != nil {
Expand Down
9 changes: 9 additions & 0 deletions pkg/karmadactl/cmdinit/utils/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,15 @@ 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 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 2b1440e

Please sign in to comment.