Operator support work with crds v1.7.0

Signed-off-by: Lan Liang <gcslyp@gmail.com>
This commit is contained in:
Lan Liang 2023-10-13 08:17:19 +00:00
parent f1f1a82dc7
commit 3fbd7219d1
7 changed files with 53 additions and 18 deletions

View File

@ -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

View File

@ -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.

View File

@ -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
}

0
operator/pkg/util/testdata/testa.yaml vendored Normal file
View File

0
operator/pkg/util/testdata/testb.yaml vendored Normal file
View File

View File

@ -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)

View File

@ -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)
}
}
}