Skip to content

Commit

Permalink
adding local file, and label support to "--v3 manage cluster"
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Haigh <[email protected]>
  • Loading branch information
MichaelHaigh committed May 24, 2024
1 parent 66d3eb9 commit 652be27
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 21 deletions.
3 changes: 3 additions & 0 deletions astraSDK/k8s.py
Original file line number Diff line number Diff line change
Expand Up @@ -1016,6 +1016,7 @@ def main(
apiToken,
regCred,
registry=None,
label=None, # should be of 'acs.example.com/policy=allowed' format
name="astra-connector",
namespace="astra-connector",
):
Expand All @@ -1039,6 +1040,8 @@ def main(
},
},
}
if label:
body["spec"]["labels"] = {label.split("=")[0]: label.split("=")[1]}
return createResource(
quiet=self.quiet,
dry_run=self.dry_run,
Expand Down
8 changes: 4 additions & 4 deletions tkSrc/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ def createV3ConnectorOperator(v3, dry_run, skip_tls_verify, verbose, operator_ve
context, config_file = tuple(v3.split("@"))
helpers.run(
f"kubectl --insecure-skip-tls-verify={skip_tls_verify} --context={context} "
f"-v={6 if verbose else 0} apply --dry_run={dry_run if dry_run else 'none'} -f "
f"{helpers.getOperatorURL(operator_version)}",
f"-v={6 if verbose else 0} apply --dry_run={dry_run if dry_run else 'none'} "
f"-f {operator_version}",
env={"KUBECONFIG": os.path.expanduser(config_file)} if config_file != "None" else None,
)

Expand Down Expand Up @@ -314,7 +314,7 @@ def createV3Hook(
name=helpers.isRFC1123(name),
action=operation.split("-")[1],
appName=app,
arguments=helpers.prependDump(helpers.createHookList(hookArguments), prepend=4),
arguments=helpers.prependDump(helpers.createNargsList(hookArguments), prepend=4),
hookSource=encodedStr,
matchingCriteria=helpers.prependDump(
helpers.createCriteriaList(
Expand Down Expand Up @@ -579,7 +579,7 @@ def main(args, ard, config=None):
args.script,
args.operation.split("-")[0],
args.operation.split("-")[1],
helpers.createHookList(args.hookArguments),
helpers.createNargsList(args.hookArguments),
matchingCriteria=helpers.createCriteriaList(
args.containerImage,
args.namespace,
Expand Down
16 changes: 9 additions & 7 deletions tkSrc/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,22 @@ def createHelmStr(flagName, values):
return returnStr


def createHookList(hookArguments):
"""Create a list of strings to be used for --hookArguments, as nargs="*" can provide
a variety of different types of lists of lists depending on how the user uses it.
User Input argParse Value createHookList Return
---------- -------------- ---------------------
def createNargsList(arguments):
"""Create a list of strings to be used for --hookArguments and --labels, as nargs="*" can
provide a variety of different types of lists of lists depending on how the user uses it.
User Input argParse Value createNargsList Return
---------- -------------- ----------------------
-a arg1 [['arg1']] ['arg1']
-a arg1 arg2 [['arg1', 'arg2']] ['arg1', 'arg2']
-a arg1 -a arg2 [['arg1'], ['arg2']] ['arg1', 'arg2']
-a "arg1 s_arg" arg2 [['arg1 s_arg', 'arg2']] ['arg1 s_arg', 'arg2']
-a "arg1 s_arg" arg2 -a arg3 [['arg1 s_arg', 'arg2'], ['arg3']] ['arg1 s_arg', 'arg2', 'arg3']
"""
if arguments is None:
return None
returnList = []
if hookArguments:
for arg in hookArguments:
if arguments:
for arg in arguments:
if isinstance(arg, list):
for a in arg:
returnList.append(a)
Expand Down
5 changes: 4 additions & 1 deletion tkSrc/manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ def manageV3Cluster(
cloudID,
headless,
ard,
label=None,
config=None,
):
helpers.isRFC1123(clusterName)
Expand Down Expand Up @@ -216,6 +217,7 @@ def manageV3Cluster(
apiToken["metadata"]["name"],
regCred,
registry=registry,
label=label,
)
if not connector:
raise SystemExit("astraSDK.k8s.createAstraConnector() failed")
Expand Down Expand Up @@ -438,12 +440,13 @@ def main(args, ard, config=None):
args.quiet,
args.verbose,
args.clusterName,
args.operator_version,
args.filename if args.filename else helpers.getOperatorURL(args.operator_version),
args.regCred,
args.registry,
args.cloudID,
args.headless,
ard,
label=args.label,
config=config,
)
else:
Expand Down
36 changes: 27 additions & 9 deletions tkSrc/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -1183,7 +1183,7 @@ def create_asup_args(self):
"--dataWindowEnd",
default=None,
help=f"specify an ISO-8601 timestamp, like: {now.isoformat(timespec='seconds')}"
" (defaults to current time of request)"
" (defaults to current time of request)",
)
quickTime = self.subparserCreateAsup.add_argument_group(
"Quick Time Frame",
Expand Down Expand Up @@ -1842,14 +1842,6 @@ def manage_cluster_args(self):
required=(False if len(self.acl.clouds) == 1 else True),
help="The cloudID to add the cluster to (only required if # of clouds > 1)",
)
self.subparserManageCluster.add_argument(
"-v",
"--operator-version",
required=False,
default="24.02.0-202403151353",
help="Optionally specify the astra-connector-operator version "
"(default: %(default)s)",
)
self.subparserManageCluster.add_argument(
"--regCred",
choices=(None if self.plaidMode else self.acl.credentials),
Expand All @@ -1863,9 +1855,35 @@ def manage_cluster_args(self):
help="optionally specify the FQDN of the ACP image source registry "
"(defaults to cr.<astra-control-fqdn>)",
)
self.subparserManageCluster.add_argument(
"-l",
"--label",
default=None,
help="optionally specify a label to be added to the AstraConnector CR, for "
"example: 'acs.example.com/policy=allowed'",
)
self.subparserManageCluster.add_argument(
"--headless", action="store_true", default=False, help=argparse.SUPPRESS
)
versionGroup = self.subparserManageCluster.add_argument_group(
"operatorGroup", "Astra Connector Operator Version to install"
)
verMEGroup = versionGroup.add_mutually_exclusive_group()
verMEGroup.add_argument(
"-v",
"--operator-version",
required=False,
default="24.02.0-202403151353",
help="Optionally specify the astra-connector-operator version to install from "
"GitHub (default: %(default)s)",
)
verMEGroup.add_argument(
"-f",
"--filename",
required=False,
default=None,
help="Optionally specify the local astra-connector-operator file to install",
)
else:
self.subparserManageCluster.add_argument(
"cluster",
Expand Down

0 comments on commit 652be27

Please sign in to comment.