Repository: kubean-io/kubean
Pull request #273 (2022-11-01 04:57:18)

Disable cn proxy sources to improve kubean image build efficiency
Signed-off-by: bo.jiang <bo.jiang@daocloud.io>

<!--  

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?**
/kind feature

**What this PR does / why we need it**:
Disable cn proxy sources to improve kubean image build efficiency.

**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 ed616abe9..4a840e402 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
-	ImageRepo map[ImageRepoType]string `json:"imageRepo" yaml:"imageRepo"`
+	RegistryRepo string `json:"registryRepo,omitempty" yaml:"registryRepo,omitempty"`
 	// +optional
 	FilesRepo string `json:"filesRepo,omitempty" yaml:"filesRepo,omitempty"`
 	// +optional
@@ -52,21 +52,6 @@ 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 d00e35b32..2cba0373b 100644
--- a/api/apis/manifest/v1alpha1/zz_generated.deepcopy.go
+++ b/api/apis/manifest/v1alpha1/zz_generated.deepcopy.go
@@ -108,13 +108,6 @@ 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 4a5360854..a7f938df6 100644
--- a/api/charts/crds/kubean.io_manifests.yaml
+++ b/api/charts/crds/kubean.io_manifests.yaml
@@ -86,10 +86,8 @@ spec:
                           type: string
                       type: object
                     type: array
-                  imageRepo:
-                    additionalProperties:
-                      type: string
-                    type: object
+                  registryRepo:
+                    type: string
                   yumRepo:
                     items:
                       type: string
diff --git a/build/images/kubean-operator/Dockerfile b/build/images/kubean-operator/Dockerfile
index 59b168ddb..2a9449ce8 100644
--- a/build/images/kubean-operator/Dockerfile
+++ b/build/images/kubean-operator/Dockerfile
@@ -2,8 +2,9 @@ FROM golang:1.17.3 as build
 
 WORKDIR /kubean
 
-ENV GO111MODULE=on \
-    GOPROXY=https://goproxy.cn,direct
+# ENV GO111MODULE=on \
+#     GOPROXY=https://goproxy.cn,direct
+ENV GO111MODULE=on
 
 COPY . .
 
@@ -11,8 +12,8 @@ RUN CGO_ENABLED=0 GOOS=linux go build -mod vendor -o kubean-operator ./cmd/kubea
 
 FROM alpine:3.15
 
-RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
+# RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
 
-COPY --from=build /kubean/kubean-operator  /bin/
+COPY --from=build /kubean/kubean-operator /bin/
 
 CMD ["/bin/kubean-operator"]
diff --git a/charts/kubean/crds/kubean.io_manifests.yaml b/charts/kubean/crds/kubean.io_manifests.yaml
index 4a5360854..a7f938df6 100644
--- a/charts/kubean/crds/kubean.io_manifests.yaml
+++ b/charts/kubean/crds/kubean.io_manifests.yaml
@@ -86,10 +86,8 @@ spec:
                           type: string
                       type: object
                     type: array
-                  imageRepo:
-                    additionalProperties:
-                      type: string
-                    type: object
+                  registryRepo:
+                    type: string
                   yumRepo:
                     items:
                       type: string
