Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Remove unneeded operator flags #1527

Merged
merged 29 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
ca8e978
Remove max pipeline flags
skhalash Oct 14, 2024
ba9bfb1
Merge branch 'main' of github.com:kyma-project/telemetry-manager into…
skhalash Oct 15, 2024
0f8d30c
Make lint
skhalash Oct 15, 2024
e75be0d
Remove metric flags
skhalash Oct 15, 2024
d13f134
Remove a flag to disable webhooks
skhalash Oct 15, 2024
3036c99
Remove forbidden plugins flags
skhalash Oct 15, 2024
f62af30
Move pipeline defaults
skhalash Oct 15, 2024
1416689
Move resource requirements for fluent bit
skhalash Oct 15, 2024
2095c71
Remove rest of the flags
skhalash Oct 15, 2024
92a2a2d
Extract validating webhook register funcs
skhalash Oct 15, 2024
3aba038
Merge branch 'main' of github.com:kyma-project/telemetry-manager into…
skhalash Oct 15, 2024
6f0f44c
Improve setup logs
skhalash Oct 15, 2024
95ac13f
Fix build
skhalash Oct 15, 2024
199cfb9
Fix
skhalash Oct 15, 2024
6c6e413
Remove log level flag
skhalash Oct 16, 2024
3e0f479
Simplify priority class flags
skhalash Oct 16, 2024
bc57901
WIP
skhalash Oct 16, 2024
70d612f
Fix
skhalash Oct 16, 2024
f2816e9
Fix flushing logs
skhalash Oct 16, 2024
101b596
Revert
skhalash Oct 16, 2024
52d430e
Merge branch 'main' of github.com:kyma-project/telemetry-manager into…
skhalash Oct 16, 2024
8ca123c
Fix priority class
skhalash Oct 16, 2024
923b446
Fix RBAC
skhalash Oct 16, 2024
2a969da
Fix sample
skhalash Oct 16, 2024
3dd0b91
Arranged flags according to CR comment
skhalash Oct 16, 2024
9bfbc20
Address CR comments
skhalash Oct 17, 2024
f9a8e88
Fix logging order
skhalash Oct 17, 2024
cd3516f
Merge branch 'main' of github.com:kyma-project/telemetry-manager into…
skhalash Oct 17, 2024
dc9c031
Remove log
skhalash Oct 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 12 additions & 17 deletions apis/telemetry/v1alpha1/logpipeline_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,24 @@ import (
)

var (
forbiddenFilters = []string{"kubernetes", "rewrite_tag"}
validHostNamePattern = regexp.MustCompile(`^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])$`)
ErrInvalidPipelineDefinition = errors.New("invalid log pipeline definition")
)

