Merge pull request #6258 from XiShanYongYe-Chang/fix-6255
when cluster is not-ready doesn't cleanup MultiClusterService and EndpointSlice work
This commit is contained in:
commit
f4773821b7
|
@ -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{
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue