Skip to content

Commit

Permalink
singleEndpointConfig: use omitempty
Browse files Browse the repository at this point in the history
Signed-off-by: Benedikt Bongartz <[email protected]>
  • Loading branch information
frzifus committed Oct 6, 2024
1 parent 2526626 commit 6df1e40
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 26 deletions.
23 changes: 0 additions & 23 deletions apis/v1beta1/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"fmt"
"net"
"reflect"
"slices"
"sort"
"strconv"
"strings"
Expand Down Expand Up @@ -262,7 +261,6 @@ func (c *Config) applyDefaultForComponentKinds(logger logr.Logger, componentKind
// field. It is marshaled due to internal use. To avoid adding invalid fields to the
// collector config, this temporary workaround removes this field.
// TODO: Try to get rid of it or move it into the parser.GetDefaultConfig method.
removeKeysRecursively(out, "listenaddress")
cfg.Object[componentName] = out
}
}
Expand All @@ -271,27 +269,6 @@ func (c *Config) applyDefaultForComponentKinds(logger logr.Logger, componentKind
return nil
}

func removeKeysRecursively(m map[string]interface{}, keysToRemove ...string) {
for k, v := range m {
if slices.Contains(keysToRemove, k) {
delete(m, k)
continue
}

if nm, ok := v.(map[string]interface{}); ok {
removeKeysRecursively(nm, keysToRemove...)
}

if ns, ok := v.([]interface{}); ok {
for _, item := range ns {
if nestedMap, ok := item.(map[string]interface{}); ok {
removeKeysRecursively(nestedMap, keysToRemove...)
}
}
}
}
}

func (c *Config) GetReceiverPorts(logger logr.Logger) ([]corev1.ServicePort, error) {
return c.getPortsForComponentKinds(logger, KindReceiver)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/components/generic_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (g *GenericParser[T]) GetDefaultConfig(logger logr.Logger, config interface
if err := mapstructure.Decode(config, &parsed); err != nil {
return nil, err
}
return g.defaultsApplier(logger, g.settings.defaultRecAddr, g.settings.port, parsed)
return g.defaultsApplier(logger, g.settings.defaultRecAddr, g.settings.GetServicePort().Port, parsed)
}

func (g *GenericParser[T]) GetLivenessProbe(logger logr.Logger, config interface{}) (*corev1.Probe, error) {
Expand Down
4 changes: 2 additions & 2 deletions internal/components/single_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ var (
// SingleEndpointConfig represents the minimal struct for a given YAML configuration input containing either
// endpoint or listen_address.
type SingleEndpointConfig struct {
Endpoint string `mapstructure:"endpoint,omitempty"`
ListenAddress string `mapstructure:"listen_address,omitempty"`
Endpoint string `mapstructure:"endpoint,omitempty" yaml:"endpoint,omitempty"`
ListenAddress string `mapstructure:"listen_address,omitempty" yaml:"listen_address,omitempty"`
}

func (g *SingleEndpointConfig) GetPortNumOrDefault(logger logr.Logger, p int32) int32 {
Expand Down

0 comments on commit 6df1e40

Please sign in to comment.