Skip to content

Commit

Permalink
Merge pull request #185 from sassoftware/k8s_versioning
Browse files Browse the repository at this point in the history
K8s versioning
  • Loading branch information
lasiva authored Nov 10, 2022
2 parents c500e4e + 6cea514 commit 45cd73f
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 76 deletions.
9 changes: 7 additions & 2 deletions pre_install_report/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ Kubernetes may orchestrate once Viya is deployed. The report and the informatio
be considered a snapshot in time.

The Kubernetes cluster for a SAS Viya deployment must meet the requirements documented in [SAS® Viya® Operations](https://go.documentation.sas.com/doc/en/itopscdc/default/itopssr/titlepage.htm)
Ensure that the Kubernetes version is within the documented range for the selected cloud provider.
Ensure that the Kubernetes version is within the documented range for the selected cloud provider.
If the Kubernetes server version is below the default minimum, a warning will be included in the report.


### Memory and vCPU Check
Expand Down Expand Up @@ -147,6 +148,10 @@ web-viewable, HTML format.
You can modify the <tool-download-dir>/viya4-ark/pre_install_report/viya_deployment_settings.ini file to alter the
minimum and aggregate settings for CPU and memory on nodes. For more information, see the details in the file.

If you modify the VIYA_K8S_VERSION_MIN to a version less than the minimum Kubernetes version supported by this
release of the report tool, you are operating outside the supported capabilities of the report tool. SAS recommends
using a release of Viya 4 ARK tools that matches the required minimum you are working with.

## Known Issues

The following issue may impact the performance and expected results of this tool.
Expand All @@ -167,4 +172,4 @@ They will look similar to the resources shown below:
kubectl -n <namespace> delete replicaset.apps/hello-world-6665cf748b
kubectl -n <namespace> delete pod/hello-world-6665cf748b-5x2jq
kubectl -n <namespace> delete pod/hello-world-6665cf748b-tkq79
```
```
68 changes: 40 additions & 28 deletions pre_install_report/library/pre_install_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class ViyaPreInstallCheck():
The gathered data can be written to disk as an HTML report and a JSON file containing the gathered data.
"""

def __init__(self, sas_logger: ViyaARKLogger, viya_kubelet_version_min,
def __init__(self, sas_logger: ViyaARKLogger, viya_k8s_version_min,
viya_min_aggregate_worker_CPU_cores,
viya_min_aggregate_worker_memory):
"""
Expand All @@ -65,7 +65,8 @@ def __init__(self, sas_logger: ViyaARKLogger, viya_kubelet_version_min,
self._kubectl: KubectlInterface = None
self.sas_logger = sas_logger
self.logger = self.sas_logger.get_logger()
self._viya_kubelet_version_min = viya_kubelet_version_min
self._viya_k8s_version_min = viya_k8s_version_min
self._validated_kubernetes_version_min = None
self._viya_min_aggregate_worker_CPU_cores: Text = viya_min_aggregate_worker_CPU_cores
self._viya_min_aggregate_worker_memory: Text = viya_min_aggregate_worker_memory
self._calculated_aggregate_memory = None
Expand All @@ -76,21 +77,26 @@ def __init__(self, sas_logger: ViyaARKLogger, viya_kubelet_version_min,

def _parse_release_info(self, release_info):
"""
This method checks that the format of the VIYA_KUBELET_VERSION_MIN specfied in the
user modifiable properies file is valid.
This method checks that the format of the VIYA_K8S_VERSION_MIN specified in the
user modifiable ini file is valid.
:param release_info: The minimum Kubelet version loaded from properties file.
:return tuple of major version, minor version, patch
:param release_info: The minimum K8s version loaded from ini file.
:return tuple of major version, minor version
"""
try:
info = tuple(release_info.split("."))
return info
if (len(info) == 2):
x = [int(i) for a, i in enumerate(info)]
self.logger.debug('release tuple to int {} '.format(x))
k8s_min_rel_str = ''.join(release_info)
self._validated_kubernetes_version_min = k8s_min_rel_str
else:
print('****' + viya_messages.KUBELET_VERSION_ERROR)
sys.exit(viya_messages.BAD_OPT_RC_)

except ValueError:
print(viya_messages.KUBELET_VERSION_ERROR)
sys.exit(viya_messages.BAD_OPT_RC_)
if (len(info) != 3):
print(viya_messages.KUBELET_VERSION_ERROR)
sys.exit(viya_messages.BAD_OPT_RC_)

def _validate_k8s_server_version(self, version):
"""
Expand Down Expand Up @@ -140,7 +146,10 @@ def _k8s_server_version_min(self):
try:
curr_version = semantic_version.Version(str(self._k8s_server_version))

if(curr_version in semantic_version.SimpleSpec(viya_constants.MIN_K8S_SERVER_VERSION)):
self._parse_release_info(self._viya_k8s_version_min)
min_k8s_version = "<" + self._validated_kubernetes_version_min

if(curr_version in semantic_version.SimpleSpec(min_k8s_version)):
self.logger.error("This release of Kubernetes is not supported {}.{}.x"
.format(str(curr_version.major),
str(curr_version.minor)))
Expand Down Expand Up @@ -683,26 +692,26 @@ def _check_memory_errors(self, global_data, total_capacity_memory, quantity_, ag
global_data.append(aggregate_memory_data)
return global_data

def _check_kubelet_errors(self, global_data, aggregate_kubelet_failures):
def _check_k8s_errors(self, global_data, aggregate_k8s_failures):
"""
Check kubelet version against SAS kubelet version requirements
Check Server k8s version against SAS k8s version requirements
global_data: list with global data about worker nodes retrieved
aggregate_kubelet_failures: count of kubelet version errors
aggregate_k8s_failures: count of k8s version errors
return: updated global data about worker nodes retrieved
"""
aggregate_kubelet_data = {}
aggregate_k8s_data = {}
node_status_msg = ""
if self._aggregate_nodeStatus_failures > 0:
node_status_msg = " Check Node(s). All Nodes NOT in Ready Status." \
+ ' Issues Found: ' + str(self._aggregate_nodeStatus_failures)
aggregate_kubelet_data.update({'aggregate_kubelet_failures': node_status_msg})
if aggregate_kubelet_failures > 0:
aggregate_kubelet_data.update({'aggregate_kubelet_failures':
'Check Kubelet Version on nodes.' +
' Issues Found: ' + str(aggregate_kubelet_failures) +
'.' + node_status_msg})
global_data.append(aggregate_kubelet_data)
aggregate_k8s_data.update({'aggregate_k8s_failures': node_status_msg})
if aggregate_k8s_failures > 0:
aggregate_k8s_data.update({'aggregate_k8s_failures:':
'Check K8s Version on nodes.' +
' Issues Found: ' + str(aggregate_k8s_failures) +
'.' + node_status_msg})
global_data.append(aggregate_k8s_data)

return global_data

Expand Down Expand Up @@ -795,7 +804,7 @@ def evaluate_nodes(self, nodes_data, global_data, cluster_info, quantity_):
"""
aggregate_cpu_failures = int(0)
aggregate_memory_failures = int(0)
aggregate_kubelet_failures = int(0)
aggregate_k8s_failures = int(0)
total_cpu_cores = float(0)

total_capacity_memory = quantity_("0G")
Expand Down Expand Up @@ -838,10 +847,10 @@ def evaluate_nodes(self, nodes_data, global_data, cluster_info, quantity_):
else:
self._set_status(1, node, 'kubeletversion')
node['error']['kubeletversion'] = viya_constants.SET + ': ' + kubeletversion + ', ' + \
str(viya_constants.EXPECTED) + ': ' + viya_constants.MIN_K8S_SERVER_VERSION[1:] + ' or later '
str(viya_constants.EXPECTED) + ': ' + self._validated_kubernetes_version_min + ' or later '

aggregate_kubelet_failures += 1
self.logger.debug("aggregate_kubelet_failures {} ".format(str(aggregate_kubelet_failures)))
aggregate_k8s_failures += 1
self.logger.debug("aggregate_k8s_failures {} ".format(str(aggregate_k8s_failures)))
self.logger.debug("node kubeletversion{} ".format(pprint.pformat(node)))

global_data = self._check_workers(global_data, nodes_data)
Expand All @@ -850,7 +859,7 @@ def evaluate_nodes(self, nodes_data, global_data, cluster_info, quantity_):
global_data = self._check_memory_errors(global_data, total_capacity_memory, quantity_,
aggregate_memory_failures)

global_data = self._check_kubelet_errors(global_data, aggregate_kubelet_failures)
global_data = self._check_k8s_errors(global_data, aggregate_k8s_failures)

global_data.append(nodes_data)
global_data = self._update_k8s_version(global_data, self._k8s_server_version)
Expand All @@ -876,7 +885,7 @@ def _get_cpu_units(self, node, key):

def _set_status(self, status, node, key):
"""Set the status flag on dictionary object with node details - to indicate compliance with
cpu, memory kubelet version requirements
cpu, memory k8s version requirements
status: status to be set on dict objectwith node details
node: node dictionary object
Expand Down Expand Up @@ -1055,6 +1064,9 @@ def get_calculated_aggregate_memory(self):
def set_k8s_version(self, version: Text):
self._k8s_server_version = version

def set_k8s_version_min(self, version: Text):
self._viya_k8s_version_min = version

def generate_report(self,
global_data,
master_data,
Expand Down
3 changes: 0 additions & 3 deletions pre_install_report/library/utils/viya_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,3 @@
VIYA_PERCENTAGE_OF_INSTANCE = "85"
MEMORY_WITHIN_RANGE = " Memory within Range"
SERVER_K8S_VERSION = "Server_k8s_version"

# Any versions below this minimum are not supported
MIN_K8S_SERVER_VERSION = '<1.20'
2 changes: 1 addition & 1 deletion pre_install_report/library/utils/viya_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"to access the Kubernetes cluster."
CHECK_NAMESPACE = ' ERROR: Check available permissions in namespace and if it is valid: '
LIMIT_ERROR = 'ERROR: The value in the viya_deployment_settings.ini file is not valid: {} = {}'
KUBELET_VERSION_ERROR = 'ERROR: Check the VIYA_KUBELET_VERSION_MIN value ' \
KUBELET_VERSION_ERROR = 'ERROR: Check the VIYA_K8S_VERSION_MIN value ' \
'specified in the pre_install_report/viya_deployment_settings.ini file'
OPTION_ERROR = "ERROR: option {} not recognized"
OPTION_VALUES_ERROR = "ERROR: Provide valid values for all required options. Check options -i, -p and -H."
Expand Down
16 changes: 12 additions & 4 deletions pre_install_report/pre_install_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,10 +252,18 @@ def main(argv):
check_limits = _read_config_file('viya_deployment_settings.ini')

with LRPIndicator(enter_message="Gathering facts"):
sas_pre_check_report: ViyaPreInstallCheck = \
ViyaPreInstallCheck(sas_logger, check_limits['items']['VIYA_KUBELET_VERSION_MIN'],
check_limits['items']['VIYA_MIN_AGGREGATE_WORKER_CPU_CORES'],
check_limits['items']['VIYA_MIN_AGGREGATE_WORKER_MEMORY'])
try:
sas_pre_check_report: ViyaPreInstallCheck = \
ViyaPreInstallCheck(sas_logger, check_limits['items']['VIYA_K8S_VERSION_MIN'],
check_limits['items']['VIYA_MIN_AGGREGATE_WORKER_CPU_CORES'],
check_limits['items']['VIYA_MIN_AGGREGATE_WORKER_MEMORY'])
except KeyError as e:
print()
print(viya_messages.EXCEPTION_MESSAGE.format(e) +
' Check for missing key/value in the viya_deployment_settings.ini')
print()
sys.exit(viya_messages.RUNTIME_ERROR_RC_)

# gather the details for the report
try:
print()
Expand Down
Loading

0 comments on commit 45cd73f

Please sign in to comment.