public static boolean matchesSelector(LabelSelector labelSelector, HasMetadata cr) {
        if (labelSelector != null && labelSelector.getMatchLabels() != null) {
            if (cr.getMetadata().getLabels() != null) {
                return cr.getMetadata().getLabels().entrySet().containsAll(labelSelector.getMatchLabels().entrySet());
            } else {
                return labelSelector.getMatchLabels().isEmpty();
            }
        }

        return true;
    }
@Test
    public void testMatchesSelector()   {
        Pod testResource = new PodBuilder()
                .withNewMetadata()
                    .withName("test-pod")
                .endMetadata()
                .withNewSpec()
                .endSpec()
                .build();

        // Resources without any labels
        LabelSelector selector = null;
        assertThat(matchesSelector(selector, testResource), is(true));

        selector = new LabelSelectorBuilder().withMatchLabels(emptyMap()).build();
        assertThat(matchesSelector(selector, testResource), is(true));

        selector = new LabelSelectorBuilder().withMatchLabels(Map.of("label2", "value2")).build();
        assertThat(matchesSelector(selector, testResource), is(false));

        // Resources with Labels
        testResource.getMetadata().setLabels(Map.of("label1", "value1", "label2", "value2"));

        selector = null;
        assertThat(matchesSelector(selector, testResource), is(true));

        selector = new LabelSelectorBuilder().withMatchLabels(emptyMap()).build();
        assertThat(matchesSelector(selector, testResource), is(true));

        selector = new LabelSelectorBuilder().withMatchLabels(Map.of("label2", "value2")).build();
        assertThat(matchesSelector(selector, testResource), is(true));

        selector = new LabelSelectorBuilder().withMatchLabels(Map.of("label2", "value2", "label1", "value1")).build();
        assertThat(matchesSelector(selector, testResource), is(true));

        selector = new LabelSelectorBuilder().withMatchLabels(Map.of("label2", "value1")).build();
        assertThat(matchesSelector(selector, testResource), is(false));

        selector = new LabelSelectorBuilder().withMatchLabels(Map.of("label3", "value3")).build();
        assertThat(matchesSelector(selector, testResource), is(false));

        selector = new LabelSelectorBuilder().withMatchLabels(Map.of("label2", "value2", "label1", "value1", "label3", "value3")).build();
        assertThat(matchesSelector(selector, testResource), is(false));
    }