Skip to content

Commit

Permalink
NETOBSERV-971 remove omitempty on portNames.enable
Browse files Browse the repository at this point in the history
This was making it impossible to set it to false, as default is true and
omitempty would remove it after marshaling
  • Loading branch information
jotak committed Apr 3, 2023
1 parent bb80b4f commit eaff5f8
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
3 changes: 2 additions & 1 deletion api/v1beta1/flowcollector_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,8 @@ type FlowCollectorConsolePlugin struct {
type ConsolePluginPortConfig struct {
//+kubebuilder:default:=true
// enable the console plugin port-to-service name translation
Enable bool `json:"enable,omitempty"`
// +optional
Enable bool `json:"enable"`

// portNames defines additional port names to use in the console.
// Example: portNames: {"3100": "loki"}
Expand Down
27 changes: 27 additions & 0 deletions controllers/consoleplugin/consoleplugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,33 @@ func TestLabels(t *testing.T) {
assert.Empty(svc.Spec.Selector["version"])
}

func TestFrontendConfigSerDe(t *testing.T) {
assert := assert.New(t)

cfg := flowslatest.FlowCollectorConsolePlugin{
PortNaming: flowslatest.ConsolePluginPortConfig{
Enable: false,
PortNames: map[string]string{
"3100": "loki",
"8080": "my-service",
},
},
}
jmar, err := json.Marshal(cfg)
assert.NoError(err)
assert.Contains(string(jmar), `"enable":false`)
var jfl flowslatest.FlowCollectorConsolePlugin
err = json.Unmarshal(jmar, &jfl)
assert.NoError(err)
assert.False(jfl.PortNaming.Enable)

loki := flowslatest.FlowCollectorLoki{URL: "http://foo:1234"}
spec := flowslatest.FlowCollectorSpec{ConsolePlugin: cfg, Loki: loki}
builder := newBuilder(testNamespace, testImage, &spec, &certWatcher)

Check failure on line 317 in controllers/consoleplugin/consoleplugin_test.go

View workflow job for this annotation

GitHub Actions / Build, lint, test (1.19)

undeclared name: `certWatcher` (typecheck)
cm, _ := builder.configMap()
assert.Contains(cm.Data["config.yaml"], `enable: false`)
}

func TestAutoScalerUpdateCheck(t *testing.T) {
assert := assert.New(t)

Expand Down

0 comments on commit eaff5f8

Please sign in to comment.