mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 13:37:30 +00:00
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 ```
This commit is contained in:
commit
63c1ed12aa
@ -4689,7 +4689,7 @@ runTests() {
|
|||||||
kube::test::if_has_string "${output_message}" "yes"
|
kube::test::if_has_string "${output_message}" "yes"
|
||||||
|
|
||||||
output_message=$(! kubectl auth can-i get /logs/ --subresource=log 2>&1 "${kube_flags[@]}")
|
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[@]}")
|
output_message=$(kubectl auth can-i list jobs.batch/bar -n foo --quiet 2>&1 "${kube_flags[@]}")
|
||||||
kube::test::if_empty_string "${output_message}"
|
kube::test::if_empty_string "${output_message}"
|
||||||
|
@ -156,10 +156,10 @@ func (o *CanIOptions) Complete(f cmdutil.Factory, args []string) error {
|
|||||||
func (o *CanIOptions) Validate() error {
|
func (o *CanIOptions) Validate() error {
|
||||||
if o.NonResourceURL != "" {
|
if o.NonResourceURL != "" {
|
||||||
if o.Subresource != "" {
|
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 != "" {
|
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
|
return nil
|
||||||
|
@ -124,8 +124,9 @@ func TestRunAccessCheck(t *testing.T) {
|
|||||||
APIRegistry: api.Registry,
|
APIRegistry: api.Registry,
|
||||||
NegotiatedSerializer: ns,
|
NegotiatedSerializer: ns,
|
||||||
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
|
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
|
||||||
if req.URL.Path != "/apis/authorization.k8s.io/v1/selfsubjectaccessreviews" {
|
expectPath := "/apis/authorization.k8s.io/v1/selfsubjectaccessreviews"
|
||||||
t.Errorf("%s: %v", test.name, req.URL.Path)
|
if req.URL.Path != expectPath {
|
||||||
|
t.Errorf("%s: expected %v, got %v", test.name, expectPath, req.URL.Path)
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
bodyBits, err := ioutil.ReadAll(req.Body)
|
bodyBits, err := ioutil.ReadAll(req.Body)
|
||||||
|
@ -157,7 +157,6 @@ func (o *ReconcileOptions) RunReconcile() error {
|
|||||||
}
|
}
|
||||||
shallowInfoCopy.Object = result.Role.GetObject()
|
shallowInfoCopy.Object = result.Role.GetObject()
|
||||||
o.Print(&shallowInfoCopy)
|
o.Print(&shallowInfoCopy)
|
||||||
return nil
|
|
||||||
|
|
||||||
case *rbac.ClusterRole:
|
case *rbac.ClusterRole:
|
||||||
reconcileOptions := reconciliation.ReconcileRoleOptions{
|
reconcileOptions := reconciliation.ReconcileRoleOptions{
|
||||||
@ -174,7 +173,6 @@ func (o *ReconcileOptions) RunReconcile() error {
|
|||||||
}
|
}
|
||||||
shallowInfoCopy.Object = result.Role.GetObject()
|
shallowInfoCopy.Object = result.Role.GetObject()
|
||||||
o.Print(&shallowInfoCopy)
|
o.Print(&shallowInfoCopy)
|
||||||
return nil
|
|
||||||
|
|
||||||
case *rbac.RoleBinding:
|
case *rbac.RoleBinding:
|
||||||
reconcileOptions := reconciliation.ReconcileRoleBindingOptions{
|
reconcileOptions := reconciliation.ReconcileRoleBindingOptions{
|
||||||
@ -192,7 +190,6 @@ func (o *ReconcileOptions) RunReconcile() error {
|
|||||||
}
|
}
|
||||||
shallowInfoCopy.Object = result.RoleBinding.GetObject()
|
shallowInfoCopy.Object = result.RoleBinding.GetObject()
|
||||||
o.Print(&shallowInfoCopy)
|
o.Print(&shallowInfoCopy)
|
||||||
return nil
|
|
||||||
|
|
||||||
case *rbac.ClusterRoleBinding:
|
case *rbac.ClusterRoleBinding:
|
||||||
reconcileOptions := reconciliation.ReconcileRoleBindingOptions{
|
reconcileOptions := reconciliation.ReconcileRoleBindingOptions{
|
||||||
@ -209,7 +206,6 @@ func (o *ReconcileOptions) RunReconcile() error {
|
|||||||
}
|
}
|
||||||
shallowInfoCopy.Object = result.RoleBinding.GetObject()
|
shallowInfoCopy.Object = result.RoleBinding.GetObject()
|
||||||
o.Print(&shallowInfoCopy)
|
o.Print(&shallowInfoCopy)
|
||||||
return nil
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
glog.V(1).Infof("skipping %#v", info.Object.GetObjectKind())
|
glog.V(1).Infof("skipping %#v", info.Object.GetObjectKind())
|
||||||
|
Loading…
Reference in New Issue
Block a user