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

Add variable grafana_ingress_host to expose Grafana #468

Merged
merged 4 commits into from
May 29, 2020

Conversation

surajssd
Copy link
Member

Fixes: #456

Copy link
Member

@invidian invidian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think commits can be squashed for it into one.

pkg/components/prometheus-operator/template.go Outdated Show resolved Hide resolved
@surajssd surajssd force-pushed the surajssd/add-support-for-grafana-ingress branch from 1db5fd8 to 0af84cd Compare May 21, 2020 16:26
@surajssd surajssd requested a review from invidian May 21, 2020 16:26
invidian
invidian previously approved these changes May 21, 2020
@surajssd surajssd force-pushed the surajssd/add-support-for-grafana-ingress branch 2 times, most recently from 08362fe to 69b5df9 Compare May 22, 2020 01:52
@surajssd surajssd requested a review from johananl May 26, 2020 05:12
@surajssd surajssd force-pushed the surajssd/add-support-for-grafana-ingress branch from 69b5df9 to c5dc6e6 Compare May 26, 2020 13:10
@johananl
Copy link
Member

TestAWSIngress: aws_test.go:49: got an HTTP error: Get "https://httpbin.ci1590498787-sj.test.lokomotive-k8s.net/get": dial tcp 3.121.121.100:443: connect: connection refused
    TestAWSIngress: aws_test.go:67: could not get a successful HTTP response in time

@surajssd surajssd force-pushed the surajssd/add-support-for-grafana-ingress branch 3 times, most recently from 4acff23 to 89d1350 Compare May 27, 2020 00:06
Copy link
Member

@invidian invidian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, though again, I'd squash into one commit, as both commits are related to 1 specific feature. If we revert the feature, docs should be reverted as well. Same with bisecting, if we stop at one commit, the other should be in place as well.

@surajssd surajssd force-pushed the surajssd/add-support-for-grafana-ingress branch from 89d1350 to 6d0a61e Compare May 27, 2020 11:25
@surajssd surajssd requested a review from invidian May 27, 2020 12:26
invidian
invidian previously approved these changes May 27, 2020
@surajssd
Copy link
Member Author

So it was decided in a meeting that we create block for grafana like this:

component "prometheus-operator" {
...
  grafana {
    admin_password = ""

    ingress {
      host = ""

      # In future
      ingress_class = ""
      certmanager_cluster_issuer = ""
    }
  }
}

@surajssd surajssd force-pushed the surajssd/add-support-for-grafana-ingress branch from 35acb77 to 45a5ec3 Compare May 29, 2020 10:22
@surajssd surajssd requested a review from invidian May 29, 2020 10:25
@invidian
Copy link
Member

Grafana admin password should not be a compulsory option. If not provided the chart automatically creates one for you, just like Rook Ceph.

Hm, okay. I think we should have a bit more documentation how to obtain this password then, so it is not so cryptic to the users.

@surajssd
Copy link
Member Author

Hm, okay. I think we should have a bit more documentation how to obtain this password then, so it is not so cryptic to the users.

That I plan to handle as a part of #480

@iaguis
Copy link
Contributor

iaguis commented May 29, 2020

I wonder if it makes sense to allow exposing grafana and allow having an insecure default password so easily. So if a user does

  grafana {
    ingress {
      host                       = "grafana.mydomain.net"
      class                      = "contour"
      certmanager_cluster_issuer = "letsencrypt-production"
    }
  }

and this exposes grafana with admin:admin password, this is surprising and insecure. Should we do something about it?

@surajssd
Copy link
Member Author

I wonder if it makes sense to allow exposing grafana and allow having an insecure default password so easily.

@iaguis there is a default password but it is not admin. The password if not specified is generated by helm automatically and stored in a secret, as mentioned in the docs.

@iaguis
Copy link
Contributor

iaguis commented May 29, 2020

@iaguis there is a default password but it is not admin. The password if not specified is generated by helm automatically and stored in a secret, as mentioned in the docs.

Ah, all good then 👍

pkg/components/util/types.go Outdated Show resolved Hide resolved
@@ -115,16 +122,26 @@ func newComponent() *component {
"tier": "control-plane",
},
},
Grafana: &Grafana{},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need it here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we do need it. Otherwise you will see some nil pointer exceptions.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think those can be avoided by checking them then? It doesn't make much sense to me to put it here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests are also passing if I remove it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I'm able to trigger it when I modified the tests, hmm.

Copy link
Member

@invidian invidian May 29, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can make Grafana field not a pointer?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's wrong with it? What do you think would be potential implications if we don't make it a pointer?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure about the possible implications, but if it's a pointer, it means we should handle the cases when it's nil. Also, if defined here, if provides no "default" values, as we usually use newComponent for, so I'd remove it.

Please have a look at the patch I posted. It adds the handling and test for it.

@surajssd surajssd force-pushed the surajssd/add-support-for-grafana-ingress branch from 45a5ec3 to 9d7efe6 Compare May 29, 2020 11:32
@invidian
Copy link
Member

How about something like this?

diff --git a/pkg/components/prometheus-operator/component.go b/pkg/components/prometheus-operator/component.go
index b3791da3..137b997f 100644
--- a/pkg/components/prometheus-operator/component.go
+++ b/pkg/components/prometheus-operator/component.go
@@ -123,7 +123,6 @@ func newComponent() *component {
                                "tier":    "control-plane",
                        },
                },
-               Grafana: &Grafana{},
        }
 }

