diff --git a/kustomize/crds/cluster.clusterpedia.io_clustersyncresources.yaml b/kustomize/crds/cluster.clusterpedia.io_clustersyncresources.yaml index 99b37f082..cb37d77eb 100644 --- a/kustomize/crds/cluster.clusterpedia.io_clustersyncresources.yaml +++ b/kustomize/crds/cluster.clusterpedia.io_clustersyncresources.yaml @@ -35,6 +35,10 @@ spec: syncResources: items: properties: + excludedResource: + items: + type: string + type: array group: type: string resources: diff --git a/kustomize/crds/cluster.clusterpedia.io_pediaclusters.yaml b/kustomize/crds/cluster.clusterpedia.io_pediaclusters.yaml index 28e25bf5a..e05c9d795 100644 --- a/kustomize/crds/cluster.clusterpedia.io_pediaclusters.yaml +++ b/kustomize/crds/cluster.clusterpedia.io_pediaclusters.yaml @@ -79,6 +79,10 @@ spec: syncResources: items: properties: + excludedResource: + items: + type: string + type: array group: type: string resources: diff --git a/pkg/generated/openapi/zz_generated.openapi.go b/pkg/generated/openapi/zz_generated.openapi.go index 5361791e7..78c0dce70 100644 --- a/pkg/generated/openapi/zz_generated.openapi.go +++ b/pkg/generated/openapi/zz_generated.openapi.go @@ -141,6 +141,20 @@ func schema_clusterpedia_io_api_cluster_v1alpha2_ClusterGroupResources(ref commo }, }, }, + "excludedResource": { + SchemaProps: spec.SchemaProps{ + Type: []string{"array"}, + Items: &spec.SchemaOrArray{ + Schema: &spec.Schema{ + SchemaProps: spec.SchemaProps{ + Default: "", + Type: []string{"string"}, + Format: "", + }, + }, + }, + }, + }, }, Required: []string{"group", "resources"}, }, diff --git a/pkg/synchromanager/clustersynchro/cluster_synchro.go b/pkg/synchromanager/clustersynchro/cluster_synchro.go index 527c7a259..7c4651d07 100644 --- a/pkg/synchromanager/clustersynchro/cluster_synchro.go +++ b/pkg/synchromanager/clustersynchro/cluster_synchro.go @@ -59,10 +59,11 @@ type ClusterSynchro struct { storageResourceVersions map[schema.GroupVersionResource]map[string]interface{} storageResourceSynchros sync.Map - syncResources atomic.Value // []clusterv1alpha2.ClusterGroupResources - setSyncResourcesCh chan struct{} - resourceNegotiator *ResourceNegotiator - groupResourceStatus atomic.Value // *GroupResourceStatus + syncResources atomic.Value // []clusterv1alpha2.ClusterGroupResources + excludedSyncResources atomic.Value // []clusterv1alpha2.ClusterGroupResources + setSyncResourcesCh chan struct{} + resourceNegotiator *ResourceNegotiator + groupResourceStatus atomic.Value // *GroupResourceStatus runningCondition atomic.Value // metav1.Condition healthyCondition atomic.Value // metav1.Condition @@ -315,6 +316,7 @@ func (s *ClusterSynchro) refreshSyncResources() { if syncResources == nil { return } + groupResourceStatus, storageResourceSyncConfigs := s.resourceNegotiator.NegotiateSyncResources(syncResources) lastGroupResourceStatus := s.groupResourceStatus.Load().(*GroupResourceStatus) diff --git a/pkg/synchromanager/clustersynchro/resource_negotiator.go b/pkg/synchromanager/clustersynchro/resource_negotiator.go index b7e2ced4f..b41376aad 100644 --- a/pkg/synchromanager/clustersynchro/resource_negotiator.go +++ b/pkg/synchromanager/clustersynchro/resource_negotiator.go @@ -85,7 +85,11 @@ func (negotiator *ResourceNegotiator) NegotiateSyncResources(syncResources []clu var groupResourceStatus = NewGroupResourceStatus() var storageResourceSyncConfigs = make(map[schema.GroupVersionResource]syncConfig) for _, groupResources := range syncResources { + excludedResourcesSet := sets.New(groupResources.ExcludedResource...) for _, resource := range groupResources.Resources { + if excludedResourcesSet.Has(resource) { + continue + } syncGR := schema.GroupResource{Group: groupResources.Group, Resource: resource} apiResource, supportedVersions := negotiator.dynamicDiscovery.GetAPIResourceAndVersions(syncGR) if apiResource == nil || len(supportedVersions) == 0 { diff --git a/staging/src/github.com/clusterpedia-io/api/cluster/v1alpha2/types.go b/staging/src/github.com/clusterpedia-io/api/cluster/v1alpha2/types.go index 63e62de33..0d7914ff0 100644 --- a/staging/src/github.com/clusterpedia-io/api/cluster/v1alpha2/types.go +++ b/staging/src/github.com/clusterpedia-io/api/cluster/v1alpha2/types.go @@ -109,6 +109,9 @@ type ClusterGroupResources struct { // +kubebuilder:validation:Required // +kubebuilder:validation:MinItems=1 Resources []string `json:"resources"` + + // +optional + ExcludedResource []string `json:"excludedResource"` } type ClusterStatus struct { diff --git a/staging/src/github.com/clusterpedia-io/api/cluster/v1alpha2/zz_generated.deepcopy.go b/staging/src/github.com/clusterpedia-io/api/cluster/v1alpha2/zz_generated.deepcopy.go index fdb4a9d7c..f43b4f831 100644 --- a/staging/src/github.com/clusterpedia-io/api/cluster/v1alpha2/zz_generated.deepcopy.go +++ b/staging/src/github.com/clusterpedia-io/api/cluster/v1alpha2/zz_generated.deepcopy.go @@ -23,6 +23,11 @@ func (in *ClusterGroupResources) DeepCopyInto(out *ClusterGroupResources) { *out = make([]string, len(*in)) copy(*out, *in) } + if in.ExcludedResource != nil { + in, out := &in.ExcludedResource, &out.ExcludedResource + *out = make([]string, len(*in)) + copy(*out, *in) + } return }