Skip to content
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
6 changes: 6 additions & 0 deletions pkg/reconciler/topology/partitionset/partitioning_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,12 @@ func TestPartition(t *testing.T) {
for _, v := range matchLabelsMap {
require.Equal(t, "prod", v["environment"], "Expected that all partitions have a label selector for environment = prod")
}

matchLabelsMap = partition(shards, []string{"region", "environment"}, map[string]string{"environment": "prod"})
require.Equal(t, map[string]map[string]string{
"+environment=prod+region=Asia": {"environment": "prod", "region": "Asia"},
"+environment=prod+region=Europe": {"environment": "prod", "region": "Europe"},
}, matchLabelsMap, "Labels being both a dimension and in the shard selector should only be considered once")
}

func TestGeneratePartitionName(t *testing.T) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,13 @@ func TestReconcile(t *testing.T) {
wantPartitionCount: 2,
wantCountCreated: 2,
},
"Existing partition kept with selector and dimension overlapping": {
withMatchLabelOverlap: true,
existingValidPartition: true,
wantPartitionsReady: true,
wantPartitionCount: 2,
wantCountCreated: 1,
},
}

for name, tc := range tests {
Expand Down
11 changes: 5 additions & 6 deletions pkg/reconciler/topology/partitionset/partitionset_reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,12 +196,11 @@ func (c *controller) reconcile(ctx context.Context, partitionSet *topologyv1alph
// so that Partitions not referring to any Shard would not get created.
func partition(shards []*corev1alpha1.Shard, dimensions []string, shardSelectorLabels map[string]string) (matchLabelsMap map[string]map[string]string) {
matchLabelsMap = make(map[string]map[string]string)
l := make([]string, len(dimensions), len(dimensions)+len(shardSelectorLabels))
copy(l, dimensions)
for label := range shardSelectorLabels {
l = append(l, label)
}
sort.Strings(l) // Sorting for consistent comparison.
// A label can be both a dimension and part of the shard selector matchLabels.
// It must only be considered once, otherwise the generated key would not
// match the one computed from the matchLabels of existing Partitions.
// sets.List returns the labels sorted for consistent comparison.
l := sets.List(sets.KeySet(shardSelectorLabels).Insert(dimensions...))
for _, shard := range shards {
key := ""
selector := make(map[string]string)
Expand Down
Loading