This repository has been archived by the owner on May 6, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 385
Add basic Register broker command to Svcat #2162
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
Copyright 2018 The Kubernetes Authors. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package broker_test | ||
|
||
import ( | ||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
|
||
"testing" | ||
|
||
_ "github.com/kubernetes-incubator/service-catalog/internal/test" | ||
) | ||
|
||
func TestBroker(t *testing.T) { | ||
RegisterFailHandler(Fail) | ||
RunSpecs(t, "Broker Suite") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
Copyright 2018 The Kubernetes Authors. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package broker | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/kubernetes-incubator/service-catalog/cmd/svcat/command" | ||
"github.com/kubernetes-incubator/service-catalog/cmd/svcat/output" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// RegisterCmd contains the information needed to register a broker | ||
type RegisterCmd struct { | ||
BrokerName string | ||
Context *command.Context | ||
URL string | ||
} | ||
|
||
// NewRegisterCmd builds a "svcat register" command | ||
func NewRegisterCmd(cxt *command.Context) *cobra.Command { | ||
registerCmd := &RegisterCmd{ | ||
Context: cxt, | ||
} | ||
cmd := &cobra.Command{ | ||
Use: "register NAME --url URL", | ||
Short: "Registers a new broker with service catalog", | ||
Example: command.NormalizeExamples(` | ||
svcat register mysqlbroker --url http://mysqlbroker.com | ||
`), | ||
PreRunE: command.PreRunE(registerCmd), | ||
RunE: command.RunE(registerCmd), | ||
} | ||
cmd.Flags().StringVar(®isterCmd.URL, "url", "", | ||
"The broker URL (Required)") | ||
cmd.MarkFlagRequired("url") | ||
return cmd | ||
} | ||
|
||
// Validate checks that the required arguements have been provided | ||
func (c *RegisterCmd) Validate(args []string) error { | ||
if len(args) == 0 { | ||
return fmt.Errorf("a broker name is required") | ||
} | ||
c.BrokerName = args[0] | ||
|
||
return nil | ||
} | ||
|
||
// Run runs the command | ||
func (c *RegisterCmd) Run() error { | ||
return c.Register() | ||
} | ||
|
||
// Register calls out to the pkg lib to create the broker and displays the output | ||
func (c *RegisterCmd) Register() error { | ||
broker, err := c.Context.App.Register(c.BrokerName, c.URL) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
output.WriteBrokerDetails(c.Context.Output, broker) | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
/* | ||
Copyright 2018 The Kubernetes Authors. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package broker_test | ||
|
||
import ( | ||
"bytes" | ||
|
||
. "github.com/kubernetes-incubator/service-catalog/cmd/svcat/broker" | ||
"github.com/kubernetes-incubator/service-catalog/cmd/svcat/command" | ||
"github.com/kubernetes-incubator/service-catalog/cmd/svcat/test" | ||
"github.com/kubernetes-incubator/service-catalog/pkg/apis/servicecatalog/v1beta1" | ||
"github.com/kubernetes-incubator/service-catalog/pkg/svcat" | ||
"github.com/kubernetes-incubator/service-catalog/pkg/svcat/service-catalog/service-catalogfakes" | ||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
"k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
var _ = Describe("Register Command", func() { | ||
Describe("NewRegisterCmd", func() { | ||
It("Builds and returns a cobra command", func() { | ||
cxt := &command.Context{} | ||
cmd := NewRegisterCmd(cxt) | ||
Expect(*cmd).NotTo(BeNil()) | ||
Expect(cmd.Use).To(Equal("register NAME --url URL")) | ||
Expect(cmd.Short).To(ContainSubstring("Registers a new broker with service catalog")) | ||
Expect(cmd.Example).To(ContainSubstring("svcat register mysqlbroker --url http://mysqlbroker.com")) | ||
Expect(len(cmd.Aliases)).To(Equal(0)) | ||
}) | ||
}) | ||
Describe("Validate", func() { | ||
It("errors if a broker name is not provided", func() { | ||
cmd := RegisterCmd{ | ||
BrokerName: "", | ||
Context: nil, | ||
URL: "http://bananabroker.com", | ||
} | ||
err := cmd.Validate([]string{}) | ||
Expect(err).To(HaveOccurred()) | ||
}) | ||
}) | ||
Describe("Register", func() { | ||
It("Calls the pkg/svcat libs Register method with the passed in variables and prints output to the user", func() { | ||
brokerName := "foobarbroker" | ||
brokerURL := "http://foobar.com" | ||
|
||
brokerToReturn := &v1beta1.ClusterServiceBroker{ | ||
ObjectMeta: v1.ObjectMeta{ | ||
Name: brokerName, | ||
}, | ||
Spec: v1beta1.ClusterServiceBrokerSpec{ | ||
CommonServiceBrokerSpec: v1beta1.CommonServiceBrokerSpec{ | ||
URL: brokerURL, | ||
}, | ||
}, | ||
} | ||
|
||
outputBuffer := &bytes.Buffer{} | ||
|
||
fakeApp, _ := svcat.NewApp(nil, nil, "default") | ||
fakeSDK := new(servicecatalogfakes.FakeSvcatClient) | ||
fakeSDK.RegisterReturns(brokerToReturn, nil) | ||
fakeApp.SvcatClient = fakeSDK | ||
cmd := RegisterCmd{ | ||
Context: svcattest.NewContext(outputBuffer, fakeApp), | ||
BrokerName: brokerName, | ||
URL: brokerURL, | ||
} | ||
err := cmd.Register() | ||
|
||
Expect(err).NotTo(HaveOccurred()) | ||
returnedName, returnedURL := fakeSDK.RegisterArgsForCall(0) | ||
Expect(returnedName).To(Equal(brokerName)) | ||
Expect(returnedURL).To(Equal(brokerURL)) | ||
|
||
output := outputBuffer.String() | ||
Expect(output).To(ContainSubstring(brokerName)) | ||
Expect(output).To(ContainSubstring(brokerURL)) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Name: ups-broker | ||
URL: http://upsbroker.com | ||
Status: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -239,18 +239,18 @@ func (sdk *SDK) WaitForBinding(ns, name string, interval time.Duration, timeout | |
return binding, err | ||
} | ||
|
||
// IsBindingReady returns if the instance is in the Ready status. | ||
// IsBindingReady returns true if the instance is in the Ready status. | ||
func (sdk *SDK) IsBindingReady(binding *v1beta1.ServiceBinding) bool { | ||
return sdk.BindingHasStatus(binding, v1beta1.ServiceBindingConditionReady) | ||
return sdk.bindingHasStatus(binding, v1beta1.ServiceBindingConditionReady) | ||
} | ||
|
||
// IsBindingFailed returns if the instance is in the Failed status. | ||
// IsBindingFailed returns true if the instance is in the Failed status. | ||
func (sdk *SDK) IsBindingFailed(binding *v1beta1.ServiceBinding) bool { | ||
return sdk.BindingHasStatus(binding, v1beta1.ServiceBindingConditionFailed) | ||
return sdk.bindingHasStatus(binding, v1beta1.ServiceBindingConditionFailed) | ||
} | ||
|
||
// BindingHasStatus returns if the instance is in the specified status. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i didn't write that as part of this PR, but thanks |
||
func (sdk *SDK) BindingHasStatus(binding *v1beta1.ServiceBinding, status v1beta1.ServiceBindingConditionType) bool { | ||
func (sdk *SDK) bindingHasStatus(binding *v1beta1.ServiceBinding, status v1beta1.ServiceBindingConditionType) bool { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
if binding == nil { | ||
return false | ||
} | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this needs to be
svcat register broker mysqlbroker ...
, so it's aligned withsvcat sync broker mysqlbroker
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure about that. I would think
register
would be likeprovision
andbind
, neither of which require you to specify the object types they create. @carolynvs thoughts?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm with Jonathan on that, for our domain specific verbs that only apply to a single resource type (in this case a broker), I would prefer that we are consistent and not require the redundant noun.