Skip to content

Commit 074e681

Browse files
authored
Merge pull request #15160 from agarwalnit/master
Added cloud-spanner emulator add-on.
2 parents cdc9bf6 + e4b7598 commit 074e681

File tree

8 files changed

+139
-2
lines changed

8 files changed

+139
-2
lines changed

cmd/minikube/cmd/config/addons_list_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ func TestAddonsList(t *testing.T) {
7777
Ambassador *interface{} `json:"ambassador"`
7878
}
7979

80-
b := make([]byte, 571)
80+
b := make([]byte, 590)
8181
r, w, err := os.Pipe()
8282
if err != nil {
8383
t.Fatalf("failed to create pipe: %v", err)

deploy/addons/assets.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,4 +151,8 @@ var (
151151
// HeadlampAssets assets for headlamp addon
152152
//go:embed headlamp/*.yaml headlamp/*.tmpl
153153
HeadlampAssets embed.FS
154+
155+
// CloudSpanner assets for cloud-spanner addon
156+
//go:embed cloud-spanner/*.yaml
157+
CloudSpanner embed.FS
154158
)
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
---
2+
apiVersion: apps/v1
3+
kind: Deployment
4+
metadata:
5+
name: cloud-spanner-emulator
6+
labels:
7+
app: cloud-spanner-emulator
8+
gcp-auth-skip-secret: "true"
9+
kubernetes.io/minikube-addons-endpoint: cloud-spanner
10+
spec:
11+
replicas: 1
12+
selector:
13+
matchLabels:
14+
app: cloud-spanner-emulator
15+
template:
16+
metadata:
17+
labels:
18+
app: cloud-spanner-emulator
19+
spec:
20+
containers:
21+
- name: cloud-spanner-emulator
22+
image: gcr.io/cloud-spanner-emulator/emulator:latest
23+
imagePullPolicy: IfNotPresent
24+
ports:
25+
- containerPort: 9020
26+
name: http
27+
- containerPort: 9010
28+
name: grpc
29+
30+
---
31+
apiVersion: v1
32+
kind: Service
33+
metadata:
34+
name: cloud-spanner-emulator
35+
labels:
36+
app: cloud-spanner-emulator
37+
spec:
38+
type: NodePort
39+
ports:
40+
- port: 9020
41+
name: http
42+
- port: 9010
43+
name: grpc
44+
selector:
45+
app: cloud-spanner-emulator

pkg/addons/config.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,4 +207,9 @@ var Addons = []*Addon{
207207
set: SetBool,
208208
callbacks: []setFn{EnableOrDisableAddon},
209209
},
210+
{
211+
name: "cloud-spanner",
212+
set: SetBool,
213+
callbacks: []setFn{EnableOrDisableAddon},
214+
},
210215
}

pkg/minikube/assets/addons.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -742,6 +742,13 @@ var Addons = map[string]*Addon{
742742
map[string]string{
743743
"Headlamp": "ghcr.io",
744744
}),
745+
"cloud-spanner": NewAddon([]*BinAsset{
746+
MustBinAsset(addons.CloudSpanner, "cloud-spanner/deployment.yaml", vmpath.GuestAddonsDir, "deployment.yaml", "6040"),
747+
}, false, "cloud-spanner", "Google", "", "https://minikube.sigs.k8s.io/docs/handbook/addons/cloud-spanner/", map[string]string{
748+
"CloudSpannerAddon": "cloud-spanner-emulator/emulator",
749+
}, map[string]string{
750+
"CloudSpannerAddon": "gcr.io",
751+
}),
745752
}
746753

747754
// parseMapString creates a map based on `str` which is encoded as <key1>=<value1>,<key2>=<value2>,...

site/content/en/docs/contrib/tests.en.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ tests the GCP Auth addon with either phony or real credentials and makes sure th
4444

4545
#### validateHeadlampAddon
4646

