Skip to content

Commit

Permalink
Adapt v1beta1 log pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
skhalash committed Sep 25, 2024
1 parent 4a197da commit a8c9558
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 24 deletions.
19 changes: 10 additions & 9 deletions apis/telemetry/v1alpha1/logpipeline_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 3 additions & 1 deletion apis/telemetry/v1alpha1/logpipeline_conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand Down Expand Up @@ -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"},
Expand Down
6 changes: 5 additions & 1 deletion apis/telemetry/v1beta1/logpipeline_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
16 changes: 8 additions & 8 deletions apis/telemetry/v1beta1/logpipeline_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
},
Expand All @@ -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"},
},
Expand All @@ -271,7 +271,7 @@ func TestValidateWithValidInputIncludeContainersSystemFlag(t *testing.T) {
logPipeline := &LogPipeline{
Spec: LogPipelineSpec{
Input: LogPipelineInput{
Runtime: &LogPipelineRuntimeInput{
Runtime: LogPipelineRuntimeInput{
Namespaces: LogPipelineInputNamespaces{
System: true,
},
Expand All @@ -291,7 +291,7 @@ func TestValidateWithValidInputExcludeContainersSystemFlag(t *testing.T) {
logPipeline := &LogPipeline{
Spec: LogPipelineSpec{
Input: LogPipelineInput{
Runtime: &LogPipelineRuntimeInput{
Runtime: LogPipelineRuntimeInput{
Namespaces: LogPipelineInputNamespaces{
System: true,
},
Expand All @@ -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"},
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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"},
Expand Down
11 changes: 6 additions & 5 deletions apis/telemetry/v1beta1/zz_generated.deepcopy.go

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

0 comments on commit a8c9558

Please sign in to comment.