kubevirt: Specify monitorNamespace not work

Is this a BUG REPORT or FEATURE REQUEST?:

Uncomment only one, leave it on its own line:

/kind bug

/kind enhancement

What happened:

  1. install kubevirt v0.26.0
  2. install prometheus operator
  3. update kubevirt object using following yaml
apiVersion: kubevirt.io/v1alpha3
kind: KubeVirt
metadata:
  name: kubevirt
spec:
  monitorNamespace: monitoring
  monitorAccount: prometheus-k8s

servicemonitor not created What you expected to happen: servicemonitor created under monitoring namespace How to reproduce it (as minimally and precisely as possible):

Anything else we need to know?: if i create namespace openshift-monitoring, servicemonitor will be created under namespace openshift-monitoring,but what i want is servicemonitor created under namespace monitoring Environment:

  • KubeVirt version (use virtctl version): v0.26.0
  • Kubernetes version (use kubectl version):
  • VM or VMI specifications:
  • Cloud provider or hardware configuration:
  • OS (e.g. from /etc/os-release):
  • Kernel (e.g. uname -a):
  • Install tools:
  • Others:

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 1
  • Comments: 20 (15 by maintainers)

Most upvoted comments

Hi @wavezhang and @petrkotas,

I recently also encounter this issue with minikube. This issue results from a minor bug.

KubeVirt’s virt-operator checks the existence of the MonitorNamespace and MonitorServiceAccount. KubeVirt will automatically create a ServiceMonitor resource in the MonitorNamespace, as well as an appropriate role and rolebinding in KubeVirt’s namespace.

https://github.com/kubevirt/kubevirt/blob/fc076e0166a9556d730e452b6026eb68815257aa/pkg/virt-operator/install-strategy/strategy.go#L130-L131

When deploying on a platform other than openshift, MonitorNamespace and MonirotServiceAccount have to be specified as AdditionalProperties of KubeVirt CR. The AdditionalProperties then are passed as a JSON string when virt-operator creating the Install Strategy.

https://github.com/kubevirt/kubevirt/blob/fc076e0166a9556d730e452b6026eb68815257aa/pkg/virt-operator/kubevirt.go#L726

More specifically, the MonitorNamespace and MonirotServiceAccount are extracted from a JSON map: https://github.com/kubevirt/kubevirt/blob/fc076e0166a9556d730e452b6026eb68815257aa/pkg/virt-operator/util/config.go#L397-L411

And the JSON keys of MonitorNamespace and MonitorServiceAccount are: https://github.com/kubevirt/kubevirt/blob/fc076e0166a9556d730e452b6026eb68815257aa/pkg/virt-operator/util/config.go#L57-L61

When extracting values from a JSON map, the key name is expected to start with capitalized characters, as mentioned in @mlsorensen 's example.

I’ll submit a quick fix.