Skip to content

Commit

Permalink
Making the linter happy
Browse files Browse the repository at this point in the history
  • Loading branch information
meln5674 committed Jul 26, 2022
1 parent fa886e7 commit 3b8e4e6
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 20 deletions.
37 changes: 21 additions & 16 deletions controllers/grafanadatasource/datasource_pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,20 @@ func (i *DatasourcePipelineImpl) ProcessDatasource(known *v1.ConfigMap) error {
return nil
}

func applyCustomJsonData(datasource *v1alpha1.GrafanaDataSourceFields, unmarshaledDatasource map[string]interface{}) (needsRemarshaling bool) {
if datasource.CustomJsonData != nil {
needsRemarshaling = true
unmarshaledDatasource["jsonData"] = unmarshaledDatasource["customJsonData"]
delete(unmarshaledDatasource, "customJsonData")
}
if datasource.CustomSecureJsonData != nil {
needsRemarshaling = true
unmarshaledDatasource["secureJsonData"] = unmarshaledDatasource["customSecureJsonData"]
delete(unmarshaledDatasource, "customSecureJsonData")
}
return
}

func (i *DatasourcePipelineImpl) parse() error {
datasources := struct {
ApiVersion int `json:"apiVersion"`
Expand All @@ -52,29 +66,20 @@ func (i *DatasourcePipelineImpl) parse() error {
return err
}
unmarshaledDatasourceList, ok := unmarshaledDatasources["datasources"].([]interface{})
needsRemarshaling := false
if ok {
needsRemarshaling := false
for ix, datasource := range i.datasource.Spec.Datasources {
unmarshaledDatasource, ok := unmarshaledDatasourceList[ix].(map[string]interface{})
if !ok {
continue
}
if datasource.CustomJsonData != nil {
needsRemarshaling = true
unmarshaledDatasource["jsonData"] = unmarshaledDatasource["customJsonData"]
delete(unmarshaledDatasource, "customJsonData")
}
if datasource.CustomSecureJsonData != nil {
needsRemarshaling = true
unmarshaledDatasource["secureJsonData"] = unmarshaledDatasource["customSecureJsonData"]
delete(unmarshaledDatasource, "customSecureJsonData")
}
needsRemarshaling = needsRemarshaling || applyCustomJsonData(&datasource, unmarshaledDatasource)
}
if needsRemarshaling {
bytes, err = yaml.Marshal(unmarshaledDatasources)
if err != nil {
return err
}
}
if needsRemarshaling {
bytes, err = yaml.Marshal(unmarshaledDatasources)
if err != nil {
return err
}
}
i.contents = string(bytes)
Expand Down
4 changes: 2 additions & 2 deletions deploy/manifests/latest/crds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -212,13 +212,13 @@ spec:
customJsonData:
description: CustomJsonData will be used in place of jsonData,
if present, and supports arbitrary JSON, not just those of
offical datasources
official datasources
type: object
x-kubernetes-preserve-unknown-fields: true
customSecureJsonData:
description: SecureCustomJsonData will be used in place of secureJsonData,
if present, and supports arbitrary JSON, not just those of
offical datasources
official datasources
type: object
x-kubernetes-preserve-unknown-fields: true
database:
Expand Down
4 changes: 2 additions & 2 deletions documentation/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -598,14 +598,14 @@ GrafanaDataSourceSpec defines the desired state of GrafanaDataSource
<td><b>customJsonData</b></td>
<td>object</td>
<td>
CustomJsonData will be used in place of jsonData, if present, and supports arbitrary JSON, not just those of offical datasources<br/>
CustomJsonData will be used in place of jsonData, if present, and supports arbitrary JSON, not just those of official datasources<br/>
</td>
<td>false</td>
</tr><tr>
<td><b>customSecureJsonData</b></td>
<td>object</td>
<td>
SecureCustomJsonData will be used in place of secureJsonData, if present, and supports arbitrary JSON, not just those of offical datasources<br/>
SecureCustomJsonData will be used in place of secureJsonData, if present, and supports arbitrary JSON, not just those of official datasources<br/>
</td>
<td>false</td>
</tr><tr>
Expand Down

0 comments on commit 3b8e4e6

Please sign in to comment.