-
Notifications
You must be signed in to change notification settings - Fork 238
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
Feat: Add spanner database mockgcp #1829
Feat: Add spanner database mockgcp #1829
Conversation
Code LGTM. I'll look at that test failure :-) |
I think the test failure is that we need to implement DropDatabase in mockgcp...
I got this by running (I determined it was externalwithsubresource by downloading the raw logs and searching for |
Thanks @justinsb, fixed those issues. Ready for another review. |
I think there are some merge conflicts now that we merged SpannerInstance - mind rebasing? |
55823e4
to
45efbf0
Compare
@@ -8,7 +8,6 @@ metadata: | |||
cnrm.cloud.google.com/managed-by-kcc: "true" | |||
cnrm.cloud.google.com/stability-level: stable | |||
cnrm.cloud.google.com/system: "true" | |||
cnrm.cloud.google.com/tf2crd: "true" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This infers the spanner database is using the TF controller. I think that is good, because we are not ready to turn on the direct controller on this resource yet.
Then to test the mockGCP with the direct controller, you would need to use the KCC_USE_DIRECT_RECONCILERS
flag. Right now you can put the test coverage for "direct controller" here https://github.com/GoogleCloudPlatform/k8s-config-connector/blob/master/scripts/github-actions/tests-e2e-direct.sh with KCC_USE_DIRECT_RECONCILERS flag.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was just my hack to enable testing the direct controller manually in a real gcp environment with make deploy-controller && kubectl delete pods --namespace cnrm-system --all
. Not planning to merge it, will remove later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this looks good. You can consider spliting the mockGCP test (for TF controller) so it can goes in first.
hack/compare-mock
Outdated
@@ -5,6 +5,8 @@ set -x | |||
|
|||
export KUBEBUILDER_ASSETS=$(go run sigs.k8s.io/controller-runtime/tools/setup-envtest@latest use -p path) | |||
|
|||
export KCC_USE_DIRECT_RECONCILERS=SpannerDatabase |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: cleanup. (I know this PR is WIP)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am a bit confused on this actually. What is our final / production method for switching a resource to use the "direct" controller instead of the terraform-based controller?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To switch a resource to the direct controller, you only need to remove the CRD's tf2crd
label (for DCL based it is dcl2crd
). If a resource is not yet ready for direct controller but you want to run mock test against the direct controller, you can use the KCC_USE_DIRECT_RECONCILERS
flag.
In other words, direct controller is the default.
@@ -59,7 +59,7 @@ import ( | |||
"github.com/GoogleCloudPlatform/k8s-config-connector/mockgcp/mocksecretmanager" | |||
"github.com/GoogleCloudPlatform/k8s-config-connector/mockgcp/mockservicenetworking" | |||
"github.com/GoogleCloudPlatform/k8s-config-connector/mockgcp/mockserviceusage" | |||
mockspannerinstance "github.com/GoogleCloudPlatform/k8s-config-connector/mockgcp/mockspanner/admin" | |||
mockspanner "github.com/GoogleCloudPlatform/k8s-config-connector/mockgcp/mockspanner/admin" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually I had a question on this -- Why did you create the admin/
subdirectory for the instance mock? For other resources it looks like the code is placed directly in mockgcp/mock<resourcename>/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm trying to align that with its cloud client API https://pkg.go.dev/cloud.google.com/go/spanner#section-directories where the admin/
has instance and database and executor
has executor. I assume that's how spanner categorize its resources (and maybe will add more resources in the executor dir). But I don't have strong preference on this.
return nil, err | ||
} | ||
|
||
return s.operations.NewLRO(ctx) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we would want to use StartLRO if possible which better reflects the actual service behavior. (Feel free to make the improvement in follow up PRs.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I will look into this. Thanks 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is just a copy of your code from #1761. And, actually, I would prefer to reorganize and put the "util" code elsewhere, there is some guidance I've seen to avoid "util" files / packages, since they tend to become dumping grounds. WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, I'm not a fan of utils
or helpers
. I think those functions are generic and could be reused by other mock functions. Feel free to refactor the code!
a991444
to
31cb74c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/lgtm
Looks great! Some minor questions
Statements: req.Statements, | ||
} | ||
return s.operations.StartLRO(ctx, fqn, metadata, func() (proto.Message, error) { | ||
// Many fields are not populated in the LRO result |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: set the createTime, updateTime
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no field for updateTime for this resource, but just double-checked that createTime is being set.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, it looks like the Database uses Reconciling
(bool) to tell if the update succeeds or not.
// Given a list of DDL extra statement strings, find one with the format | ||
// "ALTER DATABASE `%s` SET OPTIONS (version_retention_period = '%s')" | ||
// and return the version_retention_period, or "1h" if no match. | ||
func versionRetentionPeriodFromDDL(ddl []string) string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah cool!
generation: 2 | ||
labels: | ||
cnrm-test: "true" | ||
name: spannerdatabase-test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: There's some naming convention requirement. I think this should be spannerdatabase-${uniqueId}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed, thanks :) I think I had accidentally changed this for manual testing.
|
||
--- | ||
|
||
PATCH https://spanner.googleapis.com/v1/projects/${projectId}/instances/spannerinstance-${uniqueId}/databases/spannerdatabase-test/ddl?alt=json |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe I miss something.
I don't see a update.yaml file under https://github.com/GoogleCloudPlatform/k8s-config-connector/blob/master/pkg/test/resourcefixture/testdata/basic/spanner/v1beta1/spannerdatabase/
How this patch is triggered?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an implementation detail of the terraform controller. I think it works around the issue that it's impossible to specify extra DDL statements for Postgres-flavor databases in the create call by just always taking two steps (even if it's a GOOGLESQL-flavor database).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That makes sense. I see this is a really good example on relying the mockgcp to test, validate and verify controller operations.
LGTM! (Failure on tests-e2e-fixtures looks unrelated and looks like envtest crashed, hopefully if we can get to mockkubeapiserver that should address these sorts of flakes!) |
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: yuwenma 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 |
/lgtm |
be7c60d
into
GoogleCloudPlatform:master
Change description
Tasks
make ready-pr
to ensure this PR is ready for review.