kustomize icon indicating copy to clipboard operation
kustomize copied to clipboard

Support adding namespace to ServiceMonitor namespaceSelector

Open sagikazarmark opened this issue 2 years ago • 2 comments

Is your feature request related to a problem? Please describe.

ServiceMonitors are often supposed to be namespace constrained for a specific application. It's possible to apply namespace selectors to a ServiceMonitor:

apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
  name: some-monitor
spec:
  namespaceSelector:
    matchNames:
      - NAMESPACE

It would be nice if that namespace could come from Kustomize.

Describe the solution you'd like

Make transformers array aware:

namespace:
  - path: spec/namespaceSelector/matchNames[]/0 // Or some alternative syntax
    group: monitoring.coreos.com
    version: v1
    kind: ServiceMonitor
    create: true

Describe alternatives you've considered

Using replacements could be an option, but using the namespace transformer would be much more elegant.

Additional context

#1710 describes a solution using vars, but that's considered deprecated.

#610 added partial support for this and this specific use case actually came up in https://github.com/kubernetes-sigs/kustomize/pull/610#issuecomment-493067658 , but it doesn't work at the moment.

I realize this is a very specific use case, but it's also a very common one and the final solution could always be made generic enough not to be constrained to this specific use case.

sagikazarmark avatar Aug 15 '22 12:08 sagikazarmark

@sagikazarmark: This issue is currently awaiting triage.

SIG CLI takes a lead on issue triage for this repo, but any Kubernetes member can accept issues by applying the triage/accepted label.

The triage/accepted label can be added by org members by writing /triage accepted in a comment.

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.

k8s-ci-robot avatar Aug 15 '22 12:08 k8s-ci-robot

This looks very similar to the use case described in https://github.com/kubernetes-sigs/kustomize/issues/4544. I think configuring the name reference transformer is a better solution, since it does not rely on the position in the array. Please take a look at the example I gave here: https://github.com/kubernetes-sigs/kustomize/issues/4544#issuecomment-1211138762

KnVerey avatar Aug 16 '22 22:08 KnVerey

@KnVerey thanks for your response!

I guess what you suggest works, but from a UX perspective there is room for improvement IMO:

  • In order for it to work, you need a namespace object in the same kustomization
  • You need to specify an existing namespace name
  • It doesn't work with no defaults

Ideally, I should be able to add a namespace when no matchNames is defined. It should work even if the namespace comes outside of the kustomization (eg. imported into another kustomization).

Configuration is an elegant way to do that IMO, but it may not be the best solution.

sagikazarmark avatar Aug 17 '22 14:08 sagikazarmark

The Kubernetes project currently lacks enough contributors to adequately respond to all issues and PRs.

This bot triages issues and PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue or PR as fresh with /remove-lifecycle stale
  • Mark this issue or PR as rotten with /lifecycle rotten
  • Close this issue or PR with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

k8s-triage-robot avatar Nov 15 '22 15:11 k8s-triage-robot

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.

This bot triages issues and PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue or PR as fresh with /remove-lifecycle rotten
  • Close this issue or PR with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle rotten

k8s-triage-robot avatar Dec 15 '22 15:12 k8s-triage-robot

When a ServiceMonitor has a missing namespaceSelector then it is treated as the current namespace.

i.e. simply leave off namespaceSelector and the metadata.namespace field will be the namespace selector. Which kustomize's namespace transformer will already set.

james-callahan avatar Jan 13 '23 01:01 james-callahan

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.

This bot triages issues according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Reopen this issue with /reopen
  • Mark this issue as fresh with /remove-lifecycle rotten
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/close not-planned

k8s-triage-robot avatar Feb 12 '23 01:02 k8s-triage-robot

@k8s-triage-robot: Closing this issue, marking it as "Not Planned".

In response to this:

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.

This bot triages issues according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Reopen this issue with /reopen
  • Mark this issue as fresh with /remove-lifecycle rotten
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/close not-planned

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.

k8s-ci-robot avatar Feb 12 '23 01:02 k8s-ci-robot