Skip to content
This repository has been archived by the owner on Feb 22, 2022. It is now read-only.

[stable/chart] prometheus-operator: Make namespace info explicit #13180

Closed
wants to merge 1 commit into from

Conversation

surajssd
Copy link
Contributor

@surajssd surajssd commented Apr 22, 2019

For all the configs that have missing namespace information, this commit
adds following line to metadata of those namespaced objects.

namespace: {{ .Release.Namespace }}

Checklist

  • DCO signed
  • title of the PR contains starts with chart name e.g. [stable/chart]

@helm-bot helm-bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Apr 22, 2019
@k8s-ci-robot k8s-ci-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Apr 22, 2019
@k8s-ci-robot
Copy link
Contributor

Hi @surajssd. Thanks for your PR.

I'm waiting for a helm member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

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.

@helm-bot helm-bot added the Contribution Allowed If the contributor has signed the DCO or the CNCF CLA (prior to the move to a DCO). label Apr 22, 2019
@vsliouniaev
Copy link
Collaborator

The namespace to install the chart into is specified by the helm --namespace argument. What's the benefit of adding these?

@surajssd
Copy link
Contributor Author

The namespace to install the chart into is specified by the helm --namespace argument. What's the benefit of adding these?

That's right. This value is placed by helm cli/tiller, somewhere. But this behavior is inconsistent with the helm rendering libraries. So if you go ahead and use libraries to parse certain charts which has no parameterizing like above they won't have namespace field in it.

Following is run in the prometheus dir that is downloaded from stable. In kubectl the default namespace is default.

$ helm fetch \
    --repo https://kubernetes-charts.storage.googleapis.com \
    --untar \
    --untardir ./ \
    prometheus-operator

$ helm template --namespace monitoring . | kubectl apply -f -
podsecuritypolicy.extensions/release-name-grafana created
podsecuritypolicy.extensions/release-name-kube-state-metrics created
podsecuritypolicy.extensions/release-name-prometheus-node-exporter created
...
servicemonitor.monitoring.coreos.com/release-name-prometheus-op-operator created
servicemonitor.monitoring.coreos.com/release-name-prometheus-op-prometheus created
Error from server (NotFound): namespaces "monitoring" not found
Error from server (NotFound): namespaces "monitoring" not found

Above in template sub-command I expect that the namespace I am giving is placed under the namespace field in metadata of each object. But it only replaces {{ .Release.Namespace }}.

The last two errors are because it is looking for namespace monitoring which does not exists. Even if it is present this means that half of the things will be created in monitoring namespace and other half in the default namespace.

$ kubectl get pods
NAME                                                   READY   STATUS                  RESTARTS   AGE
release-name-grafana-5759d4d766-rwk88                  0/2     Init:CrashLoopBackOff   5          3m45s
release-name-grafana-test                              0/1     Error                   0          3m46s
release-name-kube-state-metrics-856fbc6f6-nq69k        1/1     Running                 0          3m45s
release-name-prometheus-op-operator-7fc4955ddd-zhqbv   0/1     CrashLoopBackOff        5          3m45s

Above does not deploy very well.

You might argue that this should be fixed in upstream helm tool. But prometheus operator uses this way of fixating namespace in some places.

e.g.:

metadata:
name: {{ template "prometheus-operator.fullname" . }}-operator-cleanup
namespace: {{ .Release.Namespace }}
annotations:

IMHO being explicit is no harm.

@stale
Copy link

stale bot commented May 22, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Any further update will cause the issue/pull request to no longer be considered stale. Thank you for your contributions.

@stale stale bot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label May 22, 2019
@stale stale bot removed the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label May 31, 2019
@surajssd surajssd changed the title prometheus-operator: Make namespace info explicit [stable/chart] prometheus-operator: Make namespace info explicit May 31, 2019
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: surajssd
To fully approve this pull request, please assign additional approvers.
We suggest the following additional approver: anothertobi

If they are not already assigned, you can assign the PR to them by writing /assign @anothertobi in a comment when ready.

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

@surajssd
Copy link
Contributor Author

/assign @anothertobi

For all the configs that have missing namespace information, this commit
adds following line to metadata of those namespaced objects.

```
namespace: {{ .Release.Namespace }}
```

Signed-off-by: Suraj Deshmukh <surajd.service@gmail.com>
@surajssd
Copy link
Contributor Author

@vsliouniaev updated this PR as well!

@vsliouniaev
Copy link
Collaborator

@surajssd, in order for this to work with all the resources provisioned by the chart, you would also have to do this for charts listed in the requirements.yaml kube-state-metrics and prometheus-node-exporter don't have the namespace made explicit. There's a pull request open for Grafana here, that hasn't gotten much traction: #14325. I think these charts would have to accept this change first before prometheus-operator can incorporate it.

If you want to install the chart into a specific namespace using rendered templates, you can accomplish this by setting the correct namespace on the kubectl context. If you want to create templates with the namespace already populated, I think you can achieve this with some creative use of the yq tool.

@stale
Copy link

stale bot commented Jun 30, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Any further update will cause the issue/pull request to no longer be considered stale. Thank you for your contributions.

@stale stale bot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Jun 30, 2019
@surajssd surajssd closed this Jul 1, 2019
@surajssd surajssd deleted the prom-operator-ns-info branch July 1, 2019 12:57
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Contribution Allowed If the contributor has signed the DCO or the CNCF CLA (prior to the move to a DCO). lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. 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.

5 participants