Skip to content
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

🌱 cache: add replication tests for WorkspaceType resource #2578

Merged

Conversation

p0lyn0mial
Copy link
Contributor

Summary

  • switch to dynamic clients
  • provide generic functions for creating replication scenarios
  • cover replication of WorkspaceType resource

Related issue(s)

replaces #2449

"replicate-workspace-type",
"WorkspaceType",
tenancyv1alpha1.SchemeGroupVersion.WithResource("workspacetypes"),
&tenancyv1alpha1.WorkspaceType{ObjectMeta: metav1.ObjectMeta{Name: "replicate-workspace-type"}, Spec: tenancyv1alpha1.WorkspaceTypeSpec{}},
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

on the next iteration, we could change the scenarios to only provide a resource and some type information.

// The test exercises creation, modification and removal of the Shard object.
func replicateWorkspaceTypeScenario(ctx context.Context, t *testing.T, server framework.RunningServer, kcpShardClusterDynamicClient kcpdynamic.ClusterInterface, cacheKcpClusterDynamicClient kcpdynamic.ClusterInterface) {
t.Helper()
replicateResource(ctx,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the bottom line is that now a new scenario requires calling replicateResource

// The test exercises creation, modification and removal of the resource.
func replicateResource(ctx context.Context, t *testing.T,
server framework.RunningServer, kcpShardClusterDynamicClient kcpdynamic.ClusterInterface, cacheKcpClusterDynamicClient kcpdynamic.ClusterInterface,
clusterName logicalcluster.Name, resourceName string, kind string, gvr schema.GroupVersionResource, res runtime.Object, resWithModifiedSpec runtime.Object) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a lot of parameters for a function, some of them are not specific, e.g: server, kcpShardClusterDynamicClient, cacheKcpClusterDynamicClient.
Others are specific to a testScenario, e.g.: t, gvr
It feels like it would be possible to reduce the number of parameters that need to be provided.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, an alternative would be to provide a struct but filling all required fields would at the calling line look the same (almost) as providing params. I will try to think about how it could be changed.

"APIExport",
apisv1alpha1.SchemeGroupVersion.WithResource("apiexports"),
&apisv1alpha1.APIExport{ObjectMeta: metav1.ObjectMeta{Name: "wild.wild.west"}},
&apisv1alpha1.APIExport{ObjectMeta: metav1.ObjectMeta{Name: "wild.wild.west"}, Spec: apisv1alpha1.APIExportSpec{LatestResourceSchemas: []string{"foo.bar"}}},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like having the resource definitions outside of the call to replicateResource may improve the readability.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, maybe we could bring them closer to the place where we define scenarios

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'm not sure exactly how it should look, I will try to think about it and change it on the next iteration

Copy link
Contributor

@fgiloux fgiloux Jan 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For now could you have the fields on a new line like in replicateAPIExportNegativeScenario?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done, ptal

}

// 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, kcpShardClusterClient kcpclientset.ClusterInterface, cacheKcpClusterClient kcpclientset.ClusterInterface) {
func replicateAPIResourceSchemaScenario(ctx context.Context, t *testing.T, server framework.RunningServer, kcpShardClusterDynamicClient kcpdynamic.ClusterInterface, cacheKcpClusterDynamicClient kcpdynamic.ClusterInterface) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to have a few lines of comment to describe what needs to be done to test the replication of a new resource.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i will add it to the generic functions

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@p0lyn0mial p0lyn0mial force-pushed the replication-e2e-workspace-type branch from c18419a to 7db7403 Compare January 10, 2023 10:45
@fgiloux
Copy link
Contributor

fgiloux commented Jan 10, 2023

/lgtm

I think it is a good improvement compared to what we have.
I am fine with factoring the parameters to replicateResource and separating the "create" and "update" definition from the function call in a later iteration.

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Jan 10, 2023
@sttts
Copy link
Member

sttts commented Jan 10, 2023

/approve

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Jan 10, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: sttts

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jan 10, 2023
@openshift-merge-robot openshift-merge-robot merged commit d82daf7 into kcp-dev:main Jan 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants