Support resource definition using manifest URL (#478)

Support resource definition using manifest URL

SUMMARY

Closes #451

ISSUE TYPE


Feature Pull Request

COMPONENT NAME

k8s
k8s_scale
k8s_service

Reviewed-by: Mike Graves <mgraves@redhat.com>
Reviewed-by: Abhijeet Kasurde <None>
Reviewed-by: Bikouo Aubin <None>
This commit is contained in:
Bikouo Aubin
2022-07-04 14:49:53 +02:00
committed by GitHub
parent 9f51fc0ef0
commit 7d0f0449ae
12 changed files with 256 additions and 39 deletions

View File

@@ -5,6 +5,7 @@ import os
from typing import cast, Dict, Iterable, List, Optional, Union
from ansible.module_utils.six import string_types
from ansible.module_utils.urls import Request
try:
import yaml
@@ -53,7 +54,11 @@ def create_definitions(params: Dict) -> List[ResourceDefinition]:
definitions = from_yaml(d)
elif params.get("src"):
d = cast(str, params.get("src"))
definitions = from_file(d)
if hasattr(d, "startswith") and d.startswith(("https://", "http://", "ftp://")):
data = Request().open("GET", d).read().decode("utf8")
definitions = from_yaml(data)
else:
definitions = from_file(d)
else:
# We'll create an empty definition and let merge_params set values
# from the module parameters.

View File

@@ -305,7 +305,6 @@ class K8sService:
def create(self, resource: Resource, definition: Dict) -> Dict:
namespace = definition["metadata"].get("namespace")
name = definition["metadata"].get("name")
results = {"changed": False, "result": {}}
if self.module.check_mode and not self.client.dry_run:
k8s_obj = _encode_stringdata(definition)
@@ -327,7 +326,7 @@ class K8sService:
name
)
)
return results
return dict()
except Exception as e:
reason = e.body if hasattr(e, "body") else e
msg = "Failed to create object: {0}".format(reason)