Skip to content

Commit a98a7c9

Browse files
Jan-MCyberDem0n
authored andcommitted
Reorganize Readme (zalando#142)
removing parts of config. * chaning secret name pattern to make things shorter. * Move section on self building docker image. * Fix typo. * Bump image. * bump version for pdb fix. * Changes in regards to review. * Fix xhyve driver link. * Move to new api, remove service account, not needed for minikube. * Changed minimal manifest and example to use right file. * Added service account for operator again, it is needed in pods anyways later.
1 parent 7a76be7 commit a98a7c9

File tree

7 files changed

+97
-84
lines changed

7 files changed

+97
-84
lines changed

Makefile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,13 @@ endif
1111
LOCAL_BUILD_FLAGS ?= $(BUILD_FLAGS)
1212
LDFLAGS ?= -X=main.version=$(VERSION)
1313
DOCKERFILE = docker/Dockerfile
14-
IMAGE ?= pierone.example.com/acid/$(BINARY)
14+
IMAGE ?= registry.opensource.zalan.do/acid/$(BINARY)
1515
TAG ?= $(VERSION)
1616
GITHEAD = $(shell git rev-parse --short HEAD)
1717
GITURL = $(shell git config --get remote.origin.url)
1818
GITSTATUS = $(shell git status --porcelain || echo "no changes")
1919
SOURCES = cmd/main.go
2020
VERSION ?= $(shell git describe --tags --always --dirty)
21-
IMAGE ?= pierone.example.com/acid/$(BINARY)
2221
DIRS := cmd pkg
2322
PKG := `go list ./... | grep -v /vendor/`
2423

README.md

Lines changed: 68 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -27,48 +27,7 @@ it manages and updates them with the new docker images; afterwards, all pods fro
2727
This project is currently in development. It is used internally by Zalando in order to run staging databases on Kubernetes.
2828
Please, report any issues discovered to https://github.com/zalando-incubator/postgres-operator/issues.
2929

30-
## Setting up Go
31-
32-
Postgres operator is written in Go. Use the [installation instructions](https://golang.org/doc/install#install) if you don't have Go on your system.
33-
You won't be able to compile the operator with Go older than 1.7. We recommend installing [the latest one](https://golang.org/dl/).
34-
35-
Go projects expect their source code and all the dependencies to be located under the [GOPATH](https://github.com/golang/go/wiki/GOPATH).
36-
Normally, one would create a directory for the GOPATH (i.e. ~/go) and place the source code under the ~/go/src subdirectories.
37-
38-
Given the schema above, the postgres operator source code located at `github.com/zalando-incubator/postgres-operator` should be put at
39-
-`~/go/src/github.com/zalando-incubator/postgres-operator`.
40-
41-
$ export GOPATH=~/go
42-
$ mkdir -p ${GOPATH}/src/github.com/zalando-incubator/
43-
$ cd ${GOPATH}/src/github.com/zalando-incubator/ && git clone https://github.com/zalando-incubator/postgres-operator.git
44-
45-
46-
## Building the operator
47-
48-
You need Glide to fetch all dependencies. Install it with:
49-
50-
$ make tools
51-
52-
Next, install dependencies with glide by issuing:
53-
54-
$ make deps
55-
56-
This would take a while to complete. You have to redo `make deps` every time you dependencies list changes, i.e. after adding a new library dependency.
57-
58-
Build the operator docker image and pushing it to Pier One:
59-
60-
$ make docker push
61-
62-
You may define the TAG variable to assign an explicit tag to your docker image and the IMAGE to set the image name.
63-
By default, the tag is computed with `git describe --tags --always --dirty` and the image is `pierone.stups.zalan.do/acid/postgres-operator`
64-
65-
Building the operator binary (for testing the out-of-cluster option):
66-
67-
$ make
68-
69-
The binary will be placed into the build directory.
70-
71-
## Testing the operator
30+
## Running and testing the operator
7231

7332
The best way to test the operator is to run it in minikube. Minikube is a tool to run Kubernetes cluster locally.
7433

@@ -81,51 +40,31 @@ After the installation, issue the
8140

8241
$ minikube start
8342

84-
Note: if you are running on a Mac, make sure to use the [xhyve driver](https://github.com/kubernetes/minikube/blob/master/DRIVERS.md#xhyve-driver)
43+
Note: if you are running on a Mac, make sure to use the [xhyve driver](https://github.com/kubernetes/minikube/blob/master/docs/drivers.md#xhyve-driver)
8544
instead of the default docker-machine one for performance reasons.
8645

8746
One you have it started successfully, use [the quickstart guide](https://github.com/kubernetes/minikube#quickstart) in order
8847
to test your that your setup is working.
8948

9049
Note: if you use multiple kubernetes clusters, you can switch to minikube with `kubectl config use-context minikube`
9150

92-
### Deploy etcd
93-
94-
Etcd is required to deploy the operator.
95-
96-
$ kubectl --context minikube create -f https://raw.githubusercontent.com/coreos/etcd/master/hack/kubernetes-deploy/etcd.yml
97-
9851
### Create ConfigMap
9952

10053
ConfigMap is used to store configuration of the operator
10154

10255
$ kubectl --context minikube create -f manifests/configmap.yaml
10356

104-
### Deploy fake Teams API
105-
106-
Teams API is used as a source of human users.
107-
108-
$ kubectl --context minikube create -f manifests/fake-teams-api.yaml
109-
11057
### Deploying the operator
11158

112-
You need to install the service account definition in your minikube cluster. You can run without it, but then you
113-
have to change the service account references in the postgres-operator manifest as well.
59+
First you need to install the service account definition in your minikube cluster.
11460

11561
$ kubectl --context minikube create -f manifests/serviceaccount.yaml
11662

117-
The fastest way to run your docker image locally is to reuse the docker from minikube. That way, there is no need to
118-
pull docker images from pierone or push them, as the image is essentially there once you build it. The following steps
119-
will get you the docker image built and deployed.
63+
Next deploy the postgers-operator from the Docker image Zalando is using:
12064

121-
$ eval $(minikube docker-env)
122-
$ export TAG=$(git describe --tags --always --dirty)
123-
$ make docker
124-
$ sed -e "s/\(image\:.*\:\).*$/\1$TAG/" manifests/postgres-operator.yaml|kubectl --context minikube create -f -
65+
$ kubectl --context minikube create -f manifests/postgres-operator.yaml
12566

126-
The last line changes the docker image tag in the manifest to the one the operator image has been built with and removes
127-
the serviceAccountName definition, as the ServiceAccount is not defined in minikube (neither it should, as one has admin
128-
permissions there).
67+
If you perfer to build the image yourself follow up down below.
12968

13069
### Check if CustomResourceDefinition has been registered
13170

@@ -137,33 +76,89 @@ permissions there).
13776

13877
### Create a new spilo cluster
13978

140-
$ kubectl --context minikube create -f manifests/testpostgresql.yaml
79+
$ kubectl --context minikube create -f manifests/minimal-postgres-manifest.yaml
14180

14281
### Watch Pods being created
14382

14483
$ kubectl --context minikube get pods -w --show-labels
14584

14685
### Connect to PostgreSQL
14786

148-
We can use the generated secret of the `postgres` robot user to connect to our `acid-testcluster` master running in Minikube:
87+
We can use the generated secret of the `postgres` robot user to connect to our `acid-test-cluster` master running in Minikube:
14988

150-
$ export HOST_PORT=$(minikube service acid-testcluster --url | sed 's,.*/,,')
89+
$ export HOST_PORT=$(minikube service acid-test-cluster --url | sed 's,.*/,,')
15190
$ export PGHOST=$(echo $HOST_PORT | cut -d: -f 1)
15291
$ export PGPORT=$(echo $HOST_PORT | cut -d: -f 2)
153-
$ export PGPASSWORD=$(kubectl --context minikube get secret postgres.acid-testcluster.credentials.postgresql.acid.zalan.do -o 'jsonpath={.data.password}' | base64 -d)
92+
$ export PGPASSWORD=$(kubectl --context minikube get secret postgres.acid-test-cluster.credentials -o 'jsonpath={.data.password}' | base64 -d)
15493
$ psql -U postgres
15594

95+
96+
# Setup development environment
97+
98+
The following steps guide you through the setup to work on the operator itself.
99+
100+
## Setting up Go
101+
102+
Postgres operator is written in Go. Use the [installation instructions](https://golang.org/doc/install#install) if you don't have Go on your system.
103+
You won't be able to compile the operator with Go older than 1.7. We recommend installing [the latest one](https://golang.org/dl/).
104+
105+
Go projects expect their source code and all the dependencies to be located under the [GOPATH](https://github.com/golang/go/wiki/GOPATH).
106+
Normally, one would create a directory for the GOPATH (i.e. ~/go) and place the source code under the ~/go/src subdirectories.
107+
108+
Given the schema above, the postgres operator source code located at `github.com/zalando-incubator/postgres-operator` should be put at
109+
-`~/go/src/github.com/zalando-incubator/postgres-operator`.
110+
111+
$ export GOPATH=~/go
112+
$ mkdir -p ${GOPATH}/src/github.com/zalando-incubator/
113+
$ cd ${GOPATH}/src/github.com/zalando-incubator/ && git clone https://github.com/zalando-incubator/postgres-operator.git
114+
115+
116+
## Building the operator
117+
118+
You need Glide to fetch all dependencies. Install it with:
119+
120+
$ make tools
121+
122+
Next, install dependencies with glide by issuing:
123+
124+
$ make deps
125+
126+
This would take a while to complete. You have to redo `make deps` every time you dependencies list changes, i.e. after adding a new library dependency.
127+
128+
Build the operator docker image and pushing it to Pier One:
129+
130+
$ make docker push
131+
132+
You may define the TAG variable to assign an explicit tag to your docker image and the IMAGE to set the image name.
133+
By default, the tag is computed with `git describe --tags --always --dirty` and the image is `pierone.stups.zalan.do/acid/postgres-operator`
134+
135+
Building the operator binary (for testing the out-of-cluster option):
136+
137+
$ make
138+
139+
The binary will be placed into the build directory.
140+
141+
### Deploying self build image
142+
143+
The fastest way to run your docker image locally is to reuse the docker from minikube.
144+
The following steps will get you the docker image built and deployed.
145+
146+
$ eval $(minikube docker-env)
147+
$ export TAG=$(git describe --tags --always --dirty)
148+
$ make docker
149+
$ sed -e "s/\(image\:.*\:\).*$/\1$TAG/" manifests/postgres-operator.yaml|kubectl --context minikube create -f -
150+
156151
### Debugging the operator itself
157152

158153
There is a web interface in the operator to observe its internal state. The operator listens on port 8080. It is possible to expose it to the localhost:8080 by doing:
159154

160155
$ kubectl --context minikube port-forward $(kubectl --context minikube get pod -l name=postgres-operator -o jsonpath={.items..metadata.name}) 8080:8080
161-
156+
162157
The inner 'query' gets the name of the postgres operator pod, and the outer enables port forwarding. Afterwards, you can access the operator API with:
163158

164159
$ curl http://127.0.0.1:8080/$endpoint| jq .
165160

166-
The available endpoints are listed below. Note that the worker ID is an integer from 0 up to 'workers' - 1 (value configured in the operator configuration and defaults to 4)
161+
The available endpoints are listed below. Note that the worker ID is an integer from 0 up to 'workers' - 1 (value configured in the operator configuration and defaults to 4)
167162

168163
* /workers/all/queue - state of the workers queue (cluster events to process)
169164
* /workers/$id/queue - state of the queue for the worker $id
@@ -181,5 +176,3 @@ The operator also supports pprof endpoints listed at the [pprof package](https:/
181176
* /debug/pprof/profile
182177
* /debug/pprof/symbol
183178
* /debug/pprof/trace
184-
185-

manifests/testpostgresql.yaml renamed to manifests/complete-postgres-manifest.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ apiVersion: "acid.zalan.do/v1"
22
kind: postgresql
33

44
metadata:
5-
name: acid-testcluster17
5+
name: acid-test-cluster
66
spec:
77
teamId: "ACID"
88
volume:
@@ -18,7 +18,7 @@ spec:
1818
foo: zalando
1919
#Expert section
2020
postgresql:
21-
version: "9.6"
21+
version: "10"
2222
parameters:
2323
shared_buffers: "32MB"
2424
max_connections: "10"

manifests/configmap.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ data:
1111
debug_logging: "true"
1212
dns_name_format: '{cluster}.{team}.staging.{hostedzone}'
1313
docker_image: registry.opensource.zalan.do/acid/demospilo-10:1.3-p3
14+
secret_name_template: '{username}.{cluster}.credentials'
1415
etcd_host: ""
15-
secret_name_template: '{username}.{cluster}.credentials.{tprkind}.{tprgroup}'
1616
infrastructure_roles_secret_name: postgresql-infrastructure-roles
1717
oauth_token_secret_name: postgresql-operator
1818
pam_configuration: |
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
apiVersion: "acid.zalan.do/v1"
2+
kind: postgresql
3+
metadata:
4+
name: acid-minimal-cluster
5+
spec:
6+
teamId: "ACID"
7+
volume:
8+
size: 1Gi
9+
numberOfInstances: 2
10+
users:
11+
# database owner
12+
zalando:
13+
- superuser
14+
- createdb
15+
16+
# role for application foo
17+
foo_user:
18+
19+
#databases: name->owner
20+
databases:
21+
foo: zalando
22+
postgresql:
23+
version: "10"

manifests/postgres-operator.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
apiVersion: extensions/v1beta1
1+
apiVersion: apps/v1beta1
22
kind: Deployment
33
metadata:
44
name: postgres-operator
@@ -12,7 +12,7 @@ spec:
1212
serviceAccountName: operator
1313
containers:
1414
- name: postgres-operator
15-
image: pierone.stups.zalan.do/acid/postgres-operator:workerassgn
15+
image: registry.opensource.zalan.do/acid/postgres-operator:c17aabb
1616
imagePullPolicy: IfNotPresent
1717
env:
1818
- name: WATCH_NAMESPACE

manifests/serviceaccount.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,3 @@ apiVersion: v1
22
kind: ServiceAccount
33
metadata:
44
name: operator
5-
imagePullSecrets:
6-
- name: pierone.example.com

0 commit comments

Comments
 (0)