Skip to content

Commit 054029e

Browse files
committed
fix(run_kubectl_command): with apply typos fixed
Signed-off-by: Erdinc Kaya <[email protected]>
1 parent adcae81 commit 054029e

File tree

5 files changed

+35
-27
lines changed

5 files changed

+35
-27
lines changed

hpecp/cli/base.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def get_profile():
5555
"""Retrieve the profile - if supplied."""
5656
profile = os.getenv("PROFILE", default="default")
5757
_log.debug(
58-
"PROFILE envirionment variable exists with value '{}'".format(profile)
58+
"PROFILE environment variable exists with value '{}'".format(profile)
5959
)
6060
return profile
6161

hpecp/cli/k8scluster.py

+6-12
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def __dir__(self):
6464
"statuses",
6565
"upgrade_cluster",
6666
"wait_for_status",
67-
"run_kubectl_command"
67+
"run_kubectl_command",
6868
]
6969

7070
def __init__(self):
@@ -321,7 +321,7 @@ def get_available_addons(self, id=None, k8s_version=None):
321321
print(
322322
"'k8s_version' parameter must be quoted, e.g. \\\"1.20.11\\\" or \"'1.20.11'\"",
323323
file=sys.stderr,
324-
)
324+
)
325325
sys.exit(1)
326326
print(
327327
base.get_client().k8s_cluster.get_available_addons(
@@ -554,15 +554,13 @@ def import_generic_cluster_with_json(
554554
)
555555

556556
@base.intercept_exception
557-
def run_kubectl_command(
558-
self, id, op, yaml
559-
):
557+
def run_kubectl_command(self, id, op, yaml):
560558
"""Run a kubectl command on k8s cluster.
561-
559+
562560
Parameters
563561
------
564562
:param id: The k8s cluster ID, as full resource path </api/v2/k8scluster/1>
565-
:param op: operation to pass to kubectl, either 'create' or 'delete'
563+
:param op: operation to pass to kubectl, either 'create', 'apply' or 'delete'
566564
:param yaml: base64 encoded yaml file to operate
567565
568566
Returns
@@ -573,8 +571,4 @@ def run_kubectl_command(
573571
------
574572
APIException
575573
"""
576-
print(
577-
base.get_client().k8s_cluster.run_kubectl_command(
578-
id, op, yaml
579-
)
580-
)
574+
print(base.get_client().k8s_cluster.run_kubectl_command(id, op, yaml))

hpecp/gateway.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,12 @@ class GatewayController(AbstractWaitableResourceController):
205205
# raise NotImplementedError()
206206

207207
def create_with_ssh_key(
208-
self, ip, proxy_node_hostname, ssh_key_data, ssh_passphrase=None, tags=[]
208+
self,
209+
ip,
210+
proxy_node_hostname,
211+
ssh_key_data,
212+
ssh_passphrase=None,
213+
tags=[],
209214
):
210215
"""Create a gateway instance using SSH key credentials to access the
211216
host.
@@ -253,7 +258,7 @@ def create_with_ssh_key(
253258
}
254259

255260
if ssh_passphrase is not None:
256-
data['credentials']['ssh_key_passphrase'] = ssh_passphrase
261+
data["credentials"]["ssh_key_passphrase"] = ssh_passphrase
257262

258263
response = self.client._request(
259264
url="/api/v1/workers/",

hpecp/k8s_cluster.py

+17-10
Original file line numberDiff line numberDiff line change
@@ -672,15 +672,15 @@ def import_generic_cluster_with_json(self, json):
672672
)
673673
return CaseInsensitiveDict(response.headers)["Location"]
674674

675-
def run_kubectl_command(self, id, op='create', yaml=''):
675+
def run_kubectl_command(self, id, op="apply", yaml=""):
676676
"""Run a kubectl command on k8s cluster.
677-
677+
678678
Parameters
679679
------
680680
id: str
681681
The k8s cluster ID (i.e., '/api/v2/k8s_cluster/1')
682682
op: str
683-
op can be either 'create' or 'delete'
683+
op can be either 'create', 'apply' or 'delete'
684684
yaml: str
685685
base64 encoding of the yaml file
686686
@@ -693,17 +693,24 @@ def run_kubectl_command(self, id, op='create', yaml=''):
693693
APIException
694694
"""
695695

696-
data = {
697-
"op": op,
698-
"data": yaml
699-
}
696+
assert isinstance(
697+
id, basestring
698+
), "ID must be provided in /api/v2/k8scluster/<int> format"
699+
700+
assert op in [
701+
"create",
702+
"apply",
703+
"delete",
704+
], 'op must be either "create", "apply", "delete"'
705+
706+
# TODO: assert yaml is a valid base64 encoded string of a yaml
707+
708+
data = {"op": op, "data": yaml}
700709

701710
response = self.client._request(
702711
url="{}/kubectl".format(id),
703712
http_method="post",
704-
description=(
705-
"K8sClusterController/" "run_kubectl_command"
706-
),
713+
description=("K8sClusterController/" "run_kubectl_command"),
707714
data=data,
708715
)
709716
return response.text

hpecp/k8s_worker.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,9 @@ class K8sWorkerController(AbstractWaitableResourceController):
107107
# """Not Implemented yet"""
108108
# raise NotImplementedError()
109109

110-
def create_with_ssh_key(self, ip, ssh_key_data, ssh_passphrase=None, tags=[]):
110+
def create_with_ssh_key(
111+
self, ip, ssh_key_data, ssh_passphrase=None, tags=[]
112+
):
111113
"""Create a gateway instance using SSH key credentials to access the host.
112114
113115
Parameters
@@ -145,7 +147,7 @@ def create_with_ssh_key(self, ip, ssh_key_data, ssh_passphrase=None, tags=[]):
145147
}
146148

147149
if ssh_passphrase is not None:
148-
data['credentials']['ssh_key_passphrase'] = ssh_passphrase
150+
data["credentials"]["ssh_key_passphrase"] = ssh_passphrase
149151

150152
response = self.client._request(
151153
url="/api/v2/worker/k8shost/",

0 commit comments

Comments
 (0)