Skip to content

Commit

Permalink
Feature/enable external crds (#160)
Browse files Browse the repository at this point in the history
* init change for the stackset spec+status, without fallback to get these data from ingress
fix all comments and generate Traffic in StacksetStatus correctly
refactor backendport being intorstring type and use also that in the ActualTraffic to make external controllers happy
make sure we catch if we forget to populate ingressSpec

Signed-off-by: Sandor Szücs <[email protected]>

* add test for backendPort setting
create a better example how to run the e2e tests
drop println and add a bit more test coverage

Signed-off-by: Sandor Szücs <[email protected]>

* fix: unit test should be stable
basic e2e tests with checking actual traffic status
refactor: rename helper functions and tests according to ingress based traffic switching
add e2e test for stackset based traffic switching

Signed-off-by: Sandor Szücs <[email protected]>

* add traffic switching mixed ingress/stackset for desired/actual

Signed-off-by: Sandor Szücs <[email protected]>

* add basic tests for external ingress

Signed-off-by: Sandor Szücs <[email protected]>

* add external ingress based traffic switch

Signed-off-by: Sandor Szücs <[email protected]>

fix: shorten stackset names to fix dns entries

Signed-off-by: Martin Linkhorst <[email protected]>

* add relevant information for externalIngress and the actual/desired traffic in spec/status

Signed-off-by: Sandor Szücs <[email protected]>

* change version to show feature external-ingress for controllers providing the routes

Signed-off-by: Sandor Szücs <[email protected]>

* provide upgrade information

Signed-off-by: Sandor Szücs <[email protected]>

* remove commented code and leftovers

Signed-off-by: Sandor Szücs <[email protected]>

* fix vm size for builds

Signed-off-by: Sandor Szücs <[email protected]>

* fix release message

Signed-off-by: Sandor Szücs <[email protected]>

* fix nitpicks

Signed-off-by: Sandor Szücs <[email protected]>

* add StackName to zv1.ActualTraffic that is shown in the stackset.status

Signed-off-by: Sandor Szücs <[email protected]>

* remove commented test case

Signed-off-by: Sandor Szücs <[email protected]>

* rename it to make it clear

Signed-off-by: Sandor Szücs <[email protected]>

* Improvements for the external CRDs PR (#169)

* Add ssc.stacksetManagesTraffic, populate it correctly

Signed-off-by: Alexey Ermakov <[email protected]>

* Don't update ingress with desired weights for migrated stacksets

Signed-off-by: Alexey Ermakov <[email protected]>

* e2e: improve the traffic switching tests

 * Test the authoritative annotation
 * Always test both stackset and ingress (for the actual traffic)
 * Add some helper functions to simplify the code
 * Drop two tests already covered by the existing tests

Signed-off-by: Alexey Ermakov <[email protected]>

* Desired traffic: write back to the stackset

Signed-off-by: Alexey Ermakov <[email protected]>

* added link to fabric gateway

Signed-off-by: Sandor Szücs <[email protected]>

* Always use stackset.spec for managing traffic with external ingresses

Signed-off-by: Alexey Ermakov <[email protected]>

* externalIngressBackendPort: correctly set when updating

Signed-off-by: Alexey Ermakov <[email protected]>

* Fixup go modules

Signed-off-by: Alexey Ermakov <[email protected]>

* Sort traffic weights to avoid useless updates

Signed-off-by: Alexey Ermakov <[email protected]>

* Status: drop stacks with 0 traffic

Signed-off-by: Alexey Ermakov <[email protected]>

* Desired traffic: remove stacks with 0 weights

Signed-off-by: Alexey Ermakov <[email protected]>

* implement -migrate-to=<ingress|stackset> to enable stackset desired traffic migrations

Signed-off-by: Sandor Szücs <[email protected]>

* fix compile error, due to NewStackSetController change

Signed-off-by: Sandor Szücs <[email protected]>

* switch arg

Signed-off-by: Sandor Szücs <[email protected]>

* add logs to understand what we are doing in migration

Signed-off-by: Sandor Szücs <[email protected]>

* build fixes

Signed-off-by: Sandor Szücs <[email protected]>

* add a debug purpose log to see that we actuall have something set...

Signed-off-by: Sandor Szücs <[email protected]>

* add debug printlns

Signed-off-by: Sandor Szücs <[email protected]>

* move migration handling

Signed-off-by: Sandor Szücs <[email protected]>

* run migration as first task before start watch

Signed-off-by: Sandor Szücs <[email protected]>

* cleanup printlns

Signed-off-by: Sandor Szücs <[email protected]>

* Status: always include all stacks

Signed-off-by: Alexey Ermakov <[email protected]>

* added spec changes in CRD jsonschema

Signed-off-by: Sandor Szücs <[email protected]>

* use EnumVar from kingpin as commented

Signed-off-by: Sandor Szücs <[email protected]>
  • Loading branch information
szuecs authored Nov 4, 2019
1 parent 5ed54eb commit 7395993
Show file tree
Hide file tree
Showing 28 changed files with 1,751 additions and 280 deletions.
43 changes: 37 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ The `StackSet` is a declarative way of describing the application stack as a
whole, and the `Stacks` describe individual versions of the
application. The `StackSet` also allows defining a "global" load balancer
spanning all stacks of the stackset which makes it possible to switch
traffic to different stacks at the load balancer (Ingress) level.
traffic to different stacks at the load balancer (for example Ingress) level.


```
+-----------------------+
| |
| Load Balancer |
| (Ingress) |
| (for example Ingress) |
| |
+--+--------+--------+--+
| 0% | 20% | 80%
Expand All @@ -70,10 +70,16 @@ spec:
ingress:
hosts: [my-app.example.org, alt.name.org]
backendPort: 80
# optional desired traffic weights defined by stack
traffic:
- stackName: mystack-v1
weight: 80
- stackName: mystack-v2
weight: 20
stackLifecycle:
scaledownTTLSeconds: 300
limit: 5 # maximum number of scaled down stacks to keep.
# If there are more than `limit` stacks, the oldest stacks which are scaled down
limit: 5 # maximum number of scaled down stacks to keep.
# If there are more than `limit` stacks, the oldest stacks which are scaled down
# will be deleted.
stackTemplate:
spec:
Expand Down Expand Up @@ -174,9 +180,13 @@ behavior for the `StackSet`:

* Automatically create new Stacks when the `StackSet` is updated with a new
version in the `stackTemplate`.
* Do traffic switching between Stacks at the Ingress layer. Ingress
* Do traffic switching between Stacks at the Ingress layer, if you
have the ingress definition in the spec. Ingress
resources are automatically updated when new stacks are created. (This
require that your ingress controller implements the annotation `zalando.org/backend-weights: {"my-app-1": 80, "my-app-2": 20}`, for example use [skipper](https://github.com/zalando/skipper) for Ingress).
require that your ingress controller implements the annotation
`zalando.org/backend-weights: {"my-app-1": 80, "my-app-2": 20}`, for
example use [skipper](https://github.com/zalando/skipper) for
Ingress) or read the information from stackset `status.traffic`.
* Safely switch traffic to scaled down stacks. If a stack is scaled down, it
will be scaled up automatically before traffic is directed to it.
* Dynamically provision Ingresses per stack, with per stack host names. I.e.
Expand All @@ -190,6 +200,10 @@ behavior for the `StackSet`:
`Deployment`, `Ingress` and optionally `HorizontalPodAutoscaler`.
* Command line utility (`traffic`) for showing and switching traffic between
stacks.
* You can opt-out of the global `Ingress` creation with
`externalIngress:` spec, such that external controllers can manage
the Ingress or CRD creation, that will configure the routing into
the cluster.

## Docs

Expand Down Expand Up @@ -363,3 +377,20 @@ To understand how this works see the upstream
for generating client interface code for CRDs.

[crd]: https://kubernetes.io/docs/concepts/extend-kubernetes/api-extension/custom-resources/

## Upgrade

### <= v1.0.0 to >= v1.1.0

Clients that write the desired traffic switching value have to move
from ingress annotation `zalando.org/stack-traffic-weights: '{"mystack-v1":80, "mystack-v2": 20}'`
to stackset `spec.traffic`:

```yaml
spec:
traffic:
- stackName: mystack-v1
weight: 80
- stackName: mystack-v2
weight: 20
```
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v1.0
v1.1
22 changes: 22 additions & 0 deletions cmd/e2e/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,25 @@ go test -parallel $NUM_PARALLEL github.com/zalando-incubator/stackset-controller

Over here `$NUM_PARALLEL` can be set to a sufficiently high value which indicates how many
of the parallel type tests can be run concurrently.

#### Example - run E2E test

1. Start apiserver proxy
```
kubectl proxy
```
2. use kubectl watch to show what happens
```
watch -n 10 "kubectl get -n foo stackset,stack,ing,ep,deployment"
```
3. recreate namespace `foo` and run local build stackset-controller
```
kubectl delete namespace foo; kubectl create namespace foo
make
./build/stackset-controller --apiserver=http://127.0.0.1:8001 --controller-id=foo
```
4. rebuild e2e test and run e2e tests in `foo` namespace
```
rm -f build/e2e; make build/e2e
CLUSTER_DOMAIN=example.org CLUSTER_NAME=example E2E_NAMESPACE=foo CONTROLLER_ID=foo KUBECONFIG=$HOME/.kube/config ./build/e2e -test.v #-test.run=TestTrafficSwitch
```
Loading

0 comments on commit 7395993

Please sign in to comment.