Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use non-fqdn url for grafana to support non-standard cluster names #791

Merged
merged 3 commits into from Jul 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 7 additions & 5 deletions controllers/grafana/grafana_controller.go
Expand Up @@ -30,8 +30,10 @@ import (
"sigs.k8s.io/controller-runtime/pkg/source"
)

const ControllerName = "grafana-controller"
const DefaultClientTimeoutSeconds = 5
const (
ControllerName = "grafana-controller"
DefaultClientTimeoutSeconds = 5
)

var log = logf.Log.WithName(ControllerName)

Expand Down Expand Up @@ -266,7 +268,7 @@ func (r *ReconcileGrafana) getGrafanaAdminUrl(cr *grafanav1alpha1.Grafana, state
}
}

var servicePort = int32(model.GetGrafanaPort(cr))
servicePort := int32(model.GetGrafanaPort(cr))

// Otherwise rely on the service
if state.GrafanaService != nil {
Expand All @@ -279,11 +281,11 @@ func (r *ReconcileGrafana) getGrafanaAdminUrl(cr *grafanav1alpha1.Grafana, state
case "https":
protocol = "https"
default:
return "", stdErr.New(fmt.Sprintf("server protocol %v is not supported, please use either http or https", protocol))
return "", fmt.Errorf("server protocol %v is not supported, please use either http or https", protocol)
}
}

return fmt.Sprintf("%v://%v.%v.svc.cluster.local:%d", protocol, state.GrafanaService.Name, cr.Namespace,
return fmt.Sprintf("%v://%v.%v:%d", protocol, state.GrafanaService.Name, cr.Namespace,
servicePort), nil
}

Expand Down
8 changes: 4 additions & 4 deletions controllers/grafana/grafana_controller_test.go
Expand Up @@ -136,25 +136,25 @@ func TestReconcileGrafana_getGrafanaAdminUrl(t *testing.T) {
{
name: "server spec is nil",
server: nil,
want: "http://grafana.monitoring.svc.cluster.local:3000",
want: "http://grafana.monitoring:3000",
wantFail: false,
},
{
name: "server protocol: not specified",
server: &Srv{Protocol: ""},
want: "http://grafana.monitoring.svc.cluster.local:3000",
want: "http://grafana.monitoring:3000",
wantFail: false,
},
{
name: "server protocol: http",
server: &Srv{Protocol: "http"},
want: "http://grafana.monitoring.svc.cluster.local:3000",
want: "http://grafana.monitoring:3000",
wantFail: false,
},
{
name: "server protocol: https",
server: &Srv{Protocol: "https"},
want: "https://grafana.monitoring.svc.cluster.local:3000",
want: "https://grafana.monitoring:3000",
wantFail: false,
},
{
Expand Down