@@ -439,7 +439,7 @@ function edit_manifest() {
439439 echo " opt: $1 , value: $2 "
440440 fi
441441
442- if [[ $1 == " filter_" * ]]; then
442+ if [[ $1 == " filter_" * && $1 != " filter_regexes " ]]; then
443443 " $YQ_BIN " e --inplace " .spec.template.spec.containers[0].env[] |= select(.name==\" ENABLE_FLOW_FILTER\" ).value|=\" true\" " " $3 "
444444 # add first filter in the array
445445 currentFilters=$( " $YQ_BIN " -r " .spec.template.spec.containers[0].env[] | select(.name == \" FLOW_FILTER_RULES\" ).value" " $3 " )
@@ -572,9 +572,6 @@ function edit_manifest() {
572572 " filter_regexes" )
573573 copyFLPConfig " $3 "
574574
575- # remove send step
576- " $YQ_BIN " e -oj --inplace " del(.pipeline[] | select(.name==\" send\" ))" " $json "
577-
578575 # define rules from arg
579576 IFS=' ,' read -ra regexes <<< " $2"
580577 rules=()
@@ -589,13 +586,23 @@ function edit_manifest() {
589586 IFS=,
590587 echo " ${rules[*]} "
591588 )
592-
593- # add filter param & pipeline
594- " $YQ_BIN " e -oj --inplace " .parameters += {\" name\" :\" filter\" ,\" transform\" :{\" type\" :\" filter\" ,\" filter\" :{\" rules\" :[{\" type\" :\" keep_entry_all_satisfied\" ,\" keepEntryAllSatisfied\" :[$rulesStr ]}]}}}" " $json "
595- " $YQ_BIN " e -oj --inplace " .pipeline += {\" name\" :\" filter\" ,\" follows\" :\" enrich\" }" " $json "
596-
597- # add send step back
598- " $YQ_BIN " e -oj --inplace " .pipeline += {\" name\" :\" send\" ,\" follows\" :\" filter\" }" " $json "
589+ rule=" {\" type\" :\" keep_entry_all_satisfied\" ,\" keepEntryAllSatisfied\" :[$rulesStr ]}"
590+
591+ existingFilterStage=$( " $YQ_BIN " -r " .pipeline[] | select(.name == \" filter\" )" " $json " )
592+ if [[ " $existingFilterStage " == " " ]]; then
593+ # remove send step
594+ " $YQ_BIN " e -oj --inplace " del(.pipeline[] | select(.name==\" send\" ))" " $json "
595+
596+ # add filter param & pipeline
597+ " $YQ_BIN " e -oj --inplace " .parameters += {\" name\" :\" filter\" ,\" transform\" :{\" type\" :\" filter\" ,\" filter\" :{\" rules\" :[$rule ]}}}" " $json "
598+ " $YQ_BIN " e -oj --inplace " .pipeline += {\" name\" :\" filter\" ,\" follows\" :\" enrich\" }" " $json "
599+
600+ # add send step back
601+ " $YQ_BIN " e -oj --inplace " .pipeline += {\" name\" :\" send\" ,\" follows\" :\" filter\" }" " $json "
602+ else
603+ # add rules to existing filter param
604+ " $YQ_BIN " e --inplace " .parameters[] |= select(.name == \" filter\" ).transform.filter.rules += $rule " " $json "
605+ fi
599606
600607 updateFLPConfig " $json " " $3 "
601608 ;;
@@ -613,6 +620,7 @@ function edit_manifest() {
613620
614621# define key and value at script level to make them available all the time
615622# these will be updated by check_args_and_apply first and overriden by defaultValue when needed
623+ prevKey=" "
616624key=" "
617625value=" "
618626
@@ -629,11 +637,14 @@ function defaultValue() {
629637function check_args_and_apply() {
630638 # Iterate through the command-line arguments
631639 for option in $1 ; do
640+ prevKey=" $key "
632641 key=" ${option%% =* } "
633642 value=" ${option#* =} "
634643 case " $key " in
635644 or) # Increment flow filter array
636- edit_manifest " add_filter" " " " $2 "
645+ if [[ " $prevKey " != * regexes ]]; then
646+ edit_manifest " add_filter" " " " $2 "
647+ fi
637648 ;;
638649 * background) # Run command in background
639650 defaultValue " true"
0 commit comments