Commit Graph

33 Commits

Author SHA1 Message Date
Chuck McAndrew
b40eaf279a Add ability to use server_side_apply to utils.create_from_yaml 2024-06-27 16:05:50 -07:00
Jürgen Hötzel
1729f35c7e Prevent ConstructorError when parsing YAML containing '=' scalars
pyyaml assignes '=' to tag:yaml.org,2002:value even though there's
no constructor for it. Removing the implicit resolver for '=' fixes
the issue.
2023-04-30 18:07:39 +02:00
Huan-Ting,Chen
18fb9a0915 feat: add create from directory support 2022-01-21 16:33:45 +08:00
Matt Campbell
13814c0f7e Allow optional list of YAML objects as param to create_from_yaml util 2021-07-19 14:23:14 -04:00
Huan-Ting,Chen
65a0ffc844 Fix empty yaml document error 2021-07-17 16:41:16 +08:00
abhiabhi94
44fe8bf1c2 Refactor utils
- move regex compilation to the top of the module to enable caching.
2021-03-10 08:15:32 +05:30
Tao He
bbdfb73cdf Fixes for code format.
Signed-off-by: Tao He <sighingnow@gmail.com>
2020-09-24 10:08:33 +08:00
Tao He
9e534d021f Returns the created k8s objects in create_from_{dict,yaml}.
Signed-off-by: Tao He <sighingnow@gmail.com>
2020-09-24 02:34:59 +08:00
Christian Clauss
5b94a9a5da
Use ==/!= to compare str, bytes, and int literals
Identity is not the same thing as equality in Python so use ==/!= to compare str, bytes, and int literals. On n Python >= 3.8, these instances will raise SyntaxWarnings so it is best to fix them now. https://docs.python.org/3.8/whatsnew/3.8.html#porting-to-python-3-8
2019-11-16 14:12:46 +01:00
Kubernetes Prow Robot
1ad4afff35
Merge pull request #824 from tnqn/verbose
Fix AttributeError in create_from_yaml
2019-07-23 12:48:14 -07:00
Oz N Tiram
6100392c47 Add optional namespace to create_from_dict
This follows up on the addition to create_from_yaml, the behavior is the
same.
2019-07-23 05:33:40 +02:00
Oz N Tiram
9e40421bcc create_from_yaml function deals with files only
Adding the ability to deal with strings containing yaml seems to repel
to much. So we stay with create_from_yaml with a bad name.

This removes the need fro StringIO to wrap strings.
Also note:

```
with open('foo.txt') as f:
    y = yaml.safe_load_all(f)

for i in y:
    print(i)

\# raises ValueError: I/O operation on closed file.
```

Hence, we indent the whole method body into the open block.

with open('foo.txt') as f:
    y = yaml.safe_load_all(f)
    for i in y:
        print(i)
2019-06-20 23:02:41 +02:00
Oz N Tiram
ed67d89f9b Remove un-necessary if block 2019-06-20 19:53:28 +02:00
Oz N Tiram
5c912f986f Throw exception from create_from_dict
This is instead of doing this in create_from_yaml
2019-06-20 18:37:58 +02:00
Oz N Tiram
4fa0e87bd7 Correct the documentation for create_from_dict
The function can create one or more Kuberenetes objects
based on the content of data. It can handle all API objects
incuding `List` type, which by itself can contain more than
one Kuberenetes API objects.
2019-06-20 14:30:27 +02:00
Oz N Tiram
34898387c3 Merge remote-tracking branch 'upstream/master' into util-improvements 2019-06-20 14:06:00 +02:00
Oz N Tiram
f6566ee5e6 Rename yml_document paramter and update documentation
Renaming `yml_document` in `create_from_dict` to data. This is a bit
 clearer that this it a data item and not a string (usually document
 read from the file system).
 Also update the documentation to describe better what the functions
 `create_from_dict` and `create_from_yaml` do.
2019-06-20 13:27:33 +02:00
Kubernetes Prow Robot
c86e4898fb
Merge pull request #782 from johscheuer/create-from-yaml-namespaced
Add method to dynamically set namespace in yaml files
2019-06-18 13:23:51 -07:00
Quan Tian
7ac1070077 Fix AttributeError in create_from_yaml
Some models don't have attribute 'status', like V1ConfigMap,
V1ClusterRole, and V1NetworkPolicy. AttributeError would be raised if
these resources are created via create_from_yaml with verbose enabled.

This patch checks if attribute 'status' exists before accessing it.
2019-05-03 10:41:00 -07:00
Oz N Tiram
139848efcb Relax pycodestyle: import only allowed at the top
While this is a really good convention, sometimes one must import
stuff inside a try except block. This block is still at the top, but pycodestyle
treats like it isn't, because it's in an idented block, and the outeer scope.
2019-04-09 23:42:01 +02:00
Oz N Tiram
38894cc397
Fix import for StringIO
This is embarrassing.
2019-04-09 23:03:02 +02:00
Oz Tiram
408d405704 Handle StringIO for Python2 properly 2019-04-09 22:51:54 +02:00
Johannes M. Scheuermann
80339ef3f7 Add more documentation to new namespace parameter 2019-04-08 07:52:01 +02:00
Oz Tiram
0779fc9c66 Fix collection of execptions when applying yaml
This fixes of all tests and keeps the original API.

 It's the users responsiblility to do something the execptions
 when using `create_from_dict`, no air bag or breaks are supplied here.
2019-04-05 08:20:57 +02:00
Oz Tiram
50ef8746a9 Merge branch 'master' into util-improvements 2019-04-05 00:23:34 +02:00
Oz Tiram
cee4e49eda Rename create_from_map to create_from_dict, add tests 2019-03-26 23:54:34 +01:00
Oz Tiram
aa28bc7067 Allow create from string or from dict
This is a fix for #722
2019-03-26 23:26:08 +01:00
Johannes M. Scheuermann
15d36c9688 Use optional parameter for method 2019-03-26 21:45:14 +01:00
Johannes M. Scheuermann
06776ced35 Rebase code and add namespaced method 2019-03-25 16:17:12 +01:00
Xianglong Wang
9b989ddc2d Add rbac support for yaml 2019-03-20 17:54:33 -05:00
micw523
c0f71c3ba6 Add list / multi resource support 2019-03-19 00:36:32 -05:00
Xianglong Wang
725687038f Add codestyle tracking, fix codestyle 2018-11-02 16:00:47 -05:00
micw523
5a92ba65aa Add kubectl create -f feature 2018-10-31 19:34:18 -05:00