Skip to content

Commit

Permalink
Merge pull request #65 from sassoftware/jowood_issue_64
Browse files Browse the repository at this point in the history
Update sas_kubectl to handle renamed "APIVERSION" column in `kubectl api-resources` response at v1.20.0
  • Loading branch information
sasjowood authored Feb 5, 2021
2 parents 9c18218 + 8e08350 commit 3dd644a
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions viya_ark_library/k8s/sas_kubectl.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
_HEADER_NAME_ = "NAME"
_HEADER_SHORTNAME_ = "SHORTNAMES"
_HEADER_APIGROUP_ = "APIGROUP"
_HEADER_APIVERSION_ = "APIVERSION"
_HEADER_NAMESPACED_ = "NAMESPACED"
_HEADER_KIND_ = "KIND"
_HEADER_VERBS_ = "VERBS"
Expand Down Expand Up @@ -140,7 +141,16 @@ def api_resources(self, ignore_errors: bool = False) -> KubernetesApiResources:
# get the index of all expected headers #
name_index: int = api_resource_headers.index(_HEADER_NAME_)
shortname_index: int = api_resource_headers.index(_HEADER_SHORTNAME_)
apigroup_index: int = api_resource_headers.index(_HEADER_APIGROUP_)

# the "APIGROUP" header is renamed to "APIVERSION" at kubectl v1.20.0
# since group describes the values listed at all versions, this method will
# return the value as the "api_group"
apigroup_index: int = -1
if _HEADER_APIGROUP_ in api_resource_headers:
apigroup_index = api_resource_headers.index(_HEADER_APIGROUP_)
elif _HEADER_APIVERSION_ in api_resource_headers:
apigroup_index = api_resource_headers.index(_HEADER_APIVERSION_)

namespaced_index: int = api_resource_headers.index(_HEADER_NAMESPACED_)
kind_index: int = api_resource_headers.index(_HEADER_KIND_)
verbs_index: int = api_resource_headers.index(_HEADER_VERBS_)
Expand Down Expand Up @@ -176,11 +186,12 @@ def api_resources(self, ignore_errors: bool = False) -> KubernetesApiResources:
break

# get the api group value #
for char in api_resource_line[apigroup_index:]:
if char != " ":
api_group = api_group + char
else:
break
if apigroup_index != -1:
for char in api_resource_line[apigroup_index:]:
if char != " ":
api_group = api_group + char
else:
break

# get the namespaced value #
for char in api_resource_line[namespaced_index:]:
Expand Down Expand Up @@ -258,7 +269,7 @@ def manage_resource(self, action: Text, file: Text, ignore_errors: bool = False,
# define the command #
cmd: Text = f" {action} -f {file}"
# run the command #
return (self.do(cmd, ignore_errors))
return self.do(cmd, ignore_errors)

def config_view(self, ignore_errors: bool = False) -> Dict:
# get the raw config response
Expand Down

0 comments on commit 3dd644a

Please sign in to comment.