Repository: kubean-io/kubean (go)

Issue:
feature：kubean pod log optimize
kubean-localservice cm in the follow log picture
online mode:  is not expected to be showed
offline mode:  is expected to be showed

![企业微信截图_7dd08fe2-d947-4423-a4c6-7492f44f6b7d](https://user-images.githubusercontent.com/99961476/204423983-595493f5-f89b-4470-8876-7f28cba6024b.png)


Pull request description:
optimize logs output
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**:

* fix #353 , optimize logs output 

**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/cmd/kubean-operator/app/app.go b/cmd/kubean-operator/app/app.go
index 51423711f..5b945ea1b 100644
--- a/cmd/kubean-operator/app/app.go
+++ b/cmd/kubean-operator/app/app.go
@@ -157,9 +157,10 @@ func setupManager(mgr controllerruntime.Manager, opt *Options, stopChan <-chan s
 	}
 
 	infomanifestController := &infomanifest.Controller{
-		Client:                mgr.GetClient(),
-		InfoManifestClientSet: infomanifestClientSet,
-		ClientSet:             ClientSet,
+		Client:                  mgr.GetClient(),
+		InfoManifestClientSet:   infomanifestClientSet,
+		ClientSet:               ClientSet,
+		OfflineversionClientSet: offlineversionClientSet,
 	}
 	if err := infomanifestController.SetupWithManager(mgr); err != nil {
 		klog.Errorf("ControllerManager Infomanifest but %s", err)
diff --git a/docs/zh/airgap_patch_usage.md b/docs/zh/airgap_patch_usage.md
index 944851f47..ca9bb4ab3 100644
--- a/docs/zh/airgap_patch_usage.md
+++ b/docs/zh/airgap_patch_usage.md
@@ -33,7 +33,7 @@
 3. 使用镜像，等待运行退出后，`data` 文件夹中生成增量离线包
 
     ```bash
-    docker run -v $(pwd)/manifest.yml:/manifest.yml -v $(pwd)/data:/data ghcr.io/kubean-io/airgap-patch:v0.4.0-rc5 
+    docker run -v $(pwd)/manifest.yml:/manifest.yml -v $(pwd)/data:/data ghcr.io/hangscer8/airgap-patch:v0.2.2
     ```
 
 ## 使用增量离线包
diff --git a/pkg/controllers/infomanifest/controller.go b/pkg/controllers/infomanifest/controller.go
index 41b8aef8b..eff9ef08c 100644
--- a/pkg/controllers/infomanifest/controller.go
+++ b/pkg/controllers/infomanifest/controller.go
@@ -18,6 +18,7 @@ import (
 	"k8s.io/klog/v2"
 	manifestv1alpha1 "kubean.io/api/apis/manifest/v1alpha1"
 	"kubean.io/api/constants"
+	localartifactsetClientSet "kubean.io/api/generated/localartifactset/clientset/versioned"
 	manifestClientSet "kubean.io/api/generated/manifest/clientset/versioned"
 	controllerruntime "sigs.k8s.io/controller-runtime"
 	"sigs.k8s.io/controller-runtime/pkg/client"
@@ -31,8 +32,9 @@ const LocalServiceConfigMap = "kubean-localservice"
 
 type Controller struct {
 	client.Client
-	InfoManifestClientSet manifestClientSet.Interface
-	ClientSet             kubernetes.Interface
+	InfoManifestClientSet   manifestClientSet.Interface
+	ClientSet               kubernetes.Interface
+	OfflineversionClientSet localartifactsetClientSet.Interface
 }
 
 func (c *Controller) Start(ctx context.Context) error {
@@ -141,6 +143,10 @@ func (c *Controller) ParseConfigMapToLocalService(localServiceConfigMap *corev1.
 }
 
 func (c *Controller) UpdateGlobalLocalService() {
+	if c.IsOnlineENV() {
+		// if not airgap env , then do nothing and return
+		return
+	}
 	localServiceConfigMap, err := c.FetchLocalServiceCM(util.GetCurrentNSOrDefault())
 	if err != nil {
 		klog.Warningf("ignoring %s", err.Error())
@@ -166,6 +172,7 @@ func (c *Controller) UpdateGlobalLocalService() {
 	}
 }
 
+// UpdateLocalAvailableImage update image infos to global-infomanifest-cr.
 func (c *Controller) UpdateLocalAvailableImage() {
 	global, err := c.FetchGlobalInfoManifest()
 	if err != nil {
@@ -187,11 +194,24 @@ func (c *Controller) UpdateLocalAvailableImage() {
 	}
 }
 
+// IsOnlineENV indicates what the running env is onLine or air-gap.
+func (c *Controller) IsOnlineENV() bool {
+	result, err := c.OfflineversionClientSet.KubeanV1alpha1().LocalArtifactSets().List(context.Background(), metav1.ListOptions{})
+	if err != nil {
+		klog.Errorf("%s ", err.Error())
+		return true
+	}
+	if len(result.Items) == 0 {
+		return true
+	}
+	return false
+}
+
 func (c *Controller) Reconcile(ctx context.Context, req controllerruntime.Request) (controllerruntime.Result, error) {
 	if req.Name == constants.InfoManifestGlobal {
 		return controllerruntime.Result{Requeue: false}, nil
 	}
-	klog.Warningf("InfoManifest Controller receive event %s", req.Name)
+	klog.Infof("InfoManifest Controller receive event %s", req.Name)
 	latestInfoManifest, err := c.FetchLatestInfoManifest()
 	if err != nil {
 		klog.Warningf("%s ", err.Error())


Test patch:
diff --git a/pkg/controllers/infomanifest/controller_test.go b/pkg/controllers/infomanifest/controller_test.go
index 314109dd5..44cdfe19f 100644
--- a/pkg/controllers/infomanifest/controller_test.go
+++ b/pkg/controllers/infomanifest/controller_test.go
@@ -17,6 +17,7 @@ import (
 	localartifactsetv1alpha1 "kubean.io/api/apis/localartifactset/v1alpha1"
 	manifestv1alpha1 "kubean.io/api/apis/manifest/v1alpha1"
 	"kubean.io/api/constants"
+	localartifactsetv1alpha1fake "kubean.io/api/generated/localartifactset/clientset/versioned/fake"
 	manifestv1alpha1fake "kubean.io/api/generated/manifest/clientset/versioned/fake"
 )
 
@@ -284,9 +285,10 @@ func Test_EnsureGlobalInfoManifestBeingLatest(t *testing.T) {
 
 func Test_UpdateGlobalLocalService1(t *testing.T) {
 	controller := &Controller{
-		Client:                newFakeClient(),
-		ClientSet:             clientsetfake.NewSimpleClientset(),
-		InfoManifestClientSet: manifestv1alpha1fake.NewSimpleClientset(),
+		Client:                  newFakeClient(),
+		ClientSet:               clientsetfake.NewSimpleClientset(),
+		InfoManifestClientSet:   manifestv1alpha1fake.NewSimpleClientset(),
+		OfflineversionClientSet: localartifactsetv1alpha1fake.NewSimpleClientset(),
 	}
 	tests := []struct {
 		name string
@@ -316,6 +318,7 @@ func Test_UpdateGlobalLocalService1(t *testing.T) {
 					},
 					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'"},
 				}
+				addLocalArtifactSet(controller)
 				controller.ClientSet.CoreV1().ConfigMaps("default").Create(context.Background(), configMap, metav1.CreateOptions{})
 				controller.Create(context.Background(), global)
 				controller.InfoManifestClientSet.KubeanV1alpha1().Manifests().Create(context.Background(), global, metav1.CreateOptions{})
@@ -362,6 +365,7 @@ func Test_UpdateGlobalLocalService1(t *testing.T) {
 					},
 					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'"},
 				}
+				addLocalArtifactSet(controller)
 				controller.ClientSet.CoreV1().ConfigMaps("default").Update(context.Background(), configMap, metav1.UpdateOptions{})
 				controller.Create(context.Background(), global)
 				controller.InfoManifestClientSet.KubeanV1alpha1().Manifests().Create(context.Background(), global, metav1.CreateOptions{})
@@ -536,3 +540,57 @@ func TestNewGlobalInfoManifest(t *testing.T) {
 		})
 	}
 }
+
+func addLocalArtifactSet(controller *Controller) {
+	set := &localartifactsetv1alpha1.LocalArtifactSet{
+		ObjectMeta: metav1.ObjectMeta{
+			Name: "set-1",
+		},
+		Spec: localartifactsetv1alpha1.Spec{
+			Items: []*localartifactsetv1alpha1.SoftwareInfo{
+				{
+					Name:         "etcd-1",
+					VersionRange: []string{"1.1", "1.2"},
+				},
+			},
+		},
+	}
+	controller.OfflineversionClientSet.KubeanV1alpha1().LocalArtifactSets().Create(context.Background(), set, metav1.CreateOptions{})
+}
+
+func TestIsOnlineENV(t *testing.T) {
+	controller := &Controller{
+		Client:                  newFakeClient(),
+		ClientSet:               clientsetfake.NewSimpleClientset(),
+		InfoManifestClientSet:   manifestv1alpha1fake.NewSimpleClientset(),
+		OfflineversionClientSet: localartifactsetv1alpha1fake.NewSimpleClientset(),
+	}
+	tests := []struct {
+		name string
+		args func() bool
+		want bool
+	}{
+		{
+			name: "list nothing",
+			args: func() bool {
+				return controller.IsOnlineENV()
+			},
+			want: true,
+		},
+		{
+			name: "airgap env",
+			args: func() bool {
+				addLocalArtifactSet(controller)
+				return controller.IsOnlineENV()
+			},
+			want: false,
+		},
+	}
+	for _, test := range tests {
+		t.Run(test.name, func(t *testing.T) {
+			if test.args() != test.want {
+				t.Fatal()
+			}
+		})
+	}
+}