diff --git a/pkg/components/prometheus-operator/component_test.go b/pkg/components/prometheus-operator/component_test.go
index 8e2608fb..b0b6cd39 100644
--- a/pkg/components/prometheus-operator/component_test.go
+++ b/pkg/components/prometheus-operator/component_test.go
@@ -26,18 +26,25 @@ func TestEmptyConfig(t *testing.T) {
        c := newComponent()
        emptyConfig := hcl.EmptyBody()
        evalContext := hcl.EvalContext{}
-       diagnostics := c.LoadConfig(&emptyConfig, &evalContext)

-       if diagnostics.HasErrors() {
+       if d := c.LoadConfig(&emptyConfig, &evalContext); d.HasErrors() {
                t.Fatalf("Empty config should not return errors")
        }
+
+       m, err := c.RenderManifests()
+       if err != nil {
+               t.Fatalf("Rendering manifests with valid config should succeed, got: %s", err)
+       }
+       if len(m) <= 0 {
+               t.Fatalf("Rendered manifests shouldn't be empty")
+       }
 }

 func TestRenderManifest(t *testing.T) {
        configHCL := `
 component "prometheus-operator" {
   grafana {
-       admin_password = "foobar"
+    admin_password = "foobar"
   }
   namespace = "monitoring"
 }
diff --git a/pkg/components/prometheus-operator/template.go b/pkg/components/prometheus-operator/template.go
index 3a96fe0f..7089874c 100644
--- a/pkg/components/prometheus-operator/template.go
+++ b/pkg/components/prometheus-operator/template.go
@@ -48,7 +48,6 @@ alertmanager:
               storage: "{{.AlertManagerStorageSize}}"

 grafana:
-  adminPassword: {{.Grafana.AdminPassword}}
   plugins: "grafana-piechart-panel"
   testFramework:
     enabled: false
@@ -57,6 +56,8 @@ grafana:
       searchNamespace: ALL
   rbac:
     pspUseAppArmor: false
+  {{- if .Grafana}}
+  adminPassword: {{.Grafana.AdminPassword}}
   {{ if .Grafana.Ingress }}
   ingress:
     enabled: true
@@ -71,6 +72,7 @@ grafana:
       - {{ .Grafana.Ingress.Host }}
       secretName: {{ .Grafana.Ingress.Host }}-tls
   {{ end }}
+  {{- end}}

 kubeEtcd:
   enabled: {{.Monitor.Etcd}}

iaguis
iaguis previously approved these changes May 29, 2020
Copy link
Contributor

@iaguis iaguis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very small nit but LGTM

pkg/components/prometheus-operator/component_test.go Outdated Show resolved Hide resolved
@surajssd surajssd force-pushed the surajssd/add-support-for-grafana-ingress branch from 9d7efe6 to 503beb8 Compare May 29, 2020 12:27
@surajssd surajssd requested a review from invidian May 29, 2020 12:29
@surajssd
Copy link
Member Author

@invidian PTAL, added table driven tests. Also taken care of the test that fails.

t.Errorf("%s - Wrong config should have returned an error", tc.desc)
}

m, err := c.RenderManifests()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I want error, meaning loading the HCL failed, this should not be executed, or?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By want error it means that the test is expecting an error.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, sorry. I mean, if we fail to load the HCL, the component will be in the possibly undefined state, so we should not try to render it then.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes changed that now it is using t.Run so now I can return using t.Fatal.

@surajssd surajssd force-pushed the surajssd/add-support-for-grafana-ingress branch from 503beb8 to 152bc61 Compare May 29, 2020 13:35
invidian
invidian previously approved these changes May 29, 2020
Copy link
Member

@invidian invidian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just one nit, but otherwise LGTM

pkg/components/prometheus-operator/component.go Outdated Show resolved Hide resolved
* Changes the UX for grafana component. Now all the grafana related
information goes into a block.

* Adds a new variable `grafana.ingress.host` where user can provide the
ingress Host URL to expose Grafana on.

* Adds a new variable `grafana.ingress.class` so that user can provide
the ingress class to be used for Grafana's ingress object.

* Adds a new variable `grafana.ingress.certmanager_cluster_issuer` so
that user can choose the cluster issuer for certmanager so that it can
generate TLS cert for Grafana's Ingress.

* Adds documentation of the above variables.

Signed-off-by: Suraj Deshmukh <suraj@kinvolk.io>
- Modify the tests to run in a table.

- Remove the test which checks for empty config. It is not a failure
condition and is incorporated in above table.

- Add test that verifies if the user provides ingress host or not. It is
a compulsory field if not provided the test should fail.

Signed-off-by: Suraj Deshmukh <suraj@kinvolk.io>
Signed-off-by: Suraj Deshmukh <suraj@kinvolk.io>
Signed-off-by: Suraj Deshmukh <suraj@kinvolk.io>
Copy link
Member

@invidian invidian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. One last thing which can be done independently of this patch, I guess we should test if exposing ingress works as expected via e2e test?

@surajssd
Copy link
Member Author

LGTM. One last thing which can be done independently of this patch, I guess we should test if exposing ingress works as expected via e2e test?

Testing on packet can be tricky because:

  • Someone has to expose the EIP on Route53.
  • How do we use unique EIP per CI run? And make corresponding entries?

@surajssd surajssd merged commit 5640eed into master May 29, 2020
@surajssd surajssd deleted the surajssd/add-support-for-grafana-ingress branch May 29, 2020 14:06
@invidian
Copy link
Member

The testing can be done on any platform. But should be done at at least one.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow user to expose Grafana over ingress
4 participants