Skip to content

Commit

Permalink
resource tree panic fix
Browse files Browse the repository at this point in the history
  • Loading branch information
iamayushm committed Aug 16, 2023
1 parent 285406f commit 981aef6
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 13 deletions.
54 changes: 42 additions & 12 deletions api/restHandler/AppListingRestHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -1633,10 +1633,25 @@ func (handler AppListingRestHandlerImpl) PortNumberExtraction(resp []k8s.BatchRe
portsEndpoint := make([]int64, 0)
portEndpointSlice := make([]int64, 0)
for _, portHolder := range resp {
if portHolder.ManifestResponse.Manifest.Object["kind"] == "Service" {
spec := portHolder.ManifestResponse.Manifest.Object["spec"].(map[string]interface{})
kind, ok := portHolder.ManifestResponse.Manifest.Object["kind"]
if !ok {
handler.logger.Errorw("kind not found in resource tree, unable to extract port no")
return resourceTree, nil
}
if kind == k8s.ServiceKind {
specField, ok := portHolder.ManifestResponse.Manifest.Object["spec"]
if !ok {
handler.logger.Errorw("spec not found in resource tree, unable to extract port no")
return resourceTree, nil
}
spec := specField.(map[string]interface{})
if spec != nil {
portList := spec["ports"].([]interface{})
ports, ok := spec["ports"]
if !ok {
handler.logger.Errorw("ports not found in resource tree, unable to extract port no")
return resourceTree, nil
}
portList := ports.([]interface{})
for _, portItem := range portList {
if portItem.(map[string]interface{}) != nil {
portNumbers := portItem.(map[string]interface{})["port"]
Expand All @@ -1650,13 +1665,23 @@ func (handler AppListingRestHandlerImpl) PortNumberExtraction(resp []k8s.BatchRe
handler.logger.Errorw("spec doest not contain data", "err", spec)
}
}
if portHolder.ManifestResponse.Manifest.Object["kind"] == "Endpoints" {
if portHolder.ManifestResponse.Manifest.Object["subsets"] != nil {
subsets := portHolder.ManifestResponse.Manifest.Object["subsets"].([]interface{})
if kind == k8s.EndpointsKind {
subsetsField, ok := portHolder.ManifestResponse.Manifest.Object["subsets"]
if !ok {
handler.logger.Errorw("spec not found in resource tree, unable to extract port no")
return resourceTree, nil
}
if subsetsField != nil {
subsets := subsetsField.([]interface{})
for _, subset := range subsets {
subsetObj := subset.(map[string]interface{})
if subsetObj != nil {
portsIfs := subsetObj["ports"].([]interface{})
ports, ok := subsetObj["ports"]
if !ok {
handler.logger.Errorw("ports not found in resource tree endpoints, unable to extract port no")
return resourceTree, nil
}
portsIfs := ports.([]interface{})
for _, portsIf := range portsIfs {
portsIfObj := portsIf.(map[string]interface{})
if portsIfObj != nil {
Expand All @@ -1668,9 +1693,14 @@ func (handler AppListingRestHandlerImpl) PortNumberExtraction(resp []k8s.BatchRe
}
}
}
if portHolder.ManifestResponse.Manifest.Object["kind"] == "EndpointSlice" {
if portHolder.ManifestResponse.Manifest.Object["ports"] != nil {
endPointsSlicePorts := portHolder.ManifestResponse.Manifest.Object["ports"].([]interface{})
if kind == "EndpointSlice" {
portsField, ok := portHolder.ManifestResponse.Manifest.Object["ports"]
if !ok {
handler.logger.Errorw("ports not found in resource tree endpoint, unable to extract port no")
return resourceTree, nil
}
if portsField != nil {
endPointsSlicePorts := portsField.([]interface{})
for _, val := range endPointsSlicePorts {
portNumbers := val.(map[string]interface{})["port"]
portNumber := portNumbers.(int64)
Expand All @@ -1689,10 +1719,10 @@ func (handler AppListingRestHandlerImpl) PortNumberExtraction(resp []k8s.BatchRe
for _, val := range resourceTreeVal {
value := val.(map[string]interface{})
for key, _type := range value {
if key == "kind" && _type == "Endpoints" {
if key == "kind" && _type == k8s.EndpointsKind {
value["port"] = portsEndpoint
}
if key == "kind" && _type == "Service" {
if key == "kind" && _type == k8s.ServiceKind {
value["port"] = portsService
}
if key == "kind" && _type == "EndpointSlice" {
Expand Down
6 changes: 5 additions & 1 deletion pkg/appStore/deployment/service/InstalledAppService.go
Original file line number Diff line number Diff line change
Expand Up @@ -1209,7 +1209,11 @@ func (impl InstalledAppServiceImpl) checkHibernate(resp map[string]interface{},
responseTree := resp
canBeHibernated := 0
hibernated := 0
for _, node := range responseTree["nodes"].(interface{}).([]interface{}) {
responseTreeNodes, ok := responseTree["nodes"]
if !ok {
return resp, ""
}
for _, node := range responseTreeNodes.(interface{}).([]interface{}) {
currNode := node.(interface{}).(map[string]interface{})
resName := util3.InterfaceToString(currNode["name"])
resKind := util3.InterfaceToString(currNode["kind"])
Expand Down

0 comments on commit 981aef6

Please sign in to comment.