fix generation bug (#2047)

This commit is contained in:
zryfish
2020-05-06 10:52:56 +08:00
committed by GitHub
parent 3ff82c7299
commit 7cdf67f9f2
2 changed files with 31 additions and 4 deletions

View File

@@ -131,6 +131,10 @@ func (h *handler) populateProxyAddress() error {
return nil 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 { func (h *handler) generateDefaultDeployment(cluster *v1alpha1.Cluster, w io.Writer) error {
if cluster.Spec.Connection.Type == v1alpha1.ConnectionTypeDirect { if cluster.Spec.Connection.Type == v1alpha1.ConnectionTypeDirect {
@@ -143,12 +147,24 @@ func (h *handler) generateDefaultDeployment(cluster *v1alpha1.Cluster, w io.Writ
APIVersion: "apps/v1", APIVersion: "apps/v1",
}, },
ObjectMeta: metav1.ObjectMeta{ ObjectMeta: metav1.ObjectMeta{
Name: "cluster-agent", Name: "cluster-agent",
Namespace: "kubesphere-system",
}, },
Spec: appsv1.DeploymentSpec{ 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{ Template: corev1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{}, ObjectMeta: metav1.ObjectMeta{
Labels: map[string]string{
"app": "agent",
"app.kubernetes.io/part-of": "tower",
},
},
Spec: corev1.PodSpec{ Spec: corev1.PodSpec{
Containers: []corev1.Container{ Containers: []corev1.Container{
{ {

View File

@@ -61,12 +61,19 @@ kind: Deployment
metadata: metadata:
creationTimestamp: null creationTimestamp: null
name: cluster-agent name: cluster-agent
namespace: kubesphere-system
spec: spec:
selector: {} selector:
matchLabels:
app: agent
app.kubernetes.io/part-of: tower
strategy: {} strategy: {}
template: template:
metadata: metadata:
creationTimestamp: null creationTimestamp: null
labels:
app: agent
app.kubernetes.io/part-of: tower
spec: spec:
containers: containers:
- command: - command:
@@ -146,6 +153,10 @@ func TestGeranteAgentDeployment(t *testing.T) {
t.Fatalf("expecting error %v, got %v", testCase.expectedError, err) 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)
}
}) })
} }