diff --git a/operator/config/samples/karmada.yaml b/operator/config/samples/karmada.yaml index 17ae6ac45..cf2452e46 100644 --- a/operator/config/samples/karmada.yaml +++ b/operator/config/samples/karmada.yaml @@ -31,19 +31,19 @@ spec: serviceSubnet: 10.96.0.0/12 karmadaAggregatedAPIServer: imageRepository: docker.io/karmada/karmada-aggregated-apiserver - imageTag: v1.6.0 + imageTag: v1.7.0 replicas: 1 karmadaControllerManager: imageRepository: docker.io/karmada/karmada-controller-manager - imageTag: v1.6.0 + imageTag: v1.7.0 replicas: 1 karmadaScheduler: imageRepository: docker.io/karmada/karmada-scheduler - imageTag: v1.6.0 + imageTag: v1.7.0 replicas: 1 karmadaWebhook: imageRepository: docker.io/karmada/karmada-webhook - imageTag: v1.6.0 + imageTag: v1.7.0 replicas: 1 kubeControllerManager: imageRepository: registry.k8s.io/kube-controller-manager diff --git a/operator/pkg/constants/constants.go b/operator/pkg/constants/constants.go index 3bbd5c406..d31d9b31e 100644 --- a/operator/pkg/constants/constants.go +++ b/operator/pkg/constants/constants.go @@ -15,7 +15,7 @@ const ( // EtcdDefaultVersion defines the default of the karmada etcd image tag EtcdDefaultVersion = "3.5.9-0" // KarmadaDefaultVersion defines the default of the karmada components image tag - KarmadaDefaultVersion = "v1.6.0" + KarmadaDefaultVersion = "v1.7.0" // KubeDefaultVersion defines the default of the karmada apiserver and kubeControllerManager image tag KubeDefaultVersion = "v1.25.4" // KarmadaDefaultServiceSubnet defines the default of the subnet used by k8s services. diff --git a/operator/pkg/tasks/init/karmadaresource.go b/operator/pkg/tasks/init/karmadaresource.go index 33047f15b..1d1f9ef3c 100644 --- a/operator/pkg/tasks/init/karmadaresource.go +++ b/operator/pkg/tasks/init/karmadaresource.go @@ -115,12 +115,8 @@ func runCrds(r workflow.RunData) error { } func createCrds(crdsClient *crdsclient.Clientset, crdsPath string) error { - for _, file := range util.ListFiles(crdsPath) { - if file.IsDir() || path.Ext(file.Name()) != ".yaml" { - continue - } - - crdBytes, err := util.ReadYamlFile(path.Join(crdsPath, file.Name())) + for _, file := range util.ListFileWithSuffix(crdsPath, ".yaml") { + crdBytes, err := util.ReadYamlFile(file.AbsPath) if err != nil { return err } @@ -138,18 +134,13 @@ func createCrds(crdsClient *crdsclient.Clientset, crdsPath string) error { } func patchCrds(crdsClient *crdsclient.Clientset, patchPath string, caBundle string) error { - for _, file := range util.ListFiles(patchPath) { - if file.IsDir() || path.Ext(file.Name()) != ".yaml" { - continue - } - + for _, file := range util.ListFileWithSuffix(patchPath, ".yaml") { reg, err := regexp.Compile("{{caBundle}}") if err != nil { return err } - crdPath := path.Join(patchPath, file.Name()) - crdBytes, err := util.ReplaceYamlForReg(crdPath, caBundle, reg) + crdBytes, err := util.ReplaceYamlForReg(file.AbsPath, caBundle, reg) if err != nil { return err } diff --git a/operator/pkg/util/testdata/testa.yaml b/operator/pkg/util/testdata/testa.yaml new file mode 100644 index 000000000..e69de29bb diff --git a/operator/pkg/util/testdata/testb.yaml b/operator/pkg/util/testdata/testb.yaml new file mode 100644 index 000000000..e69de29bb diff --git a/operator/pkg/util/util.go b/operator/pkg/util/util.go index b7ec11c17..2c3bae045 100644 --- a/operator/pkg/util/util.go +++ b/operator/pkg/util/util.go @@ -10,6 +10,7 @@ import ( "os" "path/filepath" "regexp" + "strings" "time" "k8s.io/klog/v2" @@ -145,6 +146,28 @@ func ListFiles(path string) []os.FileInfo { return files } +type FileExtInfo struct { + os.FileInfo + AbsPath string +} + +func ListFileWithSuffix(path, suffix string) []FileExtInfo { + files := []FileExtInfo{} + if err := filepath.Walk(path, func(path string, info os.FileInfo, err error) error { + if !info.IsDir() && strings.HasSuffix(path, suffix) { + files = append(files, FileExtInfo{ + AbsPath: path, + FileInfo: info, + }) + } + return nil + }); err != nil { + fmt.Println(err) + } + + return files +} + // PathExists check whether the path is exist func PathExists(path string) (bool, error) { _, err := os.Stat(path) diff --git a/operator/pkg/util/util_test.go b/operator/pkg/util/util_test.go new file mode 100644 index 000000000..2a68aa702 --- /dev/null +++ b/operator/pkg/util/util_test.go @@ -0,0 +1,21 @@ +package util + +import ( + "strings" + "testing" +) + +func TestListFileWithSuffix(t *testing.T) { + suffix := ".yaml" + files := ListFileWithSuffix(".", suffix) + want := 2 + got := len(files) + if want != got { + t.Errorf("Expected %d ,but got :%d", want, got) + } + for _, f := range files { + if !strings.HasSuffix(f.AbsPath, suffix) { + t.Errorf("Want suffix with %s , but not exist, path is:%s", suffix, f.AbsPath) + } + } +}