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

Adds odo catalog list services -o json #2066

Merged

Conversation

cdrage
Copy link
Member

@cdrage cdrage commented Aug 30, 2019

Adds the ability to list catalog services and output to json.

The format is as follows:

{
  "kind": "ServiceList",
  "apiVersion": "odo.openshift.io/v1alpha1",
  "metadata": {
    "creationTimestamp": null
  },
  "items": [
    {
      "name": "cakephp-mysql-persistent",
      "hidden": false,
      "planList": [
        "default"
      ]
    },
  ]
}

Closes #1357

@cdrage
Copy link
Member Author

cdrage commented Aug 30, 2019

Ready for reviewing! @dharmit @kadel @girishramnani

Unfortunately for tests, I can't test against service catalog... any ideas @amitkrout ? See my commented out test!

@cdrage
Copy link
Member Author

cdrage commented Sep 3, 2019

/retest all

Copy link
Member

@dharmit dharmit left a comment

Choose a reason for hiding this comment

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

Code looks good to me. But I feel like having the MachineReadableSuccessOutput function be a part of machineoutput package.

@@ -397,3 +399,21 @@ func isRequired(required []string, name string) bool {
}
return false
}

// MachineReadableSuccessOutput prints out machine readable output
func MachineReadableSuccessOutput(services []occlient.Service) {
Copy link
Member

Choose a reason for hiding this comment

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

Since the function is dealing with machine output, wouldn't it be helpful to keep it under the machineoutput package?

Copy link
Member Author

Choose a reason for hiding this comment

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

No, as each output will be different.. Or else we'll run into an issue where in the machineout package, we will have multiple functions with different names :(

For example, It'd probably be named ServiceCatalogList or something along those lines, IMO doesn't make sense. But I could be wrong.

Copy link
Member

Choose a reason for hiding this comment

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

I agree with the function name point you raised. To purely counter that point, we have adopted similar approach for auto-completion where everything lives under pkg/odo/util/completion/completionhandlers.go.

Besides that, I think, there's scope of avoiding duplication of code by putting it under machineoutput package. For example, we have renamed Success and Error structs in that package to GenericSuccess and GenericError respectively.

@kadel can you please share your thoughts?

Copy link
Contributor

@amitkrout amitkrout left a comment

Choose a reason for hiding this comment

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

Create a separate test file cmd_catalog_test.go under integration package

@cdrage
Copy link
Member Author

cdrage commented Sep 5, 2019

You have a good point on putting the functions under machineoutout package instead, thanks @dharmit !

Ready for another review 👍

@@ -37,6 +37,13 @@ var _ = Describe("odo service command tests", func() {
})
})

Context("checking machine readable output for service catalog", func() {
Copy link
Contributor

Choose a reason for hiding this comment

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

+1, This is a good place to validate instead of creating a separate test file.

Context("checking machine readable output for service catalog", func() {
It("should succeed listing catalog components", func() {
// Since service catalog is constantly changing, we simply check to see if this command passes.. rather than checking the JSON each time.
helper.CmdShouldPass("odo", "catalog", "list", "services", "-o", "json")
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of matching the whole json can you match the basic key value pair like "kind": "ServiceList" and atleast one "items": [ you mentioned in pr description.

@amitkrout
Copy link
Contributor

Create a separate test file cmd_catalog_test.go under integration package

#2066 (comment)

Copy link
Contributor

@amitkrout amitkrout left a comment

Choose a reason for hiding this comment

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

Remove file - tests/integration/json_test.go

@cdrage
Copy link
Member Author

cdrage commented Sep 6, 2019

Updated based on your comments @amitkrout

It("should succeed listing catalog components", func() {
// Since service catalog is constantly changing, we simply check to see if this command passes.. rather than checking the JSON each time.
output := helper.CmdShouldPass("odo", "catalog", "list", "services", "-o", "json")
Expect(output).To(ContainSubstring("CatalogListServices"))
Copy link
Contributor

Choose a reason for hiding this comment

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

+1

@amitkrout
Copy link
Contributor

/retest

Adds the ability to list catalog services and output to json.

The format is as follows:

```json
{
  "kind": "ServiceList",
  "apiVersion": "odo.openshift.io/v1alpha1",
  "metadata": {
    "creationTimestamp": null
  },
  "items": [
    {
      "name": "cakephp-mysql-persistent",
      "hidden": false,
      "planList": [
        "default"
      ]
    },
  ]
}
```
Copy link
Contributor

@amitkrout amitkrout left a comment

Choose a reason for hiding this comment

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

/approve

@openshift-ci-robot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: amitkrout

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

The pull request process is described here

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-robot openshift-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. Required by Prow. label Sep 9, 2019
@girishramnani
Copy link
Contributor

Looks good
/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. Required by Prow. label Sep 9, 2019
@openshift-bot
Copy link

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-merge-robot openshift-merge-robot merged commit 66662e4 into redhat-developer:master Sep 9, 2019
@cdrage cdrage deleted the add-servicelist-json branch January 14, 2022 14:51
@rm3l rm3l added the estimated-size/M (10-20) Rough sizing for Epics. About 1 sprint of work for one person label Jun 18, 2023
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. Required by Prow. estimated-size/M (10-20) Rough sizing for Epics. About 1 sprint of work for one person lgtm Indicates that a PR is ready to be merged. Required by Prow.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Machine output in case of catalog list operation
8 participants