Skip to content

Commit

Permalink
fix(grafana.spec.client): changed headers format to a map of key valu…
Browse files Browse the repository at this point in the history
…e to simplify syntax

Signed-off-by: christophe.boucharlat <[email protected]>
  • Loading branch information
xorilog committed Nov 14, 2024
1 parent e441bf2 commit c234a9a
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 119 deletions.
12 changes: 2 additions & 10 deletions api/v1beta1/grafana_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,17 +119,9 @@ type GrafanaClient struct {
// TLS Configuration used to talk with the grafana instance.
// +optional
TLS *TLSConfig `json:"tls,omitempty"`
// Optional list of Header configuration objects that specify headers key and their value.
// Optional map of header key and value.
// +optional
Headers *[]Header `json:"headers,omitempty"`
}

// Header specifies http.Header key and value
type Header struct {
// Header name
Key string `json:"key,omitempty"`
// Header value
Value string `json:"value,omitempty"`
Headers *map[string]string `json:"headers,omitempty"`
}

// GrafanaPreferences holds Grafana preferences API settings
Expand Down
23 changes: 5 additions & 18 deletions api/v1beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 4 additions & 13 deletions config/crd/bases/grafana.integreatly.org_grafanas.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,10 @@ spec:
grafana instance.
properties:
headers:
description: Optional list of Header configuration objects that
specify headers key and their value.
items:
description: Header specifies http.Header key and value
properties:
key:
description: Header name
type: string
value:
description: Header value
type: string
type: object
type: array
additionalProperties:
type: string
description: Optional map of header key and value.
type: object
preferIngress:
description: If the operator should send it's request through
the grafana instances ingress object instead of through the
Expand Down
15 changes: 1 addition & 14 deletions controllers/client/grafana_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ func NewGeneratedGrafanaClient(ctx context.Context, c client.Client, grafana *v1

transport := NewInstrumentedRoundTripper(grafana.Name, metrics.GrafanaApiRequests, grafana.IsExternal(), tlsConfig)
if grafana.Spec.Client.Headers != nil {
transport.(*instrumentedRoundTripper).addHeaders(extractClientHeaders(grafana))
transport.(*instrumentedRoundTripper).addHeaders(*grafana.Spec.Client.Headers)
}

client := &http.Client{
Expand All @@ -169,16 +169,3 @@ func NewGeneratedGrafanaClient(ctx context.Context, c client.Client, grafana *v1

return cl, nil
}

func extractClientHeaders(grafana *v1beta1.Grafana) map[string]string {
if grafana.Spec.Client.Headers == nil {
return nil
}

headers := make(map[string]string, len(*grafana.Spec.Client.Headers))
for _, h := range *grafana.Spec.Client.Headers {
headers[h.Key] = h.Value
}

return headers
}
2 changes: 1 addition & 1 deletion controllers/client/http_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func NewHTTPClient(ctx context.Context, c client.Client, grafana *v1beta1.Grafan

transport := NewInstrumentedRoundTripper(grafana.Name, metrics.GrafanaApiRequests, grafana.IsExternal(), tlsConfig)
if grafana.Spec.Client.Headers != nil {
transport.(*instrumentedRoundTripper).addHeaders(extractClientHeaders(grafana))
transport.(*instrumentedRoundTripper).addHeaders(*grafana.Spec.Client.Headers)
}

return &http.Client{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,10 @@ spec:
grafana instance.
properties:
headers:
description: Optional list of Header configuration objects that
specify headers key and their value.
items:
description: Header specifies http.Header key and value
properties:
key:
description: Header name
type: string
value:
description: Header value
type: string
type: object
type: array
additionalProperties:
type: string
description: Optional map of header key and value.
type: object
preferIngress:
description: If the operator should send it's request through
the grafana instances ingress object instead of through the
Expand Down
17 changes: 4 additions & 13 deletions deploy/kustomize/base/crds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1883,19 +1883,10 @@ spec:
grafana instance.
properties:
headers:
description: Optional list of Header configuration objects that
specify headers key and their value.
items:
description: Header specifies http.Header key and value
properties:
key:
description: Header name
type: string
value:
description: Header value
type: string
type: object
type: array
additionalProperties:
type: string
description: Optional map of header key and value.
type: object
preferIngress:
description: If the operator should send it's request through
the grafana instances ingress object instead of through the
Expand Down
40 changes: 3 additions & 37 deletions docs/docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -3785,10 +3785,10 @@ Client defines how the grafana-operator talks to the grafana instance.
</tr>
</thead>
<tbody><tr>
<td><b><a href="#grafanaspecclientheadersindex">headers</a></b></td>
<td>[]object</td>
<td><b>headers</b></td>
<td>map[string]string</td>
<td>
Optional list of Header configuration objects that specify headers key and their value.<br/>
Optional map of header key and value.<br/>
</td>
<td>false</td>
</tr><tr>
Expand Down Expand Up @@ -3818,40 +3818,6 @@ Client defines how the grafana-operator talks to the grafana instance.
</table>


### Grafana.spec.client.headers[index]
<sup><sup>[↩ Parent](#grafanaspecclient)</sup></sup>



Header specifies http.Header key and value

<table>
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Description</th>
<th>Required</th>
</tr>
</thead>
<tbody><tr>
<td><b>key</b></td>
<td>string</td>
<td>
Header name<br/>
</td>
<td>false</td>
</tr><tr>
<td><b>value</b></td>
<td>string</td>
<td>
Header value<br/>
</td>
<td>false</td>
</tr></tbody>
</table>


### Grafana.spec.client.tls
<sup><sup>[↩ Parent](#grafanaspecclient)</sup></sup>

Expand Down

0 comments on commit c234a9a

Please sign in to comment.