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

Add kubeRBACProxy property to support querying in cluster prometheus in openshift #3700

Merged
merged 10 commits into from
Oct 24, 2024

Conversation

mittal-ishaan
Copy link
Contributor

@mittal-ishaan mittal-ishaan commented Oct 6, 2024

What does this PR change?

  • Add kubeRBACProxy property to set KUBE_RBAC_PROXY_ENABLED as true in the env var of the cost-model.
  • createPrometheusClusterRoleBinding property to create cluster role binding to grant required permissions to the serviceaccount to query prometheus with kube-rbac-proxy enabled.
  • Add the role binding to grant permissions this external prometheus to scrape metrics from kubecost.
  • Add a check that both kubeRBACProxy and BearerToken property can not be set together,

Does this PR rely on any other PRs?

opencost/opencost#2944

How does this PR impact users? (This is the kind of thing that goes in release notes!)

THis will enable openshift cluster users to configure installing kubecost while using their in-cluster prometheus.

Links to Issues or tickets this PR addresses or fixes

Closes #3690

What risks are associated with merging this PR? What is required to fully test this PR?

NA

How was this PR tested?

tested by installing kubecost using custom built cost-model image having these changes while disabling the bundled prometheus and using the in-cluster prometheus.

Have you made an update to documentation? If so, please provide the corresponding PR.

https://github.com/kubecost/docs/pull/1144/files

@mittal-ishaan mittal-ishaan force-pushed the openshift_in_cluster_prom branch from 96579c5 to 64a1cfa Compare October 6, 2024 16:12
@jessegoodier
Copy link
Collaborator

This looks good to me. Let's merge when the opencost PR is merged.

@mittal-ishaan mittal-ishaan force-pushed the openshift_in_cluster_prom branch from 8da5e63 to 4082b4b Compare October 11, 2024 20:57
@jessegoodier jessegoodier enabled auto-merge (squash) October 24, 2024 21:38
Copy link
Collaborator

@jessegoodier jessegoodier left a comment

Choose a reason for hiding this comment

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

LGTM!

@jessegoodier jessegoodier merged commit b01e76c into develop Oct 24, 2024
20 checks passed
@jessegoodier jessegoodier deleted the openshift_in_cluster_prom branch October 24, 2024 21:48
subjects:
- kind: ServiceAccount
name: {{ .Values.global.platforms.openshift.monitoringServiceAccountName | quote }}
namespace: openshift-monitoring
Copy link
Member

Choose a reason for hiding this comment

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

Is it safe to assume that the ServiceAccount we want to bind to will always be in openshift-monitoring?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, you are correct here. It is not safe to assume the namespace. I would have to correct this.

Comment on lines +14 to +16
# createMonitoringClusterRoleBinding: false # Create a Cluster Role Binding to allow using in-cluster prometheus or thanos.
# createMonitoringResourceReaderRoleBinding: false # Create a Role and Role Binding to allow in-cluster prometheus or thanos to list and watch resources. This will be necessary if you are not using bundled prometheus and need to add scrape config for resources.
# monitoringServiceAccountName: prometheus-k8s # Name of the service account to bind to the Resource Reader Role Binding.
Copy link
Member

Choose a reason for hiding this comment

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

We should add these comments to the main values.yaml file as well!

Copy link
Member

Choose a reason for hiding this comment

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

If possible, I think we should also uncomment them and set default values when possible. Example:

  # Platforms is a higher-level abstraction for platform-specific values and settings.
  platforms:
    # Deploying to OpenShift (OCP) requires enabling this option.
    openshift:
      enabled: true  # Deploy Kubecost to OpenShift.
      createMonitoringClusterRoleBinding: false  # Create a Cluster Role Binding to allow using in-cluster prometheus or thanos.
      createMonitoringResourceReaderRoleBinding: false  # Create a Role and Role Binding to allow in-cluster prometheus or thanos to list and watch resources. This will be necessary if you are not using bundled prometheus and need to add scrape config for resources.
      monitoringServiceAccountName: prometheus-k8s  # Name of the service account to bind to the Resource Reader Role Binding.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure, will uncomment these. I added these specific to openshift and should make it more generalized. Should I move these to global instead? instead of having them under openshift?

@jessegoodier
Copy link
Collaborator

Good finds Thomas.

Ishaan- we merged because we have an urgent need with some customers and needed to test. Thank you for getting this done so quickly!

Comment on lines +47 to +48
kind: ClusterRole
name: cluster-monitoring-view
Copy link
Member

Choose a reason for hiding this comment

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

What ClusterRole is this referring to? I couldn't find any reference to this in the Helm chart. Is this an existing ClusterRole that's specific to OpenShift installs?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Awesome, thanks for clarifying! Lets leave a comment in the template?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure 👍

@mittal-ishaan
Copy link
Contributor Author

mittal-ishaan commented Oct 25, 2024

Thank you Thomas for pointing these out.
I will create a PR to fix these today itself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[OpenShift]: Using the existing Prometheus in an OpenShift cluster?
3 participants