Repository: kubean-io/kubean
Pull request #156 (2022-09-22 08:53:54)

keep one minio bucket
Signed-off-by: hang.jiang <hang.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?**
<!-- 
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 feature

**What this PR does / why we need it**:

* keep one minio bucket

**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**:



kubean-pr-robot[bot]: [APPROVALNOTIFIER] This PR is **APPROVED**

This pull-request has been approved by: *<a href="https://github.com/kubean-io/kubean/pull/156#" title="Author self-approved">hangscer8</a>*

The full list of commands accepted by this bot can be found [here](https://go.k8s.io/bot-commands?repo=kubean-io%2Fkubean).

The pull request process is described [here](https://git.k8s.io/community/contributors/guide/owners.md#the-code-review-process)

<details >
Needs approval from an approver in each of these files:

- ~~[OWNERS](https://github.com/kubean-io/kubean/blob/main/OWNERS)~~ [hangscer8]

Approvers can indicate their approval by writing `/approve` in a comment
Approvers can cancel approval by writing `/approve cancel` in a comment
</details>
<!-- META={"approvers":[]} -->

Patch:
diff --git a/artifacts/import_files.sh b/artifacts/import_files.sh
index 39e7b378e..651672743 100755
--- a/artifacts/import_files.sh
+++ b/artifacts/import_files.sh
@@ -15,6 +15,14 @@ function add_mc_host_conf() {
   fi
 }
 
+function ensure_kubean_bucket() {
+  if ! mc ls kubeaniominioserver/kubean >/dev/null 2>&1; then
+    echo "create bucket 'kubean'"
+    mc mb kubeaniominioserver/kubean
+    mc policy set download kubeaniominioserver/kubean
+  fi
+}
+
 function del_mc_host_conf() {
   echo "remove mc config"
   mc config host remove kubeaniominioserver
@@ -35,26 +43,20 @@ function import_files() {
     echo "unzip successfully"
   fi
 
-  for bucketName in offline-files/*; do
-    bucketName=${bucketName//offline-files\//} ## remove dir prefix
-    if ! mc ls kubeaniominioserver/"$bucketName" >/dev/null 2>&1 ; then
-      echo "create bucket $bucketName"
-      mc mb kubeaniominioserver/"$bucketName"
-      mc policy set download kubeaniominioserver/"$bucketName"
-    fi
-  done
-
-  for path in $(find offline-files); do
-    if [ -f "$path" ]; then
-      ## mc cp offline-files/a/b/c/d.txt kubeaniominioserver/a/b/c/d.txt
-      minioFileName=${path//offline-files/kubeaniominioserver}
-      mc cp --no-color "$path" "$minioFileName"
-    fi
+  for dirName in offline-files/*; do
+     mc cp --no-color --recursive "$dirName" "kubeaniominioserver/kubean/"
   done
 
 }
 
+start=$(date +%s)
+
 check_mc_cmd
 add_mc_host_conf
+ensure_kubean_bucket
 import_files
 del_mc_host_conf
+
+end=$(date +%s)
+take=$((end - start))
+echo "Importing files spends ${take} seconds"
diff --git a/artifacts/import_images.sh b/artifacts/import_images.sh
index 52c05f223..83ecbb9e7 100755
--- a/artifacts/import_images.sh
+++ b/artifacts/import_images.sh
@@ -57,5 +57,11 @@ function import_images() {
   echo "import completed!"
 }
 
+start=$(date +%s)
+
 check_skopeo_cmd
 import_images
+
+end=$(date +%s)
+take=$((end - start))
+echo "Importing images spends ${take} seconds"
diff --git a/artifacts/import_iso.sh b/artifacts/import_iso.sh
index e2a727c2e..f7feba87c 100644
--- a/artifacts/import_iso.sh
+++ b/artifacts/import_iso.sh
@@ -116,4 +116,4 @@ remove_mc_host_conf
 
 end=$(date +%s)
 take=$((end - start))
-echo "It spends ${take} seconds"
+echo "Importing ISO spends ${take} seconds"
diff --git a/artifacts/import_ospkgs.sh b/artifacts/import_ospkgs.sh
index ba7327968..42e81e38b 100755
--- a/artifacts/import_ospkgs.sh
+++ b/artifacts/import_ospkgs.sh
@@ -17,6 +17,14 @@ function add_mc_host_conf() {
   fi
 }
 
+function ensure_kubean_bucket() {
+  if ! mc ls kubeaniominioserver/kubean >/dev/null 2>&1; then
+    echo "create bucket 'kubean'"
+    mc mb kubeaniominioserver/kubean
+    mc policy set download kubeaniominioserver/kubean
+  fi
+}
+
 function remove_mc_host_conf() {
   echo "remove mc config"
   mc config host remove kubeaniominioserver
@@ -40,25 +48,19 @@ function import_os_packages() {
 
   tar -xvf "$TAR_GZ_FILE_PATH" ## got resources folder
 
-  for bucketName in resources/*; do
-    bucketName=${bucketName//resources\//} ## remove dir prefix
-    if ! mc ls kubeaniominioserver/"$bucketName" >/dev/null 2>&1; then
-      echo "create bucket $bucketName"
-      mc mb kubeaniominioserver/"$bucketName"
-      mc policy set download kubeaniominioserver/"$bucketName"
-    fi
-  done
-
-  for path in $(find resources); do
-    if [ -f "$path" ]; then
-      ## mc cp resources/centos/7/x86_64/x.rpm kubeaniominioserver/centos/7/x86_64/x.rpm
-      minioFileName=${path//resources/kubeaniominioserver}
-      mc cp --no-color "$path" "$minioFileName"
-    fi
+  for dirName in resources/*; do
+    mc cp --no-color --recursive "$dirName" "kubeaniominioserver/kubean/"
   done
 }
 
+start=$(date +%s)
+
 check_mc_cmd
 add_mc_host_conf
+ensure_kubean_bucket
 import_os_packages
 remove_mc_host_conf
+
+end=$(date +%s)
+take=$((end - start))
+echo "Importing OS pkgs spends ${take} seconds"
diff --git a/artifacts/offlineDemo/vars-conf-cm.yml b/artifacts/offlineDemo/vars-conf-cm.yml
index 782819455..67490dbcb 100644
--- a/artifacts/offlineDemo/vars-conf-cm.yml
+++ b/artifacts/offlineDemo/vars-conf-cm.yml
@@ -8,7 +8,7 @@ data:
     registry_host: "REGISTRY_HOST:REGISTRY_PORT"
     minio_address: "http://MINIO_API_HOST:MINIO_API_PORT"
 
-    files_repo: "{{ minio_address }}"
+    files_repo: "{{ minio_address }}/kubean"
     container_manager: docker ## containerd
     docker_version: "20.10"
     docker_cli_version: "20.10"
diff --git a/doc/offline.zh.md b/doc/offline.zh.md
index 669dc00cb..b926c0708 100644
--- a/doc/offline.zh.md
+++ b/doc/offline.zh.md
@@ -154,12 +154,12 @@ sslverify=0
 $ ./gen_repo_conf.sh --url-mode ${linux_distribution} ${repo_base_url}
 
 # 执行脚本创建 URL 源配置文件
-$ ./gen_repo_conf.sh --url-mode centos ${minio_address}/centos/\$releasever/os/\$basearch
+$ ./gen_repo_conf.sh --url-mode centos ${minio_address}/kubean/centos/\$releasever/os/\$basearch
 # 查看 URL 源配置文件
 $ cat /etc/yum.repos.d/Kubean-URL.repo
 [kubean-extra]
 name=Kubean Extra Repo
-baseurl=http://10.20.30.40:9000/centos/$releasever/os/$basearch
+baseurl=http://10.20.30.40:9000/kubean/centos/$releasever/os/$basearch
 enabled=1
 gpgcheck=0
 sslverify=0
@@ -192,7 +192,7 @@ spec:
     - actionType: playbook
       action: enable-repo.yml  # 在部署集群前, 先执行 enable-repo 的 playbook, 为每个节点创建指定 url 的源配置
       extraArgs: |
-        -e "{yum_repo_url_list: ['http://10.20.30.40:9000/centos/\$releasever/os/\$basearch']}"
+        -e "{yum_repo_url_list: ['http://10.20.30.40:9000/kubean/centos/\$releasever/os/\$basearch']}"
     - actionType: playbook
       action: disable-firewalld.yml
   postHook:
@@ -212,7 +212,7 @@ spec:
 registry_host: "{{ registry_address }}"
 
 ### 配置二进制文件服务的地址
-files_repo: "{{ minio_address }}"
+files_repo: "{{ minio_address }}/kubean"
 
 ### 如果使用 CentOS / RedHat / AlmaLinux / Fedora, 需要配置 yum 源文件服务地址:
 yum_repo: "{{ minio_address }}"
diff --git a/pkg/controllers/infomanifest/controller.go b/pkg/controllers/infomanifest/controller.go
index de229c8df..9503b57d3 100644
--- a/pkg/controllers/infomanifest/controller.go
+++ b/pkg/controllers/infomanifest/controller.go
@@ -172,7 +172,7 @@ func (c *Controller) UpdateLocalAvailableImage() {
 		klog.Warningf("ignoring %s", err.Error())
 		return
 	}
-	imageRepo := "ghcr.io"
+	imageRepo := "ghcr.m.daocloud.io"
 	if len(global.Spec.LocalService.RegistryRepo) != 0 {
 		imageRepo = global.Spec.LocalService.RegistryRepo
 	}


Test patch:
diff --git a/pkg/controllers/infomanifest/controller_test.go b/pkg/controllers/infomanifest/controller_test.go
index 047df3c69..a409a1db1 100644
--- a/pkg/controllers/infomanifest/controller_test.go
+++ b/pkg/controllers/infomanifest/controller_test.go
@@ -414,7 +414,7 @@ func Test_UpdateLocalAvailableImage(t *testing.T) {
 				controller.InfoManifestClientSet.KubeanV1alpha1().KubeanInfoManifests().Create(context.Background(), global, metav1.CreateOptions{})
 				controller.UpdateLocalAvailableImage()
 			},
-			want: "ghcr.io/kubean-io/spray-job:123",
+			want: "ghcr.m.daocloud.io/kubean-io/spray-job:123",
 		},
 		{
 			name: "update local kubespray image with local registry",