diff --git a/cmd/controller-manager/app/controllermanager.go b/cmd/controller-manager/app/controllermanager.go index f9bc837637d8..74c1589581f7 100644 --- a/cmd/controller-manager/app/controllermanager.go +++ b/cmd/controller-manager/app/controllermanager.go @@ -492,7 +492,6 @@ func startEndpointSliceSyncController(ctx controllerscontext.Context) (enabled b return false, err } return true, nil - } func startEndpointSliceController(ctx controllerscontext.Context) (enabled bool, err error) { diff --git a/pkg/apis/networking/v1alpha1/service_types.go b/pkg/apis/networking/v1alpha1/service_types.go index 59374bb0f5a6..7a1d6a62e12d 100644 --- a/pkg/apis/networking/v1alpha1/service_types.go +++ b/pkg/apis/networking/v1alpha1/service_types.go @@ -32,6 +32,10 @@ const ( ResourceNamespaceScopedMultiClusterService = true // ServiceApplied indicates whether the service is propagated to member clusters ServiceApplied string = "ServiceApplied" + // EndpointSliceCollected indicates whether the endpointslice is collected from provision clusters + EndpointSliceCollected string = "EndpointSliceCollected" + // EndpointSliceSynced indicates whether the EndpointSlice is synced to consumption clusters + EndpointSliceSynced string = "EndpointSliceSynced" ) // +genclient diff --git a/pkg/controllers/mcsendpointslice/endpointslicecollect_controller.go b/pkg/controllers/mcsendpointslice/endpointslicecollect_controller.go index 0d26d10cb442..2fbb268eeb61 100644 --- a/pkg/controllers/mcsendpointslice/endpointslicecollect_controller.go +++ b/pkg/controllers/mcsendpointslice/endpointslicecollect_controller.go @@ -101,6 +101,10 @@ func (c *EndpointSliceCollectController) Reconcile(ctx context.Context, req cont return controllerruntime.Result{}, nil } + if !helper.MultiClusterServiceCrossClusterEnabled(mcs) { + return controllerruntime.Result{}, nil + } + var err error defer func() { if err != nil { @@ -108,7 +112,7 @@ func (c *EndpointSliceCollectController) Reconcile(ctx context.Context, req cont c.EventRecorder.Eventf(mcs, corev1.EventTypeWarning, events.EventReasonCollectEndpointSliceFailed, err.Error()) return } - _ = c.updateEndpointSliceCollected(mcs, metav1.ConditionFalse, "EndpointSliceCollectedSucceed", "EndpointSlice are collected successfully") + _ = c.updateEndpointSliceCollected(mcs, metav1.ConditionTrue, "EndpointSliceCollectedSucceed", "EndpointSlice are collected successfully") c.EventRecorder.Eventf(mcs, corev1.EventTypeNormal, events.EventReasonCollectEndpointSliceSucceed, "EndpointSlice are collected successfully") }() @@ -479,7 +483,7 @@ func (c *EndpointSliceCollectController) reportEndpointSliceWithEndpointSliceCre func (c *EndpointSliceCollectController) updateEndpointSliceCollected(mcs *networkingv1alpha1.MultiClusterService, status metav1.ConditionStatus, reason, message string) error { EndpointSliceCollected := metav1.Condition{ - Type: workv1alpha1.WorkApplied, + Type: networkingv1alpha1.EndpointSliceCollected, Status: status, Reason: reason, Message: message, @@ -511,6 +515,8 @@ func reportEndpointSlice(c client.Client, endpointSlice *unstructured.Unstructur Name: names.GenerateMCSWorkName(endpointSlice.GetKind(), endpointSlice.GetName(), endpointSlice.GetNamespace(), clusterName), Namespace: executionSpace, Labels: map[string]string{ + util.ServiceNamespaceLabel: endpointSlice.GetNamespace(), + util.ServiceNameLabel: endpointSlice.GetLabels()[discoveryv1.LabelServiceName], networkingv1alpha1.MultiClusterServicePermanentIDLabel: util.GetLabelValue(mcs.Labels, networkingv1alpha1.MultiClusterServicePermanentIDLabel), // indicate the Work should be not propagated since it's collected resource. util.PropagationInstruction: util.PropagationInstructionSuppressed, diff --git a/pkg/controllers/mcsendpointslice/endpointslicesync_controller.go b/pkg/controllers/mcsendpointslice/endpointslicesync_controller.go index fb2854c83224..0e4df3f2e520 100644 --- a/pkg/controllers/mcsendpointslice/endpointslicesync_controller.go +++ b/pkg/controllers/mcsendpointslice/endpointslicesync_controller.go @@ -91,10 +91,11 @@ func (c *EndpointsliceSyncController) Reconcile(ctx context.Context, req control defer func() { if err != nil { _ = c.updateEndpointSliceSynced(mcs, metav1.ConditionFalse, "EndpointSliceSyncFailed", err.Error()) - c.EventRecorder.Eventf(mcs, corev1.EventTypeWarning, events.EventReasonScheduleBindingFailed, err.Error()) + c.EventRecorder.Eventf(mcs, corev1.EventTypeWarning, events.EventReasonSyncEndpointSliceFailed, err.Error()) + return } - _ = c.updateEndpointSliceSynced(mcs, metav1.ConditionFalse, "EndpointSliceSyncSucceed", "EndpointSlice are synced successfully") - c.EventRecorder.Eventf(mcs, corev1.EventTypeWarning, events.EventReasonScheduleBindingSucceed, "EndpointSlice are synced successfully") + _ = c.updateEndpointSliceSynced(mcs, metav1.ConditionTrue, "EndpointSliceSyncSucceed", "EndpointSlice are synced successfully") + c.EventRecorder.Eventf(mcs, corev1.EventTypeWarning, events.EventReasonSyncEndpointSliceFailed, "EndpointSlice are synced successfully") }() // TDB: When cluster range changes in mcs, we should delete/create the corresponding work @@ -107,7 +108,7 @@ func (c *EndpointsliceSyncController) Reconcile(ctx context.Context, req control func (c *EndpointsliceSyncController) updateEndpointSliceSynced(mcs *networkingv1alpha1.MultiClusterService, status metav1.ConditionStatus, reason, message string) error { EndpointSliceCollected := metav1.Condition{ - Type: workv1alpha1.WorkApplied, + Type: networkingv1alpha1.EndpointSliceSynced, Status: status, Reason: reason, Message: message, diff --git a/pkg/util/helper/mcs.go b/pkg/util/helper/mcs.go index 3ac65583da87..a81470cfb77c 100644 --- a/pkg/util/helper/mcs.go +++ b/pkg/util/helper/mcs.go @@ -99,3 +99,13 @@ func DeleteEndpointSlice(c client.Client, selector labels.Set) error { func IsServiceApplied(mcsStatus *corev1.ServiceStatus) bool { return meta.IsStatusConditionTrue(mcsStatus.Conditions, networkingv1alpha1.ServiceApplied) } + +func MultiClusterServiceCrossClusterEnabled(mcs *networkingv1alpha1.MultiClusterService) bool { + for _, svcType := range mcs.Spec.Types { + if svcType == networkingv1alpha1.ExposureTypeCrossCluster { + return true + } + } + + return false +} diff --git a/pkg/webhook/multiclusterservice/mutating.go b/pkg/webhook/multiclusterservice/mutating.go index 4504f81cff5a..e9b7e8c8daec 100644 --- a/pkg/webhook/multiclusterservice/mutating.go +++ b/pkg/webhook/multiclusterservice/mutating.go @@ -22,9 +22,10 @@ import ( "net/http" "github.com/google/uuid" + "sigs.k8s.io/controller-runtime/pkg/webhook/admission" + networkingv1alpha1 "github.com/karmada-io/karmada/pkg/apis/networking/v1alpha1" "github.com/karmada-io/karmada/pkg/util" - "sigs.k8s.io/controller-runtime/pkg/webhook/admission" ) // MutatingAdmission mutates API request if necessary.