Skip to content

Commit

Permalink
feat: fix conflicts with pp
Browse files Browse the repository at this point in the history
Signed-off-by: jwcesign <jwcesign@gmail.com>
  • Loading branch information
jwcesign committed Dec 14, 2023
1 parent 0865183 commit 63c22d2
Show file tree
Hide file tree
Showing 21 changed files with 545 additions and 242 deletions.
32 changes: 29 additions & 3 deletions api/openapi-spec/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -20975,6 +20975,16 @@
}
}
},
"com.github.karmada-io.karmada.pkg.apis.networking.v1alpha1.ClusterSelector": {
"description": "ClusterSelector specifies the cluster to be selected.",
"type": "object",
"properties": {
"name": {
"description": "Name is the name of the cluster to be selected.",
"type": "string"
}
}
},
"com.github.karmada-io.karmada.pkg.apis.networking.v1alpha1.ExposurePort": {
"description": "ExposurePort describes which port will be exposed.",
"type": "object",
Expand Down Expand Up @@ -21160,6 +21170,14 @@
"types"
],
"properties": {
"consumerClusters": {
"description": "ConsumerClusters specifies the clusters where the service will be exposed, for clients. If leave it empty, the service will be exposed to all clusters.",
"type": "array",
"items": {
"default": {},
"$ref": "#/definitions/com.github.karmada-io.karmada.pkg.apis.networking.v1alpha1.ClusterSelector"
}
},
"ports": {
"description": "Ports is the list of ports that are exposed by this MultiClusterService. No specified port will be filtered out during the service exposure and discovery process. All ports in the referencing service will be exposed by default.",
"type": "array",
Expand All @@ -21168,21 +21186,29 @@
"$ref": "#/definitions/com.github.karmada-io.karmada.pkg.apis.networking.v1alpha1.ExposurePort"
}
},
"providerClusters": {
"description": "ProviderClusters specifies the clusters which will provision the service backend. If leave it empty, we will collect the backend endpoints from all clusters and sync them to the ServiceConsumptionClusters.",
"type": "array",
"items": {
"default": {},
"$ref": "#/definitions/com.github.karmada-io.karmada.pkg.apis.networking.v1alpha1.ClusterSelector"
}
},
"range": {
"description": "Range specifies the ranges where the referencing service should be exposed. Only valid and optional in case of Types contains CrossCluster. If not set and Types contains CrossCluster, all clusters will be selected, that means the referencing service will be exposed across all registered clusters. Deprecated: in favor of ServiceProvisionClusters/ServiceConsumptionClusters.",
"description": "Range specifies the ranges where the referencing service should be exposed. Only valid and optional in case of Types contains CrossCluster. If not set and Types contains CrossCluster, all clusters will be selected, that means the referencing service will be exposed across all registered clusters. Deprecated: in favor of ProviderClusters/ConsumerClusters.",
"default": {},
"$ref": "#/definitions/com.github.karmada-io.karmada.pkg.apis.networking.v1alpha1.ExposureRange"
},
"serviceConsumptionClusters": {
"description": "ServiceConsumptionClusters specifies the clusters where the service will be exposed, for clients. If leave it empty, the service will be exposed to all clusters.",
"description": "ServiceConsumptionClusters specifies the clusters where the service will be exposed, for clients. If leave it empty, the service will be exposed to all clusters. Deprecated: in favor of ProviderClusters/ConsumerClusters.",
"type": "array",
"items": {
"type": "string",
"default": ""
}
},
"serviceProvisionClusters": {
"description": "ServiceProvisionClusters specifies the clusters which will provision the service backend. If leave it empty, we will collect the backend endpoints from all clusters and sync them to the ServiceConsumptionClusters.",
"description": "ServiceProvisionClusters specifies the clusters which will provision the service backend. If leave it empty, we will collect the backend endpoints from all clusters and sync them to the ServiceConsumptionClusters. Deprecated: in favor of ProviderClusters/ConsumerClusters.",
"type": "array",
"items": {
"type": "string",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,18 @@ spec:
spec:
description: Spec is the desired state of the MultiClusterService.
properties:
consumerClusters:
description: ConsumerClusters specifies the clusters where the service
will be exposed, for clients. If leave it empty, the service will
be exposed to all clusters.
items:
description: ClusterSelector specifies the cluster to be selected.
properties:
name:
description: Name is the name of the cluster to be selected.
type: string
type: object
type: array
ports:
description: Ports is the list of ports that are exposed by this MultiClusterService.
No specified port will be filtered out during the service exposure
Expand All @@ -65,12 +77,24 @@ spec:
- port
type: object
type: array
providerClusters:
description: ProviderClusters specifies the clusters which will provision
the service backend. If leave it empty, we will collect the backend
endpoints from all clusters and sync them to the ServiceConsumptionClusters.
items:
description: ClusterSelector specifies the cluster to be selected.
properties:
name:
description: Name is the name of the cluster to be selected.
type: string
type: object
type: array
range:
description: 'Range specifies the ranges where the referencing service
should be exposed. Only valid and optional in case of Types contains
CrossCluster. If not set and Types contains CrossCluster, all clusters
will be selected, that means the referencing service will be exposed
across all registered clusters. Deprecated: in favor of ServiceProvisionClusters/ServiceConsumptionClusters.'
across all registered clusters. Deprecated: in favor of ProviderClusters/ConsumerClusters.'
properties:
clusterNames:
description: ClusterNames is the list of clusters to be selected.
Expand All @@ -79,16 +103,18 @@ spec:
type: array
type: object
serviceConsumptionClusters:
description: ServiceConsumptionClusters specifies the clusters where
description: 'ServiceConsumptionClusters specifies the clusters where
the service will be exposed, for clients. If leave it empty, the
service will be exposed to all clusters.
service will be exposed to all clusters. Deprecated: in favor of
ProviderClusters/ConsumerClusters.'
items:
type: string
type: array
serviceProvisionClusters:
description: ServiceProvisionClusters specifies the clusters which
description: 'ServiceProvisionClusters specifies the clusters which
will provision the service backend. If leave it empty, we will collect
the backend endpoints from all clusters and sync them to the ServiceConsumptionClusters.
Deprecated: in favor of ProviderClusters/ConsumerClusters.'
items:
type: string
type: array
Expand Down
6 changes: 3 additions & 3 deletions hack/util.sh
Original file line number Diff line number Diff line change
Expand Up @@ -713,13 +713,13 @@ function util:create_gopath_tree() {
local repo_root=$1
local go_path=$2

local go_pkg_dir="${go_path}/src/${KARMADA_GO_PACKAGE}"
go_pkg_dir=$(dirname "${go_pkg_dir}")
local karmada_pkg_dir="${go_path}/src/${KARMADA_GO_PACKAGE}"
local go_pkg_dir=$(dirname "${karmada_pkg_dir}")

mkdir -p "${go_pkg_dir}"

if [[ ! -e "${go_pkg_dir}" || "$(readlink "${go_pkg_dir}")" != "${repo_root}" ]]; then
ln -snf "${repo_root}" "${go_pkg_dir}"
ln -snf "${repo_root}" "${karmada_pkg_dir}"
fi
}

Expand Down
22 changes: 21 additions & 1 deletion pkg/apis/networking/v1alpha1/service_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,20 +79,40 @@ type MultiClusterServiceSpec struct {
// If not set and Types contains CrossCluster, all clusters will
// be selected, that means the referencing service will be exposed
// across all registered clusters.
// Deprecated: in favor of ServiceProvisionClusters/ServiceConsumptionClusters.
// Deprecated: in favor of ProviderClusters/ConsumerClusters.
// +optional
Range ExposureRange `json:"range,omitempty"`

// ServiceProvisionClusters specifies the clusters which will provision the service backend.
// If leave it empty, we will collect the backend endpoints from all clusters and sync
// them to the ServiceConsumptionClusters.
// Deprecated: in favor of ProviderClusters/ConsumerClusters.
// +optional
ServiceProvisionClusters []string `json:"serviceProvisionClusters,omitempty"`

// ServiceConsumptionClusters specifies the clusters where the service will be exposed, for clients.
// If leave it empty, the service will be exposed to all clusters.
// Deprecated: in favor of ProviderClusters/ConsumerClusters.
// +optional
ServiceConsumptionClusters []string `json:"serviceConsumptionClusters,omitempty"`

// ProviderClusters specifies the clusters which will provision the service backend.
// If leave it empty, we will collect the backend endpoints from all clusters and sync
// them to the ServiceConsumptionClusters.
// +optional
ProviderClusters []ClusterSelector `json:"providerClusters,omitempty"`

// ConsumerClusters specifies the clusters where the service will be exposed, for clients.
// If leave it empty, the service will be exposed to all clusters.
// +optional
ConsumerClusters []ClusterSelector `json:"consumerClusters,omitempty"`
}

// ClusterSelector specifies the cluster to be selected.
type ClusterSelector struct {
// Name is the name of the cluster to be selected.
// +required
Name string `json:"name,omitempty"`
}

// ExposureType describes how to expose the service.
Expand Down
6 changes: 6 additions & 0 deletions pkg/apis/networking/v1alpha1/well_known_constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,10 @@ const (
// The reason for generating a new unique identifier instead of simply using metadata.UUID is because:
// In backup scenarios, when applying the backup resource manifest in a new cluster, the UUID may change.
MultiClusterServicePermanentIDLabel = "multiclusterservice.karmada.io/permanent-id"

// MultiClusterServiceNameAnnotation is the name of a MultiClusterService object.
MultiClusterServiceNameAnnotation = "multiclusterservice.karmada.io/name"

// MultiClusterServiceNamespaceAnnotation is the namespace of a MultiClusterService object.
MultiClusterServiceNamespaceAnnotation = "multiclusterservice.karmada.io/namespace"
)
26 changes: 26 additions & 0 deletions pkg/apis/networking/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions pkg/apis/work/v1alpha2/well_known_constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ const (

// WorkNameLabel is added to objects to specify associated Work's name.
WorkNameLabel = "work.karmada.io/name"

// WorkClusterNameLabel is added to ResoruceBinding to represent what kind of resource manage this Binding.
BindingManagedByLabel = "binding.karmada.io/managed-by"
)

// Define resource conflict resolution
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ func reportEndpointSlice(c client.Client, endpointSlice *unstructured.Unstructur

workMeta := metav1.ObjectMeta{
// Karmada will synchronize this work to other cluster namespaces and add the cluster name to prevent conflicts.
Name: names.GenerateMCSWorkName(endpointSlice.GetKind(), endpointSlice.GetName(), endpointSlice.GetNamespace(), clusterName),
Name: names.GenerateWorkName(endpointSlice.GetKind(), endpointSlice.GetName(), endpointSlice.GetNamespace()),
Namespace: executionSpace,
Labels: map[string]string{
util.MultiClusterServiceNamespaceLabel: endpointSlice.GetNamespace(),
Expand All @@ -400,7 +400,7 @@ func cleanupWorkWithEndpointSliceDelete(c client.Client, endpointSliceKey keys.F

workNamespaceKey := types.NamespacedName{
Namespace: executionSpace,
Name: names.GenerateMCSWorkName(endpointSliceKey.Kind, endpointSliceKey.Name, endpointSliceKey.Namespace, endpointSliceKey.Cluster),
Name: names.GenerateWorkName(endpointSliceKey.Kind, endpointSliceKey.Name, endpointSliceKey.Namespace),
}
work := &workv1alpha1.Work{}
if err := c.Get(context.TODO(), workNamespaceKey, work); err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/client-go/tools/record"
"k8s.io/client-go/util/retry"
"k8s.io/klog/v2"
Expand Down Expand Up @@ -192,7 +191,7 @@ func (c *EndpointsliceDispatchController) newClusterFunc() handler.MapFunc {

var requests []reconcile.Request
for _, mcs := range mcsList.Items {
clusterSet, err := helper.GetConsumptionClustres(c.Client, mcs.DeepCopy())
clusterSet, _, err := helper.GetConsumerClustres(c.Client, mcs.DeepCopy())
if err != nil {
klog.Errorf("Failed to get provision clusters, error: %v", err)
continue
Expand Down Expand Up @@ -284,7 +283,7 @@ func (c *EndpointsliceDispatchController) cleanOrphanDispatchedEndpointSlice(ctx
continue
}

consumptionClusters, err := helper.GetConsumptionClustres(c.Client, mcs)
consumptionClusters, _, err := helper.GetConsumerClustres(c.Client, mcs)
if err != nil {
klog.Errorf("Failed to get consumption clusters, error is: %v", err)
return err
Expand Down Expand Up @@ -316,15 +315,12 @@ func (c *EndpointsliceDispatchController) dispatchEndpointSlice(ctx context.Cont
return err
}

consumptionClusters := sets.New[string](mcs.Spec.ServiceConsumptionClusters...)
if len(consumptionClusters) == 0 {
consumptionClusters, err = util.GetClusterSet(c.Client)
if err != nil {
klog.Errorf("Failed to get cluster set, error is: %v", err)
return err
}
consumerClusters, _, err := helper.GetConsumerClustres(c.Client, mcs)
if err != nil {
klog.Errorf("Failed to get consumer clusters, error is: %v", err)
return err
}
for clusterName := range consumptionClusters {
for clusterName := range consumerClusters {
if clusterName == epsSourceCluster {
continue
}
Expand Down
Loading

0 comments on commit 63c22d2

Please sign in to comment.