Skip to content

Commit

Permalink
v1
Browse files Browse the repository at this point in the history
Signed-off-by: jwcesign <[email protected]>
  • Loading branch information
jwcesign committed Nov 27, 2023
1 parent e59b884 commit 02b9ff4
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 8 deletions.
1 change: 0 additions & 1 deletion cmd/controller-manager/app/controllermanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 4 additions & 0 deletions pkg/apis/networking/v1alpha1/service_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,18 @@ 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 {
_ = c.updateEndpointSliceCollected(mcs, metav1.ConditionFalse, "EndpointSliceCollectedFailed", err.Error())
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")
}()

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down
10 changes: 10 additions & 0 deletions pkg/util/helper/mcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
3 changes: 2 additions & 1 deletion pkg/webhook/multiclusterservice/mutating.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 02b9ff4

Please sign in to comment.