Skip to content

Commit

Permalink
removing non-registration option 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 28, 2024
1 parent 652be27 commit 9b165cc
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 109 deletions.
57 changes: 1 addition & 56 deletions astraSDK/k8s.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import yaml
from datetime import datetime, timedelta, timezone

from .common import BaseCommon, KubeCommon, SDKCommon
from .common import KubeCommon, SDKCommon


class getResources(KubeCommon):
Expand Down Expand Up @@ -1055,58 +1055,3 @@ def main(
version=body["apiVersion"].split("/")[1],
group=body["apiVersion"].split("/")[0],
)


class createHeadlessConnector(BaseCommon):
"""Creates an AstraConnector custom resource without registering to Astra Control"""

def __init__(
self, quiet=True, dry_run=False, verbose=False, config_context=None, skip_tls_verify=False
):
"""quiet: Will there be CLI output or just return (datastructure)
dry-run: False (default): submit and persist the resource
True or non-empty str: submit request without persisting the resource
verbose: Print all of the rest call info: URL, Method, Headers, Request Body
config_context: the kubeconfig:context mapping to execute against
None: use system defaults
str "None:<context>": use default kubeconfig w/ specified context
str "<config_file>:<context>": use specified file and context
skip_tls_verify: Whether to skip TLS/SSL verification"""
self.quiet = quiet
self.dry_run = dry_run
self.verbose = verbose
self.config_context = config_context
self.skip_tls_verify = skip_tls_verify
super().__init__()

def main(
self, clusterName, regCred, registry, name="astra-connector", namespace="astra-connector"
):
body = {
"apiVersion": "astra.netapp.io/v1",
"kind": "AstraConnector",
"metadata": {"name": name, "namespace": namespace},
"spec": {
"astra": {
"clusterName": clusterName,
"clusterId": "123",
"cloudId": "123",
"accountId": "123",
},
"natsSyncClient": {"cloudBridgeURL": "127.0.0.1"},
"imageRegistry": {"name": registry, "secret": regCred},
},
}
return createResource(
quiet=self.quiet,
dry_run=self.dry_run,
verbose=self.verbose,
config_context=self.config_context,
skip_tls_verify=self.skip_tls_verify,
).main(
body["kind"].lower() + "s",
namespace,
body,
version=body["apiVersion"].split("/")[1],
group=body["apiVersion"].split("/")[0],
)
90 changes: 40 additions & 50 deletions tkSrc/manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,75 +152,66 @@ def manageV3Cluster(
regCred,
registry,
cloudID,
headless,
ard,
label=None,
config=None,
):
helpers.isRFC1123(clusterName)
# Create the Astra Connector Operator and Astra API token secret
create.createV3ConnectorOperator(v3, dry_run, skip_tls_verify, verbose, operator_version)
# Create the astra API token secret
if not headless:
apiToken = astraSDK.k8s.createAstraApiToken(
quiet=quiet,
dry_run=dry_run,
verbose=verbose,
config_context=v3,
skip_tls_verify=skip_tls_verify,
config=config,
).main()
# Handle the registry secret
if not regCred:
cred = astraSDK.k8s.createRegCred(
quiet=quiet,
dry_run=dry_run,
verbose=verbose,
config_context=v3,
skip_tls_verify=skip_tls_verify,
config=config,
).main(registry=registry, namespace="astra-connector")
if not cred:
raise SystemExit("astraSDK.k8s.createRegCred() failed")
regCred = cred["metadata"]["name"]
else:
apiToken = astraSDK.k8s.createAstraApiToken(
quiet=quiet,
dry_run=dry_run,
verbose=verbose,
config_context=v3,
skip_tls_verify=skip_tls_verify,
config=config,
).main()
# Verify / create the registry secret depending on user input
if regCred:
if ard.needsattr("credentials"):
ard.credentials = astraSDK.k8s.getSecrets(
config_context=v3, skip_tls_verify=skip_tls_verify
).main()
cred = ard.getSingleDict("credentials", "metadata.name", regCred)
# Create the AstraConnector CR
if headless:
connector = astraSDK.k8s.createHeadlessConnector(
quiet=quiet,
dry_run=dry_run,
verbose=verbose,
config_context=v3,
skip_tls_verify=skip_tls_verify,
).main(clusterName, regCred, registry)
else:
rc = astraSDK.clusters.addCluster(quiet=quiet, verbose=verbose, config=config).main(
cloudID, name=clusterName, connectorInstall=True
)
if not rc:
raise SystemExit("astraSDK.clusters.addCluster() failed")
connector = astraSDK.k8s.createAstraConnector(
cred = astraSDK.k8s.createRegCred(
quiet=quiet,
dry_run=dry_run,
verbose=verbose,
config_context=v3,
skip_tls_verify=skip_tls_verify,
config=config,
).main(
clusterName,
rc["id"],
cloudID,
apiToken["metadata"]["name"],
regCred,
registry=registry,
label=label,
)
).main(registry=registry, namespace="astra-connector")
if not cred:
raise SystemExit("astraSDK.k8s.createRegCred() failed")
regCred = cred["metadata"]["name"]
# Create the cluster
cluster = astraSDK.clusters.addCluster(quiet=quiet, verbose=verbose, config=config).main(
cloudID, name=clusterName, connectorInstall=True
)
if not cluster:
raise SystemExit("astraSDK.clusters.addCluster() failed")
# Create the AstraConnector CR
connector = astraSDK.k8s.createAstraConnector(
quiet=quiet,
dry_run=dry_run,
verbose=verbose,
config_context=v3,
skip_tls_verify=skip_tls_verify,
config=config,
).main(
clusterName,
cluster["id"],
cloudID,
apiToken["metadata"]["name"],
regCred,
registry=registry,
label=label,
)
if not connector:
raise SystemExit("astraSDK.k8s.createAstraConnector() failed")
return connector


def validateBucketArgs(args):
Expand Down Expand Up @@ -444,7 +435,6 @@ def main(args, ard, config=None):
args.regCred,
args.registry,
args.cloudID,
args.headless,
ard,
label=args.label,
config=config,
Expand Down
3 changes: 0 additions & 3 deletions tkSrc/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -1862,9 +1862,6 @@ def manage_cluster_args(self):
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"
)
Expand Down

0 comments on commit 9b165cc

Please sign in to comment.