Skip to content

Commit ec38b9a

Browse files
author
Xavier R Guérin
committed
Merged patterns, Job controller example
1 parent cd74532 commit ec38b9a

39 files changed

+2153
-2
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*.sw?
2+
/target/

.idea/compiler.xml

+14
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/encodings.xml

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/inspectionProfiles/Project_Default.xml

+10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/jarRepositories.xml

+35
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

+17
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/saveactions_settings.xml

+16
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/workspace.xml

+132
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

+61-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,61 @@
1-
# cloud-native-patterns
2-
Design patterns for cloud-native systems
1+
# Cloud-native Patterns
2+
3+
This repository contains patterns that can be used to design complex,
4+
cloud-native applications. The paper [A Cloud Native Platform for Stateful Streaming](https://arxiv.org/abs/2006.00064)
5+
contains an in-depth description of these patterns.
6+
7+
## Patterns
8+
9+
### Controller
10+
11+
Kubernetes defines controllers as "control loops that tracks at least one
12+
resource type". We constrain that definition further: in cloud native Streams,
13+
a controller is a control loop that tracks a single resource type. Controllers
14+
take some action on creation, modification and deletion of a resource type. As
15+
with regular resources, custom resources can be monitored using controllers.
16+
17+
### Conductor
18+
19+
In contrast to controllers, the conductor pattern observes events from multiple
20+
resources and does not save state updates in a local cache. Instead, they are
21+
concurrent control loops that maintain a state machine that transitions based on
22+
resource events, all towards a final goal. Conductors do not own any resources.
23+
Rather, they register themselves with existing controllers as generic event
24+
listeners which receive the same notifications that each controller does.
25+
26+
### Coordinator
27+
28+
When asynchronous agents need to modify the same resource, we use the
29+
coordinator pattern. The coordinator pattern implements a multiple-reader,
30+
single-writer access model by granting ownership of the resource to a single
31+
agent and serializing asynchronous modification requests coming from other
32+
agents. Coordinators are synchronous command queues that serially execute
33+
modification commands on resources. In cloud native Streams, this pattern means
34+
that the controller for a resource owns that resource, and other controllers
35+
which want to modify it must make requests to that controller.
36+
37+
## Getting started
38+
39+
The repository contains a custom `Job` resource example that makes use of those
40+
patterns. It is located in the `com.ibm.cnp.samples` package.
41+
42+
### Compiling the code
43+
44+
To compile the code, simply import the repository as a `Maven` project in your
45+
favorite IDE, or run the following command at the root of the repository:
46+
```bash
47+
$ mvn package
48+
```
49+
50+
### Running the example
51+
52+
You need first to install the `Job` custom resource definition into your
53+
Kubernetes cluster:
54+
```bash
55+
$ kubectl apply -f ${REPO_ROOT}/crds/job.yaml
56+
```
57+
Then, run the `com.ibm.cnp.samples.Main` class either through your IDE or
58+
by typing the following command at the root of the repository:
59+
```bash
60+
$ mvn exec:java
61+
```

cloud-native-patterns.iml

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module type="JAVA_MODULE" version="4" />

crds/job.yaml

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
apiVersion: apiextensions.k8s.io/v1
2+
kind: CustomResourceDefinition
3+
metadata:
4+
name: cnpjobs.cnp.ibm.com
5+
spec:
6+
group: cnp.ibm.com
7+
versions:
8+
- name: v1
9+
served: true
10+
storage: true
11+
schema:
12+
openAPIV3Schema:
13+
type: object
14+
properties:
15+
spec:
16+
type: object
17+
properties:
18+
state:
19+
type: string
20+
desired:
21+
type: integer
22+
image:
23+
type: string
24+
args:
25+
type: array
26+
items:
27+
type: string
28+
additionalPrinterColumns:
29+
- name: State
30+
type: string
31+
description: The job submission status
32+
jsonPath: .spec.state
33+
- name: Desired
34+
type: integer
35+
description: Desired number of pods
36+
jsonPath: .spec.desired
37+
scope: Namespaced
38+
names:
39+
kind: Job
40+
singular: cnpjob
41+
plural: cnpjobs
42+
shortNames:
43+
- cj
44+
- cjs

examples/job.yaml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
apiVersion: cnp.ibm.com/v1
2+
kind: Job
3+
metadata:
4+
name: example
5+
spec:
6+
desired: 1
7+
image: busybox
8+
args: ['sh', '-c', 'echo "Hello, Kubernetes!" && sleep 3600']

0 commit comments

Comments
 (0)