Repository: kubean-io/kubean
Pull request #266 (2022-10-31 06:59:55)

Manifest crd support multi image repo
<!--  

Thanks for sending a pull request!  Here are some tips for you:

* make sure your commit is signed off

-->

**What type of PR is this?**
<!-- 
Uncomment only one ` /kind <>` line, hit enter to put that in a new line, and remove leading whitespaces from that line:

/kind api-change
/kind bug
/kind cleanup
/kind design
/kind documentation
/kind failing-test
/kind feature
/kind flake
-->

/kind bug

**What this PR does / why we need it**:

* adjust to multi harbor projects

**Which issue(s) this PR fixes**:
<!--
*Automatically closes linked issue when PR is merged.
Usage: `Fixes #<issue number>`, or `Fixes (paste link of issue)`.
_If PR is about `failing-tests or flakes`, please post the related issues/tests in a comment and do not use `Fixes`_*
-->
Fixes #

**Special notes for your reviewer**:




Patch:
diff --git a/api/apis/manifest/v1alpha1/types.go b/api/apis/manifest/v1alpha1/types.go
index 4a840e402..ed616abe9 100644
--- a/api/apis/manifest/v1alpha1/types.go
+++ b/api/apis/manifest/v1alpha1/types.go
@@ -43,7 +43,7 @@ type Spec struct {
 
 type LocalService struct {
 	// +optional
-	RegistryRepo string `json:"registryRepo,omitempty" yaml:"registryRepo,omitempty"`
+	ImageRepo map[ImageRepoType]string `json:"imageRepo" yaml:"imageRepo"`
 	// +optional
 	FilesRepo string `json:"filesRepo,omitempty" yaml:"filesRepo,omitempty"`
 	// +optional
@@ -52,6 +52,21 @@ type LocalService struct {
 	HostsMap []*HostsMap `json:"hostsMap,omitempty" yaml:"hostsMap,omitempty"`
 }
 
+func (localService *LocalService) GetGHCRImageRepo() string {
+	if localService.ImageRepo == nil {
+		return ""
+	}
+	return localService.ImageRepo[GithubImageRepo]
+}
+
+type ImageRepoType string
+
+const KubeImageRepo ImageRepoType = "kubeImageRepo"
+const GCRImageRepo ImageRepoType = "gcrImageRepo"
+const GithubImageRepo ImageRepoType = "githubImageRepo"
+const DockerImageRepo ImageRepoType = "dockerImageRepo"
+const QuayImageRepo ImageRepoType = "quayImageRepo"
+
 type HostsMap struct {
 	// +required
 	Domain string `json:"domain,omitempty" yaml:"domain,omitempty"`
diff --git a/api/apis/manifest/v1alpha1/zz_generated.deepcopy.go b/api/apis/manifest/v1alpha1/zz_generated.deepcopy.go
index 2cba0373b..d00e35b32 100644
--- a/api/apis/manifest/v1alpha1/zz_generated.deepcopy.go
+++ b/api/apis/manifest/v1alpha1/zz_generated.deepcopy.go
@@ -108,6 +108,13 @@ func (in *LocalAvailable) DeepCopy() *LocalAvailable {
 // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
 func (in *LocalService) DeepCopyInto(out *LocalService) {
 	*out = *in
+	if in.ImageRepo != nil {
+		in, out := &in.ImageRepo, &out.ImageRepo
+		*out = make(map[ImageRepoType]string, len(*in))
+		for key, val := range *in {
+			(*out)[key] = val
+		}
+	}
 	if in.YumRepo != nil {
 		in, out := &in.YumRepo, &out.YumRepo
 		*out = make([]string, len(*in))
diff --git a/api/charts/crds/kubean.io_manifests.yaml b/api/charts/crds/kubean.io_manifests.yaml
index a7f938df6..4a5360854 100644
--- a/api/charts/crds/kubean.io_manifests.yaml
+++ b/api/charts/crds/kubean.io_manifests.yaml
@@ -86,8 +86,10 @@ spec:
                           type: string
                       type: object
                     type: array
-                  registryRepo:
-                    type: string
+                  imageRepo:
+                    additionalProperties:
+                      type: string
+                    type: object
                   yumRepo:
                     items:
                       type: string
diff --git a/build/os-packages/packages.yml b/build/os-packages/packages.yml
index bde519828..e1abba947 100644
--- a/build/os-packages/packages.yml
+++ b/build/os-packages/packages.yml
@@ -16,10 +16,10 @@ docker:
     - containerd.io-1.6.4-3.1.el7
     - docker-ce-18.09.9-3.el7
     - docker-ce-19.03.15-3.el7
-    - docker-ce-20.10.20-3.el7
+    - docker-ce-20.10.17-3.el7
     - docker-ce-cli-18.09.9-3.el7
     - docker-ce-cli-19.03.15-3.el7
-    - docker-ce-cli-20.10.20-3.el7
+    - docker-ce-cli-20.10.17-3.el7
 
   redhat8:
     - containerd.io-1.4.9-3.1.el8
@@ -27,7 +27,7 @@ docker:
     - containerd.io-1.6.4-3.1.el8
     - docker-ce-3:18.09.9-3.el7
     - docker-ce-3:19.03.15-3.el8
-    - docker-ce-3:20.10.20-3.el8
+    - docker-ce-3:20.10.17-3.el8
     - docker-ce-cli-1:18.09.9-3.el7
     - docker-ce-cli-1:19.03.15-3.el8
-    - docker-ce-cli-1:20.10.20-3.el8
+    - docker-ce-cli-1:20.10.17-3.el8
diff --git a/charts/kubean/crds/kubean.io_manifests.yaml b/charts/kubean/crds/kubean.io_manifests.yaml
index a7f938df6..4a5360854 100644
--- a/charts/kubean/crds/kubean.io_manifests.yaml
+++ b/charts/kubean/crds/kubean.io_manifests.yaml
@@ -86,8 +86,10 @@ spec:
                           type: string
                       type: object
                     type: array
-                  registryRepo:
-                    type: string
+                  imageRepo:
+                    additionalProperties:
+                      type: string
+                    type: object
                   yumRepo:
                     items:
                       type: string
diff --git a/pkg/controllers/infomanifest/controller.go b/pkg/controllers/infomanifest/controller.go
index 39ce982e6..41b8aef8b 100644
--- a/pkg/controllers/infomanifest/controller.go
+++ b/pkg/controllers/infomanifest/controller.go
@@ -173,8 +173,8 @@ func (c *Controller) UpdateLocalAvailableImage() {
 		return
 	}
 	imageRepo := "ghcr.m.daocloud.io"
-	if len(global.Spec.LocalService.RegistryRepo) != 0 {
-		imageRepo = global.Spec.LocalService.RegistryRepo
+	if len(global.Spec.LocalService.GetGHCRImageRepo()) != 0 {
+		imageRepo = global.Spec.LocalService.GetGHCRImageRepo() // ghcr.io
 	}
 	newImageName := fmt.Sprintf("%s/kubean-io/spray-job:%s", imageRepo, global.Spec.KubeanVersion)
 	if global.Status.LocalAvailable.KubesprayImage != newImageName {
diff --git a/playbooks/cluster-info.yml b/playbooks/cluster-info.yml
index 071d82d76..7e128879c 100644
--- a/playbooks/cluster-info.yml
+++ b/playbooks/cluster-info.yml
@@ -10,7 +10,7 @@
         kubectl -n kube-system get pod
         kubectl get --raw='/readyz?verbose'
       register: clusterinfo
-      retries: 5
-      delay: 30
+      retries: 3
+      delay: 10
       until: clusterinfo.rc == 0
     - debug: var=clusterinfo.stdout_lines
diff --git a/vendor/kubean.io/api/apis/manifest/v1alpha1/types.go b/vendor/kubean.io/api/apis/manifest/v1alpha1/types.go
index 4a840e402..ed616abe9 100644
--- a/vendor/kubean.io/api/apis/manifest/v1alpha1/types.go
+++ b/vendor/kubean.io/api/apis/manifest/v1alpha1/types.go
@@ -43,7 +43,7 @@ type Spec struct {
 
 type LocalService struct {
 	// +optional
-	RegistryRepo string `json:"registryRepo,omitempty" yaml:"registryRepo,omitempty"`
+	ImageRepo map[ImageRepoType]string `json:"imageRepo" yaml:"imageRepo"`
 	// +optional
 	FilesRepo string `json:"filesRepo,omitempty" yaml:"filesRepo,omitempty"`
 	// +optional
@@ -52,6 +52,21 @@ type LocalService struct {
 	HostsMap []*HostsMap `json:"hostsMap,omitempty" yaml:"hostsMap,omitempty"`
 }
 
+func (localService *LocalService) GetGHCRImageRepo() string {
+	if localService.ImageRepo == nil {
+		return ""
+	}
+	return localService.ImageRepo[GithubImageRepo]
+}
+
+type ImageRepoType string
+
+const KubeImageRepo ImageRepoType = "kubeImageRepo"
+const GCRImageRepo ImageRepoType = "gcrImageRepo"
+const GithubImageRepo ImageRepoType = "githubImageRepo"
+const DockerImageRepo ImageRepoType = "dockerImageRepo"
+const QuayImageRepo ImageRepoType = "quayImageRepo"
+
 type HostsMap struct {
 	// +required
 	Domain string `json:"domain,omitempty" yaml:"domain,omitempty"`
diff --git a/vendor/kubean.io/api/apis/manifest/v1alpha1/zz_generated.deepcopy.go b/vendor/kubean.io/api/apis/manifest/v1alpha1/zz_generated.deepcopy.go
index 2cba0373b..d00e35b32 100644
--- a/vendor/kubean.io/api/apis/manifest/v1alpha1/zz_generated.deepcopy.go
+++ b/vendor/kubean.io/api/apis/manifest/v1alpha1/zz_generated.deepcopy.go
@@ -108,6 +108,13 @@ func (in *LocalAvailable) DeepCopy() *LocalAvailable {
 // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
 func (in *LocalService) DeepCopyInto(out *LocalService) {
 	*out = *in
+	if in.ImageRepo != nil {
+		in, out := &in.ImageRepo, &out.ImageRepo
+		*out = make(map[ImageRepoType]string, len(*in))
+		for key, val := range *in {
+			(*out)[key] = val
+		}
+	}
 	if in.YumRepo != nil {
 		in, out := &in.YumRepo, &out.YumRepo
 		*out = make([]string, len(*in))


Test patch:
diff --git a/pkg/controllers/infomanifest/controller_test.go b/pkg/controllers/infomanifest/controller_test.go
index 16cd73474..96fc6d97d 100644
--- a/pkg/controllers/infomanifest/controller_test.go
+++ b/pkg/controllers/infomanifest/controller_test.go
@@ -168,11 +168,17 @@ func Test_ParseConfigMapToLocalService(t *testing.T) {
 		},
 		{
 			name: "good string data",
-			arg:  &corev1.ConfigMap{Data: map[string]string{"localService": "      registryRepo: 'temp-registry.daocloud.io:5000'\n      filesRepo: 'http://temp-registry.daocloud.io:9000'\n      yumRepo:\n        - 'http://temp-registry.daocloud.io:9000/kubean/centos-iso/\\$releasever/os/\\$basearch'\n        - 'http://temp-registry.daocloud.io:9000/centos/\\$releasever/os/\\$basearch'\n      hostsMap:\n        - domain: temp-registry.daocloud.io\n          address: 'a.b.c.d'"}},
+			arg:  &corev1.ConfigMap{Data: map[string]string{"localService": "      imageRepo: \n        kubeImageRepo: \"temp-registry.daocloud.io:5000/registry.k8s.io\"\n        gcrImageRepo: \"temp-registry.daocloud.io:5000/gcr.io\"\n        githubImageRepo: \"a\"\n        dockerImageRepo: \"b\"\n        quayImageRepo: \"c\"\n      filesRepo: 'http://temp-registry.daocloud.io:9000'\n      yumRepo:\n        - 'http://temp-registry.daocloud.io:9000/kubean/centos-iso/\\$releasever/os/\\$basearch'\n        - 'http://temp-registry.daocloud.io:9000/centos/\\$releasever/os/\\$basearch'\n      hostsMap:\n        - domain: temp-registry.daocloud.io\n          address: 'a.b.c.d'\n"}},
 			want: &manifestv1alpha1.LocalService{
-				RegistryRepo: "temp-registry.daocloud.io:5000",
-				FilesRepo:    "http://temp-registry.daocloud.io:9000",
-				YumRepo:      []string{"http://temp-registry.daocloud.io:9000/kubean/centos-iso/\\$releasever/os/\\$basearch", "http://temp-registry.daocloud.io:9000/centos/\\$releasever/os/\\$basearch"},
+				ImageRepo: map[manifestv1alpha1.ImageRepoType]string{
+					"kubeImageRepo":   "temp-registry.daocloud.io:5000/registry.k8s.io",
+					"gcrImageRepo":    "temp-registry.daocloud.io:5000/gcr.io",
+					"githubImageRepo": "a",
+					"dockerImageRepo": "b",
+					"quayImageRepo":   "c",
+				},
+				FilesRepo: "http://temp-registry.daocloud.io:9000",
+				YumRepo:   []string{"http://temp-registry.daocloud.io:9000/kubean/centos-iso/\\$releasever/os/\\$basearch", "http://temp-registry.daocloud.io:9000/centos/\\$releasever/os/\\$basearch"},
 				HostsMap: []*manifestv1alpha1.HostsMap{
 					{Domain: "temp-registry.daocloud.io", Address: "a.b.c.d"},
 				},
@@ -308,7 +314,7 @@ func Test_UpdateGlobalLocalService1(t *testing.T) {
 						Name:      LocalServiceConfigMap,
 						Namespace: "default",
 					},
-					Data: map[string]string{"localService": "      registryRepo: 'temp-registry.daocloud.io:5000'\n      filesRepo: 'http://temp-registry.daocloud.io:9000'\n      yumRepo:\n        - 'http://temp-registry.daocloud.io:9000/kubean/centos-iso/\\$releasever/os/\\$basearch'\n        - 'http://temp-registry.daocloud.io:9000/centos/\\$releasever/os/\\$basearch'\n      hostsMap: \n        - domain: temp-registry.daocloud.io\n          address: 'a.b.c.d'"},
+					Data: map[string]string{"localService": "      imageRepo: \n        kubeImageRepo: \"temp-registry.daocloud.io:5000/registry.k8s.io\"\n        gcrImageRepo: \"temp-registry.daocloud.io:5000/gcr.io\"\n        githubImageRepo: \"a\"\n        dockerImageRepo: \"b\"\n        quayImageRepo: \"c\"\n      filesRepo: 'http://temp-registry.daocloud.io:9000'\n      yumRepo:\n        - 'http://temp-registry.daocloud.io:9000/kubean/centos-iso/\\$releasever/os/\\$basearch'\n        - 'http://temp-registry.daocloud.io:9000/centos/\\$releasever/os/\\$basearch'\n      hostsMap: \n        - domain: temp-registry.daocloud.io\n          address: 'a.b.c.d'"},
 				}
 				controller.ClientSet.CoreV1().ConfigMaps("default").Create(context.Background(), configMap, metav1.CreateOptions{})
 				controller.Create(context.Background(), global)
@@ -316,9 +322,15 @@ func Test_UpdateGlobalLocalService1(t *testing.T) {
 				controller.UpdateGlobalLocalService()
 			},
 			want: manifestv1alpha1.LocalService{
-				RegistryRepo: "temp-registry.daocloud.io:5000",
-				FilesRepo:    "http://temp-registry.daocloud.io:9000",
-				YumRepo:      []string{"http://temp-registry.daocloud.io:9000/kubean/centos-iso/\\$releasever/os/\\$basearch", "http://temp-registry.daocloud.io:9000/centos/\\$releasever/os/\\$basearch"},
+				ImageRepo: map[manifestv1alpha1.ImageRepoType]string{
+					"kubeImageRepo":   "temp-registry.daocloud.io:5000/registry.k8s.io",
+					"gcrImageRepo":    "temp-registry.daocloud.io:5000/gcr.io",
+					"githubImageRepo": "a",
+					"dockerImageRepo": "b",
+					"quayImageRepo":   "c",
+				},
+				FilesRepo: "http://temp-registry.daocloud.io:9000",
+				YumRepo:   []string{"http://temp-registry.daocloud.io:9000/kubean/centos-iso/\\$releasever/os/\\$basearch", "http://temp-registry.daocloud.io:9000/centos/\\$releasever/os/\\$basearch"},
 				HostsMap: []*manifestv1alpha1.HostsMap{
 					{
 						Domain:  "temp-registry.daocloud.io",
@@ -348,7 +360,7 @@ func Test_UpdateGlobalLocalService1(t *testing.T) {
 						Name:      LocalServiceConfigMap,
 						Namespace: "default",
 					},
-					Data: map[string]string{"localService": "      registryRepo: 'temp-registry.daocloud.io:5000'\n      filesRepo: 'http://temp-registry.daocloud.io:9000'\n      yumRepo:\n        - 'http://temp-registry.daocloud.io:9000/kubean/centos-iso/\\$releasever/os/\\$basearch'\n        - 'http://temp-registry.daocloud.io:9000/centos/\\$releasever/os/\\$basearch'\n      hostsMap: \n        - domain: temp-registry.daocloud.io\n          address: 'a.b.c.d1'"},
+					Data: map[string]string{"localService": "      imageRepo: \n        kubeImageRepo: \"temp-registry.daocloud.io:5000/registry.k8s.io\"\n        gcrImageRepo: \"temp-registry.daocloud.io:5000/gcr.io\"\n        githubImageRepo: \"a\"\n        dockerImageRepo: \"b\"\n        quayImageRepo: \"c\"\n      filesRepo: 'http://temp-registry.daocloud.io:9000'\n      yumRepo:\n        - 'http://temp-registry.daocloud.io:9000/kubean/centos-iso/\\$releasever/os/\\$basearch'\n        - 'http://temp-registry.daocloud.io:9000/centos/\\$releasever/os/\\$basearch'\n      hostsMap: \n        - domain: temp-registry.daocloud.io\n          address: 'a.b.c.d1'"},
 				}
 				controller.ClientSet.CoreV1().ConfigMaps("default").Update(context.Background(), configMap, metav1.UpdateOptions{})
 				controller.Create(context.Background(), global)
@@ -356,9 +368,15 @@ func Test_UpdateGlobalLocalService1(t *testing.T) {
 				controller.UpdateGlobalLocalService()
 			},
 			want: manifestv1alpha1.LocalService{
-				RegistryRepo: "temp-registry.daocloud.io:5000",
-				FilesRepo:    "http://temp-registry.daocloud.io:9000",
-				YumRepo:      []string{"http://temp-registry.daocloud.io:9000/kubean/centos-iso/\\$releasever/os/\\$basearch", "http://temp-registry.daocloud.io:9000/centos/\\$releasever/os/\\$basearch"},
+				ImageRepo: map[manifestv1alpha1.ImageRepoType]string{
+					"kubeImageRepo":   "temp-registry.daocloud.io:5000/registry.k8s.io",
+					"gcrImageRepo":    "temp-registry.daocloud.io:5000/gcr.io",
+					"githubImageRepo": "a",
+					"dockerImageRepo": "b",
+					"quayImageRepo":   "c",
+				},
+				FilesRepo: "http://temp-registry.daocloud.io:9000",
+				YumRepo:   []string{"http://temp-registry.daocloud.io:9000/kubean/centos-iso/\\$releasever/os/\\$basearch", "http://temp-registry.daocloud.io:9000/centos/\\$releasever/os/\\$basearch"},
 				HostsMap: []*manifestv1alpha1.HostsMap{
 					{
 						Domain:  "temp-registry.daocloud.io",
@@ -429,7 +447,10 @@ func Test_UpdateLocalAvailableImage(t *testing.T) {
 						Labels: map[string]string{OriginLabel: "v2"},
 					},
 					Spec: manifestv1alpha1.Spec{
-						LocalService:  manifestv1alpha1.LocalService{RegistryRepo: "abc.io"},
+						LocalService: manifestv1alpha1.LocalService{ImageRepo: map[manifestv1alpha1.ImageRepoType]string{
+							"dockerImageRepo": "abc.io",
+							"githubImageRepo": "ghcr.io",
+						}},
 						KubeanVersion: "123456",
 					},
 				}
@@ -437,7 +458,7 @@ func Test_UpdateLocalAvailableImage(t *testing.T) {
 				controller.InfoManifestClientSet.KubeanV1alpha1().Manifests().Update(context.Background(), global, metav1.UpdateOptions{})
 				controller.UpdateLocalAvailableImage()
 			},
-			want: "abc.io/kubean-io/spray-job:123456",
+			want: "ghcr.io/kubean-io/spray-job:123456",
 		},
 	}