func (lp *LogPipeline) Validate(vc *LogPipelineValidationConfig) error {
if err := lp.validateOutput(vc.DeniedOutPutPlugins); err != nil {
func (lp *LogPipeline) Validate() error {
if err := lp.validateOutput(); err != nil {
return err
}

if err := lp.validateFilters(vc.DeniedFilterPlugins); err != nil {
if err := lp.validateFilters(); err != nil {
return err
}

return lp.validateInput()
}

func (lp *LogPipeline) validateOutput(deniedOutputPlugins []string) error {
func (lp *LogPipeline) validateOutput() error {
output := lp.Spec.Output
if err := checkSingleOutputPlugin(output); err != nil {
return err
Expand All @@ -38,7 +39,7 @@ func (lp *LogPipeline) validateOutput(deniedOutputPlugins []string) error {
}
}

return validateCustomOutput(deniedOutputPlugins, output.Custom)
return validateCustomOutput(output.Custom)
}

func checkSingleOutputPlugin(output Output) error {
Expand Down Expand Up @@ -84,7 +85,7 @@ func validHostname(host string) bool {
return validHostNamePattern.MatchString(host)
}

func validateCustomOutput(deniedOutputPlugin []string, content string) error {
func validateCustomOutput(content string) error {
if content == "" {
return nil
}
Expand All @@ -100,12 +101,6 @@ func validateCustomOutput(deniedOutputPlugin []string, content string) error {

pluginName := section.GetByKey("name").Value

for _, deniedPlugin := range deniedOutputPlugin {
if strings.EqualFold(pluginName, deniedPlugin) {
return fmt.Errorf("output plugin '%s' is forbidden. ", pluginName)
}
}

if section.ContainsKey("match") {
return fmt.Errorf("output plugin '%s' contains match condition. Match conditions are forbidden", pluginName)
}
Expand All @@ -121,17 +116,17 @@ func secretRefAndValueIsPresent(v ValueType) bool {
return v.Value != "" && v.ValueFrom != nil
}

func (lp *LogPipeline) validateFilters(deniedFilterPlugins []string) error {
func (lp *LogPipeline) validateFilters() error {
for _, filterPlugin := range lp.Spec.Filters {
if err := validateCustomFilter(filterPlugin.Custom, deniedFilterPlugins); err != nil {
if err := validateCustomFilter(filterPlugin.Custom); err != nil {
return err
}
}

return nil
}

func validateCustomFilter(content string, deniedFilterPlugins []string) error {
func validateCustomFilter(content string) error {
if content == "" {
return nil
}
Expand All @@ -147,8 +142,8 @@ func validateCustomFilter(content string, deniedFilterPlugins []string) error {

pluginName := section.GetByKey("name").Value

for _, deniedPlugin := range deniedFilterPlugins {
if strings.EqualFold(pluginName, deniedPlugin) {
for _, forbiddenFilter := range forbiddenFilters {
if strings.EqualFold(pluginName, forbiddenFilter) {
return fmt.Errorf("filter plugin '%s' is forbidden. ", pluginName)
}
}
Expand Down
59 changes: 13 additions & 46 deletions apis/telemetry/v1alpha1/logpipeline_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ func TestContainsNoOutputPlugins(t *testing.T) {
Output: Output{},
}}

vc := getLogPipelineValidationConfig()
result := logPipeline.validateOutput(vc.DeniedOutPutPlugins)
result := logPipeline.validateOutput()

require.Error(t, result)
require.Contains(t, result.Error(), "no output plugin is defined, you must define one output plugin")
Expand All @@ -32,31 +31,12 @@ func TestContainsMultipleOutputPlugins(t *testing.T) {
},
},
}}
vc := getLogPipelineValidationConfig()
result := logPipeline.validateOutput(vc.DeniedOutPutPlugins)
result := logPipeline.validateOutput()

require.Error(t, result)
require.Contains(t, result.Error(), "multiple output plugins are defined, you must define only one output")
}

func TestDeniedOutputPlugins(t *testing.T) {
logPipeline := &LogPipeline{
ObjectMeta: metav1.ObjectMeta{Name: "foo"},
Spec: LogPipelineSpec{
Output: Output{
Custom: `
Name lua`,
},
},
}

vc := getLogPipelineValidationConfig()
err := logPipeline.validateOutput(vc.DeniedOutPutPlugins)

require.Error(t, err)
require.Contains(t, err.Error(), "plugin 'lua' is forbidden. ")
}

func TestValidateCustomOutput(t *testing.T) {
logPipeline := &LogPipeline{
Spec: LogPipelineSpec{
Expand All @@ -67,8 +47,7 @@ func TestValidateCustomOutput(t *testing.T) {
},
}

vc := getLogPipelineValidationConfig()
err := logPipeline.validateOutput(vc.DeniedOutPutPlugins)
err := logPipeline.validateOutput()
require.NoError(t, err)
}

Expand All @@ -83,8 +62,7 @@ func TestValidateCustomHasForbiddenParameter(t *testing.T) {
},
}

vc := getLogPipelineValidationConfig()
err := logPipeline.validateOutput(vc.DeniedOutPutPlugins)
err := logPipeline.validateOutput()
require.Error(t, err)
}

Expand All @@ -98,8 +76,7 @@ func TestValidateCustomOutputsContainsNoName(t *testing.T) {
},
}

vc := getLogPipelineValidationConfig()
err := logPipeline.validateOutput(vc.DeniedOutPutPlugins)
err := logPipeline.validateOutput()

require.Error(t, err)
require.Contains(t, err.Error(), "configuration section must have name attribute")
Expand All @@ -123,8 +100,7 @@ func TestBothValueAndValueFromPresent(t *testing.T) {
},
},
}}
vc := getLogPipelineValidationConfig()
err := logPipeline.validateOutput(vc.DeniedOutPutPlugins)
err := logPipeline.validateOutput()
require.Error(t, err)
require.Contains(t, err.Error(), "http output host must have either a value or secret key reference")
}
Expand All @@ -146,15 +122,10 @@ func TestValueFromSecretKeyRef(t *testing.T) {
},
},
}}
vc := getLogPipelineValidationConfig()
err := logPipeline.validateOutput(vc.DeniedOutPutPlugins)
err := logPipeline.validateOutput()
require.NoError(t, err)
}

func getLogPipelineValidationConfig() LogPipelineValidationConfig {
return LogPipelineValidationConfig{DeniedOutPutPlugins: []string{"lua", "multiline"}, DeniedFilterPlugins: []string{"lua", "multiline"}}
}

func TestValidateCustomFilter(t *testing.T) {
logPipeline := &LogPipeline{
ObjectMeta: metav1.ObjectMeta{Name: "foo"},
Expand All @@ -166,8 +137,7 @@ func TestValidateCustomFilter(t *testing.T) {
},
}

vc := getLogPipelineValidationConfig()
err := logPipeline.validateFilters(vc.DeniedFilterPlugins)
err := logPipeline.validateFilters()
require.NoError(t, err)
}

Expand All @@ -182,8 +152,7 @@ func TestValidateCustomFiltersContainsNoName(t *testing.T) {
},
}

vc := getLogPipelineValidationConfig()
err := logPipeline.validateFilters(vc.DeniedFilterPlugins)
err := logPipeline.validateFilters()
require.Error(t, err)
require.Contains(t, err.Error(), "configuration section must have name attribute")
}
Expand All @@ -200,8 +169,7 @@ func TestValidateCustomFiltersContainsMatch(t *testing.T) {
},
}

