Skip to content

Commit

Permalink
Merge pull request kubernetes#52761 from yuexiao-wang/validate-message
Browse files Browse the repository at this point in the history
Automatic merge from submit-queue (batch tested with PRs 52880, 52855, 52761, 52885, 52929). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>..

Adjust the validating messages

Signed-off-by: yuexiao-wang <[email protected]>

**What this PR does / why we need it**:
1.  Adjust the validating messages for user understanding 
2.  Add error messages for easliy testing.
3.  Optimize the  code for switch case.

**Which issue this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close that issue when PR gets merged)*: fixes #

**Special notes for your reviewer**:

**Release note**:
```release-note
NONE
```
  • Loading branch information
Kubernetes Submit Queue authored Sep 24, 2017
2 parents 8e7f5d8 + 142c2dd commit 63c1ed1
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 9 deletions.
2 changes: 1 addition & 1 deletion hack/make-rules/test-cmd-util.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4689,7 +4689,7 @@ runTests() {
kube::test::if_has_string "${output_message}" "yes"

output_message=$(! kubectl auth can-i get /logs/ --subresource=log 2>&1 "${kube_flags[@]}")
kube::test::if_has_string "${output_message}" "subresource can not be used with nonResourceURL"
kube::test::if_has_string "${output_message}" "subresource can not be used with NonResourceURL"

output_message=$(kubectl auth can-i list jobs.batch/bar -n foo --quiet 2>&1 "${kube_flags[@]}")
kube::test::if_empty_string "${output_message}"
Expand Down
4 changes: 2 additions & 2 deletions pkg/kubectl/cmd/auth/cani.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,10 @@ func (o *CanIOptions) Complete(f cmdutil.Factory, args []string) error {
func (o *CanIOptions) Validate() error {
if o.NonResourceURL != "" {
if o.Subresource != "" {
return fmt.Errorf("--subresource can not be used with nonResourceURL")
return fmt.Errorf("--subresource can not be used with NonResourceURL")
}
if o.Resource != (schema.GroupVersionResource{}) || o.ResourceName != "" {
return fmt.Errorf("nonResourceURL and Resource can not specified together")
return fmt.Errorf("NonResourceURL and ResourceName can not specified together")
}
}
return nil
Expand Down
5 changes: 3 additions & 2 deletions pkg/kubectl/cmd/auth/cani_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,9 @@ func TestRunAccessCheck(t *testing.T) {
APIRegistry: api.Registry,
NegotiatedSerializer: ns,
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
if req.URL.Path != "/apis/authorization.k8s.io/v1/selfsubjectaccessreviews" {
t.Errorf("%s: %v", test.name, req.URL.Path)
expectPath := "/apis/authorization.k8s.io/v1/selfsubjectaccessreviews"
if req.URL.Path != expectPath {
t.Errorf("%s: expected %v, got %v", test.name, expectPath, req.URL.Path)
return nil, nil
}
bodyBits, err := ioutil.ReadAll(req.Body)
Expand Down
4 changes: 0 additions & 4 deletions pkg/kubectl/cmd/auth/reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ func (o *ReconcileOptions) RunReconcile() error {
}
shallowInfoCopy.Object = result.Role.GetObject()
o.Print(&shallowInfoCopy)
return nil

case *rbac.ClusterRole:
reconcileOptions := reconciliation.ReconcileRoleOptions{
Expand All @@ -174,7 +173,6 @@ func (o *ReconcileOptions) RunReconcile() error {
}
shallowInfoCopy.Object = result.Role.GetObject()
o.Print(&shallowInfoCopy)
return nil

case *rbac.RoleBinding:
reconcileOptions := reconciliation.ReconcileRoleBindingOptions{
Expand All @@ -192,7 +190,6 @@ func (o *ReconcileOptions) RunReconcile() error {
}
shallowInfoCopy.Object = result.RoleBinding.GetObject()
o.Print(&shallowInfoCopy)
return nil

case *rbac.ClusterRoleBinding:
reconcileOptions := reconciliation.ReconcileRoleBindingOptions{
Expand All @@ -209,7 +206,6 @@ func (o *ReconcileOptions) RunReconcile() error {
}
shallowInfoCopy.Object = result.RoleBinding.GetObject()
o.Print(&shallowInfoCopy)
return nil

default:
glog.V(1).Infof("skipping %#v", info.Object.GetObjectKind())
Expand Down

0 comments on commit 63c1ed1

Please sign in to comment.