Skip to content
This repository has been archived by the owner on Jun 26, 2023. It is now read-only.

[MTB] added block other tenant resources benchmark #1318

Conversation

phoenixking25
Copy link
Contributor

/assign @JimBugwadia

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Dec 12, 2020
@k8s-ci-robot k8s-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Dec 12, 2020
@@ -14,5 +14,6 @@ type RunOptions struct {
Label string
KClient *kubernetes.Clientset
TClient *kubernetes.Clientset
OClient *kubernetes.Clientset
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we be a little bit more descriptive while naming different clients?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, agreed. What would be good names here? Something like:

  • ClusterAdminClient
  • Tenant1Client
  • Tenant2Client

@@ -130,6 +140,9 @@ func validateFlags(cmd *cobra.Command) error {
return fmt.Errorf("tenant namespace must be set via --namespace or -n")
}

benchmarkRunOptions.OtherNamespace, _ = cmd.Flags().GetString("other-namespace")
benchmarkRunOptions.OtherTenant, _ = cmd.Flags().GetString("other-tenant-admin")
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we can add the arguments in a list itself like -n test test2 --as bob-k8s-access bob2-k8s-access?

Copy link
Contributor

Choose a reason for hiding this comment

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

That's a great idea! @phoenixking25 what do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like the Cobra CLI package allows this:

cmd --slice a --slice b --slice c,d,e

spf13/cobra#661

Comment on lines 41 to 47
if len(resource.Verbs) == 0 {
continue
}

if resource.Namespaced {
continue
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if len(resource.Verbs) == 0 {
continue
}
if resource.Namespaced {
continue
}
if len(resource.Verbs) == 0 || resource.Namespaced {
continue
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Please refactor as suggested.

Comment on lines 55 to 79
for _, resource := range primaryNamespaceResources {
for _, verb := range verbs {
access, msg, err := utils.RunAccessCheck(options.OClient, options.TenantNamespace, resource, verb)
if err != nil {
options.Logger.Debug(err.Error())
return err
}
if access {
return fmt.Errorf(msg)
}
}
}

for _, resource := range primaryNamespaceResources {
for _, verb := range verbs {
access, msg, err := utils.RunAccessCheck(options.TClient, options.OtherNamespace, resource, verb)
if err != nil {
options.Logger.Debug(err.Error())
return err
}
if access {
return fmt.Errorf(msg)
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I think these two for loops can be clubbed into a single for loop.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah this can be made a separate function, right now this particular piece of duplicated at three places

Copy link
Contributor

Choose a reason for hiding this comment

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

Please refactor as suggested.

Copy link
Contributor

@JimBugwadia JimBugwadia left a comment

Choose a reason for hiding this comment

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

see comments.

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jan 11, 2021
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jan 19, 2021
@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jan 19, 2021
@JimBugwadia
Copy link
Contributor

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Jan 19, 2021
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Divya063, JimBugwadia, phoenixking25

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm Indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants