diff --git a/api/v1beta1/grafana_types.go b/api/v1beta1/grafana_types.go index 4927eed72..9d0155774 100644 --- a/api/v1beta1/grafana_types.go +++ b/api/v1beta1/grafana_types.go @@ -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 diff --git a/api/v1beta1/zz_generated.deepcopy.go b/api/v1beta1/zz_generated.deepcopy.go index d461cc650..e1f2ff625 100644 --- a/api/v1beta1/zz_generated.deepcopy.go +++ b/api/v1beta1/zz_generated.deepcopy.go @@ -555,11 +555,13 @@ func (in *GrafanaClient) DeepCopyInto(out *GrafanaClient) { } if in.Headers != nil { in, out := &in.Headers, &out.Headers - *out = new([]Header) + *out = new(map[string]string) if **in != nil { in, out := *in, *out - *out = make([]Header, len(*in)) - copy(*out, *in) + *out = make(map[string]string, len(*in)) + for key, val := range *in { + (*out)[key] = val + } } } } @@ -1533,21 +1535,6 @@ func (in *GrafanaStatus) DeepCopy() *GrafanaStatus { return out } -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *Header) DeepCopyInto(out *Header) { - *out = *in -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Header. -func (in *Header) DeepCopy() *Header { - if in == nil { - return nil - } - out := new(Header) - in.DeepCopyInto(out) - return out -} - // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *IngressNetworkingV1) DeepCopyInto(out *IngressNetworkingV1) { *out = *in diff --git a/config/crd/bases/grafana.integreatly.org_grafanas.yaml b/config/crd/bases/grafana.integreatly.org_grafanas.yaml index bdcfa2e7d..874c87c98 100644 --- a/config/crd/bases/grafana.integreatly.org_grafanas.yaml +++ b/config/crd/bases/grafana.integreatly.org_grafanas.yaml @@ -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 diff --git a/controllers/client/grafana_client.go b/controllers/client/grafana_client.go index 563e9a7b6..0ef47e556 100644 --- a/controllers/client/grafana_client.go +++ b/controllers/client/grafana_client.go @@ -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{ @@ -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 -} diff --git a/controllers/client/http_client.go b/controllers/client/http_client.go index 20f61b929..c5a8b7aa7 100644 --- a/controllers/client/http_client.go +++ b/controllers/client/http_client.go @@ -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{ diff --git a/deploy/helm/grafana-operator/crds/grafana.integreatly.org_grafanas.yaml b/deploy/helm/grafana-operator/crds/grafana.integreatly.org_grafanas.yaml index bdcfa2e7d..874c87c98 100644 --- a/deploy/helm/grafana-operator/crds/grafana.integreatly.org_grafanas.yaml +++ b/deploy/helm/grafana-operator/crds/grafana.integreatly.org_grafanas.yaml @@ -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 diff --git a/deploy/kustomize/base/crds.yaml b/deploy/kustomize/base/crds.yaml index 1bfe9e018..083886bdb 100644 --- a/deploy/kustomize/base/crds.yaml +++ b/deploy/kustomize/base/crds.yaml @@ -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 diff --git a/docs/docs/api.md b/docs/docs/api.md index 3fc815d09..03bc3ca44 100644 --- a/docs/docs/api.md +++ b/docs/docs/api.md @@ -3785,10 +3785,10 @@ Client defines how the grafana-operator talks to the grafana instance.
Name | -Type | -Description | -Required | -
---|---|---|---|
key | -string | -
- Header name - |
- false | -
value | -string | -
- Header value - |
- false | -