Skip to content

Commit

Permalink
Use optional parameter for method
Browse files Browse the repository at this point in the history
  • Loading branch information
johscheuer committed Mar 26, 2019
1 parent 06776ce commit 15d36c9
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 62 deletions.
4 changes: 2 additions & 2 deletions kubernetes/e2e_test/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ def test_create_namespaces_apps_deployment_from_yaml(self):
Should be able to create an apps/v1beta1 deployment.
"""
k8s_client = client.api_client.ApiClient(configuration=self.config)
utils.create_namespaced_from_yaml(
utils.create_from_yaml(
k8s_client, self.path_prefix + "apps-deployment.yaml", namespace=self.test_namespace)
app_api = client.AppsV1beta1Api(k8s_client)
dep = app_api.read_namespaced_deployment(name="nginx-app",
Expand All @@ -349,7 +349,7 @@ def test_create_from_list_in_multi_resource_yaml(self):
specified in the multi-resource file
"""
k8s_client = client.api_client.ApiClient(configuration=self.config)
utils.create_namespaced_from_yaml(
utils.create_from_yaml(
k8s_client, self.path_prefix + "multi-resource-with-list.yaml", namespace=self.test_namespace)
core_api = client.CoreV1Api(k8s_client)
app_api = client.AppsV1beta1Api(k8s_client)
Expand Down
3 changes: 1 addition & 2 deletions kubernetes/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,4 @@

from __future__ import absolute_import

from .create_from_yaml import (FailToCreateError, create_from_yaml,
create_namespaced_from_yaml)
from .create_from_yaml import FailToCreateError, create_from_yaml
60 changes: 2 additions & 58 deletions kubernetes/utils/create_from_yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,49 +22,6 @@


def create_from_yaml(
k8s_client,
yaml_file,
verbose=False,
**kwargs):
"""
Perform an action from a yaml file. Pass True for verbose to
print confirmation information.
Input:
yaml_file: string. Contains the path to yaml file.
k8s_client: an ApiClient object, initialized with the client args.
verbose: If True, print confirmation from the create action.
Default is False.
Returns:
An k8s api object or list of apis objects created from YAML.
When a single object is generated, return type is dependent
on output_list.
Throws a FailToCreateError exception if creation of any object
fails with helpful messages from the server.
Available parameters for creating <kind>:
:param async_req bool
:param bool include_uninitialized: If true, partially initialized
resources are included in the response.
:param str pretty: If 'true', then the output is pretty printed.
:param str dry_run: When present, indicates that modifications
should not be persisted. An invalid or unrecognized dryRun
directive will result in an error response and no further
processing of the request.
Valid values are: - All: all dry run stages will be processed
"""

create_namespaced_from_yaml(
k8s_client,
yaml_file,
verbose,
namespace="default",
**kwargs
)


def create_namespaced_from_yaml(
k8s_client,
yaml_file,
verbose=False,
Expand Down Expand Up @@ -118,14 +75,14 @@ def create_namespaced_from_yaml(
yml_object["apiVersion"] = yml_document["apiVersion"]
yml_object["kind"] = kind
try:
create_namespaced_from_yaml_single_item(
create_from_yaml_single_item(
k8s_client, yml_object, verbose, namespace, **kwargs)
except client.rest.ApiException as api_exception:
api_exceptions.append(api_exception)
else:
# This is a single object. Call the single item method
try:
create_namespaced_from_yaml_single_item(
create_from_yaml_single_item(
k8s_client, yml_document, verbose, namespace, **kwargs)
except client.rest.ApiException as api_exception:
api_exceptions.append(api_exception)
Expand All @@ -135,19 +92,6 @@ def create_namespaced_from_yaml(


def create_from_yaml_single_item(
k8s_client,
yml_object,
verbose=False,
**kwargs):
create_namespaced_from_yaml_single_item(
k8s_client,
yml_object,
verbose,
namespace="default",
**kwargs)


def create_namespaced_from_yaml_single_item(
k8s_client,
yml_object,
verbose=False,
Expand Down

0 comments on commit 15d36c9

Please sign in to comment.