-
Notifications
You must be signed in to change notification settings - Fork 3.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
create_from_yaml custom resource #740
Comments
/assign As a side note that the create from yaml function does not have |
is there some kind of temporary workaround for this? |
We are exactly having the same issue where we need to"Apply" some CRDs via Python K8s client. As @govindKAG mentioned, is there any temporary workaround that you could suggest? |
Hi @rSrkn, there are talks of moving |
@micw523 Thanks for the info. |
@rSrkn you can write a sort of template yaml and then use the yaml python package (I recommend ruamel.yaml though) to edit the yaml file to tailor it to your specific case and then use the appropriate API method, passing this edited yaml object as the "body" parameter for the method as a quick solution. |
Is it possible that you use kubectl to create the yaml file / object? |
@micw523 Thank you , I will check the PR.
which returns a urllib3.response.HTTPResponse. We parse it and convert into a VirtualService object (which we defined). |
Sorry, I meant the author of the issue sugggests* |
Issues go stale after 90d of inactivity. If this issue is safe to close now please do so with Send feedback to sig-testing, kubernetes/test-infra and/or fejta. |
/remove-lifecycle stale Is there any progress on this? Any workaround that works? |
Issues go stale after 90d of inactivity. If this issue is safe to close now please do so with Send feedback to sig-testing, kubernetes/test-infra and/or fejta. |
/remove-lifecycle stale |
it would be very useful to me too. |
I |
my workaround was:
But still, would be great if create_from_yaml works with custom objects :) |
Thanks; way better than mine's 101 # XXX quick and ugly fallback
102 # XXX this is really dangerous for now !
103 # XXX TODO change that before prod (or at least sanitize the yaml file)
104 cmd = ['kubectl', 'apply', '-n', namespace.name, '-f', yaml_file]
105 environ = os.environ.copy()
106 environ['KUBECONFIG'] = cluster._get_kubeconfig_file()
107 subprocess.call(cmd, env=environ) # 🤮🤮🤮 |
/lifecycle frozen |
Is there any better workaround or progress on the issue? |
Would appreciate any update or ETA on this as well |
Here is my solution: def get_custom_api() -> CustomObjectsApi:
"""
获取custom api
:return:
"""
global custom_api
if custom_api is None:
custom_api = client.CustomObjectsApi(api_client)
return custom_api
def patch_custom_object_from_yaml(yaml_object: dict, group: str, version: str, namespace: str, name: str, plural: str):
"""
从yaml文件创建
:param yaml_object:
:param group:
:param version:
:param namespace:
:param name:
:param plural:
:return:
"""
return get_custom_api().patch_namespaced_custom_object(group,
version,
namespace,
plural,
name,
yaml_object)
def create_custom_object_from_yaml(yaml_object: dict, group: str, version: str, namespace: str, plural: str):
"""
从yaml文件patch
:param yaml_object:
:param group:
:param version:
:param namespace:
:param plural:
:return:
"""
return get_custom_api().create_namespaced_custom_object(group,
version,
namespace,
plural,
yaml_object)
def apply_custom_object_from_yaml(yaml_object: dict,
group: str = None,
version: str = None,
namespace: str = None,
name: str = None,
plural: str = None):
"""
apply yaml对象,创建或者更新
:param yaml_object:
:param group:
:param version:
:param namespace:
:param name:
:param plural:
:return:
"""
if not name:
name = yaml_object['metadata']['name']
if not group or not version:
api_version = yaml_object['apiVersion']
group = api_version[0: api_version.find('/')]
version = api_version[api_version.find('/') + 1:]
if not namespace:
namespace = yaml_object['metadata']['namespace']
if not plural:
plural = yaml_object['kind'].lower() + 's'
try:
exists_obj = get_custom_api().get_namespaced_custom_object(group, version, namespace, plural, name)
# 存在,进行patch
patch_custom_object_from_yaml(yaml_object, group, version, namespace, name, plural)
except ApiException as e:
if e.status == 404:
create_custom_object_from_yaml(yaml_object, group, version, namespace, plural)
else:
raise e
from the outside, use below codes to apply your yaml file import yaml
yaml_text = 'xxxxx'
obj = yaml.load(yaml_text, yaml.CLoader)
apply_custom_object_from_yaml(obj) |
Is there any update to use dynamic client in |
I don't see updates on this issue... according to k8s documentation the python client should support crds... |
|
I've got a custom resource description and I need to create custom resource for it. I've been able to create it using
client.CustomObjectsApi(api_client).create_namespaced_custom_object(...)
and usingkubectl apply -f
. I tried using the utils.create_from_yaml but it fails with a traceback:yaml is like:
Pretty obvious what the problem is from the code.
The text was updated successfully, but these errors were encountered: