Skip to content

Conversation

@Shivam-nagar23
Copy link
Member

@Shivam-nagar23 Shivam-nagar23 commented Aug 29, 2023

Description

Fixes #3829

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

Checklist:

  • The title of the PR states what changed and the related issues number (used for the release note).
  • Does this PR requires documentation updates?
  • I've updated documentation as required by this PR.
  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have tested it for all user roles.
  • I have added all the required unit/api test cases.

Does this PR introduce a user-facing change?


},
}
clusterIdString := strconv.Itoa(clusterId)
validRequest := impl.k8sCommonService.FilterK8sResources(rctx, resourceTree, validRequests, k8sAppDetail, clusterIdString, []string{k8s.ServiceKind, k8s.EndpointsKind, k8s.IngressKind})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for every usage of FilterK8sResources, we are passing validRequests as empty array...need to remove this to clean signature with irrelevant argument

if portHolder.ManifestResponse == nil {
continue
}
kind, ok := portHolder.ManifestResponse.Manifest.Object["kind"]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extract/use constant for "kind"

return resourceTree, nil
}
if kind == ServiceKind {
specField, ok := portHolder.ManifestResponse.Manifest.Object["spec"]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extract/use constant for "spec"

}
spec := specField.(map[string]interface{})
if spec != nil {
ports, ok := spec["ports"]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extract/use constant for "ports"

}
}
if kind == EndpointsKind {
subsetsField, ok := portHolder.ManifestResponse.Manifest.Object["subsets"]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extract/use constant for "subsets"

portList := ports.([]interface{})
for _, portItem := range portList {
if portItem.(map[string]interface{}) != nil {
portNumbers := portItem.(map[string]interface{})["port"]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's add ok bool validation for every type assertion. example -
portNumbers := portItem.(map[string]interface{})["port"] --> portNumbers, ok := portItem.(map[string]interface{})["port"]

}
}
} else {
impl.logger.Errorw("spec doest not contain data", "err", spec)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not returning here? also, key value pair is wrong...given spec printing err

if kind == EndpointsKind {
subsetsField, ok := portHolder.ManifestResponse.Manifest.Object["subsets"]
if !ok {
impl.logger.Errorw("spec not found in resource tree, unable to extract port no")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not looks like error, can be warn or info

if subsetObj != nil {
ports, ok := subsetObj["ports"]
if !ok {
impl.logger.Errorw("ports not found in resource tree endpoints, unable to extract port no")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

incorrect level of log

if kind == "EndpointSlice" {
portsField, ok := portHolder.ManifestResponse.Manifest.Object["ports"]
if !ok {
impl.logger.Errorw("ports not found in resource tree endpoint, unable to extract port no")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

incorrect level of log

kartik-579
kartik-579 previously approved these changes Aug 29, 2023
@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 2 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@kartik-579 kartik-579 linked an issue Aug 29, 2023 that may be closed by this pull request
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Appearing empty port number in Helm applications in Devtron resources page. Bug: Limit of 100 characters on webhook link

4 participants