Merge pull request #4433 from jwcesign/report-event
feat: report event when the service doesn't exist/when endpointslice api is disabled
This commit is contained in:
commit
515594592b
|
@ -52,10 +52,6 @@ import (
|
||||||
// EndpointsliceDispatchControllerName is the controller name that will be used when reporting events.
|
// EndpointsliceDispatchControllerName is the controller name that will be used when reporting events.
|
||||||
const EndpointsliceDispatchControllerName = "endpointslice-dispatch-controller"
|
const EndpointsliceDispatchControllerName = "endpointslice-dispatch-controller"
|
||||||
|
|
||||||
var (
|
|
||||||
endpointSliceGVK = discoveryv1.SchemeGroupVersion.WithKind("EndpointSlice")
|
|
||||||
)
|
|
||||||
|
|
||||||
type EndpointsliceDispatchController struct {
|
type EndpointsliceDispatchController struct {
|
||||||
client.Client
|
client.Client
|
||||||
EventRecorder record.EventRecorder
|
EventRecorder record.EventRecorder
|
||||||
|
@ -75,7 +71,7 @@ func (c *EndpointsliceDispatchController) Reconcile(ctx context.Context, req con
|
||||||
return controllerruntime.Result{Requeue: true}, err
|
return controllerruntime.Result{Requeue: true}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if !helper.IsWorkContains(work.Spec.Workload.Manifests, endpointSliceGVK) {
|
if !helper.IsWorkContains(work.Spec.Workload.Manifests, util.EndpointSliceGVK) {
|
||||||
return controllerruntime.Result{}, nil
|
return controllerruntime.Result{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -191,7 +187,7 @@ func (c *EndpointsliceDispatchController) newClusterFunc() handler.MapFunc {
|
||||||
|
|
||||||
var requests []reconcile.Request
|
var requests []reconcile.Request
|
||||||
for _, mcs := range mcsList.Items {
|
for _, mcs := range mcsList.Items {
|
||||||
clusterSet, _, err := helper.GetConsumerClustres(c.Client, mcs.DeepCopy())
|
clusterSet, err := helper.GetConsumerClusters(c.Client, mcs.DeepCopy())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
klog.Errorf("Failed to get provider clusters, error: %v", err)
|
klog.Errorf("Failed to get provider clusters, error: %v", err)
|
||||||
continue
|
continue
|
||||||
|
@ -283,7 +279,7 @@ func (c *EndpointsliceDispatchController) cleanOrphanDispatchedEndpointSlice(ctx
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
consumerClusters, _, err := helper.GetConsumerClustres(c.Client, mcs)
|
consumerClusters, err := helper.GetConsumerClusters(c.Client, mcs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
klog.Errorf("Failed to get consumer clusters, error is: %v", err)
|
klog.Errorf("Failed to get consumer clusters, error is: %v", err)
|
||||||
return err
|
return err
|
||||||
|
@ -315,7 +311,7 @@ func (c *EndpointsliceDispatchController) dispatchEndpointSlice(ctx context.Cont
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
consumerClusters, _, err := helper.GetConsumerClustres(c.Client, mcs)
|
consumerClusters, err := helper.GetConsumerClusters(c.Client, mcs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
klog.Errorf("Failed to get consumer clusters, error is: %v", err)
|
klog.Errorf("Failed to get consumer clusters, error is: %v", err)
|
||||||
return err
|
return err
|
||||||
|
@ -324,10 +320,45 @@ func (c *EndpointsliceDispatchController) dispatchEndpointSlice(ctx context.Cont
|
||||||
if clusterName == epsSourceCluster {
|
if clusterName == epsSourceCluster {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
clusterObj, err := util.GetCluster(c.Client, clusterName)
|
||||||
|
if err != nil {
|
||||||
|
if apierrors.IsNotFound(err) {
|
||||||
|
c.EventRecorder.Eventf(mcs, corev1.EventTypeWarning, events.EventReasonClusterNotFound, "Consumer cluster %s is not found", clusterName)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
klog.Errorf("Failed to get cluster %s, error is: %v", clusterName, err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if !util.IsClusterReady(&clusterObj.Status) {
|
||||||
|
c.EventRecorder.Eventf(mcs, corev1.EventTypeWarning, events.EventReasonSyncServiceFailed,
|
||||||
|
"Consumer cluster %s is not ready, skip to propagate EndpointSlice", clusterName)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if !helper.IsAPIEnabled(clusterObj.Status.APIEnablements, util.EndpointSliceGVK.GroupVersion().String(), util.EndpointSliceGVK.Kind) {
|
||||||
|
c.EventRecorder.Eventf(mcs, corev1.EventTypeWarning, events.EventReasonAPIIncompatible, "Consumer cluster %s does not support EndpointSlice", clusterName)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := c.ensureEndpointSliceWork(mcs, work, epsSourceCluster, clusterName); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if controllerutil.AddFinalizer(work, util.MCSEndpointSliceDispatchControllerFinalizer) {
|
||||||
|
if err := c.Client.Update(ctx, work); err != nil {
|
||||||
|
klog.Errorf("Failed to add finalizer %s for work %s/%s:%v", util.MCSEndpointSliceDispatchControllerFinalizer, work.Namespace, work.Name, err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *EndpointsliceDispatchController) ensureEndpointSliceWork(mcs *networkingv1alpha1.MultiClusterService,
|
||||||
|
work *workv1alpha1.Work, providerCluster, consumerCluster string) error {
|
||||||
// It couldn't happen here
|
// It couldn't happen here
|
||||||
if len(work.Spec.Workload.Manifests) == 0 {
|
if len(work.Spec.Workload.Manifests) == 0 {
|
||||||
continue
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// There should be only one manifest in the work, let's use the first one.
|
// There should be only one manifest in the work, let's use the first one.
|
||||||
|
@ -345,8 +376,8 @@ func (c *EndpointsliceDispatchController) dispatchEndpointSlice(ctx context.Cont
|
||||||
}
|
}
|
||||||
|
|
||||||
// Use this name to avoid naming conflicts and locate the EPS source cluster.
|
// Use this name to avoid naming conflicts and locate the EPS source cluster.
|
||||||
endpointSlice.Name = epsSourceCluster + "-" + endpointSlice.Name
|
endpointSlice.Name = providerCluster + "-" + endpointSlice.Name
|
||||||
clusterNamespace := names.GenerateExecutionSpaceName(clusterName)
|
clusterNamespace := names.GenerateExecutionSpaceName(consumerCluster)
|
||||||
endpointSlice.Labels = map[string]string{
|
endpointSlice.Labels = map[string]string{
|
||||||
discoveryv1.LabelServiceName: mcs.Name,
|
discoveryv1.LabelServiceName: mcs.Name,
|
||||||
workv1alpha1.WorkNamespaceLabel: clusterNamespace,
|
workv1alpha1.WorkNamespaceLabel: clusterNamespace,
|
||||||
|
@ -356,7 +387,7 @@ func (c *EndpointsliceDispatchController) dispatchEndpointSlice(ctx context.Cont
|
||||||
}
|
}
|
||||||
endpointSlice.Annotations = map[string]string{
|
endpointSlice.Annotations = map[string]string{
|
||||||
// This annotation is used to identify the source cluster of EndpointSlice and whether the eps are the newest version
|
// This annotation is used to identify the source cluster of EndpointSlice and whether the eps are the newest version
|
||||||
util.EndpointSliceProvisionClusterAnnotation: epsSourceCluster,
|
util.EndpointSliceProvisionClusterAnnotation: providerCluster,
|
||||||
}
|
}
|
||||||
|
|
||||||
workMeta := metav1.ObjectMeta{
|
workMeta := metav1.ObjectMeta{
|
||||||
|
@ -364,7 +395,7 @@ func (c *EndpointsliceDispatchController) dispatchEndpointSlice(ctx context.Cont
|
||||||
Namespace: clusterNamespace,
|
Namespace: clusterNamespace,
|
||||||
Finalizers: []string{util.ExecutionControllerFinalizer},
|
Finalizers: []string{util.ExecutionControllerFinalizer},
|
||||||
Annotations: map[string]string{
|
Annotations: map[string]string{
|
||||||
util.EndpointSliceProvisionClusterAnnotation: epsSourceCluster,
|
util.EndpointSliceProvisionClusterAnnotation: providerCluster,
|
||||||
},
|
},
|
||||||
Labels: map[string]string{
|
Labels: map[string]string{
|
||||||
util.ManagedByKarmadaLabel: util.ManagedByKarmadaLabelValue,
|
util.ManagedByKarmadaLabel: util.ManagedByKarmadaLabelValue,
|
||||||
|
@ -379,17 +410,9 @@ func (c *EndpointsliceDispatchController) dispatchEndpointSlice(ctx context.Cont
|
||||||
}
|
}
|
||||||
if err := helper.CreateOrUpdateWork(c.Client, workMeta, unstructuredEPS); err != nil {
|
if err := helper.CreateOrUpdateWork(c.Client, workMeta, unstructuredEPS); err != nil {
|
||||||
klog.Errorf("Failed to dispatch EndpointSlice %s/%s from %s to cluster %s:%v",
|
klog.Errorf("Failed to dispatch EndpointSlice %s/%s from %s to cluster %s:%v",
|
||||||
work.GetNamespace(), work.GetName(), epsSourceCluster, clusterName, err)
|
work.GetNamespace(), work.GetName(), providerCluster, consumerCluster, err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if controllerutil.AddFinalizer(work, util.MCSEndpointSliceDispatchControllerFinalizer) {
|
|
||||||
if err := c.Client.Update(ctx, work); err != nil {
|
|
||||||
klog.Errorf("Failed to add finalizer %s for work %s/%s:%v", util.MCSEndpointSliceDispatchControllerFinalizer, work.Namespace, work.Name, err)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,6 @@ package multiclusterservice
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
corev1 "k8s.io/api/core/v1"
|
corev1 "k8s.io/api/core/v1"
|
||||||
|
@ -86,23 +85,7 @@ func (c *MCSController) Reconcile(ctx context.Context, req controllerruntime.Req
|
||||||
return c.handleMultiClusterServiceDelete(mcs.DeepCopy())
|
return c.handleMultiClusterServiceDelete(mcs.DeepCopy())
|
||||||
}
|
}
|
||||||
|
|
||||||
providerClusters, noneExistProviderClusters, err := helper.GetProviderClusters(c.Client, mcs)
|
var err error
|
||||||
if err != nil {
|
|
||||||
klog.Errorf("Failed to get provider clusters by MultiClusterService(%s/%s):%v", mcs.Namespace, mcs.Name, err)
|
|
||||||
return controllerruntime.Result{}, err
|
|
||||||
}
|
|
||||||
consumerClusters, noneExistConsumerClusters, err := helper.GetConsumerClustres(c.Client, mcs)
|
|
||||||
if err != nil {
|
|
||||||
klog.Errorf("Failed to get consumer clusters by MultiClusterService(%s/%s):%v", mcs.Namespace, mcs.Name, err)
|
|
||||||
return controllerruntime.Result{}, err
|
|
||||||
}
|
|
||||||
if len(noneExistProviderClusters) != 0 || len(noneExistConsumerClusters) != 0 {
|
|
||||||
msgProvider := strings.Join(noneExistProviderClusters.UnsortedList(), ",")
|
|
||||||
msgConsumer := strings.Join(noneExistConsumerClusters.UnsortedList(), ",")
|
|
||||||
c.EventRecorder.Eventf(mcs, corev1.EventTypeNormal, events.EventReasonConfigurationRedundant,
|
|
||||||
fmt.Sprintf("ProviderClusters(%s)/ConsumerClusters(%s) dont's exist, Karmada will ignore them", msgProvider, msgConsumer))
|
|
||||||
}
|
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
_ = c.updateMultiClusterServiceStatus(mcs, metav1.ConditionFalse, "ServiceAppliedFailed", err.Error())
|
_ = c.updateMultiClusterServiceStatus(mcs, metav1.ConditionFalse, "ServiceAppliedFailed", err.Error())
|
||||||
|
@ -113,7 +96,7 @@ func (c *MCSController) Reconcile(ctx context.Context, req controllerruntime.Req
|
||||||
c.EventRecorder.Eventf(mcs, corev1.EventTypeNormal, events.EventReasonSyncServiceSucceed, "Service is propagated to target clusters.")
|
c.EventRecorder.Eventf(mcs, corev1.EventTypeNormal, events.EventReasonSyncServiceSucceed, "Service is propagated to target clusters.")
|
||||||
}()
|
}()
|
||||||
|
|
||||||
if err = c.handleMultiClusterServiceCreateOrUpdate(mcs.DeepCopy(), providerClusters, consumerClusters); err != nil {
|
if err = c.handleMultiClusterServiceCreateOrUpdate(mcs.DeepCopy()); err != nil {
|
||||||
return controllerruntime.Result{}, err
|
return controllerruntime.Result{}, err
|
||||||
}
|
}
|
||||||
return controllerruntime.Result{}, nil
|
return controllerruntime.Result{}, nil
|
||||||
|
@ -201,7 +184,7 @@ func (c *MCSController) cleanProviderEndpointSliceWork(work *workv1alpha1.Work)
|
||||||
|
|
||||||
var errs []error
|
var errs []error
|
||||||
for _, work := range workList.Items {
|
for _, work := range workList.Items {
|
||||||
if !helper.IsWorkContains(work.Spec.Workload.Manifests, endpointSliceGVK) {
|
if !helper.IsWorkContains(work.Spec.Workload.Manifests, util.EndpointSliceGVK) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
// This annotation is only added to the EndpointSlice work in consumer clusters' execution namespace
|
// This annotation is only added to the EndpointSlice work in consumer clusters' execution namespace
|
||||||
|
@ -230,9 +213,20 @@ func (c *MCSController) cleanProviderEndpointSliceWork(work *workv1alpha1.Work)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *MCSController) handleMultiClusterServiceCreateOrUpdate(mcs *networkingv1alpha1.MultiClusterService, providerClusters, consumerClusters sets.Set[string]) error {
|
func (c *MCSController) handleMultiClusterServiceCreateOrUpdate(mcs *networkingv1alpha1.MultiClusterService) error {
|
||||||
klog.V(4).Infof("Begin to handle MultiClusterService(%s/%s) create or update event", mcs.Namespace, mcs.Name)
|
klog.V(4).Infof("Begin to handle MultiClusterService(%s/%s) create or update event", mcs.Namespace, mcs.Name)
|
||||||
|
|
||||||
|
providerClusters, err := helper.GetProviderClusters(c.Client, mcs)
|
||||||
|
if err != nil {
|
||||||
|
klog.Errorf("Failed to get provider clusters by MultiClusterService(%s/%s):%v", mcs.Namespace, mcs.Name, err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
consumerClusters, err := helper.GetConsumerClusters(c.Client, mcs)
|
||||||
|
if err != nil {
|
||||||
|
klog.Errorf("Failed to get consumer clusters by MultiClusterService(%s/%s):%v", mcs.Namespace, mcs.Name, err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
// 1. if mcs not contain CrossCluster type, delete service work if needed
|
// 1. if mcs not contain CrossCluster type, delete service work if needed
|
||||||
if !helper.MultiClusterServiceCrossClusterEnabled(mcs) {
|
if !helper.MultiClusterServiceCrossClusterEnabled(mcs) {
|
||||||
if err := c.retrieveService(mcs); err != nil {
|
if err := c.retrieveService(mcs); err != nil {
|
||||||
|
@ -274,19 +268,17 @@ func (c *MCSController) handleMultiClusterServiceCreateOrUpdate(mcs *networkingv
|
||||||
|
|
||||||
// 5. make sure service exist
|
// 5. make sure service exist
|
||||||
svc := &corev1.Service{}
|
svc := &corev1.Service{}
|
||||||
err := c.Client.Get(context.Background(), types.NamespacedName{Namespace: mcs.Namespace, Name: mcs.Name}, svc)
|
err = c.Client.Get(context.Background(), types.NamespacedName{Namespace: mcs.Namespace, Name: mcs.Name}, svc)
|
||||||
// If the Serivice are deleted, the Service's ResourceBinding will be cleaned by GC
|
// If the Serivice are deleted, the Service's ResourceBinding will be cleaned by GC
|
||||||
if err != nil && !apierrors.IsNotFound(err) {
|
if err != nil {
|
||||||
klog.Errorf("Failed to get service(%s/%s):%v", mcs.Namespace, mcs.Name, err)
|
klog.Errorf("Failed to get service(%s/%s):%v", mcs.Namespace, mcs.Name, err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 6. if service exists, create or update corresponding ResourceBinding
|
// 6. if service exists, create or update corresponding ResourceBinding
|
||||||
if err == nil {
|
|
||||||
if err := c.propagateService(context.Background(), mcs, svc, providerClusters, consumerClusters); err != nil {
|
if err := c.propagateService(context.Background(), mcs, svc, providerClusters, consumerClusters); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
klog.V(4).Infof("Success to reconcile MultiClusterService(%s/%s)", mcs.Namespace, mcs.Name)
|
klog.V(4).Infof("Success to reconcile MultiClusterService(%s/%s)", mcs.Namespace, mcs.Name)
|
||||||
return nil
|
return nil
|
||||||
|
@ -294,9 +286,25 @@ func (c *MCSController) handleMultiClusterServiceCreateOrUpdate(mcs *networkingv
|
||||||
|
|
||||||
func (c *MCSController) propagateMultiClusterService(mcs *networkingv1alpha1.MultiClusterService, providerClusters sets.Set[string]) error {
|
func (c *MCSController) propagateMultiClusterService(mcs *networkingv1alpha1.MultiClusterService, providerClusters sets.Set[string]) error {
|
||||||
for clusterName := range providerClusters {
|
for clusterName := range providerClusters {
|
||||||
if !c.IsClusterReady(clusterName) {
|
clusterObj, err := util.GetCluster(c.Client, clusterName)
|
||||||
|
if err != nil {
|
||||||
|
if apierrors.IsNotFound(err) {
|
||||||
|
c.EventRecorder.Eventf(mcs, corev1.EventTypeWarning, events.EventReasonClusterNotFound, "Provider cluster %s is not found", clusterName)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
klog.Errorf("Failed to get cluster %s, error is: %v", clusterName, err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if !util.IsClusterReady(&clusterObj.Status) {
|
||||||
|
c.EventRecorder.Eventf(mcs, corev1.EventTypeWarning, events.EventReasonSyncServiceFailed,
|
||||||
|
"Provider cluster %s is not ready, skip to propagate MultiClusterService", clusterName)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if !helper.IsAPIEnabled(clusterObj.Status.APIEnablements, util.EndpointSliceGVK.GroupVersion().String(), util.EndpointSliceGVK.Kind) {
|
||||||
|
c.EventRecorder.Eventf(mcs, corev1.EventTypeWarning, events.EventReasonAPIIncompatible, "Provider cluster %s does not support EndpointSlice", clusterName)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
workMeta := metav1.ObjectMeta{
|
workMeta := metav1.ObjectMeta{
|
||||||
Name: names.GenerateWorkName(mcs.Kind, mcs.Name, mcs.Namespace),
|
Name: names.GenerateWorkName(mcs.Kind, mcs.Name, mcs.Namespace),
|
||||||
Namespace: names.GenerateExecutionSpaceName(clusterName),
|
Namespace: names.GenerateExecutionSpaceName(clusterName),
|
||||||
|
@ -648,7 +656,7 @@ func (c *MCSController) needSyncMultiClusterService(mcs *networkingv1alpha1.Mult
|
||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
providerClusters, _, err := helper.GetProviderClusters(c.Client, mcs)
|
providerClusters, err := helper.GetProviderClusters(c.Client, mcs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
klog.Errorf("Failed to get provider clusters by MultiClusterService(%s/%s):%v", mcs.Namespace, mcs.Name, err)
|
klog.Errorf("Failed to get provider clusters by MultiClusterService(%s/%s):%v", mcs.Namespace, mcs.Name, err)
|
||||||
return false, err
|
return false, err
|
||||||
|
@ -657,7 +665,7 @@ func (c *MCSController) needSyncMultiClusterService(mcs *networkingv1alpha1.Mult
|
||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
consumerClusters, _, err := helper.GetConsumerClustres(c.Client, mcs)
|
consumerClusters, err := helper.GetConsumerClusters(c.Client, mcs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
klog.Errorf("Failed to get consumer clusters by MultiClusterService(%s/%s):%v", mcs.Namespace, mcs.Name, err)
|
klog.Errorf("Failed to get consumer clusters by MultiClusterService(%s/%s):%v", mcs.Namespace, mcs.Name, err)
|
||||||
return false, err
|
return false, err
|
||||||
|
|
|
@ -140,6 +140,8 @@ const (
|
||||||
EventReasonDispatchEndpointSliceFailed = "DispatchEndpointSliceFailed"
|
EventReasonDispatchEndpointSliceFailed = "DispatchEndpointSliceFailed"
|
||||||
// EventReasonDispatchEndpointSliceSucceed indicates that dispatch endpointslice succeed.
|
// EventReasonDispatchEndpointSliceSucceed indicates that dispatch endpointslice succeed.
|
||||||
EventReasonDispatchEndpointSliceSucceed = "DispatchEndpointSliceSucceed"
|
EventReasonDispatchEndpointSliceSucceed = "DispatchEndpointSliceSucceed"
|
||||||
// EventReasonConfigurationRedundant indicates that MultiClusterService configuration redundant.
|
// EventReasonClusterNotFound indicates that the cluster configured in MultiClusterService does not exist.
|
||||||
EventReasonConfigurationRedundant = "ConfigurationRedundant"
|
EventReasonClusterNotFound = "ClusterNotFound"
|
||||||
|
// EventReasonAPIIncompatible indicates that the MultiClusterService may not function properly as some member clusters do not support EndpointSlice.
|
||||||
|
EventReasonAPIIncompatible = "APIIncompatible"
|
||||||
)
|
)
|
||||||
|
|
|
@ -16,7 +16,11 @@ limitations under the License.
|
||||||
|
|
||||||
package util
|
package util
|
||||||
|
|
||||||
import "time"
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
|
discoveryv1 "k8s.io/api/discovery/v1"
|
||||||
|
)
|
||||||
|
|
||||||
// Define labels used by karmada system.
|
// Define labels used by karmada system.
|
||||||
const (
|
const (
|
||||||
|
@ -211,3 +215,8 @@ const (
|
||||||
// CacheSyncTimeout refers to the time limit set on waiting for cache to sync
|
// CacheSyncTimeout refers to the time limit set on waiting for cache to sync
|
||||||
CacheSyncTimeout = 2 * time.Minute
|
CacheSyncTimeout = 2 * time.Minute
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
// EndpointSliceGVK is the GroupVersionKind of K8s native EndpointSlice.
|
||||||
|
EndpointSliceGVK = discoveryv1.SchemeGroupVersion.WithKind("EndpointSlice")
|
||||||
|
)
|
||||||
|
|
|
@ -96,6 +96,7 @@ func DeleteEndpointSlice(c client.Client, selector labels.Set) error {
|
||||||
return errors.NewAggregate(errs)
|
return errors.NewAggregate(errs)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MultiClusterServiceCrossClusterEnabled will check if it's a CrossCluster MultiClusterService.
|
||||||
func MultiClusterServiceCrossClusterEnabled(mcs *networkingv1alpha1.MultiClusterService) bool {
|
func MultiClusterServiceCrossClusterEnabled(mcs *networkingv1alpha1.MultiClusterService) bool {
|
||||||
for _, svcType := range mcs.Spec.Types {
|
for _, svcType := range mcs.Spec.Types {
|
||||||
if svcType == networkingv1alpha1.ExposureTypeCrossCluster {
|
if svcType == networkingv1alpha1.ExposureTypeCrossCluster {
|
||||||
|
@ -106,34 +107,36 @@ func MultiClusterServiceCrossClusterEnabled(mcs *networkingv1alpha1.MultiCluster
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetProviderClusters(client client.Client, mcs *networkingv1alpha1.MultiClusterService) (existClusters, noneExistClusters sets.Set[string], err error) {
|
// GetProviderClusters will extract the target provider clusters of the service
|
||||||
|
func GetProviderClusters(client client.Client, mcs *networkingv1alpha1.MultiClusterService) (sets.Set[string], error) {
|
||||||
providerClusters := sets.New[string]()
|
providerClusters := sets.New[string]()
|
||||||
for _, p := range mcs.Spec.ProviderClusters {
|
for _, p := range mcs.Spec.ProviderClusters {
|
||||||
providerClusters.Insert(p.Name)
|
providerClusters.Insert(p.Name)
|
||||||
}
|
}
|
||||||
|
if len(providerClusters) != 0 {
|
||||||
|
return providerClusters, nil
|
||||||
|
}
|
||||||
allClusters, err := util.GetClusterSet(client)
|
allClusters, err := util.GetClusterSet(client)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
klog.Errorf("Failed to get cluster set, Error: %v", err)
|
klog.Errorf("Failed to get cluster set, Error: %v", err)
|
||||||
return nil, nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if len(providerClusters) == 0 {
|
return allClusters, nil
|
||||||
return allClusters, nil, nil
|
|
||||||
}
|
|
||||||
return providerClusters.Clone().Intersection(allClusters), providerClusters.Clone().Delete(allClusters.UnsortedList()...), nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetConsumerClustres(client client.Client, mcs *networkingv1alpha1.MultiClusterService) (existClusters, noneExistClusters sets.Set[string], err error) {
|
// GetProviderClusters will extract the target consumer clusters of the service
|
||||||
|
func GetConsumerClusters(client client.Client, mcs *networkingv1alpha1.MultiClusterService) (sets.Set[string], error) {
|
||||||
consumerClusters := sets.New[string]()
|
consumerClusters := sets.New[string]()
|
||||||
for _, c := range mcs.Spec.ConsumerClusters {
|
for _, c := range mcs.Spec.ConsumerClusters {
|
||||||
consumerClusters.Insert(c.Name)
|
consumerClusters.Insert(c.Name)
|
||||||
}
|
}
|
||||||
|
if len(consumerClusters) != 0 {
|
||||||
|
return consumerClusters, nil
|
||||||
|
}
|
||||||
allClusters, err := util.GetClusterSet(client)
|
allClusters, err := util.GetClusterSet(client)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
klog.Errorf("Failed to get cluster set, Error: %v", err)
|
klog.Errorf("Failed to get cluster set, Error: %v", err)
|
||||||
return nil, nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if len(consumerClusters) == 0 {
|
return allClusters, nil
|
||||||
return allClusters, nil, nil
|
|
||||||
}
|
|
||||||
return consumerClusters.Clone().Intersection(allClusters), consumerClusters.Clone().Delete(allClusters.UnsortedList()...), nil
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue