diff --git a/kustomize/crds/cluster.clusterpedia.io_clustersyncresources.yaml b/kustomize/crds/cluster.clusterpedia.io_clustersyncresources.yaml index 99b37f082..54b4b9e14 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: + excludeResources: + 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..dc6435e2d 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: + excludeResources: + 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..24ddef36e 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 }, }, }, + "excludeResources": { + 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/resource_negotiator.go b/pkg/synchromanager/clustersynchro/resource_negotiator.go index 42b111af8..4b9ef800d 100644 --- a/pkg/synchromanager/clustersynchro/resource_negotiator.go +++ b/pkg/synchromanager/clustersynchro/resource_negotiator.go @@ -42,6 +42,7 @@ func (negotiator *ResourceNegotiator) SetSyncAllCustomResources(sync bool) { func (negotiator *ResourceNegotiator) NegotiateSyncResources(syncResources []clusterv1alpha2.ClusterGroupResources) (*GroupResourceStatus, map[schema.GroupVersionResource]syncConfig) { var syncAllResources bool var watchKubeVersion, watchAggregatorResourceTypes bool + originSyncResources := syncResources for i, syncResource := range syncResources { if syncResource.Group == "*" { syncAllResources = true @@ -62,6 +63,7 @@ func (negotiator *ResourceNegotiator) NegotiateSyncResources(syncResources []clu klog.InfoS("Skip resource sync", "cluster", negotiator.name, "group", syncResource.Group, "reason", "not match group") } else { syncResourcesByGroup.Versions = syncResource.Versions + syncResourcesByGroup.ExcludeResources = syncResource.ExcludeResources syncResources[i] = *syncResourcesByGroup if groupType == discovery.KubeResource { watchKubeVersion = true @@ -74,6 +76,18 @@ func (negotiator *ResourceNegotiator) NegotiateSyncResources(syncResources []clu if syncAllResources { syncResources = negotiator.dynamicDiscovery.GetAllResourcesAsSyncResources() + allExcludeResources := make([]string, 0) + for _, gr := range originSyncResources { + if len(gr.ExcludeResources) > 0 { + allExcludeResources = append(allExcludeResources, gr.ExcludeResources...) + } + } + allExcludeResourcesSet := sets.New(allExcludeResources...) + for k, groupResources := range syncResources { + if allExcludeResourcesSet.Has(groupResources.Resources[0]) { + syncResources[k].ExcludeResources = groupResources.Resources + } + } } else if negotiator.syncAllCustomResources && clusterpediafeature.FeatureGate.Enabled(features.AllowSyncAllCustomResources) { syncResources = negotiator.dynamicDiscovery.AttachAllCustomResourcesToSyncResources(syncResources) } @@ -85,7 +99,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.ExcludeResources...) for _, resource := range groupResources.Resources { + if excludedResourcesSet.Has(resource) { + continue + } syncGR := schema.GroupResource{Group: groupResources.Group, Resource: resource} if clusterpediafeature.FeatureGate.Enabled(features.IgnoreSyncLease) { 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..273a7b8ff 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 + ExcludeResources []string `json:"excludeResources"` } 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..1ac5b73c5 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.ExcludeResources != nil { + in, out := &in.ExcludeResources, &out.ExcludeResources + *out = make([]string, len(*in)) + copy(*out, *in) + } return }