Skip to content

Commit d3f8e36

Browse files
committed
/test: rename CachedResource to ClusterCachedResource
Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
1 parent 687e245 commit d3f8e36

8 files changed

Lines changed: 171 additions & 171 deletions

File tree

test/e2e/cache/assets/published-resource-instances.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
apiVersion: cache.kcp.io/v1alpha1
2-
kind: CachedResource
2+
kind: ClusterCachedResource
33
metadata:
44
name: instances
55
spec:

test/e2e/cache/replication_api_cache_test.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ func TestCacheServerReplicationAPI(t *testing.T) {
133133

134134
t.Logf("Wait for replication api to be ready and reporting 7 replicas")
135135
kcptestinghelpers.Eventually(t, func() (bool, string) {
136-
publishedResource, err := orgProviderKCPClient.Cluster(rootOrg).CacheV1alpha1().CachedResources().Get(ctx, "instances", metav1.GetOptions{})
136+
publishedResource, err := orgProviderKCPClient.Cluster(rootOrg).CacheV1alpha1().ClusterCachedResources().Get(ctx, "instances", metav1.GetOptions{})
137137
require.NoError(t, err)
138138
return publishedResource != nil && publishedResource.Status.ResourceCounts != nil && publishedResource.Status.ResourceCounts.Cache == 7, yamlMarshal(t, publishedResource)
139139
}, wait.ForeverTestTimeout, 100*time.Millisecond, "waiting for replication api to be ready and reporting 7 replicas")
@@ -144,7 +144,7 @@ func TestCacheServerReplicationAPI(t *testing.T) {
144144
err = dynamicClusterClient.Cluster(rootOrg).Resource(schema.GroupVersionResource{Group: "machines.svm.io", Version: "v1alpha1", Resource: "instances"}).Delete(ctx, "analytics-2", metav1.DeleteOptions{})
145145
require.NoError(t, err)
146146
kcptestinghelpers.Eventually(t, func() (bool, string) {
147-
publishedResource, err := orgProviderKCPClient.Cluster(rootOrg).CacheV1alpha1().CachedResources().Get(ctx, "instances", metav1.GetOptions{})
147+
publishedResource, err := orgProviderKCPClient.Cluster(rootOrg).CacheV1alpha1().ClusterCachedResources().Get(ctx, "instances", metav1.GetOptions{})
148148
require.NoError(t, err)
149149
return publishedResource != nil && publishedResource.Status.ResourceCounts != nil && publishedResource.Status.ResourceCounts.Cache == 5, yamlMarshal(t, publishedResource)
150150
}, wait.ForeverTestTimeout, 100*time.Millisecond, "waiting for replication api to be ready and reporting 5 replicas")
@@ -208,7 +208,7 @@ func TestReplicationWithWildcardListing(t *testing.T) {
208208
t.Parallel()
209209
var err error
210210

211-
// We need the Instances CRD + a few of its CRs for testing and a CachedResource for that Instance resource + its identity secret.
211+
// We need the Instances CRD + a few of its CRs for testing and a ClusterCachedResource for that Instance resource + its identity secret.
212212
// We iterate over two different identities, so we should have two distinct Instance resources across the cache server.
213213

214214
t.Logf("Install Instances CRD into workspace %q", ws)
@@ -245,13 +245,13 @@ func TestReplicationWithWildcardListing(t *testing.T) {
245245
}, metav1.CreateOptions{})
246246
require.NoError(t, err, "error creating identity secret %s workspace", ws)
247247

248-
t.Logf("Create a CachedResource in workspace %q", ws)
249-
_, err = kcpClusterClient.Cluster(ws).CacheV1alpha1().CachedResources().
250-
Create(ctx, &cachev1alpha1.CachedResource{
248+
t.Logf("Create a ClusterCachedResource in workspace %q", ws)
249+
_, err = kcpClusterClient.Cluster(ws).CacheV1alpha1().ClusterCachedResources().
250+
Create(ctx, &cachev1alpha1.ClusterCachedResource{
251251
ObjectMeta: metav1.ObjectMeta{
252252
Name: "instances",
253253
},
254-
Spec: cachev1alpha1.CachedResourceSpec{
254+
Spec: cachev1alpha1.ClusterCachedResourceSpec{
255255
GroupVersionResource: cachev1alpha1.GroupVersionResource{
256256
Group: "machines.svm.io",
257257
Version: "v1alpha1",
@@ -270,11 +270,11 @@ func TestReplicationWithWildcardListing(t *testing.T) {
270270
},
271271
},
272272
}, metav1.CreateOptions{})
273-
require.NoError(t, err, "error creating CachedResource in workspace %s", ws)
273+
require.NoError(t, err, "error creating ClusterCachedResource in workspace %s", ws)
274274

275275
t.Logf("Wait while the Instance objects in workspace %q are replicated", ws)
276276
kcptestinghelpers.Eventually(t, func() (bool, string) {
277-
cr, err := kcpClusterClient.Cluster(ws).CacheV1alpha1().CachedResources().
277+
cr, err := kcpClusterClient.Cluster(ws).CacheV1alpha1().ClusterCachedResources().
278278
Get(ctx, "instances", metav1.GetOptions{})
279279
require.NoError(t, err)
280280
if cr.Status.ResourceCounts == nil {
@@ -289,7 +289,7 @@ func TestReplicationWithWildcardListing(t *testing.T) {
289289
return true, ""
290290
}, wait.ForeverTestTimeout, 100*time.Millisecond, "waiting for CRD to be established")
291291

292-
cr, err := kcpClusterClient.Cluster(ws).CacheV1alpha1().CachedResources().
292+
cr, err := kcpClusterClient.Cluster(ws).CacheV1alpha1().ClusterCachedResources().
293293
Get(ctx, "instances", metav1.GetOptions{})
294294
require.NoError(t, err)
295295
require.NotEmpty(t, cr.Status.IdentityHash, "identity hash should not be empty")
@@ -338,16 +338,16 @@ func TestReplicationWithWildcardListing(t *testing.T) {
338338
)
339339
require.NoError(t, err, "scoped get from cache should succeed")
340340

341-
// Once the CachedResource in B1's ws is deleted, the instances resource should be gone from cache too.
341+
// Once the ClusterCachedResource in B1's ws is deleted, the instances resource should be gone from cache too.
342342

343-
t.Logf("Wait while CachedResource in %q workspace is deleted", wsB1Path)
344-
err = kcpClusterClient.CacheV1alpha1().CachedResources().Cluster(wsB1Path).Delete(t.Context(), "instances", metav1.DeleteOptions{})
345-
require.NoError(t, err, "deleting CachedResource %s|%s should not fail", wsB1Path, "instances")
343+
t.Logf("Wait while ClusterCachedResource in %q workspace is deleted", wsB1Path)
344+
err = kcpClusterClient.CacheV1alpha1().ClusterCachedResources().Cluster(wsB1Path).Delete(t.Context(), "instances", metav1.DeleteOptions{})
345+
require.NoError(t, err, "deleting ClusterCachedResource %s|%s should not fail", wsB1Path, "instances")
346346
kcptestinghelpers.Eventually(t, func() (bool, string) {
347-
_, err = kcpClusterClient.CacheV1alpha1().CachedResources().Cluster(wsB1Path).Get(t.Context(), "instances", metav1.GetOptions{})
347+
_, err = kcpClusterClient.CacheV1alpha1().ClusterCachedResources().Cluster(wsB1Path).Get(t.Context(), "instances", metav1.GetOptions{})
348348
return apierrors.IsNotFound(err), fmt.Sprintf("expected NotFound, got err=%v", err)
349-
}, wait.ForeverTestTimeout, 100*time.Millisecond, "waiting for CachedResource to be deleted")
350-
// Just to be safe it's better to be polling for NotFound, because the CachedResource informer
349+
}, wait.ForeverTestTimeout, 100*time.Millisecond, "waiting for ClusterCachedResource to be deleted")
350+
// Just to be safe it's better to be polling for NotFound, because the ClusterCachedResource informer
351351
// in cache-server's CRD lister might be behind, and/or the resources still being GC'd.
352352
kcptestinghelpers.Eventually(t, func() (bool, string) {
353353
_, err = cacheDynClient.Cluster(b1ClusterName).Resource(schema.GroupVersionResource{

test/e2e/framework/util.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,10 @@ func ExportVirtualWorkspaceURLs(export *apisv1alpha1.APIExportEndpointSlice) []s
9595
}
9696

9797
// ReplicationVirtualWorkspaceURLs returns the URLs of the virtual workspaces of the
98-
// given CachedResourceEndpointSlice.
99-
func ReplicationVirtualWorkspaceURLs(slice *cachev1alpha1.CachedResourceEndpointSlice) []string {
100-
urls := make([]string, 0, len(slice.Status.CachedResourceEndpoints))
101-
for _, vw := range slice.Status.CachedResourceEndpoints {
98+
// given ClusterCachedResourceEndpointSlice.
99+
func ReplicationVirtualWorkspaceURLs(slice *cachev1alpha1.ClusterCachedResourceEndpointSlice) []string {
100+
urls := make([]string, 0, len(slice.Status.ClusterCachedResourceEndpoints))
101+
for _, vw := range slice.Status.ClusterCachedResourceEndpoints {
102102
urls = append(urls, vw.URL)
103103
}
104104
return urls

test/e2e/reconciler/cache/replication_test.go

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ import (
5454

5555
cacheclient "github.com/kcp-dev/kcp/pkg/cache/client"
5656
"github.com/kcp-dev/kcp/pkg/cache/client/shard"
57-
"github.com/kcp-dev/kcp/pkg/reconciler/cache/cachedresources/replication"
57+
"github.com/kcp-dev/kcp/pkg/reconciler/cache/clustercachedresources/replication"
5858
"github.com/kcp-dev/kcp/test/e2e/framework"
5959
)
6060

@@ -414,18 +414,18 @@ func replicateResourceNegative(ctx context.Context, t *testing.T,
414414
scenario.VerifyReplication(t.Context(), t)
415415

416416
t.Logf("Delete cached %s %s/%s and check if it was brought back by the replication controller", kind, clusterName, resourceName)
417-
scenario.DeleteCachedResource(t.Context(), t)
417+
scenario.DeleteClusterCachedResource(t.Context(), t)
418418
scenario.VerifyReplication(t.Context(), t)
419419

420420
if resWithModifiedSpec != nil {
421421
t.Logf("Update cached %s %s/%s so that it differs from the source resource", kind, clusterName, scenario.resourceName)
422-
scenario.UpdateSpecCachedResource(t.Context(), t, resWithModifiedSpec)
422+
scenario.UpdateSpecClusterCachedResource(t.Context(), t, resWithModifiedSpec)
423423
t.Logf("Verify that the cached %s %s/%s was brought back by the replication controller after an update", kind, clusterName, resourceName)
424424
scenario.VerifyReplication(t.Context(), t)
425425
}
426426

427427
t.Logf("Update cached %s %s/%s so that it differs from the source resource", kind, clusterName, scenario.resourceName)
428-
scenario.UpdateMetaCachedResource(t.Context(), t)
428+
scenario.UpdateMetaClusterCachedResource(t.Context(), t)
429429
t.Logf("Verify that the cached %s %s/%s was brought back by the replication controller after an update", kind, clusterName, resourceName)
430430
scenario.VerifyReplication(t.Context(), t)
431431
}
@@ -562,7 +562,7 @@ func (b *replicateResourceScenario) UpdateSpecSourceResource(ctx context.Context
562562
})
563563
}
564564

565-
func (b *replicateResourceScenario) UpdateMetaCachedResource(ctx context.Context, t *testing.T) {
565+
func (b *replicateResourceScenario) UpdateMetaClusterCachedResource(ctx context.Context, t *testing.T) {
566566
t.Helper()
567567
b.resourceUpdateHelper(t.Context(), t, func(ctx context.Context) (*unstructured.Unstructured, error) {
568568
return b.cacheKcpClusterDynamicClient.Resource(b.gvr).Cluster(b.cluster.Path()).Get(cacheclient.WithShardInContext(t.Context(), shard.New("root")), b.resourceName, metav1.GetOptions{})
@@ -579,7 +579,7 @@ func (b *replicateResourceScenario) UpdateMetaCachedResource(ctx context.Context
579579
})
580580
}
581581

582-
func (b *replicateResourceScenario) UpdateSpecCachedResource(ctx context.Context, t *testing.T, resWithModifiedSpec runtime.Object) {
582+
func (b *replicateResourceScenario) UpdateSpecClusterCachedResource(ctx context.Context, t *testing.T, resWithModifiedSpec runtime.Object) {
583583
t.Helper()
584584
b.resourceUpdateHelper(t.Context(), t, func(ctx context.Context) (*unstructured.Unstructured, error) {
585585
return b.cacheKcpClusterDynamicClient.Resource(b.gvr).Cluster(b.cluster.Path()).Get(cacheclient.WithShardInContext(t.Context(), shard.New("root")), b.resourceName, metav1.GetOptions{})
@@ -627,7 +627,7 @@ func (b *replicateResourceScenario) DeleteSourceResourceAndVerify(ctx context.Co
627627
}, wait.ForeverTestTimeout, 100*time.Millisecond)
628628
}
629629

630-
func (b *replicateResourceScenario) DeleteCachedResource(ctx context.Context, t *testing.T) {
630+
func (b *replicateResourceScenario) DeleteClusterCachedResource(ctx context.Context, t *testing.T) {
631631
t.Helper()
632632
err := b.cacheKcpClusterDynamicClient.Resource(b.gvr).Cluster(b.cluster.Path()).Delete(cacheclient.WithShardInContext(t.Context(), shard.New("root")), b.resourceName, metav1.DeleteOptions{})
633633
require.NoError(t, err)
@@ -679,7 +679,7 @@ func (b *replicateResourceScenario) verifyResourceReplicationHelper(ctx context.
679679
if err != nil {
680680
return false, err.Error()
681681
}
682-
cachedResource, err := b.cacheKcpClusterDynamicClient.Resource(b.gvr).Cluster(b.cluster.Path()).Get(cacheclient.WithShardInContext(t.Context(), shard.New("root")), b.resourceName, metav1.GetOptions{})
682+
clusterCachedResource, err := b.cacheKcpClusterDynamicClient.Resource(b.gvr).Cluster(b.cluster.Path()).Get(cacheclient.WithShardInContext(t.Context(), shard.New("root")), b.resourceName, metav1.GetOptions{})
683683
if err != nil {
684684
if !errors.IsNotFound(err) {
685685
return true, err.Error()
@@ -692,40 +692,40 @@ func (b *replicateResourceScenario) verifyResourceReplicationHelper(ctx context.
692692
replication.AnnotationKeyOriginalResourceVersion,
693693
replication.AnnotationKeyOriginalResourceUID,
694694
)
695-
cachedResourceMeta, err := meta.Accessor(cachedResource)
695+
clusterCachedResourceMeta, err := meta.Accessor(clusterCachedResource)
696696
if err != nil {
697697
return false, err.Error()
698698
}
699-
if _, found := cachedResourceMeta.GetAnnotations()[genericapirequest.ShardAnnotationKey]; !found {
700-
t.Fatalf("replicated %s root|%s/%s, doesn't have %s annotation", b.gvr, cluster, cachedResourceMeta.GetName(), genericapirequest.ShardAnnotationKey)
699+
if _, found := clusterCachedResourceMeta.GetAnnotations()[genericapirequest.ShardAnnotationKey]; !found {
700+
t.Fatalf("replicated %s root|%s/%s, doesn't have %s annotation", b.gvr, cluster, clusterCachedResourceMeta.GetName(), genericapirequest.ShardAnnotationKey)
701701
}
702-
if _, found := cachedResourceMeta.GetAnnotations()[replication.AnnotationKeyOriginalResourceVersion]; !found {
703-
t.Fatalf("replicated %s root|%s/%s, doesn't have %s annotation", b.gvr, cluster, cachedResourceMeta.GetName(), replication.AnnotationKeyOriginalResourceVersion)
702+
if _, found := clusterCachedResourceMeta.GetAnnotations()[replication.AnnotationKeyOriginalResourceVersion]; !found {
703+
t.Fatalf("replicated %s root|%s/%s, doesn't have %s annotation", b.gvr, cluster, clusterCachedResourceMeta.GetName(), replication.AnnotationKeyOriginalResourceVersion)
704704
}
705-
if _, found := cachedResourceMeta.GetAnnotations()[replication.AnnotationKeyOriginalResourceUID]; !found {
706-
t.Fatalf("replicated %s root|%s/%s, doesn't have %s annotation", b.gvr, cluster, cachedResourceMeta.GetName(), replication.AnnotationKeyOriginalResourceUID)
705+
if _, found := clusterCachedResourceMeta.GetAnnotations()[replication.AnnotationKeyOriginalResourceUID]; !found {
706+
t.Fatalf("replicated %s root|%s/%s, doesn't have %s annotation", b.gvr, cluster, clusterCachedResourceMeta.GetName(), replication.AnnotationKeyOriginalResourceUID)
707707
}
708708
unstructured.RemoveNestedField(originalResource.Object, "metadata", "resourceVersion")
709-
unstructured.RemoveNestedField(cachedResource.Object, "metadata", "resourceVersion")
709+
unstructured.RemoveNestedField(clusterCachedResource.Object, "metadata", "resourceVersion")
710710

711711
// TODO(davidfestal): find out why the generation is not equal, specially for rbacv1.
712712
// Is it a characteristic of all built-in kcp resources (which are not backed by CRDs) ?
713713
// Issue opened: https://github.com/kcp-dev/kcp/issues/2935
714714
if b.gvr.Group == rbacv1.SchemeGroupVersion.Group {
715715
unstructured.RemoveNestedField(originalResource.Object, "metadata", "generation")
716-
unstructured.RemoveNestedField(cachedResource.Object, "metadata", "generation")
716+
unstructured.RemoveNestedField(clusterCachedResource.Object, "metadata", "generation")
717717
}
718718

719-
unstructured.RemoveNestedField(cachedResource.Object, "metadata", "annotations", genericapirequest.ShardAnnotationKey)
720-
unstructured.RemoveNestedField(cachedResource.Object, "metadata", "annotations", replication.AnnotationKeyOriginalResourceVersion)
721-
unstructured.RemoveNestedField(cachedResource.Object, "metadata", "annotations", replication.AnnotationKeyOriginalResourceUID)
722-
if cachedStatus, ok := cachedResource.Object["status"]; ok && cachedStatus == nil || (cachedStatus != nil && len(cachedStatus.(map[string]interface{})) == 0) {
719+
unstructured.RemoveNestedField(clusterCachedResource.Object, "metadata", "annotations", genericapirequest.ShardAnnotationKey)
720+
unstructured.RemoveNestedField(clusterCachedResource.Object, "metadata", "annotations", replication.AnnotationKeyOriginalResourceVersion)
721+
unstructured.RemoveNestedField(clusterCachedResource.Object, "metadata", "annotations", replication.AnnotationKeyOriginalResourceUID)
722+
if cachedStatus, ok := clusterCachedResource.Object["status"]; ok && cachedStatus == nil || (cachedStatus != nil && len(cachedStatus.(map[string]interface{})) == 0) {
723723
// TODO: worth investigating:
724724
// for some reason cached resources have an empty status set whereas the original resources don't
725-
unstructured.RemoveNestedField(cachedResource.Object, "status")
725+
unstructured.RemoveNestedField(clusterCachedResource.Object, "status")
726726
}
727-
if diff := cmp.Diff(cachedResource.Object, originalResource.Object); len(diff) > 0 {
728-
return false, fmt.Sprintf("replicated %s root|%s/%s is different from the original: %s", b.gvr, cluster, cachedResourceMeta.GetName(), diff)
727+
if diff := cmp.Diff(clusterCachedResource.Object, originalResource.Object); len(diff) > 0 {
728+
return false, fmt.Sprintf("replicated %s root|%s/%s is different from the original: %s", b.gvr, cluster, clusterCachedResourceMeta.GetName(), diff)
729729
}
730730
return true, ""
731731
}, wait.ForeverTestTimeout, 100*time.Millisecond)

0 commit comments

Comments
 (0)