-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Shovan Maity <[email protected]>
- Loading branch information
Shovan Maity
committed
Apr 2, 2020
1 parent
6199204
commit 5c3ac72
Showing
5 changed files
with
135 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
apiVersion: metacontroller.k8s.io/v1alpha1 | ||
kind: CompositeController | ||
metadata: | ||
name: crd-controller | ||
spec: | ||
generateSelector: true | ||
parentResource: | ||
apiVersion: example.com/v1 | ||
resource: pings | ||
childResources: | ||
- apiVersion: apiextensions.k8s.io/v1beta1 | ||
resource: customresourcedefinitions | ||
updateStrategy: | ||
method: InPlace | ||
hooks: | ||
sync: | ||
webhook: | ||
url: http://192.168.1.15:8080/sync | ||
--- | ||
apiVersion: metacontroller.k8s.io/v1alpha1 | ||
kind: CompositeController | ||
metadata: | ||
name: ping-pong-controller | ||
spec: | ||
generateSelector: true | ||
parentResource: | ||
apiVersion: example.com/v1 | ||
resource: pings | ||
childResources: | ||
- apiVersion: example.com/v1 | ||
resource: pongs | ||
updateStrategy: | ||
method: InPlace | ||
hooks: | ||
sync: | ||
webhook: | ||
url: http://192.168.1.15:8081/sync |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
apiVersion: apiextensions.k8s.io/v1beta1 | ||
kind: CustomResourceDefinition | ||
metadata: | ||
name: pings.example.com | ||
spec: | ||
group: example.com | ||
version: v1 | ||
names: | ||
kind: Ping | ||
plural: pings | ||
singular: ping | ||
scope: Namespaced |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
apiVersion: example.com/v1 | ||
kind: Ping | ||
metadata: | ||
name: shovan-maity | ||
spec: | ||
name: Shovan Maity |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
from http.server import BaseHTTPRequestHandler, HTTPServer | ||
import json | ||
|
||
|
||
class Controller(BaseHTTPRequestHandler): | ||
|
||
def do_POST(self): | ||
|
||
crd = [ | ||
{ | ||
"apiVersion": "apiextensions.k8s.io/v1beta1", | ||
"kind": "CustomResourceDefinition", | ||
"metadata": { | ||
"name": "pongs.example.com" | ||
}, | ||
"spec": { | ||
"group": "example.com", | ||
"version": "v1", | ||
"names": { | ||
"kind": "Pong", | ||
"singular": "pong", | ||
"plural": "pongs" | ||
}, | ||
"scope": "Namespaced" | ||
} | ||
} | ||
] | ||
|
||
# Generate desired children | ||
desired = { | ||
"children": crd | ||
} | ||
|
||
self.send_response(200) | ||
self.send_header("Content-type", "application/json") | ||
self.end_headers() | ||
self.wfile.write(json.dumps(desired).encode()) | ||
|
||
|
||
HTTPServer(("", 8080), Controller).serve_forever() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
from http.server import BaseHTTPRequestHandler, HTTPServer | ||
import json | ||
|
||
|
||
class Controller(BaseHTTPRequestHandler): | ||
|
||
def do_POST(self): | ||
|
||
# Observed ping object | ||
observed = json.loads(self.rfile.read( | ||
int(self.headers.get("content-length")))) | ||
ping = observed["parent"] | ||
|
||
name = ping.get("spec", {}).get("name", "Unknown") | ||
|
||
pong = [ | ||
{ | ||
"apiVersion": "example.com/v1", | ||
"kind": "Pong", | ||
"metadata": { | ||
"name": ping["metadata"]["name"] | ||
}, | ||
"spec": { | ||
"message": "Hello %s !!" % (name) | ||
} | ||
} | ||
] | ||
|
||
# Generate desired children | ||
desired = { | ||
"children": pong | ||
} | ||
|
||
self.send_response(200) | ||
self.send_header("Content-type", "application/json") | ||
self.end_headers() | ||
self.wfile.write(json.dumps(desired).encode()) | ||
|
||
|
||
HTTPServer(("", 8081), Controller).serve_forever() |