Skip to content

Commit faecc6a

Browse files
fix argocd controller
Signed-off-by: stoneshi-yunify <stoneshi@kubesphere.io>
1 parent 0d504b8 commit faecc6a

4 files changed

Lines changed: 0 additions & 112 deletions

File tree

controllers/argocd/multi-cluster-controller.go

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,6 @@ func (r *MultiClusterReconciler) Reconcile(ctx context.Context, req ctrl.Request
6262
}
6363
}
6464

65-
// ignore the host cluster
66-
if ignore(cluster) {
67-
return
68-
}
69-
7065
ownerRef := getOwnerReference(cluster)
7166
argoCluster := createArgoCluster(cluster)
7267
argoCluster.SetNamespace(r.argocdNamespace)
@@ -196,14 +191,6 @@ func getCluster(client client.Reader, namespacedName types.NamespacedName) (clus
196191
return
197192
}
198193

199-
func ignore(cluster *unstructured.Unstructured) bool {
200-
if cluster != nil {
201-
_, ok := cluster.GetLabels()["cluster-role.kubesphere.io/host"]
202-
return ok
203-
}
204-
return true
205-
}
206-
207194
// GetName returns the name of this controller
208195
func (r *MultiClusterReconciler) GetName() string {
209196
return "ArgoCDMultiClusterController"

controllers/argocd/multi-cluster-controller_test.go

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -37,49 +37,6 @@ import (
3737
"sigs.k8s.io/controller-runtime/pkg/client/fake"
3838
)
3939

40-
func Test_ignore(t *testing.T) {
41-
sampleCluster := &unstructured.Unstructured{}
42-
sampleCluster.SetKind("Cluster")
43-
sampleCluster.SetAPIVersion("cluster.kubesphere.io/v1alpha1")
44-
45-
type args struct {
46-
cluster func() *unstructured.Unstructured
47-
}
48-
tests := []struct {
49-
name string
50-
args args
51-
want bool
52-
}{{
53-
name: "cluster is nil",
54-
want: true,
55-
}, {
56-
name: "cluster without the particular label",
57-
args: args{cluster: func() *unstructured.Unstructured {
58-
return sampleCluster.DeepCopy()
59-
}},
60-
want: false,
61-
}, {
62-
name: "with the particular label",
63-
args: args{cluster: func() *unstructured.Unstructured {
64-
cluster := sampleCluster.DeepCopy()
65-
cluster.SetLabels(map[string]string{
66-
"cluster-role.kubesphere.io/host": "",
67-
})
68-
return cluster
69-
}},
70-
want: true,
71-
}}
72-
for _, tt := range tests {
73-
t.Run(tt.name, func(t *testing.T) {
74-
var cluster *unstructured.Unstructured
75-
if tt.args.cluster != nil {
76-
cluster = tt.args.cluster()
77-
}
78-
assert.Equalf(t, tt.want, ignore(cluster), "ignore(%v)", tt.args.cluster)
79-
})
80-
}
81-
}
82-
8340
func Test_createArgoCluster(t *testing.T) {
8441
defaultCluster := &unstructured.Unstructured{}
8542
defaultCluster.SetKind("Cluster")

controllers/fluxcd/multi-cluster-controller.go

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -57,26 +57,13 @@ func (r *MultiClusterReconciler) Reconcile(ctx context.Context, req ctrl.Request
5757
return
5858
}
5959

60-
// ignore the host cluster
61-
if ignore(cluster) {
62-
return
63-
}
64-
6560
if err = r.reconcileCluster(ctx, cluster); err != nil {
6661
return
6762
}
6863

6964
return
7065
}
7166

72-
func ignore(cluster *unstructured.Unstructured) bool {
73-
if cluster != nil {
74-
_, ok := cluster.GetLabels()["cluster-role.kubesphere.io/host"]
75-
return ok
76-
}
77-
return true
78-
}
79-
8067
func (r *MultiClusterReconciler) reconcileCluster(ctx context.Context, cluster *unstructured.Unstructured) (err error) {
8168
name := cluster.GetName()
8269
nsList := &v1.NamespaceList{}

controllers/fluxcd/multi-cluster-controller_test.go

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -37,49 +37,6 @@ import (
3737
"sigs.k8s.io/controller-runtime/pkg/log"
3838
)
3939

40-
func Test_ignore(t *testing.T) {
41-
sampleCluster := &unstructured.Unstructured{}
42-
sampleCluster.SetKind("Cluster")
43-
sampleCluster.SetAPIVersion("cluster.kubesphere.io/v1alpha1")
44-
45-
type args struct {
46-
cluster func() *unstructured.Unstructured
47-
}
48-
tests := []struct {
49-
name string
50-
args args
51-
want bool
52-
}{{
53-
name: "cluster is nil",
54-
want: true,
55-
}, {
56-
name: "cluster without the particular label",
57-
args: args{cluster: func() *unstructured.Unstructured {
58-
return sampleCluster.DeepCopy()
59-
}},
60-
want: false,
61-
}, {
62-
name: "with the particular label",
63-
args: args{cluster: func() *unstructured.Unstructured {
64-
cluster := sampleCluster.DeepCopy()
65-
cluster.SetLabels(map[string]string{
66-
"cluster-role.kubesphere.io/host": "",
67-
})
68-
return cluster
69-
}},
70-
want: true,
71-
}}
72-
for _, tt := range tests {
73-
t.Run(tt.name, func(t *testing.T) {
74-
var cluster *unstructured.Unstructured
75-
if tt.args.cluster != nil {
76-
cluster = tt.args.cluster()
77-
}
78-
assert.Equalf(t, tt.want, ignore(cluster), "ignore(%v)", tt.args.cluster)
79-
})
80-
}
81-
}
82-
8340
func TestMultiClusterReconciler_Reconcile(t *testing.T) {
8441
schema, err := v1alpha1.SchemeBuilder.Register().Build()
8542
assert.Nil(t, err)

0 commit comments

Comments
 (0)