Skip to content

Commit

Permalink
feat: support excluded sync resources
Browse files Browse the repository at this point in the history
Signed-off-by: KubeKyrie <[email protected]>
  • Loading branch information
KubeKyrie committed Jan 2, 2024
1 parent b4117dd commit 139a875
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 0 deletions.
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.

0 comments on commit 139a875

Please sign in to comment.