Merge pull request #52761 from yuexiao-wang/validate-message

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 <wang.yuexiao@zte.com.cn>

**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
```
pull/6/head
Kubernetes Submit Queue 2017-09-24 04:30:07 -07:00 committed by GitHub
commit 63c1ed12aa
4 changed files with 6 additions and 9 deletions

View File

@ -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}"

View File

@ -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

View File

@ -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)

View File

@ -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{
@ -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{
@ -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{
@ -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())