47+
#### validateCloudSpannerAddon
48+
tests the cloud-spanner addon by ensuring the deployment and pod come up and addon disables
49+
4750
## TestCertOptions
4851
makes sure minikube certs respect the --apiserver-ips and --apiserver-names parameters
4952

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
---
2+
title: "Using Cloud Spanner Addon"
3+
linkTitle: "Cloud Spanner"
4+
weight: 1
5+
date: 2022-10-14
6+
---
7+
8+
## Cloud Spanner Addon
9+
10+
[Cloud Spanner](https://cloud.google.com/spanner) is a fully managed relational database. The Cloud Spanner addon provides a local emulator to test your local application without incurring the cost of an actual spanner instance.
11+
12+
### Enable Cloud Spanner on minikube
13+
14+
To enable this addon, simply run:
15+
```shell script
16+
minikube addons enable cloud-spanner
17+
```
18+
19+
### Cloud Spanner Endpoints
20+
Cloud Spanner provides two different ports, HTTP and GRPC. List Cloud Spanner emulator urls by running:
21+
``` shell
22+
minikube service cloud-spanner-emulator
23+
24+
####################Sample Output#########################
25+
|-----------|------------------------|-------------|---------------------------|
26+
| NAMESPACE | NAME | TARGET PORT | URL |
27+
|-----------|------------------------|-------------|---------------------------|
28+
| default | cloud-spanner-emulator | http/9020 | http://192.168.49.2:30233 |
29+
| | | grpc/9010 | http://192.168.49.2:30556 |
30+
|-----------|------------------------|-------------|---------------------------|
31+
[default cloud-spanner-emulator http/9020
32+
grpc/9010 http://192.168.49.2:30233
33+
http://192.168.49.2:30556]
34+
```
35+
36+
### Using Cloud Spanner within a cluster
37+
Cloud Spanner emulator can be used via endpoint `cloud-spanner-emulator:9020` for http clients and `cloud-spanner-emulator:9010` for grpc clients respectively. If you're using the standard client library for Cloud Spanner then set `SPANNER_EMULATOR_HOST` to the GRPC endpoint `cloud-spanner-emulator:9010`.
38+
39+
### Testing installation
40+
41+
```shell script
42+
kubectl get pods -n cloud-spanner-emulator
43+
```
44+
45+
If everything went well, there should be no errors about Cloud Spanner's installation in your minikube cluster.
46+
47+
### Disable Cloud Spanner
48+
49+
To disable this addon, simply run:
50+
51+
```shell script
52+
minikube addons disable cloud-spanner
53+
```

test/integration/addons_test.go

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ func TestAddons(t *testing.T) {
6666
t.Fatalf("Failed setting GOOGLE_CLOUD_PROJECT env var: %v", err)
6767
}
6868

69-
args := append([]string{"start", "-p", profile, "--wait=true", "--memory=4000", "--alsologtostderr", "--addons=registry", "--addons=metrics-server", "--addons=volumesnapshots", "--addons=csi-hostpath-driver", "--addons=gcp-auth"}, StartArgs()...)
69+
args := append([]string{"start", "-p", profile, "--wait=true", "--memory=4000", "--alsologtostderr", "--addons=registry", "--addons=metrics-server", "--addons=volumesnapshots", "--addons=csi-hostpath-driver", "--addons=gcp-auth", "--addons=cloud-spanner"}, StartArgs()...)
7070
if !NoneDriver() { // none driver does not support ingress
7171
args = append(args, "--addons=ingress", "--addons=ingress-dns")
7272
}
@@ -97,6 +97,7 @@ func TestAddons(t *testing.T) {
9797
{"Olm", validateOlmAddon},
9898
{"CSI", validateCSIDriverAndSnapshots},
9999
{"Headlamp", validateHeadlampAddon},
100+
{"CloudSpanner", validateCloudSpannerAddon},
100101
}
101102
for _, tc := range tests {
102103
tc := tc
@@ -743,3 +744,22 @@ func validateHeadlampAddon(ctx context.Context, t *testing.T, profile string) {
743744
t.Fatalf("failed waiting for headlamp pod: %v", err)
744745
}
745746
}
747+
748+
// validateCloudSpannerAddon tests the cloud-spanner addon by ensuring the deployment and pod come up and addon disables
749+
func validateCloudSpannerAddon(ctx context.Context, t *testing.T, profile string) {
750+
defer PostMortemLogs(t, profile)
751+
752+
client, err := kapi.Client(profile)
753+
if err != nil {
754+
t.Fatalf("failed to get Kubernetes client for %s: %v", profile, err)
755+
}
756+
if err := kapi.WaitForDeploymentToStabilize(client, "default", "cloud-spanner-emulator", Minutes(6)); err != nil {
757+
t.Errorf("failed waiting for cloud-spanner-emulator deployment to stabilize: %v", err)
758+
}
759+
if _, err := PodWait(ctx, t, profile, "default", "app=cloud-spanner-emulator", Minutes(6)); err != nil {
760+
t.Errorf("failed waiting for app=cloud-spanner-emulator pod: %v", err)
761+
}
762+
if rr, err := Run(t, exec.CommandContext(ctx, Target(), "addons", "disable", "cloud-spanner", "-p", profile)); err != nil {
763+
t.Errorf("failed to disable cloud-spanner addon: args %q : %v", rr.Command(), err)
764+
}
765+
}

0 commit comments

Comments
 (0)