Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow exec and function transformers to generate resources
- Loading branch information
Showing
3 changed files
with
65 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,37 @@ | ||
def run(r, fc): | ||
add = [] | ||
remove = [] | ||
for resource in r: | ||
if resource.get("metadata") == None: | ||
resource["metadata"] = {} | ||
if resource["metadata"].get("annotations") == None: | ||
resource["metadata"]["annotations"] = {} | ||
|
||
# Flag for deletion | ||
if resource["metadata"]["name"] == "delete-me": | ||
remove.append(resource) | ||
continue | ||
|
||
# Deep-ish copy the resource | ||
cp = dict(resource) | ||
cp["metadata"] = dict(cp["metadata"]) | ||
cp["metadata"]["annotations"] = dict(cp["metadata"]["annotations"]) | ||
cp["metadata"]["name"] = resource["metadata"]["name"]+"-copy" | ||
add.append(cp) | ||
|
||
resource["metadata"]["annotations"]["modified-by"] = fc["metadata"]["name"] | ||
|
||
# Add something | ||
new = { | ||
"kind": "ConfigMap", | ||
"apiVersion": "v1", | ||
"metadata": { | ||
"name": "net-new" | ||
} | ||
} | ||
r.extend(add) | ||
r.append(new) | ||
for resource in remove: | ||
r.remove(resource) | ||
|
||
run(ctx.resource_list["items"], ctx.resource_list["functionConfig"]) |