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

refactor(cockroachdb): to use request driven options #2883

Merged
merged 22 commits into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
6f82f93
feat: use recommended cluster settings for cockroachdb
martskins Oct 29, 2024
3e60856
fix: wrap errors
martskins Oct 30, 2024
9944ec2
feat: add WithStatements option and expose recommended settings as a …
martskins Oct 30, 2024
276378c
Update modules/cockroachdb/options.go
martskins Oct 30, 2024
8dda144
Update modules/cockroachdb/cockroachdb.go
martskins Oct 30, 2024
400956f
fix: return close error on defer
martskins Oct 30, 2024
19bc4c3
chore: improvement documentation and set default value for statements…
martskins Oct 30, 2024
24d6d77
Update modules/cockroachdb/cockroachdb.go
martskins Oct 30, 2024
3919015
chore: remove unnecessary nolint directive and rename ClusterDefaults…
martskins Oct 30, 2024
6454cd4
fix: only use recommended settings in root user tests
martskins Oct 30, 2024
1070143
feat!(cockroachdb): simplify connection handling
stevenh Nov 1, 2024
7d0ed1c
refactor(cockroachdb): to use request driven options
stevenh Nov 8, 2024
93f4179
fix: various fixes and remove certs
stevenh Nov 8, 2024
dc577f0
fix: add missing data files
stevenh Nov 8, 2024
fff6d3b
chore: add reference to ErrTLSNotEnabled
stevenh Nov 8, 2024
9dd49ae
fix: lint failure for missing test helper
stevenh Nov 8, 2024
aefc89f
feat: tls strategy and strategy walk
stevenh Nov 8, 2024
2fccdd1
chore(cockroachdb): remove customizer
stevenh Nov 8, 2024
2259626
fix: check setOptions error return
stevenh Nov 11, 2024
6f70e78
fix: lint style
stevenh Nov 11, 2024
895f486
chore: various clean ups
stevenh Nov 27, 2024
51f572d
docs(cockroachdb): clarified run defaults
stevenh Dec 2, 2024
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
4 changes: 2 additions & 2 deletions docs/features/tls.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ The example will also create a client that will connect to the server using the
demonstrating how to use the generated certificate to communicate with a service.

<!--codeinclude-->
[Create a self-signed certificate](../../modules/cockroachdb/certs.go) inside_block:exampleSelfSignedCert
[Sign a self-signed certificate](../../modules/cockroachdb/certs.go) inside_block:exampleSignSelfSignedCert
[Create a self-signed certificate](../../modules/rabbitmq/examples_test.go) inside_block:exampleSelfSignedCert
[Sign a self-signed certificate](../../modules/rabbitmq/examples_test.go) inside_block:exampleSignSelfSignedCert
<!--/codeinclude-->
33 changes: 25 additions & 8 deletions docs/modules/cockroachdb.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ The Testcontainers module for CockroachDB.

Please run the following command to add the CockroachDB module to your Go dependencies:

```
```shell
go get github.com/testcontainers/testcontainers-go/modules/cockroachdb
```

Expand Down Expand Up @@ -54,23 +54,33 @@ E.g. `Run(context.Background(), "cockroachdb/cockroach:latest-v23.1")`.

Set the database that is created & dialled with `cockroachdb.WithDatabase`.

#### Password authentication
#### User and Password

You can configured the container to create a user with a password by setting `cockroachdb.WithUser` and `cockroachdb.WithPassword`.

Disable insecure mode and connect with password authentication by setting `cockroachdb.WithUser` and `cockroachdb.WithPassword`.
`cockroachdb.WithPassword` is incompatible with `cockroachdb.WithInsecure`.

#### Store size

Control the maximum amount of memory used for storage, by default this is 100% but can be changed by provided a valid option to `WithStoreSize`. Checkout https://www.cockroachlabs.com/docs/stable/cockroach-start#store for the full range of options available.

#### TLS authentication

`cockroachdb.WithTLS` lets you provide the CA certificate along with the certicate and key for the node & clients to connect with.
Internally CockroachDB requires a client certificate for the user to connect with.
`cockroachdb.WithInsecure` lets you disable the use of TLS on connections.

`cockroachdb.WithInsecure` is incompatible with `cockroachdb.WithPassword`.

#### Initialization Scripts

`cockroachdb.WithInitScripts` adds the given scripts to those automatically run when the container starts.
These will be ignored if data exists in the `/cockroach/cockroach-data` directory within the container.

A helper `cockroachdb.NewTLSConfig` exists to generate all of this for you.
`cockroachdb.WithNoClusterDefaults` disables the default cluster settings script.

!!!warning
When TLS is enabled there's a very small, unlikely chance that the underlying driver can panic when registering the driver as part of waiting for CockroachDB to be ready to accept connections. If this is repeatedly happening please open an issue.
Without this option Cockroach containers run `data/cluster-defaults.sql` on startup
which configures the settings recommended by Cockroach Labs for
[local testing clusters](https://www.cockroachlabs.com/docs/stable/local-testing)
unless data exists in the `/cockroach/cockroach-data` directory within the container.

### Container Methods

Expand All @@ -87,3 +97,10 @@ Same as `ConnectionString` but any error to generate the address will raise a pa
#### TLSConfig

Returns `*tls.Config` setup to allow you to dial your client over TLS, if enabled, else this will error with `cockroachdb.ErrTLSNotEnabled`.

!!!info
The `TLSConfig()` function is deprecated and will be removed in the next major release of _Testcontainers for Go_.

#### ConnectionConfig

Returns `*pgx.ConnConfig` which can be passed to `pgx.ConnectConfig` to open a new connection.
67 changes: 0 additions & 67 deletions modules/cockroachdb/certs.go

This file was deleted.

Loading