Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Port number fix in helm app #3843

Merged
merged 4 commits into from
Aug 29, 2023
Merged

fix: Port number fix in helm app #3843

merged 4 commits into from
Aug 29, 2023

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
@sonarcloud
Copy link

sonarcloud bot commented Aug 29, 2023

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
@Shivam-nagar23 Shivam-nagar23 merged commit 3f7b4ae into main Aug 29, 2023
5 checks passed
@Shivam-nagar23 Shivam-nagar23 deleted the helm-app-port-no-fix branch August 29, 2023 14:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants