Skip to content

Commit

Permalink
Add support for thirdparty resource watch/create/put and delete opera…
Browse files Browse the repository at this point in the history
…tions (kubernetes-client#216)

Add third-party-resources paths to OpenAPI spec to be able to create/update/watch third party resources.
  • Loading branch information
jonathan-kosgei authored and mbohlool committed May 18, 2017
1 parent 7a6bae2 commit dab09e0
Show file tree
Hide file tree
Showing 4 changed files with 318 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,4 @@ target/
# Intellij IDEA files
.idea/*
*.iml
.vscode
40 changes: 40 additions & 0 deletions examples/create_thirdparty_resource.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
## Creating a Third Party Resource

```
from __future__ import print_function
from pprint import pprint
import kubernetes
from kubernetes import config
from kubernetes.rest import ApiException
config.load_kube_config()
api_instance = kubernetes.ThirdPartyResources()
namespace = 'default'
resource = 'repos'
fqdn = 'git.k8s.com'
body = {}
body['apiVersion'] = "git.k8s.com/v1"
body['kind'] = "RePo"
body['metadata'] = {}
body['metadata']['name'] = "blog-repo"
body['repo'] = "github.com/user/my-blog"
body['username'] = "username"
body['password'] = "password"
body['branch'] = "branch"
try:
# Create a Resource
api_response = api_instance.apis_fqdn_v1_namespaces_namespace_resource_post(
namespace, fqdn, resource, body)
pprint(api_response)
except ApiException as e:
print(
"Exception when calling DefaultApi->apis_fqdn_v1_namespaces_namespace_resource_post: %s\n" %
e)
```
11 changes: 11 additions & 0 deletions scripts/preprocess_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,18 @@ def strip_tags_from_operation_id(operation, _):
operation['operationId'] = operation_id


def add_thirdparty_resource_paths(spec):
with open('thirdpartypaths.json', 'r') as third_party_spec_file:
third_party_spec = json.loads(third_party_spec_file.read())
for path in third_party_spec.keys():
if path not in spec['paths'].keys():
spec['paths'][path] = third_party_spec[path]
return spec


def process_swagger(spec):
spec = add_thirdparty_resource_paths(spec)

apply_func_to_spec_operations(spec, strip_tags_from_operation_id)

operation_ids = {}
Expand Down
266 changes: 266 additions & 0 deletions scripts/thirdpartypaths.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,266 @@
{
"/apis/{fqdn}/v1/{resource}": {
"get": {
"security": [
{
"Bearer": [

]
}
],
"summary": "Gets Resources",
"description": "Returns a list of Resources",
"tags": [
"third_party_resources"
],
"parameters": [
{
"name": "watch",
"uniqueItems": true,
"type": "boolean",
"description": "Watch for changes to the described resources and return them as a stream of add, update, and remove notifications. Specify resourceVersion.",
"in": "query"
},
{
"name": "fqdn",
"in": "path",
"required": true,
"description": "The Third party Resource fqdn",
"type": "string"
},
{
"name": "resource",
"in": "path",
"required": true,
"description": "The Resource type",
"type": "string"
}
],
"responses": {
"200": {
"description": "A list of Resources",
"schema": {
"type": "object"
}
}
}
}
},
"/apis/{fqdn}/v1/namespaces/{namespace}/{resource}": {
"post": {
"security": [
{
"Bearer": [

]
}
],
"summary": "Create a Resource",
"description": "Creates a third party resource of the type specified",
"tags": [
"third_party_resources"
],
"parameters": [
{
"name": "namespace",
"in": "path",
"required": true,
"description": "The Resource's namespace",
"type": "string"
},
{
"name": "fqdn",
"in": "path",
"required": true,
"description": "The Third party Resource fqdn",
"type": "string"
},
{
"name": "resource",
"in": "path",
"required": true,
"description": "The Resource type",
"type": "string"
},
{
"name": "body",
"in": "body",
"required": true,
"description": "The JSON schema of the Resource to create.",
"schema": {
"type": "object"
}
}
],
"responses": {
"201": {
"description": "A list of Resources",
"schema": {
"type": "object"
}
}
}
}
},
"/apis/{fqdn}/v1/namespaces/{namespace}/{resource}/{name}": {
"get": {
"security": [
{
"Bearer": [

]
}
],
"summary": "Gets a specific Resource",
"description": "Returns a specific Resource in a namespace",
"tags": [
"third_party_resources"
],
"parameters": [
{
"name": "namespace",
"in": "path",
"required": true,
"description": "The Resource's namespace",
"type": "string"
},
{
"name": "name",
"in": "path",
"required": true,
"description": "The Resource's name",
"type": "string"
},
{
"name": "fqdn",
"in": "path",
"required": true,
"description": "The Third party Resource fqdn",
"type": "string"
},
{
"name": "resource",
"in": "path",
"required": true,
"description": "The Resource type",
"type": "string"
}
],
"responses": {
"200": {
"description": "A single Resource",
"schema": {
"type": "object"
}
}
}
},
"delete": {
"security": [
{
"Bearer": [

]
}
],
"summary": "Deletes a specific Resource",
"description": "Deletes the specified Resource in the specified namespace",
"tags": [
"third_party_resources"
],
"parameters": [
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/v1.DeleteOptions"
}
},
{
"name": "gracePeriodSeconds",
"uniqueItems": true,
"type": "integer",
"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.",
"in": "query"
},
{
"name": "orphanDependents",
"uniqueItems": true,
"type": "boolean",
"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.",
"in": "query"
},
{
"name": "propagationPolicy",
"uniqueItems": true,
"type": "string",
"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.",
"in": "query"
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "object"
}
}
}
},
"put": {
"security": [
{
"Bearer": [

]
}
],
"summary": "Replace a Resource",
"description": "Replaces the specified third party resource of the type specified",
"tags": [
"third_party_resources"
],
"parameters": [
{
"name": "namespace",
"in": "path",
"required": true,
"description": "The Resource's namespace",
"type": "string"
},
{
"name": "fqdn",
"in": "path",
"required": true,
"description": "The Third party Resource fqdn",
"type": "string"
},
{
"name": "resource",
"in": "path",
"required": true,
"description": "The Resource type",
"type": "string"
},
{
"name": "body",
"in": "body",
"required": true,
"description": "The JSON schema of the Resource to create.",
"schema": {
"type": "object"
}
}
],
"responses": {
"201": {
"description": "A list of Resources",
"schema": {
"type": "object"
}
}
}
}
}
}

0 comments on commit dab09e0

Please sign in to comment.