@@ -210,6 +210,59 @@ func (s *DeploymentHandlerSuite) TestReconcile_K8sResourceScanningStatus() {
210210 s .Equal (corev1 .ConditionFalse , condition .Status )
211211}
212212
213+ func (s * DeploymentHandlerSuite ) TestReconcile_InvalidLabelSelectorCondition () {
214+ s .auditConfig .Spec .Filtering .NamespaceLabelSelector = & metav1.LabelSelector {
215+ MatchExpressions : []metav1.LabelSelectorRequirement {
216+ {Key : "tenant" , Operator : metav1 .LabelSelectorOpIn },
217+ },
218+ }
219+ d := s .createDeploymentHandler ()
220+ s .NoError (d .KubeClient .Create (s .ctx , & s .auditConfig ))
221+
222+ result , err := d .Reconcile (s .ctx )
223+ s .Error (err )
224+ s .True (result .IsZero ())
225+
226+ s .Require ().Len (d .Mondoo .Status .Conditions , 1 )
227+ condition := d .Mondoo .Status .Conditions [0 ]
228+ s .Equal ("InvalidLabelSelector" , condition .Reason )
229+ s .Contains (condition .Message , "filtering.namespaceLabelSelector" )
230+ s .Equal (corev1 .ConditionTrue , condition .Status )
231+ s .Equal (mondoov1alpha2 .K8sResourcesScanningDegraded , condition .Type )
232+ }
233+
234+ func (s * DeploymentHandlerSuite ) TestReconcile_ExternalClusterInvalidLabelSelectorCondition () {
235+ s .auditConfig .Spec .KubernetesResources .Enable = false
236+ s .auditConfig .Spec .KubernetesResources .ExternalClusters = []mondoov1alpha2.ExternalCluster {
237+ {
238+ Name : "external" ,
239+ KubeconfigSecretRef : & corev1.LocalObjectReference {
240+ Name : "external-kubeconfig" ,
241+ },
242+ Filtering : & mondoov1alpha2.Filtering {
243+ ObjectLabelSelector : & metav1.LabelSelector {
244+ MatchExpressions : []metav1.LabelSelectorRequirement {
245+ {Key : "app" , Operator : metav1 .LabelSelectorOpIn },
246+ },
247+ },
248+ },
249+ },
250+ }
251+ d := s .createDeploymentHandler ()
252+ s .NoError (d .KubeClient .Create (s .ctx , & s .auditConfig ))
253+
254+ result , err := d .Reconcile (s .ctx )
255+ s .Error (err )
256+ s .True (result .IsZero ())
257+
258+ s .Require ().Len (d .Mondoo .Status .Conditions , 1 )
259+ condition := d .Mondoo .Status .Conditions [0 ]
260+ s .Equal ("InvalidLabelSelector" , condition .Reason )
261+ s .Contains (condition .Message , "filtering.objectLabelSelector" )
262+ s .Equal (corev1 .ConditionTrue , condition .Status )
263+ s .Equal (mondoov1alpha2 .K8sResourcesScanningDegraded , condition .Type )
264+ }
265+
213266func (s * DeploymentHandlerSuite ) TestReconcile_Disable () {
214267 d := s .createDeploymentHandler ()
215268 mondooAuditConfig := & s .auditConfig
0 commit comments