VictoriaMetrics / operator

Kubernetes operator for Victoria Metrics
Apache License 2.0
424 stars 142 forks source link

VMUser: when using the operator's CRD object as `targetRefs`, an url_prefix must be generated considering `useAsDefault` #960

Closed Looka149 closed 4 months ago

Looka149 commented 4 months ago

Hi. There seems to be some unintended behavior related to vmuser.

When useAsDefault is disabled: When creating Victoriametrics Operator CRD, a port named http is always created by the Operator. In vmagent or some CRDs, the default port can be modified through .spec.port, And this value is used for the port and targetPort of the service. When a Victoriametrics Operator CRD is specified through vmuser's .spec.targetRefs.crd, the operator generates a url_prefix config using the above port.

When useAsDefault is enabled: If useAsDefault of Victoriametrics Operator CRD is enabled, the service's port and targetPort may be different. However, vmuser still generates the url_prefix by referring to .spec.port or the default port value. This causes inaccessibility issues.

example)

VMAlert manifest with useAsDefault

apiVersion: operator.victoriametrics.com/v1beta1
kind: VMAlert
...
spec:
  serviceSpec:
    metadata:
      name: vmalert-main
    spec:
      ports:
      - name: http
        port: 80
        protocol: TCP
        targetPort: 8080
      type: LoadBalancer
    useAsDefault: true
...

VMUser manifest with VMAlert target

apiVersion: operator.victoriametrics.com/v1beta1
kind: VMUser
metadata:
  name: test-vmalert
...
spec:
  targetRefs:
  - crd:
      kind: VMAlert
      name: main
      namespace: monitoring
...

VMAuth config generated by operator

users:
- url_prefix:
  - http://vmalert-main.monitoring.svc:8080  # should be 80
  username: test-vmalert