vc := getLogPipelineValidationConfig()
err := logPipeline.validateFilters(vc.DeniedFilterPlugins)
err := logPipeline.validateFilters()

require.Error(t, err)
require.Contains(t, err.Error(), "plugin 'grep' contains match condition. Match conditions are forbidden")
Expand All @@ -213,17 +181,16 @@ func TestDeniedFilterPlugins(t *testing.T) {
Spec: LogPipelineSpec{
Filters: []Filter{
{Custom: `
Name lua`,
Name kubernetes`,
},
},
},
}

vc := getLogPipelineValidationConfig()
err := logPipeline.validateFilters(vc.DeniedFilterPlugins)
err := logPipeline.validateFilters()

require.Error(t, err)
require.Contains(t, err.Error(), "plugin 'lua' is forbidden. ")
require.Contains(t, err.Error(), "plugin 'kubernetes' is forbidden. ")
}

func TestValidateWithValidInputIncludes(t *testing.T) {
Expand Down
4 changes: 0 additions & 4 deletions apis/telemetry/v1alpha1/shared_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,6 @@ func (skr *SecretKeyRef) NamespacedName() types.NamespacedName {
return types.NamespacedName{Name: skr.Name, Namespace: skr.Namespace}
}

type LogPipelineValidationConfig struct {
DeniedOutPutPlugins []string
DeniedFilterPlugins []string
}
type Header struct {
// Defines the header name.
Name string `json:"name"`
Expand Down
25 changes: 0 additions & 25 deletions apis/telemetry/v1alpha1/zz_generated.deepcopy.go

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

29 changes: 12 additions & 17 deletions apis/telemetry/v1beta1/logpipeline_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,24 @@ import (
)

var (
forbiddenFilters = []string{"kubernetes", "rewrite_tag"}
validHostNamePattern = regexp.MustCompile(`^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])$`)
ErrInvalidPipelineDefinition = errors.New("invalid log pipeline definition")
)

func (lp *LogPipeline) Validate(vc *LogPipelineValidationConfig) error {
if err := lp.validateOutput(vc.DeniedOutPutPlugins); err != nil {
func (lp *LogPipeline) Validate() error {
if err := lp.validateOutput(); err != nil {
return err
}

if err := lp.validateFilters(vc.DeniedFilterPlugins); err != nil {
if err := lp.validateFilters(); err != nil {
return err
}

return lp.validateInput()
}

func (lp *LogPipeline) validateOutput(deniedOutputPlugins []string) error {
func (lp *LogPipeline) validateOutput() error {
output := lp.Spec.Output
if err := checkSingleOutputPlugin(output); err != nil {
return err
Expand All @@ -38,7 +39,7 @@ func (lp *LogPipeline) validateOutput(deniedOutputPlugins []string) error {
}
}

return validateCustomOutput(deniedOutputPlugins, output.Custom)
return validateCustomOutput(output.Custom)
}

func checkSingleOutputPlugin(output LogPipelineOutput) error {
Expand Down Expand Up @@ -84,7 +85,7 @@ func validHostname(host string) bool {
return validHostNamePattern.MatchString(host)
}

func validateCustomOutput(deniedOutputPlugin []string, content string) error {
func validateCustomOutput(content string) error {
if content == "" {
return nil
}
Expand All @@ -100,12 +101,6 @@ func validateCustomOutput(deniedOutputPlugin []string, content string) error {

pluginName := section.GetByKey("name").Value

for _, deniedPlugin := range deniedOutputPlugin {
if strings.EqualFold(pluginName, deniedPlugin) {
return fmt.Errorf("output plugin '%s' is forbidden. ", pluginName)
}
}

if section.ContainsKey("match") {
return fmt.Errorf("output plugin '%s' contains match condition. Match conditions are forbidden", pluginName)
}
Expand All @@ -121,17 +116,17 @@ func secretRefAndValueIsPresent(v ValueType) bool {
return v.Value != "" && v.ValueFrom != nil
}

func (lp *LogPipeline) validateFilters(deniedFilterPlugins []string) error {
func (lp *LogPipeline) validateFilters() error {
for _, filterPlugin := range lp.Spec.Filters {
if err := validateCustomFilter(filterPlugin.Custom, deniedFilterPlugins); err != nil {
if err := validateCustomFilter(filterPlugin.Custom); err != nil {
return err
}
}

return nil
}

func validateCustomFilter(content string, deniedFilterPlugins []string) error {
func validateCustomFilter(content string) error {
if content == "" {
return nil
}
Expand All @@ -147,8 +142,8 @@ func validateCustomFilter(content string, deniedFilterPlugins []string) error {

pluginName := section.GetByKey("name").Value

for _, deniedPlugin := range deniedFilterPlugins {
if strings.EqualFold(pluginName, deniedPlugin) {
for _, forbiddenFilter := range forbiddenFilters {
if strings.EqualFold(pluginName, forbiddenFilter) {
return fmt.Errorf("filter plugin '%s' is forbidden. ", pluginName)
}
}
Expand Down
Loading
Loading