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

Update user.toml path and example images #172

Merged
merged 17 commits into from
Jan 31, 2018
Merged
12 changes: 9 additions & 3 deletions examples/bind-config/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Runtime binding + initial configuration

This demonstrates how to run two Habitat Services with a [binding](https://www.habitat.sh/docs/run-packages-binding/) between them, with initial configuration used to override the port of the PostgreSQL Habitat service. It also displays how different fields in the manifest file can be combined.
This demonstrates how to run two Habitat Services with a [binding](https://www.habitat.sh/docs/run-packages-binding/) between them, with initial configuration used to override the port of the Redis Habitat service. It also displays how different fields in the manifest file can be combined.

## Workflow

Expand All @@ -10,6 +10,12 @@ After the Habitat operator is up and running, execute the following command from
kubectl create -f examples/bind-config/habitat.yml
```

This will deploy two `Habitat`s, a simple HTTP server written in Go that will be bound to a PostgreSQL database. The Go server will display the database port number that was overriden by the initial configuration.
This will deploy two `Habitat`s, a simple HTTP server written in Go that will be
bound to a Redis instance. By default, the Redis database instance would [listen
on port
6379](https://github.com/habitat-sh/core-plans/blob/7bc934c31e92c959aea0444671900c57c23d5265/redis/default.toml#L3),
but we change this with the configuration stored in the `user-toml`.
Copy link
Contributor

Choose a reason for hiding this comment

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

in the commit log it's "user.toml", but here it's with a dash.

Copy link
Contributor Author

@asymmetric asymmetric Jan 31, 2018

Choose a reason for hiding this comment

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

It's with a dash because what I'm pointing at here is the Kubernetes Secret named user-toml, rather than the filename under which the Secret is mounted in the Pod.


When running on minikube, it can be accessed under port `30001` of the minikube VM. `minikube ip` can be used to retrieve the IP.
The Go web app displays the overridden database port number, and it can be
accessed under port `30001`. When running on minikube, its IP can be retrieved
with `minikube ip`.
24 changes: 12 additions & 12 deletions examples/bind-config/habitat.yml
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
apiVersion: v1
kind: Secret
metadata:
name: user-toml-secret
name: user-toml
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for explaining what "stutter" is but i don't see any repetition here in the name.

Copy link
Contributor Author

@asymmetric asymmetric Jan 31, 2018

Choose a reason for hiding this comment

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

In this case, a Service whose name ends in -service, and stuff like that.

Or a Secret whose name ends in -secret.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

kubectl get secret returning user-toml-secret is stutter IMO. Of course it's a Secret. It doesn't help to have -secret there, because that object will only be returned when you ask for Secrets.

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree with the change. I was just being nitpicky about it not fitting the "stutter" title.

type: Opaque
data:
# Each item needs to be encoded in base64, as Kubernetes expects that encoding.
# Each item needs to be base64-encoded.
# This overrides the port set in the Redis Habitat service.
# Plain text content of the secret: "port = 4444"
# This overrides the port set in the postgresql Habitat service.
user.toml: cG9ydCA9IDQ0NDQ=
---
apiVersion: habitat.sh/v1beta1
kind: Habitat
kind: Habitat
metadata:
name: example-bind-configured-db-service
name: example-bind-configured-db
spec:
image: kinvolk/postgresql-hab
image: kinvolk/redis-hab
count: 1
service:
name: postgresql
name: redis
# Name of the secret.
# This is mounted inside of the pod as a user.toml file.
configSecretName: user-toml-secret
configSecretName: user-toml
topology: standalone
---
apiVersion: habitat.sh/v1beta1
kind: Habitat
metadata:
name: example-bind-configured-web-app-service
name: example-bind-configured-web-app
spec:
image: kinvolk/bindgo-hab
count: 1
Expand All @@ -35,16 +35,16 @@ spec:
topology: standalone
bind:
- name: db
service: postgresql
service: redis
group: default
---
apiVersion: v1
kind: Service
metadata:
name: web-app-service
name: web-app
spec:
selector:
habitat-name: example-bind-configured-web-app-service
habitat-name: example-bind-configured-web-app
type: NodePort
ports:
- name: web
Expand Down
5 changes: 3 additions & 2 deletions examples/bind/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ After the Habitat operator is up and running, execute the following command from
kubectl create -f examples/bind/habitat.yml
```

This will deploy two `Habitat`s, a simple HTTP server written in Go that will be bound to a PostgreSQL database. The Go server will display the port number the database listens on.
This will deploy two `Habitat`s, a simple HTTP server written in Go that will be bound to a Redis database. The Go server will display the port number the database listens on.
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we really call the services or apps as "habitats"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, the naming is a bit weird. In Habitat they're services, but the CRD is Habitat, so same as we say ConfigMaps, I think we're justified to say Habitats.

Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure I agree and it sounds strange but OK. :)

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 agree that it sounds strange, but this was the result of a long discussion and we couldn't come up with a better name.

See this and this.


When running on minikube, it can be accessed under port `30001` of the minikube VM. `minikube ip` can be used to retrieve the IP.
The web app is listening on port `30001`. When running on minikube, its IP can
be retrieved with `minikube ip`.
8 changes: 4 additions & 4 deletions examples/bind/habitat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ kind: Habitat
metadata:
name: db
spec:
image: kinvolk/postgresql-hab
image: kinvolk/redis-hab
count: 1
service:
name: postgresql
name: redis
topology: standalone
---
apiVersion: habitat.sh/v1beta1
Expand All @@ -23,7 +23,7 @@ spec:
# Name is the name of the bind specified in the Habitat configuration files.
- name: db
# Service is the name of the service this bind refers to.
service: postgresql
service: redis
# Group is the group of the service this bind refers to.
group: default
---
Expand All @@ -33,7 +33,7 @@ metadata:
name: go-service
spec:
selector:
habitat-name: go
habitat-name: web-app
type: NodePort
ports:
- name: web
Expand Down
11 changes: 8 additions & 3 deletions examples/config/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Initial configuration

This example demostrates how initial configuration works with the Habitat operator. With the manifest file we deploy a `"Hello world."` Node.js Habitat service.
This example demonstrates how initial configuration works with the Habitat operator. With the manifest file we deploy a Redis Habitat service.
NOTE: Adding secret configuration to the `default.toml` is discouraged, as it will be uploaded as a docker image. Instead use the initial configuration `user.toml` file.

## Workflow
Expand All @@ -9,8 +9,13 @@ After the Habitat operator is up and running, execute the following command from

`kubectl create -f examples/config/habitat.yml`

This will create a [Kubernetes Secret](https://kubernetes.io/docs/concepts/configuration/secret/) with the configurations and a simple Node.js application that will display a msg. When running on minikube, it can be accessed under port `30001` of the minikube VM. `minikube ip` can be used to retrieve the IP.
Initially our app is configured to display the msg `"Hello world."`. Because we override this with the Secret we just created, our app will instead display `Hello from our Habitat-Operator!`.
This will create a [Kubernetes Secret](https://kubernetes.io/docs/concepts/configuration/secret/) with the configurations and a Redis database.

By default, Redis listens on port 6379, but we change this to 6999 by mounting a
Secret as a file under `/hab/user/redis/config/user.toml` inside the Pod.

The web app is listening on port `30001`. When running on minikube, its IP can
be retrieved with `minikube ip`.

## Deletion

Expand Down
22 changes: 11 additions & 11 deletions examples/config/habitat.yml
Original file line number Diff line number Diff line change
@@ -1,32 +1,31 @@
apiVersion: v1
kind: Secret
metadata:
name: user-toml-secret
name: user-toml
type: Opaque
data:
# Each item needs to be encoded in base64, as Kubernetes
# expects that encoding.
# Plain text content: "message = 'Hello from our Habitat-Operator!'"
user.toml: bWVzc2FnZSA9ICdIZWxsbyBmcm9tIG91ciBIYWJpdGF0LU9wZXJhdG9yISc=
# Each item needs to be base64-encoded.
# Plain text content: port = 6999
user.toml: cG9ydCA9IDY5OTkK
---
apiVersion: habitat.sh/v1beta1
kind: Habitat
metadata:
name: example-configured-habitat
spec:
image: kinvolk/nodejs-hab
image: kinvolk/redis-hab
count: 1
service:
name: mytutorialapp
name: db
topology: standalone
group: nodejs
group: redisdb
# Create Secret with the initial configuration you want.
configSecretName: user-toml-secret
configSecretName: user-toml
---
apiVersion: v1
kind: Service
metadata:
name: mytutorialapp
name: db
spec:
selector:
habitat-name: example-configured-habitat
Expand All @@ -35,7 +34,8 @@ spec:
# This endpoint displays the message from the secret
- name: web
nodePort: 30001
port: 5555
# This is the custom port set in the user.toml
port: 6999
protocol: TCP
# This endpoint exposes the Habitat supervisor API
- name: http-gateway
Expand Down
20 changes: 7 additions & 13 deletions examples/encrypted/README.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
# Encrypted Habitat example

By default supervisors will communicate with no encryption. This example demostrates how to secure the communication.
By default supervisors will communicate with no encryption. This example demonstrates how to secure the communication.

## Workflow

The user needs to generate a [ring
key](https://www.habitat.sh/docs/run-packages-security/) using `hab ring key generate foobar`, and then base64
encode it (on Linux) with `hab ring export foobar | base64 -w 0` (please refer to
encode it with (on Linux) `hab ring export foobar | base64 -w 0` (please refer to
[this
document](https://kubernetes.io/docs/concepts/configuration/secret/#creating-a-secret-manually)
for platform-specific instructions on base64 encoding).

The encoded key can then be used as the value of the `ring-key` key in a Kubernetes
secret.
Secret.

The secret's name must be the same as the filename of the key, minus the
The Secret's name must be the same as the key's filename, minus the
extension.

For example, for a key named `foobar`, the key file might be something like
`foobar-20170824094632.sym.key`, and the secret name must be
For example, for a key named `foobar`, the key filename might be something like
`foobar-20170824094632.sym.key`, and the corresponding Secret name
`foobar-20170824094632`.

The secret's name must additionally be referenced in the `Habitat` object's `ringSecretName` key.
The Secret's name must additionally be referenced in the `Habitat` object's `ringSecretName` key.

After the Habitat operator is up and running, execute the following command from the root of this repository:

Expand All @@ -34,9 +34,3 @@ kubectl create -f examples/encrypted/habitat.yml
The Habitat operator does not delete the Secret on Habitat deletion. This is
because the user might want to re-use the secret across multiple
`Habitat`s and `Habitat` lifecycles.

To delete the Secret simply run:

```
kubectl delete secret example-encrypted-ring-20170829113029
```
6 changes: 3 additions & 3 deletions examples/encrypted/habitat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ kind: Habitat
metadata:
name: example-encrypted-habitat
spec:
# the core/nginx habitat service packaged as a Docker image
image: kinvolk/consul-hab
# the core/redis habitat service packaged as a Docker image
image: kinvolk/redis-hab
count: 3
service:
name: consul
name: redis
topology: leader
# the name of the secret containing the ring key
ringSecretName: example-encrypted-ring-20170829113029
2 changes: 1 addition & 1 deletion examples/leader/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ Simply run:

`kubectl create -f examples/leader/habitat.yml`.

This will deploy 3 instances of consul Habitat service.
This will deploy 3 instances of Redis Habitat service.

Note: Whenever creating a `leader` topology specify instance `count` of 3 or more and would be best if the number is odd, this is so the election can take place.
4 changes: 2 additions & 2 deletions examples/leader/habitat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ kind: Habitat
metadata:
name: example-leader-follower-habitat
spec:
# the core/consul habitat service packaged as a Docker image
image: kinvolk/consul-hab
# the core/redis habitat service packaged as a Docker image
image: kinvolk/redis-hab
# count must be at least 3 for a leader-follower topology
count: 3
service:
Expand Down
6 changes: 3 additions & 3 deletions examples/namespaced/habitat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ metadata:
name: example-namespaced-habitat
namespace: example-namespace
spec:
# the core/nginx habitat service packaged as a Docker image
image: kinvolk/nginx-hab
# the core/redis habitat service packaged as a Docker image
image: kinvolk/redis-hab
count: 1
service:
name: nginx
name: redis
topology: standalone
# if not present, defaults to "default"
group: foobar
2 changes: 1 addition & 1 deletion examples/standalone/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ Simply run:

`kubectl create -f examples/standalone/habitat.yml`.

This will deploy an instance of an nginx Habitat service.
This will deploy an instance of a redis Habitat service.
6 changes: 3 additions & 3 deletions examples/standalone/habitat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ kind: Habitat
metadata:
name: example-standalone-habitat
spec:
# the core/nginx habitat service packaged as a Docker image
image: kinvolk/nginx-hab
# the core/redis habitat service packaged as a Docker image
image: kinvolk/redis-hab
count: 1
service:
name: nginx
name: redis
topology: standalone
# if not present, defaults to "default"
group: foobar
3 changes: 1 addition & 2 deletions pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -714,8 +714,7 @@ func (hc *HabitatController) newDeployment(h *habv1beta1.Habitat) (*appsv1beta1.
Name: initialConfigFilename,
// The Habitat supervisor creates a directory for each service under /hab/svc/<servicename>.
// We need to place the user.toml file in there in order for it to be detected.
MountPath: fmt.Sprintf("/hab/svc/%s/%s", h.Spec.Service.Name, userTOMLFile),
SubPath: userTOMLFile,
MountPath: fmt.Sprintf("/hab/user/%s/config", h.Spec.Service.Name),
ReadOnly: false,
}

Expand Down
4 changes: 2 additions & 2 deletions test/e2e/operator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const (
// TestFunction tests that the operator correctly created two Habitat Services and bound them together.
func TestFunction(t *testing.T) {
// Get Habitat object from Habitat go example.
habitatGo, err := utils.ConvertHabitat("resources/bind-config/habitat-go.yml")
habitatGo, err := utils.ConvertHabitat("resources/bind-config/webapp.yml")
if err != nil {
t.Fatal(err)
}
Expand All @@ -48,7 +48,7 @@ func TestFunction(t *testing.T) {
}

// Get Habitat object from Habitat db example.
habitatDB, err := utils.ConvertHabitat("resources/bind-config/habitat-postgresql.yml")
habitatDB, err := utils.ConvertHabitat("resources/bind-config/db.yml")
if err != nil {
t.Fatal(err)
}
Expand Down
11 changes: 11 additions & 0 deletions test/e2e/resources/bind-config/db.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: habitat.sh/v1beta1
kind: Habitat
metadata:
name: test-redis
spec:
image: kinvolk/redis-hab
count: 1
service:
name: redis
configSecretName: user-toml
topology: standalone
11 changes: 0 additions & 11 deletions test/e2e/resources/bind-config/habitat-postgresql.yml

This file was deleted.

4 changes: 2 additions & 2 deletions test/e2e/resources/bind-config/secret.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
apiVersion: v1
kind: Secret
metadata:
name: user-toml-secret
name: user-toml
type: Opaque
data:
# Each item needs to be encoded in base64, as Kubernetes expects that encoding.
# Plain text content of the secret: "port = 4444"
# This overrides the port set in the postgresql Habitat service.
# This overrides the port set in the Redis Habitat service.
user.toml: cG9ydCA9IDQ0NDQ=
4 changes: 2 additions & 2 deletions test/e2e/resources/bind-config/service.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
apiVersion: v1
kind: Service
metadata:
name: go-test-123
name: test-go
spec:
selector:
habitat-name: go-test-123
habitat-name: test-go
type: NodePort
ports:
- name: web
Expand Down
Loading