From a8c9558172a0a55141728e10545ec672870d7111 Mon Sep 17 00:00:00 2001 From: Stanislav Khalash Date: Wed, 25 Sep 2024 20:53:41 +0200 Subject: [PATCH] Adapt v1beta1 log pipeline --- .../v1alpha1/logpipeline_conversion.go | 19 ++++++++++--------- .../v1alpha1/logpipeline_conversion_test.go | 4 +++- apis/telemetry/v1beta1/logpipeline_types.go | 6 +++++- .../v1beta1/logpipeline_validation_test.go | 16 ++++++++-------- .../v1beta1/zz_generated.deepcopy.go | 11 ++++++----- 5 files changed, 32 insertions(+), 24 deletions(-) diff --git a/apis/telemetry/v1alpha1/logpipeline_conversion.go b/apis/telemetry/v1alpha1/logpipeline_conversion.go index 666cebe2a..d006d4767 100644 --- a/apis/telemetry/v1alpha1/logpipeline_conversion.go +++ b/apis/telemetry/v1alpha1/logpipeline_conversion.go @@ -23,7 +23,8 @@ func (lp *LogPipeline) ConvertTo(dstRaw conversion.Hub) error { srcAppInput := src.Spec.Input.Application dst.Spec.Input = telemetryv1beta1.LogPipelineInput{ - Runtime: &telemetryv1beta1.LogPipelineRuntimeInput{ + Runtime: telemetryv1beta1.LogPipelineRuntimeInput{ + Enabled: srcAppInput.Enabled, Namespaces: telemetryv1beta1.LogPipelineInputNamespaces(srcAppInput.Namespaces), Containers: telemetryv1beta1.LogPipelineInputContainers(srcAppInput.Containers), KeepAnnotations: srcAppInput.KeepAnnotations, @@ -111,14 +112,14 @@ func (lp *LogPipeline) ConvertFrom(srcRaw conversion.Hub) error { dst.ObjectMeta = src.ObjectMeta - if srcAppInput := src.Spec.Input.Runtime; srcAppInput != nil { - dst.Spec.Input.Application = ApplicationInput{ - Namespaces: InputNamespaces(srcAppInput.Namespaces), - Containers: InputContainers(srcAppInput.Containers), - KeepAnnotations: srcAppInput.KeepAnnotations, - DropLabels: srcAppInput.DropLabels, - KeepOriginalBody: srcAppInput.KeepOriginalBody, - } + srcRuntimeInput := src.Spec.Input.Runtime + dst.Spec.Input.Application = ApplicationInput{ + Enabled: srcRuntimeInput.Enabled, + Namespaces: InputNamespaces(srcRuntimeInput.Namespaces), + Containers: InputContainers(srcRuntimeInput.Containers), + KeepAnnotations: srcRuntimeInput.KeepAnnotations, + DropLabels: srcRuntimeInput.DropLabels, + KeepOriginalBody: srcRuntimeInput.KeepOriginalBody, } for _, f := range src.Spec.Files { diff --git a/apis/telemetry/v1alpha1/logpipeline_conversion_test.go b/apis/telemetry/v1alpha1/logpipeline_conversion_test.go index ac48db0d1..d8e37ec63 100644 --- a/apis/telemetry/v1alpha1/logpipeline_conversion_test.go +++ b/apis/telemetry/v1alpha1/logpipeline_conversion_test.go @@ -19,6 +19,7 @@ func TestConvertTo(t *testing.T) { Spec: LogPipelineSpec{ Input: Input{ Application: ApplicationInput{ + Enabled: ptr.To(true), Namespaces: InputNamespaces{ Include: []string{"default", "kube-system"}, Exclude: []string{"kube-public"}, @@ -110,7 +111,8 @@ func TestConvertFrom(t *testing.T) { }, Spec: telemetryv1beta1.LogPipelineSpec{ Input: telemetryv1beta1.LogPipelineInput{ - Runtime: &telemetryv1beta1.LogPipelineRuntimeInput{ + Runtime: telemetryv1beta1.LogPipelineRuntimeInput{ + Enabled: ptr.To(true), Namespaces: telemetryv1beta1.LogPipelineInputNamespaces{ Include: []string{"default", "kube-system"}, Exclude: []string{"kube-public"}, diff --git a/apis/telemetry/v1beta1/logpipeline_types.go b/apis/telemetry/v1beta1/logpipeline_types.go index 5879edec9..687b62118 100644 --- a/apis/telemetry/v1beta1/logpipeline_types.go +++ b/apis/telemetry/v1beta1/logpipeline_types.go @@ -59,11 +59,15 @@ type LogPipelineSpec struct { // LogPipelineInput describes a log input for a LogPipeline. type LogPipelineInput struct { // Configures in more detail from which containers application logs are enabled as input. - Runtime *LogPipelineRuntimeInput `json:"runtime,omitempty"` + Runtime LogPipelineRuntimeInput `json:"runtime,omitempty"` } // LogPipelineRuntimeInput specifies the default type of Input that handles application logs from runtime containers. It configures in more detail from which containers logs are selected as input. type LogPipelineRuntimeInput struct { + // If enabled, application logs are collected. The default is `true`. + // +optional + // +kubebuilder:default=true + Enabled *bool `json:"enabled,omitempty"` // Describes whether application logs from specific Namespaces are selected. The options are mutually exclusive. System Namespaces are excluded by default from the collection. Namespaces LogPipelineInputNamespaces `json:"namespaces,omitempty"` // Describes whether application logs from specific containers are selected. The options are mutually exclusive. diff --git a/apis/telemetry/v1beta1/logpipeline_validation_test.go b/apis/telemetry/v1beta1/logpipeline_validation_test.go index c52bcdba3..40b32a312 100644 --- a/apis/telemetry/v1beta1/logpipeline_validation_test.go +++ b/apis/telemetry/v1beta1/logpipeline_validation_test.go @@ -232,7 +232,7 @@ func TestValidateWithValidInputIncludes(t *testing.T) { logPipeline := &LogPipeline{ Spec: LogPipelineSpec{ Input: LogPipelineInput{ - Runtime: &LogPipelineRuntimeInput{ + Runtime: LogPipelineRuntimeInput{ Namespaces: LogPipelineInputNamespaces{ Include: []string{"namespace-1", "namespace-2"}, }, @@ -251,7 +251,7 @@ func TestValidateWithValidInputExcludes(t *testing.T) { logPipeline := &LogPipeline{ Spec: LogPipelineSpec{ Input: LogPipelineInput{ - Runtime: &LogPipelineRuntimeInput{ + Runtime: LogPipelineRuntimeInput{ Namespaces: LogPipelineInputNamespaces{ Exclude: []string{"namespace-1", "namespace-2"}, }, @@ -271,7 +271,7 @@ func TestValidateWithValidInputIncludeContainersSystemFlag(t *testing.T) { logPipeline := &LogPipeline{ Spec: LogPipelineSpec{ Input: LogPipelineInput{ - Runtime: &LogPipelineRuntimeInput{ + Runtime: LogPipelineRuntimeInput{ Namespaces: LogPipelineInputNamespaces{ System: true, }, @@ -291,7 +291,7 @@ func TestValidateWithValidInputExcludeContainersSystemFlag(t *testing.T) { logPipeline := &LogPipeline{ Spec: LogPipelineSpec{ Input: LogPipelineInput{ - Runtime: &LogPipelineRuntimeInput{ + Runtime: LogPipelineRuntimeInput{ Namespaces: LogPipelineInputNamespaces{ System: true, }, @@ -311,7 +311,7 @@ func TestValidateWithInvalidNamespaceSelectors(t *testing.T) { logPipeline := &LogPipeline{ Spec: LogPipelineSpec{ Input: LogPipelineInput{ - Runtime: &LogPipelineRuntimeInput{ + Runtime: LogPipelineRuntimeInput{ Namespaces: LogPipelineInputNamespaces{ Include: []string{"namespace-1", "namespace-2"}, Exclude: []string{"namespace-3"}, @@ -329,7 +329,7 @@ func TestValidateWithInvalidIncludeSystemFlag(t *testing.T) { logPipeline := &LogPipeline{ Spec: LogPipelineSpec{ Input: LogPipelineInput{ - Runtime: &LogPipelineRuntimeInput{ + Runtime: LogPipelineRuntimeInput{ Namespaces: LogPipelineInputNamespaces{ Include: []string{"namespace-1", "namespace-2"}, System: true, @@ -347,7 +347,7 @@ func TestValidateWithInvalidExcludeSystemFlag(t *testing.T) { logPipeline := &LogPipeline{ Spec: LogPipelineSpec{ Input: LogPipelineInput{ - Runtime: &LogPipelineRuntimeInput{ + Runtime: LogPipelineRuntimeInput{ Namespaces: LogPipelineInputNamespaces{ Exclude: []string{"namespace-3"}, System: true, @@ -365,7 +365,7 @@ func TestValidateWithInvalidContainerSelectors(t *testing.T) { logPipeline := &LogPipeline{ Spec: LogPipelineSpec{ Input: LogPipelineInput{ - Runtime: &LogPipelineRuntimeInput{ + Runtime: LogPipelineRuntimeInput{ Containers: LogPipelineInputContainers{ Include: []string{"container-1", "container-2"}, Exclude: []string{"container-3"}, diff --git a/apis/telemetry/v1beta1/zz_generated.deepcopy.go b/apis/telemetry/v1beta1/zz_generated.deepcopy.go index 7722b6992..2664022aa 100644 --- a/apis/telemetry/v1beta1/zz_generated.deepcopy.go +++ b/apis/telemetry/v1beta1/zz_generated.deepcopy.go @@ -202,11 +202,7 @@ func (in *LogPipelineHTTPOutputTLS) DeepCopy() *LogPipelineHTTPOutputTLS { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *LogPipelineInput) DeepCopyInto(out *LogPipelineInput) { *out = *in - if in.Runtime != nil { - in, out := &in.Runtime, &out.Runtime - *out = new(LogPipelineRuntimeInput) - (*in).DeepCopyInto(*out) - } + in.Runtime.DeepCopyInto(&out.Runtime) } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new LogPipelineInput. @@ -324,6 +320,11 @@ func (in *LogPipelineOutput) DeepCopy() *LogPipelineOutput { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *LogPipelineRuntimeInput) DeepCopyInto(out *LogPipelineRuntimeInput) { *out = *in + if in.Enabled != nil { + in, out := &in.Enabled, &out.Enabled + *out = new(bool) + **out = **in + } in.Namespaces.DeepCopyInto(&out.Namespaces) in.Containers.DeepCopyInto(&out.Containers) if in.KeepOriginalBody != nil {