From 6a081d1c993bacb6bb8717e0a763e22c4f19fd47 Mon Sep 17 00:00:00 2001 From: Josh Woods Date: Mon, 19 Apr 2021 16:38:13 -0400 Subject: [PATCH] (Issue # 86) Deployment Report: Error generating report against new Ingress definitions --- .../test/test_viya_deployment_report_utils.py | 12 +++- .../utils/viya_deployment_report_utils.py | 19 +++++- viya_ark_library/k8s/sas_k8s_objects.py | 2 + .../response_data/resources_ingresses.json | 64 ++++++++++++++++++- .../k8s/test_impl/sas_kubectl_test.py | 9 ++- 5 files changed, 98 insertions(+), 8 deletions(-) diff --git a/deployment_report/model/utils/test/test_viya_deployment_report_utils.py b/deployment_report/model/utils/test/test_viya_deployment_report_utils.py index de07e78..7c6f5dd 100644 --- a/deployment_report/model/utils/test/test_viya_deployment_report_utils.py +++ b/deployment_report/model/utils/test/test_viya_deployment_report_utils.py @@ -385,11 +385,19 @@ def test_define_service_to_ingress_relationships(gathered_resources: Dict) -> No # makes sure relationship is defined and exists assert ReportKeys.ResourceDetails.Ext.RELATIONSHIPS_LIST in service[ReportKeys.ResourceDetails.EXT_DICT] - assert len(service[ReportKeys.ResourceDetails.EXT_DICT][ReportKeys.ResourceDetails.Ext.RELATIONSHIPS_LIST]) == 1 + assert len(service[ReportKeys.ResourceDetails.EXT_DICT][ReportKeys.ResourceDetails.Ext.RELATIONSHIPS_LIST]) == 2 - # get the relationship + # get the first relationship rel: Dict = service[ReportKeys.ResourceDetails.EXT_DICT][ReportKeys.ResourceDetails.Ext.RELATIONSHIPS_LIST][0] + # make sure the relationship attributes are correct + assert rel[ReportKeys.ResourceDetails.Ext.Relationship.KIND] == KubernetesResource.Kinds.INGRESS + assert rel[ReportKeys.ResourceDetails.Ext.Relationship.NAME] == \ + TestVals.COMPONENT_SAS_ANNOTATIONS_INGRESS_NAME_DEPRECATED_DEFINITION + + # get the second relationship + rel: Dict = service[ReportKeys.ResourceDetails.EXT_DICT][ReportKeys.ResourceDetails.Ext.RELATIONSHIPS_LIST][1] + # make sure the relationship attributes are correct assert rel[ReportKeys.ResourceDetails.Ext.Relationship.KIND] == KubernetesResource.Kinds.INGRESS assert rel[ReportKeys.ResourceDetails.Ext.Relationship.NAME] == TestVals.COMPONENT_SAS_ANNOTATIONS_INGRESS_NAME diff --git a/deployment_report/model/utils/viya_deployment_report_utils.py b/deployment_report/model/utils/viya_deployment_report_utils.py index 604f6c2..8c8ceb8 100644 --- a/deployment_report/model/utils/viya_deployment_report_utils.py +++ b/deployment_report/model/utils/viya_deployment_report_utils.py @@ -162,9 +162,22 @@ def define_service_to_ingress_relationships(services: Dict, ingresses: Dict) -> # iterate over all http paths to process each backend defined # for http_path in http_paths: - # get the Service name for this path # - service_name: Text = \ - http_path[KubernetesResource.Keys.BACKEND][KubernetesResource.Keys.SERVICE_NAME] + + # init the service name var + service_name: Text = "" + + # check if this is the current Ingress definition schema + if ingress.get_api_version().startswith("networking.k8s.io"): + # get the Service name for this path # + service_name = \ + http_path[KubernetesResource.Keys.BACKEND][KubernetesResource.Keys.SERVICE][ + KubernetesResource.Keys.NAME] + + # otherwise, use the old definition schema + else: + # get the Service name for this path + service_name = \ + http_path[KubernetesResource.Keys.BACKEND][KubernetesResource.Keys.SERVICE_NAME] try: # get the Service associated with this path # diff --git a/viya_ark_library/k8s/sas_k8s_objects.py b/viya_ark_library/k8s/sas_k8s_objects.py index add7f1e..0a1ecf7 100644 --- a/viya_ark_library/k8s/sas_k8s_objects.py +++ b/viya_ark_library/k8s/sas_k8s_objects.py @@ -381,6 +381,7 @@ class Keys(object): NAMESPACE = "namespace" NODE_INFO = "nodeInfo" NODE_NAME = "nodeName" + NUMBER = "number" OBSERVED_GENERATION = "observedGeneration" OPERATING_SYSTEM = "operatingSystem" OS_IMAGE = "osImage" @@ -408,6 +409,7 @@ class Keys(object): RULES = "rules" SELECTOR = "selector" SELF_LINK = "selfLink" + SERVICE = "service" SERVICE_PORT = "servicePort" SERVICE_NAME = "serviceName" SPEC = "spec" diff --git a/viya_ark_library/k8s/test_impl/response_data/resources_ingresses.json b/viya_ark_library/k8s/test_impl/response_data/resources_ingresses.json index 20c5c8b..290c77b 100644 --- a/viya_ark_library/k8s/test_impl/response_data/resources_ingresses.json +++ b/viya_ark_library/k8s/test_impl/response_data/resources_ingresses.json @@ -23,7 +23,7 @@ "sas.com/admin": "namespace", "sas.com/deployment": "sas-viya" }, - "name": "sas-annotations", + "name": "sas-annotations-deprecated-definition", "namespace": "test", "resourceVersion": "3426839", "selfLink": "/apis/extensions/v1beta1/namespaces/test/ingresses/sas-annotations", @@ -56,5 +56,67 @@ ] } } + }, + { + "apiVersion": "networking.k8s.io/v1", + "kind": "Ingress", + "metadata": { + "annotations": { + "cadence.sas.com/display-name": "Fast R/TR", + "cadence.sas.com/name": "fast", + "cadence.sas.com/release": "20200508.1588944122646", + "cadence.sas.com/version": "2020", + "kubectl.kubernetes.io/last-applied-configuration": "", + "nginx.ingress.kubernetes.io/proxy-body-size": "2048m", + "nginx.ingress.kubernetes.io/proxy-read-timeout": "300", + "sas.com/component-name": "sas-annotations", + "sas.com/component-version": "2.2.25-20200506.1588775452057", + "sas.com/kustomize-base": "base", + "sas.com/version": "2.2.25" + }, + "creationTimestamp": "2020-05-08T13:36:33Z", + "generation": 1, + "labels": { + "app.kubernetes.io/name": "sas-annotations", + "sas.com/admin": "namespace", + "sas.com/deployment": "sas-viya" + }, + "name": "sas-annotations", + "namespace": "test", + "resourceVersion": "3426839", + "selfLink": "/apis/extensions/v1beta1/namespaces/test/ingresses/sas-annotations", + "uid": "5ab2defa-c50c-47db-8415-d9cb8b0de782" + }, + "spec": { + "rules": [ + { + "host": "k8s-master-node.test.sas.com", + "http": { + "paths": [ + { + "backend": { + "service": { + "name": "sas-annotations", + "port": { + "number": 80 + } + } + }, + "path": "/annotations" + } + ] + } + } + ] + }, + "status": { + "loadBalancer": { + "ingress": [ + { + "ip": "0.0.0.0" + } + ] + } + } } ] \ No newline at end of file diff --git a/viya_ark_library/k8s/test_impl/sas_kubectl_test.py b/viya_ark_library/k8s/test_impl/sas_kubectl_test.py index 96339c6..c8ace26 100644 --- a/viya_ark_library/k8s/test_impl/sas_kubectl_test.py +++ b/viya_ark_library/k8s/test_impl/sas_kubectl_test.py @@ -95,6 +95,7 @@ class Values(object): # Component: sas-annotations COMPONENT_SAS_ANNOTATIONS_DEPLOYMENT_NAME: Text = "sas-annotations" + COMPONENT_SAS_ANNOTATIONS_INGRESS_NAME_DEPRECATED_DEFINITION: Text = "sas-annotations-deprecated-definition" COMPONENT_SAS_ANNOTATIONS_INGRESS_NAME: Text = "sas-annotations" COMPONENT_SAS_ANNOTATIONS_POD_NAME: Text = "sas-annotations-58db55fd65-l2jrw" COMPONENT_SAS_ANNOTATIONS_REPLICA_SET_NAME: Text = "sas-annotations-58db55fd65" @@ -104,7 +105,10 @@ class Values(object): COMPONENT_SAS_ANNOTATIONS_NAME: Text = "sas-annotations" COMPONENT_SAS_ANNOTATIONS_RESOURCE_DICT: Dict[Text, List[Text]] = { KubernetesResource.Kinds.DEPLOYMENT: [COMPONENT_SAS_ANNOTATIONS_DEPLOYMENT_NAME], - KubernetesResource.Kinds.INGRESS: [COMPONENT_SAS_ANNOTATIONS_INGRESS_NAME], + KubernetesResource.Kinds.INGRESS: [ + COMPONENT_SAS_ANNOTATIONS_INGRESS_NAME, + COMPONENT_SAS_ANNOTATIONS_INGRESS_NAME_DEPRECATED_DEFINITION + ], KubernetesResource.Kinds.POD: [COMPONENT_SAS_ANNOTATIONS_POD_NAME], KubernetesResource.Kinds.REPLICA_SET: [COMPONENT_SAS_ANNOTATIONS_REPLICA_SET_NAME], KubernetesResource.Kinds.SERVICE: [COMPONENT_SAS_ANNOTATIONS_SERVICE_NAME], @@ -218,7 +222,8 @@ class Values(object): # Resource: Ingress RESOURCE_INGRESS_LIST: List[Text] = [ - COMPONENT_SAS_ANNOTATIONS_INGRESS_NAME + COMPONENT_SAS_ANNOTATIONS_INGRESS_NAME, + COMPONENT_SAS_ANNOTATIONS_INGRESS_NAME_DEPRECATED_DEFINITION ] RESOURCE_INGRESS_COUNT: int = len(RESOURCE_INGRESS_LIST)