Skip to content

Commit d1d7b1a

Browse files
authored
Merge pull request #3172 from sttts/sttts-e2e-cache-inline-scenarios
🌱 cache-server: misc cleanups
2 parents f1102d8 + b4246be commit d1d7b1a

File tree

2 files changed

+17
-30
lines changed

2 files changed

+17
-30
lines changed

sdk/apis/core/helper/replicate.go

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,11 @@ func DontReplicateForValue(replicateValue, controller string) (result string, ch
5353
// ReplicateFor ensures the controller string is part of the separated list of controller names
5454
// in the internal.kcp.io/replicate label. This function changes the annotations in-place.
5555
func ReplicateFor(annotations map[string]string, controller string) (result map[string]string, changed bool) {
56-
for k, v := range annotations {
57-
if k != core.ReplicateAnnotationKey {
58-
continue
59-
}
60-
56+
if v := annotations[core.ReplicateAnnotationKey]; v != "" {
6157
existing := sets.New[string](strings.Split(v, ",")...)
6258
if !existing.Has(controller) {
6359
existing.Insert(controller)
64-
annotations[k] = strings.Join(sets.List[string](existing), ",")
60+
annotations[core.ReplicateAnnotationKey] = strings.Join(sets.List[string](existing), ",")
6561
return annotations, true
6662
}
6763
return annotations, false
@@ -77,19 +73,15 @@ func ReplicateFor(annotations map[string]string, controller string) (result map[
7773
// DontReplicateFor ensures the controller string is not part of the separated list of controller names
7874
// in the internal.kcp.io/replicate label. This function changes the annotations in-place.
7975
func DontReplicateFor(annotations map[string]string, controller string) (result map[string]string, changed bool) {
80-
for k, v := range annotations {
81-
if k != core.ReplicateAnnotationKey {
82-
continue
83-
}
84-
76+
if v := annotations[core.ReplicateAnnotationKey]; v != "" {
8577
if v == controller {
86-
delete(annotations, k)
78+
delete(annotations, core.ReplicateAnnotationKey)
8779
return annotations, true
8880
}
8981
existing := sets.New[string](strings.Split(v, ",")...)
9082
if existing.Has(controller) {
9183
existing.Delete(controller)
92-
annotations[k] = strings.Join(sets.List[string](existing), ",")
84+
annotations[core.ReplicateAnnotationKey] = strings.Join(sets.List[string](existing), ",")
9385
return annotations, true
9486
}
9587
return annotations, false

test/e2e/reconciler/cache/replication_test.go

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -57,23 +57,6 @@ type testScenario struct {
5757
work func(ctx context.Context, t *testing.T, server framework.RunningServer, kcpShardClusterDynamicClient kcpdynamic.ClusterInterface, cacheKcpClusterDynamicClient kcpdynamic.ClusterInterface)
5858
}
5959

60-
// scenarios all test scenarios that will be run against an environment provided by the test binary.
61-
var scenarios = []testScenario{
62-
{"TestReplicateAPIExport", replicateAPIExportScenario},
63-
{"TestReplicateAPIExportNegative", replicateAPIExportNegativeScenario},
64-
{"TestReplicateAPIResourceSchema", replicateAPIResourceSchemaScenario},
65-
{"TestReplicateAPIResourceSchemaNegative", replicateAPIResourceSchemaNegativeScenario},
66-
{"TestReplicateWorkspaceType", replicateWorkspaceTypeScenario},
67-
{"TestReplicateWorkspaceTypeNegative", replicateWorkspaceTypeNegativeScenario},
68-
}
69-
70-
// disruptiveScenarios contains a list of scenarios that will be run in a private environment
71-
// so that they don't disrupt other tests.
72-
var disruptiveScenarios = []testScenario{
73-
{"TestReplicateShard", replicateShardScenario},
74-
{"TestReplicateShardNegative", replicateShardNegativeScenario},
75-
}
76-
7760
// replicateAPIResourceSchemaScenario tests if an APIResourceSchema is propagated to the cache server.
7861
// The test exercises creation, modification and removal of the APIResourceSchema object.
7962
func replicateAPIResourceSchemaScenario(ctx context.Context, t *testing.T, server framework.RunningServer, kcpShardClusterDynamicClient kcpdynamic.ClusterInterface, cacheKcpClusterDynamicClient kcpdynamic.ClusterInterface) {
@@ -436,6 +419,14 @@ func TestReplication(t *testing.T) {
436419
cacheKcpClusterDynamicClient, err := kcpdynamic.NewForConfig(cacheClientRT)
437420
require.NoError(t, err)
438421

422+
scenarios := []testScenario{
423+
{"APIExport", replicateAPIExportScenario},
424+
{"APIExportNegative", replicateAPIExportNegativeScenario},
425+
{"APIResourceSchema", replicateAPIResourceSchemaScenario},
426+
{"APIResourceSchemaNegative", replicateAPIResourceSchemaNegativeScenario},
427+
{"WorkspaceType", replicateWorkspaceTypeScenario},
428+
{"WorkspaceTypeNegative", replicateWorkspaceTypeNegativeScenario},
429+
}
439430
for _, scenario := range scenarios {
440431
scenario := scenario
441432
t.Run(scenario.name, func(t *testing.T) {
@@ -450,6 +441,10 @@ func TestReplicationDisruptive(t *testing.T) {
450441
t.Parallel()
451442
framework.Suite(t, "control-plane")
452443

444+
disruptiveScenarios := []testScenario{
445+
{"Shard", replicateShardScenario},
446+
{"ShardNegative", replicateShardNegativeScenario},
447+
}
453448
for _, scenario := range disruptiveScenarios {
454449
scenario := scenario
455450

0 commit comments

Comments
 (0)