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 Dec 28, 2023
1 parent 810c6c4 commit c842190
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ spec:
syncResources:
items:
properties:
excludedResource:
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:
excludedResource:
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.

10 changes: 6 additions & 4 deletions pkg/synchromanager/clustersynchro/cluster_synchro.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Check failure on line 63 in pkg/synchromanager/clustersynchro/cluster_synchro.go

View workflow job for this annotation

GitHub Actions / Lint with golangci-lint

`excludedSyncResources` is unused (structcheck)
setSyncResourcesCh chan struct{}
resourceNegotiator *ResourceNegotiator
groupResourceStatus atomic.Value // *GroupResourceStatus

runningCondition atomic.Value // metav1.Condition
healthyCondition atomic.Value // metav1.Condition
Expand Down Expand Up @@ -315,6 +316,7 @@ func (s *ClusterSynchro) refreshSyncResources() {
if syncResources == nil {
return
}

groupResourceStatus, storageResourceSyncConfigs := s.resourceNegotiator.NegotiateSyncResources(syncResources)

lastGroupResourceStatus := s.groupResourceStatus.Load().(*GroupResourceStatus)
Expand Down
4 changes: 4 additions & 0 deletions pkg/synchromanager/clustersynchro/resource_negotiator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
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
ExcludedResource []string `json:"excludedResource"`
}

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 c842190

Please sign in to comment.