in marketplace/deployer_util/set_ownership.py [0:0]
def main():
parser = ArgumentParser(description=_PROG_HELP)
parser.add_argument(
"--app_name", help="The name of the application instance", required=True)
parser.add_argument(
"--app_uid", help="The uid of the application instance", required=True)
parser.add_argument(
"--app_api_version",
help="The apiVersion of the Application CRD",
required=True)
parser.add_argument(
"--deployer_name",
help="The name of the deployer service account instance. "
"If deployer_uid is also set, the deployer service account is set "
"as the owner of namespaced deployer components.")
parser.add_argument(
"--deployer_uid",
help="The uid of the deployer service account instance. "
"If deployer_name is also set, the deployer service account is set "
"as the owner of namespaced deployer components.")
parser.add_argument(
"--namespace",
help="The namespace containing the application. "
"If namespace_uid is also set, the namespace is set as the owner"
"of cluster-scoped resources (otherwise unowned).")
parser.add_argument(
"--namespace_uid",
help="The namespace containing the application. "
"If namespace is also set, the namespace is set as the owner"
"of cluster-scoped resources (otherwise unowned).")
parser.add_argument(
"--manifests",
help="The folder containing the manifest templates, "
"or - to read from stdin",
required=True)
parser.add_argument(
"--dest",
help="The output file for the resulting manifest, "
"or - to write to stdout",
required=True)
parser.add_argument(
"--noapp",
action="store_true",
help="Do not look for Application resource to determine "
"what kinds to include. I.e. set owner references for "
"all of the (namespaced) resources in the manifests")
args = parser.parse_args()
resources = []
if args.manifests == "-":
resources = parse_resources_yaml(sys.stdin.read())
elif os.path.isfile(args.manifests):
resources = load_resources_yaml(args.manifests)
else:
resources = []
for filename in os.listdir(args.manifests):
resources += load_resources_yaml(os.path.join(args.manifests, filename))
if not args.noapp:
app = find_application_resource(resources)
kinds = set([x["kind"] for x in app["spec"].get("componentKinds", [])])
excluded_kinds = ["PersistentVolumeClaim", "Application"]
included_kinds = [kind for kind in kinds if kind not in excluded_kinds]
else:
included_kinds = None
if args.dest == "-":
dump(
sys.stdout,
resources,
included_kinds,
namespace=args.namespace,
namespace_uid=args.namespace_uid,
app_name=args.app_name,
app_uid=args.app_uid,
app_api_version=args.app_api_version,
deployer_name=args.deployer_name,
deployer_uid=args.deployer_uid)
sys.stdout.flush()
else:
with open(args.dest, "w", encoding='utf-8') as outfile:
dump(
outfile,
resources,
included_kinds,
namespace=args.namespace,
namespace_uid=args.namespace_uid,
app_name=args.app_name,
app_uid=args.app_uid,
app_api_version=args.app_api_version,
deployer_name=args.deployer_name,
deployer_uid=args.deployer_uid)