Skip to content

Commit dab09e0

Browse files
jonathan-kosgeimbohlool
authored andcommitted
Add support for thirdparty resource watch/create/put and delete operations (kubernetes-client#216)
Add third-party-resources paths to OpenAPI spec to be able to create/update/watch third party resources.
1 parent 7a6bae2 commit dab09e0

File tree

4 files changed

+318
-0
lines changed

4 files changed

+318
-0
lines changed

Diff for: .gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,4 @@ target/
6666
# Intellij IDEA files
6767
.idea/*
6868
*.iml
69+
.vscode

Diff for: examples/create_thirdparty_resource.md

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
## Creating a Third Party Resource
2+
3+
```
4+
from __future__ import print_function
5+
6+
from pprint import pprint
7+
8+
import kubernetes
9+
from kubernetes import config
10+
from kubernetes.rest import ApiException
11+
12+
config.load_kube_config()
13+
api_instance = kubernetes.ThirdPartyResources()
14+
15+
namespace = 'default'
16+
resource = 'repos'
17+
fqdn = 'git.k8s.com'
18+
19+
body = {}
20+
body['apiVersion'] = "git.k8s.com/v1"
21+
body['kind'] = "RePo"
22+
body['metadata'] = {}
23+
body['metadata']['name'] = "blog-repo"
24+
body['repo'] = "github.com/user/my-blog"
25+
body['username'] = "username"
26+
body['password'] = "password"
27+
body['branch'] = "branch"
28+
29+
30+
31+
try:
32+
# Create a Resource
33+
api_response = api_instance.apis_fqdn_v1_namespaces_namespace_resource_post(
34+
namespace, fqdn, resource, body)
35+
pprint(api_response)
36+
except ApiException as e:
37+
print(
38+
"Exception when calling DefaultApi->apis_fqdn_v1_namespaces_namespace_resource_post: %s\n" %
39+
e)
40+
```

Diff for: scripts/preprocess_spec.py

+11
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,18 @@ def strip_tags_from_operation_id(operation, _):
102102
operation['operationId'] = operation_id
103103

104104

105+
def add_thirdparty_resource_paths(spec):
106+
with open('thirdpartypaths.json', 'r') as third_party_spec_file:
107+
third_party_spec = json.loads(third_party_spec_file.read())
108+
for path in third_party_spec.keys():
109+
if path not in spec['paths'].keys():
110+
spec['paths'][path] = third_party_spec[path]
111+
return spec
112+
113+
105114
def process_swagger(spec):
115+
spec = add_thirdparty_resource_paths(spec)
116+
106117
apply_func_to_spec_operations(spec, strip_tags_from_operation_id)
107118

108119
operation_ids = {}

Diff for: scripts/thirdpartypaths.json

+266
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,266 @@
1+
{
2+
"/apis/{fqdn}/v1/{resource}": {
3+
"get": {
4+
"security": [
5+
{
6+
"Bearer": [
7+
8+
]
9+
}
10+
],
11+
"summary": "Gets Resources",
12+
"description": "Returns a list of Resources",
13+
"tags": [
14+
"third_party_resources"
15+
],
16+
"parameters": [
17+
{
18+
"name": "watch",
19+
"uniqueItems": true,
20+
"type": "boolean",
21+
"description": "Watch for changes to the described resources and return them as a stream of add, update, and remove notifications. Specify resourceVersion.",
22+
"in": "query"
23+
},
24+
{
25+
"name": "fqdn",
26+
"in": "path",
27+
"required": true,
28+
"description": "The Third party Resource fqdn",
29+
"type": "string"
30+
},
31+
{
32+
"name": "resource",
33+
"in": "path",
34+
"required": true,
35+
"description": "The Resource type",
36+
"type": "string"
37+
}
38+
],
39+
"responses": {
40+
"200": {
41+
"description": "A list of Resources",
42+
"schema": {
43+
"type": "object"
44+
}
45+
}
46+
}
47+
}
48+
},
49+
"/apis/{fqdn}/v1/namespaces/{namespace}/{resource}": {
50+
"post": {
51+
"security": [
52+
{
53+
"Bearer": [
54+
55+
]
56+
}
57+
],
58+
"summary": "Create a Resource",
59+
"description": "Creates a third party resource of the type specified",
60+
"tags": [
61+
"third_party_resources"
62+
],
63+
"parameters": [
64+
{
65+
"name": "namespace",
66+
"in": "path",
67+
"required": true,
68+
"description": "The Resource's namespace",
69+
"type": "string"
70+
},
71+
{
72+
"name": "fqdn",
73+
"in": "path",
74+
"required": true,
75+
"description": "The Third party Resource fqdn",
76+
"type": "string"
77+
},
78+
{
79+
"name": "resource",
80+
"in": "path",
81+
"required": true,
82+
"description": "The Resource type",
83+
"type": "string"
84+
},
85+
{
86+
"name": "body",
87+
"in": "body",
88+
"required": true,
89+
"description": "The JSON schema of the Resource to create.",
90+
"schema": {
91+
"type": "object"
92+
}
93+
}
94+
],
95+
"responses": {
96+
"201": {
97+
"description": "A list of Resources",
98+
"schema": {
99+
"type": "object"
100+
}
101+
}
102+
}
103+
}
104+
},
105+
"/apis/{fqdn}/v1/namespaces/{namespace}/{resource}/{name}": {
106+
"get": {
107+
"security": [
108+
{
109+
"Bearer": [
110+
111+
]
112+
}
113+
],
114+
"summary": "Gets a specific Resource",
115+
"description": "Returns a specific Resource in a namespace",
116+
"tags": [
117+
"third_party_resources"
118+
],
119+
"parameters": [
120+
{
121+
"name": "namespace",
122+
"in": "path",
123+
"required": true,
124+
"description": "The Resource's namespace",
125+
"type": "string"
126+
},
127+
{
128+
"name": "name",
129+
"in": "path",
130+
"required": true,
131+
"description": "The Resource's name",
132+
"type": "string"
133+
},
134+
{
135+
"name": "fqdn",
136+
"in": "path",
137+
"required": true,
138+
"description": "The Third party Resource fqdn",
139+
"type": "string"
140+
},
141+
{
142+
"name": "resource",
143+
"in": "path",
144+
"required": true,
145+
"description": "The Resource type",
146+
"type": "string"
147+
}
148+
],
149+
"responses": {
150+
"200": {
151+
"description": "A single Resource",
152+
"schema": {
153+
"type": "object"
154+
}
155+
}
156+
}
157+
},
158+
"delete": {
159+
"security": [
160+
{
161+
"Bearer": [
162+
163+
]
164+
}
165+
],
166+
"summary": "Deletes a specific Resource",
167+
"description": "Deletes the specified Resource in the specified namespace",
168+
"tags": [
169+
"third_party_resources"
170+
],
171+
"parameters": [
172+
{
173+
"name": "body",
174+
"in": "body",
175+
"required": true,
176+
"schema": {
177+
"$ref": "#/definitions/v1.DeleteOptions"
178+
}
179+
},
180+
{
181+
"name": "gracePeriodSeconds",
182+
"uniqueItems": true,
183+
"type": "integer",
184+
"description": "The duration in seconds before the object should be deleted. Value must be non-negative integer. The value zero indicates delete immediately. If this value is nil, the default grace period for the specified type will be used. Defaults to a per object value if not specified. zero means delete immediately.",
185+
"in": "query"
186+
},
187+
{
188+
"name": "orphanDependents",
189+
"uniqueItems": true,
190+
"type": "boolean",
191+
"description": "Deprecated: please use the PropagationPolicy, this field will be deprecated in 1.7. Should the dependent objects be orphaned. If true/false, the \"orphan\" finalizer will be added to/removed from the object's finalizers list. Either this field or PropagationPolicy may be set, but not both.",
192+
"in": "query"
193+
},
194+
{
195+
"name": "propagationPolicy",
196+
"uniqueItems": true,
197+
"type": "string",
198+
"description": "Whether and how garbage collection will be performed. Either this field or OrphanDependents may be set, but not both. The default policy is decided by the existing finalizer set in the metadata.finalizers and the resource-specific default policy.",
199+
"in": "query"
200+
}
201+
],
202+
"responses": {
203+
"200": {
204+
"description": "OK",
205+
"schema": {
206+
"type": "object"
207+
}
208+
}
209+
}
210+
},
211+
"put": {
212+
"security": [
213+
{
214+
"Bearer": [
215+
216+
]
217+
}
218+
],
219+
"summary": "Replace a Resource",
220+
"description": "Replaces the specified third party resource of the type specified",
221+
"tags": [
222+
"third_party_resources"
223+
],
224+
"parameters": [
225+
{
226+
"name": "namespace",
227+
"in": "path",
228+
"required": true,
229+
"description": "The Resource's namespace",
230+
"type": "string"
231+
},
232+
{
233+
"name": "fqdn",
234+
"in": "path",
235+
"required": true,
236+
"description": "The Third party Resource fqdn",
237+
"type": "string"
238+
},
239+
{
240+
"name": "resource",
241+
"in": "path",
242+
"required": true,
243+
"description": "The Resource type",
244+
"type": "string"
245+
},
246+
{
247+
"name": "body",
248+
"in": "body",
249+
"required": true,
250+
"description": "The JSON schema of the Resource to create.",
251+
"schema": {
252+
"type": "object"
253+
}
254+
}
255+
],
256+
"responses": {
257+
"201": {
258+
"description": "A list of Resources",
259+
"schema": {
260+
"type": "object"
261+
}
262+
}
263+
}
264+
}
265+
}
266+
}

0 commit comments

Comments
 (0)