Skip to content

Commit c4fad97

Browse files
committed
Remove UID-based chunk label/selector usage and replace with chunkLister utilities
1 parent c085ecd commit c4fad97

7 files changed

Lines changed: 172 additions & 412 deletions

pkg/controller/bearer_controller.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import (
2727

2828
const (
2929
BearerNameAnnotationKey = v1alpha1.GroupName + "/bearer-name"
30-
BearerUIDLabelKey = v1alpha1.GroupName + "/bearer-uid"
3130
)
3231

3332
type BearerController struct {

pkg/controller/bearer_to_chunk_controller.go

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ import (
3030
"github.com/OpenCIDN/cidn/pkg/internal/utils"
3131
apierrors "k8s.io/apimachinery/pkg/api/errors"
3232
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
33-
"k8s.io/apimachinery/pkg/labels"
3433
"k8s.io/client-go/tools/cache"
3534
"k8s.io/client-go/util/workqueue"
3635
"k8s.io/klog/v2"
@@ -109,11 +108,8 @@ func (c *BearerToChunkController) runWorker(ctx context.Context) {
109108
}
110109

111110
func (c *BearerToChunkController) cleanupBearer(bearer *v1alpha1.Bearer) {
112-
err := c.client.TaskV1alpha1().Chunks().DeleteCollection(context.Background(), metav1.DeleteOptions{}, metav1.ListOptions{
113-
LabelSelector: labels.Set{
114-
BearerUIDLabelKey: string(bearer.UID),
115-
}.String(),
116-
})
111+
chunkName := buildBearerChunkName(bearer.Name)
112+
err := c.client.TaskV1alpha1().Chunks().Delete(context.Background(), chunkName, metav1.DeleteOptions{})
117113
if err != nil {
118114
klog.Errorf("failed to delete chunks for bearer %s: %v", bearer.Name, err)
119115
}
@@ -185,21 +181,11 @@ func (c *BearerToChunkController) toChunk(ctx context.Context, bearer *v1alpha1.
185181

186182
chunk := &v1alpha1.Chunk{
187183
ObjectMeta: metav1.ObjectMeta{
188-
Name: chunkName,
189-
Labels: map[string]string{
190-
BearerUIDLabelKey: string(bearer.UID),
191-
},
184+
Name: chunkName,
185+
Labels: map[string]string{},
192186
Annotations: map[string]string{
193187
BearerNameAnnotationKey: bearer.Name,
194188
},
195-
OwnerReferences: []metav1.OwnerReference{
196-
{
197-
APIVersion: v1alpha1.GroupVersion.String(),
198-
Kind: v1alpha1.BearerKind,
199-
Name: bearer.Name,
200-
UID: bearer.UID,
201-
},
202-
},
203189
},
204190
Spec: v1alpha1.ChunkSpec{
205191
Priority: bearer.Spec.Priority + 1,

pkg/controller/blob_controller.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,16 @@ import (
2020
"context"
2121

2222
"github.com/OpenCIDN/cidn/pkg/apis/task/v1alpha1"
23+
taskv1alpha1 "github.com/OpenCIDN/cidn/pkg/apis/task/v1alpha1"
2324
"github.com/OpenCIDN/cidn/pkg/clientset/versioned"
2425
"github.com/OpenCIDN/cidn/pkg/informers/externalversions"
26+
"github.com/OpenCIDN/cidn/pkg/internal/utils"
2527
"github.com/wzshiming/sss"
28+
"k8s.io/client-go/tools/cache"
2629
)
2730

2831
const (
2932
BlobNameAnnotationKey = v1alpha1.GroupName + "/blob-name"
30-
BlobUIDLabelKey = v1alpha1.GroupName + "/blob-uid"
3133
)
3234

3335
type BlobController struct {
@@ -89,3 +91,7 @@ func (c *BlobController) Start(ctx context.Context) error {
8991

9092
return nil
9193
}
94+
95+
func chunkLister(index cache.Indexer) utils.ResourceIndexer[*taskv1alpha1.Chunk] {
96+
return utils.NewResourceIndexer[*taskv1alpha1.Chunk](index, taskv1alpha1.Resource("chunk"), "")
97+
}

pkg/controller/blob_from_chunk_controller.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -372,9 +372,11 @@ func (c *BlobFromChunkController) fromChunks(ctx context.Context, blob *v1alpha1
372372

373373
mp = mp.DeepCopy()
374374

375-
chunks, err := c.chunkInformer.Lister().List(labels.SelectorFromSet(labels.Set{
376-
BlobUIDLabelKey: string(blob.UID),
377-
}))
375+
chunks, err := chunkLister(c.chunkInformer.Informer().GetIndexer()).List(
376+
labels.Everything(),
377+
labels.SelectorFromSet(labels.Set{
378+
BlobNameAnnotationKey: blob.Name,
379+
}))
378380
if err != nil {
379381
return fmt.Errorf("failed to list chunks: %w", err)
380382
}
@@ -614,9 +616,11 @@ func verifyDestinationSha256(ctx context.Context, s3 *sss.SSS, dst *v1alpha1.Blo
614616
// deleteChunksInNonFinalStates deletes chunks that are in Running, Pending, or Unknown states
615617
// when a blob fails. This ensures cleanup of incomplete work when a blob cannot be completed.
616618
func (c *BlobFromChunkController) deleteChunksInNonFinalStates(ctx context.Context, blob *v1alpha1.Blob) {
617-
chunks, err := c.chunkInformer.Lister().List(labels.SelectorFromSet(labels.Set{
618-
BlobUIDLabelKey: string(blob.UID),
619-
}))
619+
chunks, err := chunkLister(c.chunkInformer.Informer().GetIndexer()).List(
620+
labels.Everything(),
621+
labels.SelectorFromSet(labels.Set{
622+
BlobNameAnnotationKey: blob.Name,
623+
}))
620624
if err != nil {
621625
klog.Errorf("failed to list chunks for blob %s during cleanup: %v", blob.Name, err)
622626
return

0 commit comments

Comments
 (0)