Skip to content

🌱 cache-server: misc cleanups #3172

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 21, 2024
Merged
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
18 changes: 5 additions & 13 deletions sdk/apis/core/helper/replicate.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,11 @@ func DontReplicateForValue(replicateValue, controller string) (result string, ch
// ReplicateFor ensures the controller string is part of the separated list of controller names
// in the internal.kcp.io/replicate label. This function changes the annotations in-place.
func ReplicateFor(annotations map[string]string, controller string) (result map[string]string, changed bool) {
for k, v := range annotations {
if k != core.ReplicateAnnotationKey {
continue
}

if v := annotations[core.ReplicateAnnotationKey]; v != "" {
existing := sets.New[string](strings.Split(v, ",")...)
if !existing.Has(controller) {
existing.Insert(controller)
annotations[k] = strings.Join(sets.List[string](existing), ",")
annotations[core.ReplicateAnnotationKey] = strings.Join(sets.List[string](existing), ",")
return annotations, true
}
return annotations, false
Expand All @@ -77,19 +73,15 @@ func ReplicateFor(annotations map[string]string, controller string) (result map[
// DontReplicateFor ensures the controller string is not part of the separated list of controller names
// in the internal.kcp.io/replicate label. This function changes the annotations in-place.
func DontReplicateFor(annotations map[string]string, controller string) (result map[string]string, changed bool) {
for k, v := range annotations {
if k != core.ReplicateAnnotationKey {
continue
}

if v := annotations[core.ReplicateAnnotationKey]; v != "" {
if v == controller {
delete(annotations, k)
delete(annotations, core.ReplicateAnnotationKey)
return annotations, true
}
existing := sets.New[string](strings.Split(v, ",")...)
if existing.Has(controller) {
existing.Delete(controller)
annotations[k] = strings.Join(sets.List[string](existing), ",")
annotations[core.ReplicateAnnotationKey] = strings.Join(sets.List[string](existing), ",")
return annotations, true
}
return annotations, false
Expand Down
29 changes: 12 additions & 17 deletions test/e2e/reconciler/cache/replication_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,23 +57,6 @@ type testScenario struct {
work func(ctx context.Context, t *testing.T, server framework.RunningServer, kcpShardClusterDynamicClient kcpdynamic.ClusterInterface, cacheKcpClusterDynamicClient kcpdynamic.ClusterInterface)
}

// scenarios all test scenarios that will be run against an environment provided by the test binary.
var scenarios = []testScenario{
{"TestReplicateAPIExport", replicateAPIExportScenario},
{"TestReplicateAPIExportNegative", replicateAPIExportNegativeScenario},
{"TestReplicateAPIResourceSchema", replicateAPIResourceSchemaScenario},
{"TestReplicateAPIResourceSchemaNegative", replicateAPIResourceSchemaNegativeScenario},
{"TestReplicateWorkspaceType", replicateWorkspaceTypeScenario},
{"TestReplicateWorkspaceTypeNegative", replicateWorkspaceTypeNegativeScenario},
}

// disruptiveScenarios contains a list of scenarios that will be run in a private environment
// so that they don't disrupt other tests.
var disruptiveScenarios = []testScenario{
{"TestReplicateShard", replicateShardScenario},
{"TestReplicateShardNegative", replicateShardNegativeScenario},
}

// replicateAPIResourceSchemaScenario tests if an APIResourceSchema is propagated to the cache server.
// The test exercises creation, modification and removal of the APIResourceSchema object.
func replicateAPIResourceSchemaScenario(ctx context.Context, t *testing.T, server framework.RunningServer, kcpShardClusterDynamicClient kcpdynamic.ClusterInterface, cacheKcpClusterDynamicClient kcpdynamic.ClusterInterface) {
Expand Down Expand Up @@ -436,6 +419,14 @@ func TestReplication(t *testing.T) {
cacheKcpClusterDynamicClient, err := kcpdynamic.NewForConfig(cacheClientRT)
require.NoError(t, err)

scenarios := []testScenario{
{"APIExport", replicateAPIExportScenario},
{"APIExportNegative", replicateAPIExportNegativeScenario},
{"APIResourceSchema", replicateAPIResourceSchemaScenario},
{"APIResourceSchemaNegative", replicateAPIResourceSchemaNegativeScenario},
{"WorkspaceType", replicateWorkspaceTypeScenario},
{"WorkspaceTypeNegative", replicateWorkspaceTypeNegativeScenario},
}
for _, scenario := range scenarios {
scenario := scenario
t.Run(scenario.name, func(t *testing.T) {
Expand All @@ -450,6 +441,10 @@ func TestReplicationDisruptive(t *testing.T) {
t.Parallel()
framework.Suite(t, "control-plane")

disruptiveScenarios := []testScenario{
{"Shard", replicateShardScenario},
{"ShardNegative", replicateShardNegativeScenario},
}
for _, scenario := range disruptiveScenarios {
scenario := scenario

Expand Down
Loading