Skip to content

Commit

Permalink
fix: use non-fqdn url for grafana to support non-standard cluster nam…
Browse files Browse the repository at this point in the history
…es (#791)

Signed-off-by: Igor Beliakov <demtis.register@gmail.com>

Co-authored-by: Hubert Stefanski <35736504+HubertStefanski@users.noreply.github.com>
  • Loading branch information
weisdd and HubertStefanski committed Jul 20, 2022
1 parent 4e905c0 commit 4b1c75b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
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

0 comments on commit 4b1c75b

Please sign in to comment.