Skip to content

Commit

Permalink
read defaults from CRD
Browse files Browse the repository at this point in the history
  • Loading branch information
jpinsonneau committed Dec 14, 2023
1 parent 1e4b61e commit 1a76dc3
Show file tree
Hide file tree
Showing 30 changed files with 647 additions and 186 deletions.
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ COPY main.go main.go
COPY api/ api/
COPY controllers/ controllers/
COPY pkg/ pkg/
COPY config/ config/

# Build
RUN CGO_ENABLED=0 GOOS=linux GOARCH=$TARGETARCH GO111MODULE=on go build -ldflags "-X 'main.buildVersion=$BUILD_VERSION' -X 'main.buildDate=`date +%Y-%m-%d\ %H:%M`'" -mod vendor -a -o manager main.go
Expand Down
2 changes: 1 addition & 1 deletion api/v1alpha1/flowcollector_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ type FlowCollectorEBPF struct {
// excludeInterfaces contains the interface names that will be excluded from flow tracing.
// If an entry is enclosed by slashes (such as `/br-/`), it will match as regular expression,
// otherwise it will be matched as a case-sensitive string.
//+kubebuilder:default=lo;
//+kubebuilder:default:=lo;
ExcludeInterfaces []string `json:"excludeInterfaces,omitempty"`

//+kubebuilder:validation:Enum=trace;debug;info;warn;error;fatal;panic
Expand Down
10 changes: 10 additions & 0 deletions api/v1alpha1/flowcollector_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,3 +382,13 @@ func Convert_v1beta2_DebugProcessorConfig_To_v1alpha1_DebugConfig(in *v1beta2.De
out.Env = in.Env
return nil
}

// This function need to be manually created because conversion-gen not able to create it intentionally because
// we have new defined fields in v1beta2 not in v1alpha1
// nolint:golint,stylecheck,revive
func Convert_v1alpha1_FlowCollectorEBPF_To_v1beta2_FlowCollectorEBPF(in *FlowCollectorEBPF, out *v1beta2.FlowCollectorEBPF, s apiconversion.Scope) error {
out.Debug = &v1beta2.DebugAgentConfig{
Env: in.Debug.Env,
}
return autoConvert_v1alpha1_FlowCollectorEBPF_To_v1beta2_FlowCollectorEBPF(in, out, s)
}
31 changes: 9 additions & 22 deletions api/v1alpha1/zz_generated.conversion.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions api/v1beta1/flowcollector_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ type FlowCollectorEBPF struct {
// `excludeInterfaces` contains the interface names that are excluded from flow tracing.
// An entry enclosed by slashes, such as `/br-/`, is matched as a regular expression.
// Otherwise it is matched as a case-sensitive string.
//+kubebuilder:default=lo;
//+kubebuilder:default:=lo;
//+optional
ExcludeInterfaces []string `json:"excludeInterfaces"`

Expand Down Expand Up @@ -588,11 +588,11 @@ type FlowCollectorLoki struct {
// A timeout of zero means no timeout.
Timeout *metav1.Duration `json:"timeout,omitempty"` // Warning: keep as pointer, else default is ignored

//+kubebuilder:default="1s"
//+kubebuilder:default:="1s"
// `minBackoff` is the initial backoff time for client connection between retries.
MinBackoff *metav1.Duration `json:"minBackoff,omitempty"` // Warning: keep as pointer, else default is ignored

//+kubebuilder:default="5s"
//+kubebuilder:default:="5s"
// `maxBackoff` is the maximum backoff time for client connection between retries.
MaxBackoff *metav1.Duration `json:"maxBackoff,omitempty"` // Warning: keep as pointer, else default is ignored

Expand Down
113 changes: 86 additions & 27 deletions api/v1beta1/flowcollector_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package v1beta1

import (
"fmt"
"reflect"

"github.com/netobserv/network-observability-operator/api/v1beta2"
utilconversion "github.com/netobserv/network-observability-operator/pkg/conversion"
Expand Down Expand Up @@ -82,10 +83,24 @@ func Convert_v1beta1_FlowCollector_To_v1beta2_FlowCollector(in *FlowCollector, o
out.Spec.Processor.LokiTimeout = in.Spec.Loki.Timeout
out.Spec.Processor.LokiBatchWait = in.Spec.Loki.BatchWait
out.Spec.Processor.LokiBatchSize = in.Spec.Loki.BatchSize
out.Spec.Processor.Debug.LokiMinBackoff = in.Spec.Loki.MinBackoff
out.Spec.Processor.Debug.LokiMaxBackoff = in.Spec.Loki.MaxBackoff
out.Spec.Processor.Debug.LokiMaxRetries = in.Spec.Loki.MaxRetries
out.Spec.Processor.Debug.LokiStaticLabels = in.Spec.Loki.StaticLabels
// fill cross object (Loki -> Processor) debug config
debugPath := helper.ProcessorDebugPath
out.Spec.Processor.Debug.LokiMinBackoff = helper.GetDebugDurationValue(debugPath, "lokiMinBackoff", in.Spec.Loki.MinBackoff)
out.Spec.Processor.Debug.LokiMaxBackoff = helper.GetDebugDurationValue(debugPath, "lokiMaxBackoff", in.Spec.Loki.MaxBackoff)
out.Spec.Processor.Debug.LokiMaxRetries = helper.GetDebugInt32Value(debugPath, "lokiMaxRetries", in.Spec.Loki.MaxRetries)
out.Spec.Processor.Debug.LokiStaticLabels = helper.GetDebugMapValue(debugPath, "lokiStaticLabels", &in.Spec.Loki.StaticLabels)
// clear Processor debug config if default
if reflect.DeepEqual(helper.GetDebugProcessorConfig(nil), helper.GetDebugProcessorConfig(out.Spec.Processor.Debug)) {
out.Spec.Processor.Debug = nil
}
// clear Agent debug config if default
if reflect.DeepEqual(helper.GetDebugAgentConfig(nil), helper.GetDebugAgentConfig(out.Spec.Agent.EBPF.Debug)) {
out.Spec.Agent.EBPF.Debug = nil
}
// clear Plugin debug config if default
if reflect.DeepEqual(helper.GetDebugPluginConfig(nil), helper.GetDebugPluginConfig(out.Spec.ConsolePlugin.Debug)) {
out.Spec.ConsolePlugin.Debug = nil
}
return nil
}

Expand All @@ -98,10 +113,12 @@ func Convert_v1beta2_FlowCollector_To_v1beta1_FlowCollector(in *v1beta2.FlowColl
out.Spec.Loki.Timeout = in.Spec.Processor.LokiTimeout
out.Spec.Loki.BatchWait = in.Spec.Processor.LokiBatchWait
out.Spec.Loki.BatchSize = in.Spec.Processor.LokiBatchSize
out.Spec.Loki.MinBackoff = in.Spec.Processor.Debug.LokiMinBackoff
out.Spec.Loki.MaxBackoff = in.Spec.Processor.Debug.LokiMaxBackoff
out.Spec.Loki.MaxRetries = in.Spec.Processor.Debug.LokiMaxRetries
out.Spec.Loki.StaticLabels = in.Spec.Processor.Debug.LokiStaticLabels
if in.Spec.Processor.Debug != nil {
out.Spec.Loki.MinBackoff = in.Spec.Processor.Debug.LokiMinBackoff
out.Spec.Loki.MaxBackoff = in.Spec.Processor.Debug.LokiMaxBackoff
out.Spec.Loki.MaxRetries = in.Spec.Processor.Debug.LokiMaxRetries
out.Spec.Loki.StaticLabels = helper.GetValueOrDefaultMapString(helper.ProcessorDebugPath, "lokiStaticLabels", in.Spec.Processor.Debug.LokiStaticLabels)
}
return nil
}

Expand Down Expand Up @@ -150,19 +167,17 @@ func Convert_v1beta1_FlowCollectorLoki_To_v1beta2_FlowCollectorLoki(in *FlowColl
return autoConvert_v1beta1_FlowCollectorLoki_To_v1beta2_FlowCollectorLoki(in, out, s)
}

// This function need to be manually created because conversion-gen not able to create it intentionally because
// we have new defined fields in v1beta2 not in v1beta1
// nolint:golint,stylecheck,revive
func Convert_v1beta2_FLPMetrics_To_v1beta1_FLPMetrics(in *v1beta2.FLPMetrics, out *FLPMetrics, s apiconversion.Scope) error {
return autoConvert_v1beta2_FLPMetrics_To_v1beta1_FLPMetrics(in, out, s)
}

// This function need to be manually created because conversion-gen not able to create it intentionally because
// we have new defined fields in v1beta2 not in v1beta1
// nolint:golint,stylecheck,revive
func Convert_v1beta1_FlowCollectorConsolePlugin_To_v1beta2_FlowCollectorConsolePlugin(in *FlowCollectorConsolePlugin, out *v1beta2.FlowCollectorConsolePlugin, s apiconversion.Scope) error {
out.Debug.Register = in.Register
out.Debug.Port = in.Port
debugPath := helper.PluginDebugPath
out.Debug = &v1beta2.DebugPluginConfig{
Env: map[string]string{},
Args: []string{},
Register: helper.GetDebugBoolValue(debugPath, "register", in.Register),
Port: helper.GetDebugInt32Value(debugPath, "port", &in.Port),
}
return autoConvert_v1beta1_FlowCollectorConsolePlugin_To_v1beta2_FlowCollectorConsolePlugin(in, out, s)
}

Expand Down Expand Up @@ -197,6 +212,13 @@ func Convert_v1beta1_FlowCollectorSpec_To_v1beta2_FlowCollectorSpec(in *FlowColl
return nil
}

// This function need to be manually created because conversion-gen not able to create it intentionally because
// we have new defined fields in v1beta2 not in v1beta1
// nolint:golint,stylecheck,revive
func Convert_v1beta2_FLPMetrics_To_v1beta1_FLPMetrics(in *v1beta2.FLPMetrics, out *FLPMetrics, s apiconversion.Scope) error {
return autoConvert_v1beta2_FLPMetrics_To_v1beta1_FLPMetrics(in, out, s)
}

// This function need to be manually created because conversion-gen not able to create it intentionally because
// we have camel case enum in v1beta2 which were uppercase in v1beta1
// nolint:golint,stylecheck,revive
Expand Down Expand Up @@ -250,22 +272,28 @@ func Convert_v1beta1_FlowCollectorFLP_To_v1beta2_FlowCollectorFLP(in *FlowCollec
logTypes := v1beta2.FLPLogTypes(utilconversion.UpperToPascal(*in.LogTypes))
out.LogTypes = &logTypes
}
out.Debug.Port = in.Port
out.Debug.HealthPort = in.HealthPort
out.Debug.ProfilePort = in.ProfilePort
out.Debug.EnableKubeProbes = in.EnableKubeProbes
out.Debug.DropUnusedFields = in.DropUnusedFields
out.Debug.ConversationHeartbeatInterval = in.ConversationHeartbeatInterval
out.Debug.ConversationEndTimeout = in.ConversationEndTimeout
out.Debug.ConversationTerminatingTimeout = in.ConversationTerminatingTimeout
debugPath := helper.ProcessorDebugPath
out.Debug = &v1beta2.DebugProcessorConfig{
Env: map[string]string{},
Port: helper.GetDebugInt32Value(debugPath, "port", &in.Port),
HealthPort: helper.GetDebugInt32Value(debugPath, "healthPort", &in.HealthPort),
ProfilePort: helper.GetDebugInt32Value(debugPath, "profilePort", &in.ProfilePort),
EnableKubeProbes: helper.GetDebugBoolValue(debugPath, "enableKubeProbes", in.EnableKubeProbes),
DropUnusedFields: helper.GetDebugBoolValue(debugPath, "dropUnusedFields", in.DropUnusedFields),
ConversationHeartbeatInterval: helper.GetDebugDurationValue(debugPath, "conversationHeartbeatInterval", in.ConversationHeartbeatInterval),
ConversationEndTimeout: helper.GetDebugDurationValue(debugPath, "conversationEndTimeout", in.ConversationEndTimeout),
ConversationTerminatingTimeout: helper.GetDebugDurationValue(debugPath, "conversationTerminatingTimeout", in.ConversationTerminatingTimeout),
}
return autoConvert_v1beta1_FlowCollectorFLP_To_v1beta2_FlowCollectorFLP(in, out, s)
}

// we have new defined fields in v1beta2 not in v1beta1
// nolint:golint,stylecheck,revive
func Convert_v1beta2_FlowCollectorConsolePlugin_To_v1beta1_FlowCollectorConsolePlugin(in *v1beta2.FlowCollectorConsolePlugin, out *FlowCollectorConsolePlugin, s apiconversion.Scope) error {
out.Register = in.Debug.Register
out.Port = in.Debug.Port
if in.Debug != nil {
out.Register = in.Debug.Register
out.Port = helper.GetValueOrDefaultInt32(helper.PluginDebugPath, "port", in.Debug.Port)
}
return autoConvert_v1beta2_FlowCollectorConsolePlugin_To_v1beta1_FlowCollectorConsolePlugin(in, out, s)
}

Expand All @@ -289,6 +317,17 @@ func Convert_v1beta2_FlowCollectorFLP_To_v1beta1_FlowCollectorFLP(in *v1beta2.Fl
str := utilconversion.PascalToUpper(string(*in.LogTypes), '_')
out.LogTypes = &str
}
if in.Debug != nil {
debugPath := helper.ProcessorDebugPath
out.Port = helper.GetValueOrDefaultInt32(debugPath, "port", in.Debug.Port)
out.HealthPort = helper.GetValueOrDefaultInt32(debugPath, "healthPort", in.Debug.HealthPort)
out.ProfilePort = helper.GetValueOrDefaultInt32(debugPath, "profilePort", in.Debug.ProfilePort)
out.EnableKubeProbes = in.Debug.EnableKubeProbes
out.DropUnusedFields = in.Debug.DropUnusedFields
out.ConversationHeartbeatInterval = in.Debug.ConversationHeartbeatInterval
out.ConversationEndTimeout = in.Debug.ConversationEndTimeout
out.ConversationTerminatingTimeout = in.Debug.ConversationTerminatingTimeout
}
return nil
}

Expand Down Expand Up @@ -400,3 +439,23 @@ func Convert_v1beta2_DebugProcessorConfig_To_v1beta1_DebugConfig(in *v1beta2.Deb
out.Env = in.Env
return nil
}

// This function need to be manually created because conversion-gen not able to create it intentionally because
// we have new defined fields in v1beta2 not in v1beta1
// nolint:golint,stylecheck,revive
func Convert_v1beta1_FlowCollectorEBPF_To_v1beta2_FlowCollectorEBPF(in *FlowCollectorEBPF, out *v1beta2.FlowCollectorEBPF, s apiconversion.Scope) error {
out.Debug = &v1beta2.DebugAgentConfig{
Env: in.Debug.Env,
}
return autoConvert_v1beta1_FlowCollectorEBPF_To_v1beta2_FlowCollectorEBPF(in, out, s)
}

// This function need to be manually created because conversion-gen not able to create it intentionally because
// we have new defined fields in v1beta2 not in v1beta1
// nolint:golint,stylecheck,revive
func Convert_v1beta2_FlowCollectorEBPF_To_v1beta1_FlowCollectorEBPF(in *v1beta2.FlowCollectorEBPF, out *FlowCollectorEBPF, s apiconversion.Scope) error {
if in.Debug != nil {
out.Debug.Env = in.Debug.Env
}
return autoConvert_v1beta2_FlowCollectorEBPF_To_v1beta1_FlowCollectorEBPF(in, out, s)
}
Loading

0 comments on commit 1a76dc3

Please sign in to comment.