-
Notifications
You must be signed in to change notification settings - Fork 718
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1030 from nkvoll/support-kibana-config
Add a custom config parameter to the Kibana spec.
- Loading branch information
Showing
21 changed files
with
321 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
// or more contributor license agreements. Licensed under the Elastic License; | ||
// you may not use this file except in compliance with the Elastic License. | ||
|
||
package v1alpha1 | ||
|
||
import ( | ||
"encoding/json" | ||
|
||
ucfg "github.com/elastic/go-ucfg" | ||
) | ||
|
||
// CfgOptions are config options for YAML config. Currently contains only support for dotted keys. | ||
var CfgOptions = []ucfg.Option{ucfg.PathSep(".")} | ||
|
||
// Config represents untyped YAML configuration inside a spec. | ||
type Config struct { | ||
// This field exists to work around https://github.com/kubernetes-sigs/kubebuilder/issues/528 | ||
Data map[string]interface{} | ||
} | ||
|
||
// NewConfig constructs a Config with the given unstructured configuration data. | ||
func NewConfig(cfg map[string]interface{}) Config { | ||
return Config{Data: cfg} | ||
} | ||
|
||
// MarshalJSON implements the Marshaler interface. | ||
func (c *Config) MarshalJSON() ([]byte, error) { | ||
return json.Marshal(c.Data) | ||
} | ||
|
||
// UnmarshalJSON implements the Unmarshaler interface. | ||
func (c *Config) UnmarshalJSON(data []byte) error { | ||
var out map[string]interface{} | ||
err := json.Unmarshal(data, &out) | ||
if err != nil { | ||
return err | ||
} | ||
c.Data = out | ||
return nil | ||
} | ||
|
||
// DeepCopyInto is an ~autogenerated~ deepcopy function, copying the receiver, writing into out. in must be non-nil. | ||
// This exists here to work around https://github.com/kubernetes/code-generator/issues/50 | ||
func (c *Config) DeepCopyInto(out *Config) { | ||
bytes, err := json.Marshal(c.Data) | ||
if err != nil { | ||
// we assume that it marshals cleanly because otherwise the resource would not have been | ||
// created in the API server | ||
panic(err) | ||
} | ||
var copy map[string]interface{} | ||
err = json.Unmarshal(bytes, ©) | ||
if err != nil { | ||
// we assume again optimistically because we just marshalled that the round trip works as well | ||
panic(err) | ||
} | ||
out.Data = copy | ||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
// or more contributor license agreements. Licensed under the Elastic License; | ||
// you may not use this file except in compliance with the Elastic License. | ||
|
||
package v1alpha1 | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/go-test/deep" | ||
) | ||
|
||
var testFixture = Config{ | ||
Data: map[string]interface{}{ | ||
"a": map[string]interface{}{ | ||
"b": map[string]interface{}{ | ||
"c": 1.0, | ||
}, | ||
"d": 1, | ||
}, | ||
"a.b.foo": "bar", | ||
"e": []interface{}{1, 2, 3}, | ||
"f": true, | ||
}, | ||
} | ||
|
||
var expectedJSONized = Config{ | ||
Data: map[string]interface{}{ | ||
"a": map[string]interface{}{ | ||
"b": map[string]interface{}{ | ||
"c": 1.0, | ||
}, | ||
"d": float64(1), | ||
}, | ||
"a.b.foo": "bar", | ||
"e": []interface{}{float64(1), float64(2), float64(3)}, | ||
"f": true, | ||
}, | ||
} | ||
|
||
func TestConfig_DeepCopyInto(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
in Config | ||
expected Config | ||
}{ | ||
{ | ||
name: "deep copy via JSON roundtrip changes some types", | ||
in: testFixture, | ||
expected: expectedJSONized, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
var out Config | ||
tt.in.DeepCopyInto(&out) | ||
if diff := deep.Equal(out, tt.expected); diff != nil { | ||
t.Error(diff) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestConfig_DeepCopy(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
in Config | ||
want Config | ||
}{ | ||
{ | ||
name: "deep copy via JSON roundtrip changes some types", | ||
in: testFixture, | ||
want: expectedJSONized, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if diff := deep.Equal(tt.in.DeepCopy(), &tt.want); diff != nil { | ||
t.Error(diff) | ||
} | ||
}) | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
operators/pkg/apis/common/v1alpha1/zz_generated.deepcopy.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.