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
Conversation
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.
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, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like we also need to add Role
objects and not only ClusterRole
ones - https://prow.ci.openshift.org/view/gs/origin-ci-test/pr-logs/pull/openshift_cluster-monitoring-operator/1230/pull-ci-openshift-cluster-monitoring-operator-master-e2e-agnostic-operator/1405518486192525312#1:build-log.txt%3A51
There was a problem hiding this comment.
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']))
There was a problem hiding this comment.
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.
jsonnet/main.jsonnet
Outdated
inCluster.prometheusAdapter.clusterRoleAggregatedMetricsReader.rules + | ||
inCluster.prometheusAdapter.clusterRoleServerResources.rules + | ||
inCluster.prometheus.clusterRole.rules + | ||
[role.rules for role in inCluster.prometheus.roleSpecificNamespaces.items] + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: no need for a loop as all those rules are the same ones. More in https://github.com/prometheus-operator/kube-prometheus/blob/main/jsonnet/kube-prometheus/components/prometheus.libsonnet#L215-L246
There was a problem hiding this comment.
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 + |
There was a problem hiding this comment.
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 :)
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Incorrect nesting level.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whoooops. 🙃
There was a problem hiding this comment.
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([])
🤷
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
/retest |
/lgtm |
[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 |
/retest Please review the full test history for this PR and help us cut down flakes. |
@bison: The following test failed, say
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. |
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.