diff --git a/pkg/controllers/infomanifest/controller.go b/pkg/controllers/infomanifest/controller.go
index 41b8aef8b..39ce982e6 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.GetGHCRImageRepo()) != 0 {
-		imageRepo = global.Spec.LocalService.GetGHCRImageRepo() // ghcr.io
+	if len(global.Spec.LocalService.RegistryRepo) != 0 {
+		imageRepo = global.Spec.LocalService.RegistryRepo
 	}
 	newImageName := fmt.Sprintf("%s/kubean-io/spray-job:%s", imageRepo, global.Spec.KubeanVersion)
 	if global.Status.LocalAvailable.KubesprayImage != newImageName {
diff --git a/vendor/kubean.io/api/apis/manifest/v1alpha1/types.go b/vendor/kubean.io/api/apis/manifest/v1alpha1/types.go
index ed616abe9..4a840e402 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
-	ImageRepo map[ImageRepoType]string `json:"imageRepo" yaml:"imageRepo"`
+	RegistryRepo string `json:"registryRepo,omitempty" yaml:"registryRepo,omitempty"`
 	// +optional
 	FilesRepo string `json:"filesRepo,omitempty" yaml:"filesRepo,omitempty"`
 	// +optional
@@ -52,21 +52,6 @@ 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 d00e35b32..2cba0373b 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,13 +108,6 @@ 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 96fc6d97d..16cd73474 100644
--- a/pkg/controllers/infomanifest/controller_test.go
+++ b/pkg/controllers/infomanifest/controller_test.go
@@ -168,17 +168,11 @@ func Test_ParseConfigMapToLocalService(t *testing.T) {
 		},
 		{
 			name: "good string data",
-			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"}},
+			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'"}},
 			want: &manifestv1alpha1.LocalService{
-				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"},
+				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"},
 				HostsMap: []*manifestv1alpha1.HostsMap{
 					{Domain: "temp-registry.daocloud.io", Address: "a.b.c.d"},
 				},
@@ -314,7 +308,7 @@ func Test_UpdateGlobalLocalService1(t *testing.T) {
 						Name:      LocalServiceConfigMap,
 						Namespace: "default",
 					},
-					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'"},
+					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'"},
 				}
 				controller.ClientSet.CoreV1().ConfigMaps("default").Create(context.Background(), configMap, metav1.CreateOptions{})
 				controller.Create(context.Background(), global)
@@ -322,15 +316,9 @@ func Test_UpdateGlobalLocalService1(t *testing.T) {
 				controller.UpdateGlobalLocalService()
 			},
 			want: manifestv1alpha1.LocalService{
-				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"},
+				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"},
 				HostsMap: []*manifestv1alpha1.HostsMap{
 					{
 						Domain:  "temp-registry.daocloud.io",
@@ -360,7 +348,7 @@ func Test_UpdateGlobalLocalService1(t *testing.T) {
 						Name:      LocalServiceConfigMap,
 						Namespace: "default",
 					},
-					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'"},
+					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'"},
 				}
 				controller.ClientSet.CoreV1().ConfigMaps("default").Update(context.Background(), configMap, metav1.UpdateOptions{})
 				controller.Create(context.Background(), global)
@@ -368,15 +356,9 @@ func Test_UpdateGlobalLocalService1(t *testing.T) {
 				controller.UpdateGlobalLocalService()
 			},
 			want: manifestv1alpha1.LocalService{
-				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"},
+				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"},
 				HostsMap: []*manifestv1alpha1.HostsMap{
 					{
 						Domain:  "temp-registry.daocloud.io",
@@ -447,10 +429,7 @@ func Test_UpdateLocalAvailableImage(t *testing.T) {
 						Labels: map[string]string{OriginLabel: "v2"},
 					},
 					Spec: manifestv1alpha1.Spec{
-						LocalService: manifestv1alpha1.LocalService{ImageRepo: map[manifestv1alpha1.ImageRepoType]string{
-							"dockerImageRepo": "abc.io",
-							"githubImageRepo": "ghcr.io",
-						}},
+						LocalService:  manifestv1alpha1.LocalService{RegistryRepo: "abc.io"},
 						KubeanVersion: "123456",
 					},
 				}
@@ -458,7 +437,7 @@ func Test_UpdateLocalAvailableImage(t *testing.T) {
 				controller.InfoManifestClientSet.KubeanV1alpha1().Manifests().Update(context.Background(), global, metav1.UpdateOptions{})
 				controller.UpdateLocalAvailableImage()
 			},
-			want: "ghcr.io/kubean-io/spray-job:123456",
+			want: "abc.io/kubean-io/spray-job:123456",
 		},
 	}