From 7cdf67f9f27a019c94aace621b04dba86d2e4552 Mon Sep 17 00:00:00 2001 From: zryfish Date: Wed, 6 May 2020 10:52:56 +0800 Subject: [PATCH] fix generation bug (#2047) --- pkg/kapis/cluster/v1alpha1/handler.go | 22 +++++++++++++++++++--- pkg/kapis/cluster/v1alpha1/handler_test.go | 13 ++++++++++++- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/pkg/kapis/cluster/v1alpha1/handler.go b/pkg/kapis/cluster/v1alpha1/handler.go index f74da788..9c95eee4 100644 --- a/pkg/kapis/cluster/v1alpha1/handler.go +++ b/pkg/kapis/cluster/v1alpha1/handler.go @@ -131,6 +131,10 @@ func (h *handler) populateProxyAddress() error { return nil } +// Currently, this method works because of serviceaccount/clusterrole/clusterrolebinding already +// created by kubesphere, we don't need to create them again. And it's a little bit inconvenient +// if we want to change the template. +// TODO(jeff): load template from configmap func (h *handler) generateDefaultDeployment(cluster *v1alpha1.Cluster, w io.Writer) error { if cluster.Spec.Connection.Type == v1alpha1.ConnectionTypeDirect { @@ -143,12 +147,24 @@ func (h *handler) generateDefaultDeployment(cluster *v1alpha1.Cluster, w io.Writ APIVersion: "apps/v1", }, ObjectMeta: metav1.ObjectMeta{ - Name: "cluster-agent", + Name: "cluster-agent", + Namespace: "kubesphere-system", }, Spec: appsv1.DeploymentSpec{ - Selector: &metav1.LabelSelector{}, + Selector: &metav1.LabelSelector{ + MatchLabels: map[string]string{ + "app": "agent", + "app.kubernetes.io/part-of": "tower", + }, + }, + Strategy: appsv1.DeploymentStrategy{}, Template: corev1.PodTemplateSpec{ - ObjectMeta: metav1.ObjectMeta{}, + ObjectMeta: metav1.ObjectMeta{ + Labels: map[string]string{ + "app": "agent", + "app.kubernetes.io/part-of": "tower", + }, + }, Spec: corev1.PodSpec{ Containers: []corev1.Container{ { diff --git a/pkg/kapis/cluster/v1alpha1/handler_test.go b/pkg/kapis/cluster/v1alpha1/handler_test.go index 4467757d..19013415 100644 --- a/pkg/kapis/cluster/v1alpha1/handler_test.go +++ b/pkg/kapis/cluster/v1alpha1/handler_test.go @@ -61,12 +61,19 @@ kind: Deployment metadata: creationTimestamp: null name: cluster-agent + namespace: kubesphere-system spec: - selector: {} + selector: + matchLabels: + app: agent + app.kubernetes.io/part-of: tower strategy: {} template: metadata: creationTimestamp: null + labels: + app: agent + app.kubernetes.io/part-of: tower spec: containers: - command: @@ -146,6 +153,10 @@ func TestGeranteAgentDeployment(t *testing.T) { t.Fatalf("expecting error %v, got %v", testCase.expectedError, err) } } + + if diff := cmp.Diff(testCase.expected, buf.String()); len(diff) != 0 { + t.Errorf("%T, got +, expected -, %s", testCase.expected, diff) + } }) } -- GitLab