grafana-operator: [Bug] GrafanaDashboard import does not work when oauth is enabled

Describe the bug When we create a grafana dashboard custom resource, it is not able to import dashboard and I get an error in events stating “error getting folders, expected status 200 but got 401”. I believe it is not able to hit /api/folders after enabling oauth.

here’s the full log of controller manager

2022-04-21T14:34:18.339Z        ERROR   failed to get or create namespace folder for dashboard  {"folder": "default", "dashboard": "", "error": "error getting folders, expected status 200 but got 401"}
github.com/go-logr/zapr.(*zapLogger).Error
        /go/pkg/mod/github.com/go-logr/zapr@v0.2.0/zapr.go:132
sigs.k8s.io/controller-runtime/pkg/log.(*DelegatingLogger).Error
        /go/pkg/mod/sigs.k8s.io/controller-runtime@v0.8.3/pkg/log/deleg.go:144
github.com/grafana-operator/grafana-operator/v4/controllers/grafanadashboard.(*GrafanaDashboardReconciler).reconcileDashboards
        /workspace/controllers/grafanadashboard/grafanadashboard_controller.go:283
github.com/grafana-operator/grafana-operator/v4/controllers/grafanadashboard.(*GrafanaDashboardReconciler).Reconcile
        /workspace/controllers/grafanadashboard/grafanadashboard_controller.go:101
github.com/grafana-operator/grafana-operator/v4/controllers/grafanadashboard.SetupWithManager.func1
        /workspace/controllers/grafanadashboard/grafanadashboard_controller.go:184
github.com/grafana-operator/grafana-operator/v4/controllers/grafanadashboard.SetupWithManager.func2
        /workspace/controllers/grafanadashboard/grafanadashboard_controller.go:193
2022-04-21T14:34:18.339Z        ERROR   error updating dashboard        {"error": "error getting folders, expected status 200 but got 401"}
github.com/go-logr/zapr.(*zapLogger).Error
        /go/pkg/mod/github.com/go-logr/zapr@v0.2.0/zapr.go:132
sigs.k8s.io/controller-runtime/pkg/log.(*DelegatingLogger).Error
        /go/pkg/mod/sigs.k8s.io/controller-runtime@v0.8.3/pkg/log/deleg.go:144
github.com/grafana-operator/grafana-operator/v4/controllers/grafanadashboard.(*GrafanaDashboardReconciler).manageError
        /workspace/controllers/grafanadashboard/grafanadashboard_controller.go:468
github.com/grafana-operator/grafana-operator/v4/controllers/grafanadashboard.(*GrafanaDashboardReconciler).reconcileDashboards
        /workspace/controllers/grafanadashboard/grafanadashboard_controller.go:284
github.com/grafana-operator/grafana-operator/v4/controllers/grafanadashboard.(*GrafanaDashboardReconciler).Reconcile
        /workspace/controllers/grafanadashboard/grafanadashboard_controller.go:101
github.com/grafana-operator/grafana-operator/v4/controllers/grafanadashboard.SetupWithManager.func1
        /workspace/controllers/grafanadashboard/grafanadashboard_controller.go:184
github.com/grafana-operator/grafana-operator/v4/controllers/grafanadashboard.SetupWithManager.func2
        /workspace/controllers/grafanadashboard/grafanadashboard_controller.go:193

Version Full semver version of the operator being used v4.0.1

Expected behavior Dashboard should be imported in grafana

Suspect component/Location where the bug might be occuring Please provide this if you know where this bug might occur otherwise leave as unknown

Screenshots image

Runtime (please complete the following information):

  • Grafana Operator Version - 4
  • Environment: Kubernetes
  • Deployment type: AWS, local

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 1
  • Comments: 17

Most upvoted comments

@manvindar I’ve had an oidc-enabled grafana for over a year, and it all worked just fine. I think the issue here is due to two parameters that you set in the server section:

spec:
  config:
    server:
      domain: "grafana.DOMAIN_NOT_DEFINED" # <---- remove it
      root_url: "https://grafana.DOMAIN_NOT_DEFINED"
      enforce_domain: true # <---- remove it

If you remove those two, grafana should not redirect operator’s requests to the main domain anymore, and everything should work just fine. Better to combine it with @NissesSenap recommendation:

spec:
  client:
    preferService: true

hi @NissesSenap I get the below error, it is trying to redirect to public endpoint

image