Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jsonnet: Generate CMO ClusterRole with jsonnet #1230

Merged
merged 4 commits into from Jun 22, 2021

Conversation

bison
Copy link
Contributor

@bison bison commented Jun 17, 2021

The cluster-monitoring-operator ClusterRole needs the combined set of
permissions from all its operand ClusterRoles. This replaces the
Python script used to merge all the rules into a single ClusterRole,
and instead just combines everything in jsonnet. There is no need to
deduplicate everything -- Kubernetes will handle that for us.

  • I added CHANGELOG entry for this change.
  • No user facing changes, so no entry in CHANGELOG was needed.

This renames the asset for the `cluster-monitoring-view` ClusterRole
from just `cluster-role.yaml` to `cluster-role-view.yaml` in
preperation for generating the larger CMO ClusterRole with jsonnet
instead of Python.
@openshift-ci openshift-ci bot requested review from paulfantom and sthaha June 17, 2021 13:31
@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jun 17, 2021
@simonpasquier
Copy link
Contributor

Looks like it breaks the CMO deployment but nice start!

inCluster.prometheusOperator.clusterRole.rules +
inCluster.telemeterClient.clusterRole.rules +
inCluster.thanosQuerier.clusterRole.rules +
inCluster.thanosRuler.clusterRole.rules,
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Seems like this warning is valid in our case: https://github.com/openshift/cluster-monitoring-operator/blob/master/hack/merge_cluster_roles.py#L57-L59

$ make manifests/0000_50_cluster-monitoring-operator_02-role.yaml
python2 hack/merge_cluster_roles.py hack/cluster-monitoring-operator-role.yaml.in `find assets | grep role | grep -v "role-binding"` > manifests/0000_50_cluster-monitoring-operator_02-role.yaml
hack/merge_cluster_roles.py:61: UserWarning: creating a ClusterRole from a Role
  warnings.warn('creating a ClusterRole from a {}'.format(self.manifest['kind']))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, good call. I actually meant to do that and just forgot.

inCluster.prometheusAdapter.clusterRoleAggregatedMetricsReader.rules +
inCluster.prometheusAdapter.clusterRoleServerResources.rules +
inCluster.prometheus.clusterRole.rules +
[role.rules for role in inCluster.prometheus.roleSpecificNamespaces.items] +
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ack. I dunno, seems fine and future proof though. Is the alternative to just reach into the items array and grab only the first item?

// permissions from all its operand ClusterRoles. This extends the base
// ClusterRole by just appending the rules from the others.
clusterRole+: {
rules+: inCluster.alertmanager.clusterRole.rules +
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I just remembered there are Sets in jsonnet stdlib. It would be nice to use it here. Just wrap all this in std.set([ .... ]) and we should have a nicely sorted and partially deduplicated list of rules :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, cool. Done.

- get

- delete
- - apiGroups:
Copy link
Contributor

Choose a reason for hiding this comment

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

Incorrect nesting level.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Whoooops. 🙃

Copy link
Contributor

Choose a reason for hiding this comment

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

seems like this is because of the for loop and because of std.set([]) 🤷

Copy link
Contributor

Choose a reason for hiding this comment

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

Let's ditch the std.set() as it only complicates things here (sorry for this wrong suggestion).

With std.set:

wc -l manifests/0000_50_cluster-monitoring-operator_02-role.yaml 
679 manifests/0000_50_cluster-monitoring-operator_02-role.yaml

Without std.set:

wc -l manifests/0000_50_cluster-monitoring-operator_02-role.yaml 
679 manifests/0000_50_cluster-monitoring-operator_02-role.yaml

Copy link
Contributor

Choose a reason for hiding this comment

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

For context, this is on master:

wc -l manifests/0000_50_cluster-monitoring-operator_02-role.yaml 
495 manifests/0000_50_cluster-monitoring-operator_02-role.yaml

The cluster-monitoring-operator ClusterRole needs the combined set of
permissions from all its operand ClusterRoles.  This replaces the
Python script used to merge all the rules into a single ClusterRole,
and instead just combines everything in jsonnet.  There is no need to
deduplicate everything -- Kubernetes will handle that for us.
This adds the cluster-monitoring-operator ClusterRole regenerated
using jsonnet instead of the `merge_cluster_roles.py` script.
@bison
Copy link
Contributor Author

bison commented Jun 22, 2021

/retest

@paulfantom paulfantom mentioned this pull request Jun 22, 2021
2 tasks
@paulfantom
Copy link
Contributor

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Jun 22, 2021
@openshift-ci
Copy link
Contributor

openshift-ci bot commented Jun 22, 2021

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: bison, paulfantom

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

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Jun 22, 2021

@bison: The following test failed, say /retest to rerun all failed tests:

Test name Commit Details Rerun command
ci/prow/e2e-aws-single-node edcdbce link /test e2e-aws-single-node

Full PR test history. Your PR dashboard.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

@openshift-merge-robot openshift-merge-robot merged commit 8aeb4fb into openshift:master Jun 22, 2021
@bison bison deleted the cluster-roles branch June 23, 2021 09:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants