Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support excluded sync resources #617

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ spec:
syncResources:
items:
properties:
excludeResources:
items:
type: string
type: array
group:
type: string
resources:
Expand Down
4 changes: 4 additions & 0 deletions kustomize/crds/cluster.clusterpedia.io_pediaclusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ spec:
syncResources:
items:
properties:
excludeResources:
items:
type: string
type: array
group:
type: string
resources:
Expand Down
14 changes: 14 additions & 0 deletions pkg/generated/openapi/zz_generated.openapi.go

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

18 changes: 18 additions & 0 deletions pkg/synchromanager/clustersynchro/resource_negotiator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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)
}
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

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

Loading