Skip to content

Commit

Permalink
Merge pull request #87 from sassoftware/jowood_issue_86
Browse files Browse the repository at this point in the history
(Fix for Issue # 86) Deployment Report: Error generating report against new Ingress definitions
  • Loading branch information
erharb authored Apr 21, 2021
2 parents ebb9903 + 6a081d1 commit e017e09
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 16 additions & 3 deletions deployment_report/model/utils/viya_deployment_report_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 #
Expand Down
2 changes: 2 additions & 0 deletions viya_ark_library/k8s/sas_k8s_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -408,6 +409,7 @@ class Keys(object):
RULES = "rules"
SELECTOR = "selector"
SELF_LINK = "selfLink"
SERVICE = "service"
SERVICE_PORT = "servicePort"
SERVICE_NAME = "serviceName"
SPEC = "spec"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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"
}
]
}
}
}
]
9 changes: 7 additions & 2 deletions viya_ark_library/k8s/test_impl/sas_kubectl_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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],
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit e017e09

Please sign in to comment.