Skip to content

Commit 705efd5

Browse files
authored
Merge pull request #593 from gianlucam76/sharding-annotation
(chore) move ShardingAnnotation
2 parents 3e23167 + a405a67 commit 705efd5

File tree

5 files changed

+12
-14
lines changed

5 files changed

+12
-14
lines changed

api/v1beta1/sveltoscluster_type.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ const (
2424
SveltosClusterKind = "SveltosCluster"
2525
)
2626

27+
const (
28+
ShardAnnotation = "sharding.projectsveltos.io/key"
29+
)
30+
2731
type ActiveWindow struct {
2832
// From in Cron format, see https://en.wikipedia.org/wiki/Cron.
2933
// Indicates when to un-pause the cluster (cluster in paused state receives no update from sveltos).

lib/clusterproxy/cluster_utils_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ import (
3333
libsveltosv1beta1 "github.com/projectsveltos/libsveltos/api/v1beta1"
3434
"github.com/projectsveltos/libsveltos/internal/test/helpers/external"
3535
"github.com/projectsveltos/libsveltos/lib/clusterproxy"
36-
"github.com/projectsveltos/libsveltos/lib/sharding"
3736
)
3837

3938
var _ = Describe("Cluster utils", func() {
@@ -229,8 +228,8 @@ var _ = Describe("Cluster utils", func() {
229228
Namespace: randomString(),
230229
Name: randomString(),
231230
Annotations: map[string]string{
232-
sharding.ShardAnnotation: shardKey,
233-
onboardAnnotation: randomString(),
231+
libsveltosv1beta1.ShardAnnotation: shardKey,
232+
onboardAnnotation: randomString(),
234233
},
235234
},
236235
}
@@ -240,7 +239,7 @@ var _ = Describe("Cluster utils", func() {
240239
Namespace: randomString(),
241240
Name: randomString(),
242241
Annotations: map[string]string{
243-
sharding.ShardAnnotation: randomString(),
242+
libsveltosv1beta1.ShardAnnotation: randomString(),
244243
},
245244
},
246245
}

lib/predicates/clusters_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import (
2626
"sigs.k8s.io/controller-runtime/pkg/event"
2727

2828
"github.com/projectsveltos/libsveltos/lib/predicates"
29-
"github.com/projectsveltos/libsveltos/lib/sharding"
3029

3130
clusterv1 "sigs.k8s.io/cluster-api/api/core/v1beta2"
3231

@@ -170,7 +169,7 @@ var _ = Describe("ClusterProfile Predicates: SvelotsClusterPredicates", func() {
170169
It("Update reprocesses when sveltos Cluster annotation change", func() {
171170
clusterPredicate := predicates.SveltosClusterPredicates(logger)
172171

173-
cluster.Annotations = map[string]string{sharding.ShardAnnotation: "shard1"}
172+
cluster.Annotations = map[string]string{libsveltosv1beta1.ShardAnnotation: "shard1"}
174173

175174
oldCluster := &libsveltosv1beta1.SveltosCluster{
176175
ObjectMeta: metav1.ObjectMeta{
@@ -329,7 +328,7 @@ var _ = Describe("ClusterProfile Predicates: ClusterPredicates", func() {
329328
It("Update reprocesses when v1Cluster annotation change", func() {
330329
clusterPredicate := predicates.ClusterPredicate{Logger: logger}
331330

332-
cluster.Labels = map[string]string{sharding.ShardAnnotation: "shard-production"}
331+
cluster.Labels = map[string]string{libsveltosv1beta1.ShardAnnotation: "shard-production"}
333332

334333
oldCluster := &clusterv1.Cluster{
335334
ObjectMeta: metav1.ObjectMeta{

lib/sharding/utils.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,6 @@ import (
3939
// A cluster with no shardAnnotation will only be managed by
4040
// the deployment started with no shard-key arg.
4141

42-
const (
43-
ShardAnnotation = "sharding.projectsveltos.io/key"
44-
)
45-
4642
// IsShardAMatch returns true if a cluster is a shard match.
4743
func IsShardAMatch(shardKey string, cluster client.Object) bool {
4844
annotations := cluster.GetAnnotations()
@@ -52,7 +48,7 @@ func IsShardAMatch(shardKey string, cluster client.Object) bool {
5248
return shardKey == ""
5349
}
5450

55-
v, ok := annotations[ShardAnnotation]
51+
v, ok := annotations[libsveltosv1beta1.ShardAnnotation]
5652
if !ok {
5753
// A cluster with no ShardAnnotation is only managed by
5854
// deployment started with no shard-key arg.

lib/sharding/utils_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ var _ = Describe("Sharding", func() {
8181

8282
Expect(sharding.IsShardAMatch(shard, cluster)).To(BeFalse())
8383

84-
cluster.Annotations[sharding.ShardAnnotation] = randomString()
84+
cluster.Annotations[libsveltosv1beta1.ShardAnnotation] = randomString()
8585
Expect(sharding.IsShardAMatch(shard, cluster)).To(BeFalse())
8686
})
8787

@@ -93,7 +93,7 @@ var _ = Describe("Sharding", func() {
9393
Namespace: randomString(),
9494
Name: randomString(),
9595
Annotations: map[string]string{
96-
sharding.ShardAnnotation: shard,
96+
libsveltosv1beta1.ShardAnnotation: shard,
9797
},
9898
},
9999
}

0 commit comments

Comments
 (0)