Skip to content

Print cluster info aftger login#561

Merged
openshift-merge-bot[bot] merged 1 commit intoopenshift:mainfrom
diakovnec:print_cluster_info
Dec 2, 2024
Merged

Print cluster info aftger login#561
openshift-merge-bot[bot] merged 1 commit intoopenshift:mainfrom
diakovnec:print_cluster_info

Conversation

@diakovnec
Copy link
Copy Markdown
Contributor

What type of PR is this?

feature to print cluster info after backplain login into a cluster

What this PR does / Why we need it?

Helps to get basic info while troubleshooting

Which Jira/Github issue(s) does this PR fix?

(https://issues.redhat.com/browse/OSD-25315)

Special notes for your reviewer

There a couple of things to mention:

  1. It covers 49.7 % of code but fails when PrintAccessProtectionStatus(clusterID) is called as its required to mock ocmConnection

Unexpected call to *mocks.MockOCMInterface.SetupOCMConnection([]) at /home/ydiakov/cards/osd-25315/attem_4/backplane-cli/pkg/login/printClusterInfoAfterLogin.go:40 because: there are no expected calls of the method "SetupOCMConnection" for that receiver

Unit Test Coverage

Guidelines

  • If it's a new sub-command or new function to an existing sub-command, please cover at least 50% of the code
  • If it's a bug fix for an existing sub-command, please cover 70% of the code

Test coverage checks

  • Added unit tests
  • Created jira card to add unit test
  • This PR may not need unit tests

Pre-checks (if applicable)

  • Ran unit tests locally
  • Validated the changes in a cluster
  • Included documentation changes with PR

Comment thread pkg/login/printClusterInfo.go Outdated
Comment thread pkg/login/printClusterInfo.go Outdated
Comment thread pkg/login/printClusterInfo.go Outdated
Comment thread pkg/login/printClusterInfo.go
Comment thread pkg/login/printClusterInfo.go Outdated
Comment thread cmd/ocm-backplane/login/login.go Outdated
"Name": clusterName}).Infoln("Target cluster")

//PrintClusterInfo After Login
if err := login.PrintClusterInfo(clusterID); err != nil {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can we make this function as optional? Either control via a cmd flag or config file

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I believe it can be pass in as a flag if that's you think is the way to go. Let me see if I can get it done

@diakovnec
Copy link
Copy Markdown
Contributor Author

working on suggestions

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Nov 27, 2024

Codecov Report

Attention: Patch coverage is 70.58824% with 15 lines in your changes missing coverage. Please review.

Project coverage is 45.92%. Comparing base (d6d69bc) to head (933d29e).

Files with missing lines Patch % Lines
pkg/login/printClusterInfo.go 72.09% 7 Missing and 5 partials ⚠️
cmd/ocm-backplane/login/login.go 62.50% 2 Missing and 1 partial ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #561      +/-   ##
==========================================
+ Coverage   45.58%   45.92%   +0.34%     
==========================================
  Files          84       85       +1     
  Lines        6268     6319      +51     
==========================================
+ Hits         2857     2902      +45     
  Misses       3057     3057              
- Partials      354      360       +6     
Files with missing lines Coverage Δ
cmd/ocm-backplane/login/login.go 67.92% <62.50%> (-0.12%) ⬇️
pkg/login/printClusterInfo.go 72.09% <72.09%> (ø)

... and 1 file with indirect coverage changes

Comment thread cmd/ocm-backplane/login/login.go Outdated
flags.BoolVar(
&args.clusterInfo,
"cluster-info",
false, "Print cluster information",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

May be making the help text more clear: Print basic cluster information after login

Comment thread pkg/login/printClusterInfo.go Outdated
func GetAccessProtectionStatus(clusterID string) string {
ocmConnection, err := ocm.DefaultOCMInterface.SetupOCMConnection()
if err != nil {
fmt.Println("Error setting up OCM connection: ", err)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
fmt.Println("Error setting up OCM connection: ", err)
logger.Error("Error setting up OCM connection: ", err)

logger is initialized but is not consistently used for logging messages

Comment thread pkg/login/printClusterInfo.go Outdated
}

// Display cluster information
fmt.Printf("\n%-25s %s\n", "Cluster ID:", clusterInfo.ID())
Copy link
Copy Markdown
Contributor

@xiaoyu74 xiaoyu74 Nov 28, 2024

Choose a reason for hiding this comment

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

May be better to refactor the repeated code of fmt.Printf("%-25s ...") into a helper function like:

func printClusterField(fieldName string, value interface{}) {
    fmt.Printf("%-25s %v\n", fieldName, value)
}

so you can use it like below and it can also improve the resusability in other parts of the codebase if needed.

printClusterField("Cluster ID:", clusterInfo.ID())
printClusterField("Cluster Name:", clusterInfo.Name())
...

@xiaoyu74
Copy link
Copy Markdown
Contributor

Great work Yuri, the functionality works all good, just some nits from code's perspective.

@diakovnec
Copy link
Copy Markdown
Contributor Author

Pausing this PR as I've done something wrong while rebasing as it pulled some changes I haven't made.

@diakovnec
Copy link
Copy Markdown
Contributor Author

diakovnec commented Nov 29, 2024

as was suggested in https://redhat-internal.slack.com/archives/C0326L38PEH/p1732854455926389 I've sync with upstream and added files

@openshift-ci
Copy link
Copy Markdown
Contributor

openshift-ci Bot commented Nov 29, 2024

@diakovnec: all tests passed!

Full PR test history. Your PR dashboard.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

@xiaoyu74
Copy link
Copy Markdown
Contributor

xiaoyu74 commented Dec 2, 2024

/lgtm

@openshift-ci openshift-ci Bot added the lgtm Indicates that a PR is ready to be merged. label Dec 2, 2024
@openshift-ci
Copy link
Copy Markdown
Contributor

openshift-ci Bot commented Dec 2, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: diakovnec, xiaoyu74

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci Bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Dec 2, 2024
@openshift-merge-bot openshift-merge-bot Bot merged commit 8de0639 into openshift:main Dec 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants