when cluster is not-ready doesn't cleanup MultiClusterService and EndpointSlice work

Signed-off-by: changzhen <changzhen5@huawei.com>
This commit is contained in:
changzhen 2025-04-02 16:04:41 +08:00
parent 5f258dd8b3
commit 2667cef349
2 changed files with 1 additions and 78 deletions

View File

@ -149,7 +149,7 @@ func (c *MCSController) retrieveMultiClusterService(ctx context.Context, mcs *ne
continue continue
} }
if providerClusters.Has(clusterName) && c.IsClusterReady(ctx, clusterName) { if providerClusters.Has(clusterName) {
continue continue
} }
@ -524,17 +524,6 @@ func (c *MCSController) updateMultiClusterServiceStatus(ctx context.Context, mcs
}) })
} }
// IsClusterReady checks whether the cluster is ready.
func (c *MCSController) IsClusterReady(ctx context.Context, clusterName string) bool {
cluster := &clusterv1alpha1.Cluster{}
if err := c.Client.Get(ctx, types.NamespacedName{Name: clusterName}, cluster); err != nil {
klog.Errorf("Failed to get cluster object(%s):%v", clusterName, err)
return false
}
return util.IsClusterReady(&cluster.Status)
}
// SetupWithManager creates a controller and register to controller manager. // SetupWithManager creates a controller and register to controller manager.
func (c *MCSController) SetupWithManager(mgr controllerruntime.Manager) error { func (c *MCSController) SetupWithManager(mgr controllerruntime.Manager) error {
mcsPredicateFunc := predicate.Funcs{ mcsPredicateFunc := predicate.Funcs{

View File

@ -727,72 +727,6 @@ func TestClaimMultiClusterServiceForService(t *testing.T) {
} }
} }
func TestIsClusterReady(t *testing.T) {
tests := []struct {
name string
clusterName string
clusterObj *clusterv1alpha1.Cluster
expectedReady bool
}{
{
name: "cluster is ready",
clusterName: "ready-cluster",
clusterObj: &clusterv1alpha1.Cluster{
ObjectMeta: metav1.ObjectMeta{
Name: "ready-cluster",
},
Status: clusterv1alpha1.ClusterStatus{
Conditions: []metav1.Condition{
{
Type: clusterv1alpha1.ClusterConditionReady,
Status: metav1.ConditionTrue,
},
},
},
},
expectedReady: true,
},
{
name: "cluster is not ready",
clusterName: "not-ready-cluster",
clusterObj: &clusterv1alpha1.Cluster{
ObjectMeta: metav1.ObjectMeta{
Name: "not-ready-cluster",
},
Status: clusterv1alpha1.ClusterStatus{
Conditions: []metav1.Condition{
{
Type: clusterv1alpha1.ClusterConditionReady,
Status: metav1.ConditionFalse,
},
},
},
},
expectedReady: false,
},
{
name: "cluster does not exist",
clusterName: "non-existent-cluster",
clusterObj: nil,
expectedReady: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
var objects []runtime.Object
if tt.clusterObj != nil {
objects = append(objects, tt.clusterObj)
}
controller := newFakeController(objects...)
ready := controller.IsClusterReady(context.Background(), tt.clusterName)
assert.Equal(t, tt.expectedReady, ready, "IsClusterReady() result does not match expected")
})
}
}
func TestServiceHasCrossClusterMultiClusterService(t *testing.T) { func TestServiceHasCrossClusterMultiClusterService(t *testing.T) {
tests := []struct { tests := []struct {
name string name string