|
6 | 6 |
|
7 | 7 | "github.com/netobserv/network-observability-operator/internal/pkg/cluster" |
8 | 8 | "github.com/stretchr/testify/assert" |
| 9 | + corev1 "k8s.io/api/core/v1" |
9 | 10 | metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
10 | 11 | "k8s.io/apimachinery/pkg/util/intstr" |
11 | 12 | "k8s.io/utils/ptr" |
@@ -728,6 +729,165 @@ func TestValidateFLP(t *testing.T) { |
728 | 729 | } |
729 | 730 | } |
730 | 731 |
|
| 732 | +func TestValidateScheduling(t *testing.T) { |
| 733 | + mismatchWarning := "Mismatch detected between spec.agent.ebpf.advanced.scheduling and spec.processor.advanced.scheduling. In Direct mode, it can lead to inconsistent pod scheduling that would result in errors in the flow collection process." |
| 734 | + tests := []struct { |
| 735 | + name string |
| 736 | + fc *FlowCollector |
| 737 | + expectedError string |
| 738 | + expectedWarnings admission.Warnings |
| 739 | + ocpVersion string |
| 740 | + }{ |
| 741 | + { |
| 742 | + name: "Valid default (Direct)", |
| 743 | + fc: &FlowCollector{ |
| 744 | + ObjectMeta: metav1.ObjectMeta{ |
| 745 | + Name: "cluster", |
| 746 | + }, |
| 747 | + Spec: FlowCollectorSpec{ |
| 748 | + DeploymentModel: DeploymentModelDirect, |
| 749 | + }, |
| 750 | + }, |
| 751 | + }, |
| 752 | + { |
| 753 | + name: "Invalid Agent scheduling", |
| 754 | + fc: &FlowCollector{ |
| 755 | + ObjectMeta: metav1.ObjectMeta{ |
| 756 | + Name: "cluster", |
| 757 | + }, |
| 758 | + Spec: FlowCollectorSpec{ |
| 759 | + DeploymentModel: DeploymentModelDirect, |
| 760 | + Agent: FlowCollectorAgent{ |
| 761 | + EBPF: FlowCollectorEBPF{ |
| 762 | + Advanced: &AdvancedAgentConfig{ |
| 763 | + Scheduling: &SchedulingConfig{ |
| 764 | + Tolerations: []corev1.Toleration{{Key: "key"}}, |
| 765 | + }, |
| 766 | + }, |
| 767 | + }, |
| 768 | + }, |
| 769 | + }, |
| 770 | + }, |
| 771 | + expectedWarnings: admission.Warnings{mismatchWarning}, |
| 772 | + }, |
| 773 | + { |
| 774 | + name: "Invalid FLP scheduling", |
| 775 | + fc: &FlowCollector{ |
| 776 | + ObjectMeta: metav1.ObjectMeta{ |
| 777 | + Name: "cluster", |
| 778 | + }, |
| 779 | + Spec: FlowCollectorSpec{ |
| 780 | + DeploymentModel: DeploymentModelDirect, |
| 781 | + Processor: FlowCollectorFLP{ |
| 782 | + Advanced: &AdvancedProcessorConfig{ |
| 783 | + Scheduling: &SchedulingConfig{ |
| 784 | + Tolerations: []corev1.Toleration{{Key: "key"}}, |
| 785 | + }, |
| 786 | + }, |
| 787 | + }, |
| 788 | + }, |
| 789 | + }, |
| 790 | + expectedWarnings: admission.Warnings{mismatchWarning}, |
| 791 | + }, |
| 792 | + { |
| 793 | + name: "Invalid FLP and Agent scheduling", |
| 794 | + fc: &FlowCollector{ |
| 795 | + ObjectMeta: metav1.ObjectMeta{ |
| 796 | + Name: "cluster", |
| 797 | + }, |
| 798 | + Spec: FlowCollectorSpec{ |
| 799 | + DeploymentModel: DeploymentModelDirect, |
| 800 | + Agent: FlowCollectorAgent{ |
| 801 | + EBPF: FlowCollectorEBPF{ |
| 802 | + Advanced: &AdvancedAgentConfig{ |
| 803 | + Scheduling: &SchedulingConfig{ |
| 804 | + Tolerations: []corev1.Toleration{{Key: "key1"}}, |
| 805 | + }, |
| 806 | + }, |
| 807 | + }, |
| 808 | + }, |
| 809 | + Processor: FlowCollectorFLP{ |
| 810 | + Advanced: &AdvancedProcessorConfig{ |
| 811 | + Scheduling: &SchedulingConfig{ |
| 812 | + Tolerations: []corev1.Toleration{{Key: "key2"}}, |
| 813 | + }, |
| 814 | + }, |
| 815 | + }, |
| 816 | + }, |
| 817 | + }, |
| 818 | + expectedWarnings: admission.Warnings{mismatchWarning}, |
| 819 | + }, |
| 820 | + { |
| 821 | + name: "Valid FLP and Agent scheduling", |
| 822 | + fc: &FlowCollector{ |
| 823 | + ObjectMeta: metav1.ObjectMeta{ |
| 824 | + Name: "cluster", |
| 825 | + }, |
| 826 | + Spec: FlowCollectorSpec{ |
| 827 | + DeploymentModel: DeploymentModelDirect, |
| 828 | + Agent: FlowCollectorAgent{ |
| 829 | + EBPF: FlowCollectorEBPF{ |
| 830 | + Advanced: &AdvancedAgentConfig{ |
| 831 | + Scheduling: &SchedulingConfig{ |
| 832 | + Tolerations: []corev1.Toleration{{Key: "same_key"}}, |
| 833 | + }, |
| 834 | + }, |
| 835 | + }, |
| 836 | + }, |
| 837 | + Processor: FlowCollectorFLP{ |
| 838 | + Advanced: &AdvancedProcessorConfig{ |
| 839 | + Scheduling: &SchedulingConfig{ |
| 840 | + Tolerations: []corev1.Toleration{{Key: "same_key"}}, |
| 841 | + }, |
| 842 | + }, |
| 843 | + }, |
| 844 | + }, |
| 845 | + }, |
| 846 | + }, |
| 847 | + { |
| 848 | + name: "Valid default (Kafka)", |
| 849 | + fc: &FlowCollector{ |
| 850 | + ObjectMeta: metav1.ObjectMeta{ |
| 851 | + Name: "cluster", |
| 852 | + }, |
| 853 | + Spec: FlowCollectorSpec{ |
| 854 | + DeploymentModel: DeploymentModelKafka, |
| 855 | + }, |
| 856 | + }, |
| 857 | + }, |
| 858 | + { |
| 859 | + name: "No inconsistent scheduling with Kafka", |
| 860 | + fc: &FlowCollector{ |
| 861 | + ObjectMeta: metav1.ObjectMeta{ |
| 862 | + Name: "cluster", |
| 863 | + }, |
| 864 | + Spec: FlowCollectorSpec{ |
| 865 | + Processor: FlowCollectorFLP{ |
| 866 | + Advanced: &AdvancedProcessorConfig{ |
| 867 | + Scheduling: &SchedulingConfig{ |
| 868 | + Tolerations: []corev1.Toleration{{Key: "key"}}, |
| 869 | + }, |
| 870 | + }, |
| 871 | + }, |
| 872 | + }, |
| 873 | + }, |
| 874 | + }, |
| 875 | + } |
| 876 | + |
| 877 | + CurrentClusterInfo = &cluster.Info{} |
| 878 | + r := FlowCollector{} |
| 879 | + for _, test := range tests { |
| 880 | + CurrentClusterInfo.MockOpenShiftVersion(test.ocpVersion) |
| 881 | + warnings, err := r.Validate(context.TODO(), test.fc) |
| 882 | + if test.expectedError == "" { |
| 883 | + assert.NoError(t, err, test.name) |
| 884 | + } else { |
| 885 | + assert.ErrorContains(t, err, test.expectedError, test.name) |
| 886 | + } |
| 887 | + assert.Equal(t, test.expectedWarnings, warnings, test.name) |
| 888 | + } |
| 889 | +} |
| 890 | + |
731 | 891 | func TestElligibleMetrics(t *testing.T) { |
732 | 892 | met, tot := GetElligibleMetricsForAlert(AlertPacketDropsByKernel, &AlertVariant{ |
733 | 893 | GroupBy: GroupByNamespace, |
|
0 commit comments