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

Openshift.clean() doesn't take KEEP_LABEL into account, regression 0.12 -> 0.13 #306

Closed
pkremens opened this issue Sep 6, 2019 · 6 comments

Comments

@pkremens
Copy link
Contributor

pkremens commented Sep 6, 2019

public class CleanupTest {
            List<ConfigMap> configMapList = Stream.of(
                            new ConfigMapBuilder("keep-label-map").addLabel(OpenShift.KEEP_LABEL, null).build(),
                            new ConfigMapBuilder("null-label-map").build(),
                            new ConfigMapBuilder("arbitrary-label-map").build()
            ).collect(Collectors.toList());
     
            private void createConfigMaps() {
                    for (ConfigMap configMap : configMapList) {
                            OpenShifts.master().createConfigMap(configMap);
                    }
                    new SimpleWaiter(() -> OpenShifts.master().getConfigMaps().size() == 3).waitFor();
            }
     
            private void deleteConfigMaps() {
                    for (ConfigMap configMap : OpenShifts.master().getConfigMaps()) {
                            OpenShifts.master().deleteConfigMap(configMap);
                    }
                    new SimpleWaiter(() -> OpenShifts.master().getConfigMaps().size() == 0).waitFor();
            }
     
            private void deleteConfigMaps(List<ConfigMap> removables) {
                    int expected = OpenShifts.master().getConfigMaps().size() - removables.size();
                    for (ConfigMap configMap : removables) {
                            OpenShifts.master().deleteConfigMap(configMap);
                    }
                    new SimpleWaiter(() -> OpenShifts.master().getConfigMaps().size() == expected).waitFor();
            }
     
            @BeforeEach
            public void setupEnv() {
                    deleteConfigMaps();
                    createConfigMaps();
            }
     
            @Test
            public void openshiftCleanTest() {
                    OpenShifts.master().clean();
                    Assertions.assertEquals(1, OpenShifts.master().getConfigMaps().size());
            }
     
            @Test
            public void customCleanTest() {
                    List<ConfigMap> removables = OpenShifts.master().getConfigMaps().stream()
                                    .filter(withoutKeepLabel())
                                    .collect(Collectors.toList());
                    deleteConfigMaps(removables);
                    Assertions.assertEquals(1, OpenShifts.master().getConfigMaps().size());
            }
     
            private Predicate<HasMetadata> withoutKeepLabel() {
                    return (hasMetadata) -> {
                            if (hasMetadata.getMetadata().getLabels() != null) {
                                    return !(hasMetadata.getMetadata().getLabels().containsKey(OpenShift.KEEP_LABEL));
                            } else {
                                    return true;
                            }
                    };
            }
    }

0.12

mvn clean test -Dtest=CleanupTest -Dxtf.version=0.12

[INFO] Tests run: 2, Failures: 0, Errors: 0, Skipped: 0

0.13

mvn clean test -Dtest=CleanupTest -Dxtf.version=0.13

[ERROR] Failures: 
[ERROR]   CleanupTest.openshiftCleanTest:59 expected: <1> but was: <0>    
    org.opentest4j.AssertionFailedError:
    Expected :1
    Actual   :0
            at org.junit.jupiter.api.AssertionUtils.fail(AssertionUtils.java:55)
            at org.junit.jupiter.api.AssertionUtils.failNotEqual(AssertionUtils.java:62)
            at org.junit.jupiter.api.AssertEquals.assertEquals(AssertEquals.java:150)
            at org.junit.jupiter.api.AssertEquals.assertEquals(AssertEquals.java:145)
            at org.junit.jupiter.api.Assertions.assertEquals(Assertions.java:510)
            at com.redhat.xpaas.eap.operator.junit.listener.CleanupTest.openshiftCleanTest(CleanupTest.java:59)
@pkremens
Copy link
Contributor Author

pkremens commented Sep 6, 2019

0.12

configMaps().withoutLabel(KEEP_LABEL).delete();

0.13

removables.addAll(configMaps().withoutLabel(OpenShift.KEEP_LABEL).list().getItems());

There doesn't seem to be much of a difference, maybe the issue itself is hidden in kubernetes client.

@pkremens
Copy link
Contributor Author

pkremens commented Sep 6, 2019

Indeed, it seems like the problem is located in one of the dependencies:

	@Test
	public void withoutLabelTest() {
		System.out.println(openshift.configMaps().withoutLabel(KEEP_LABEL).list().getItems().size());
	}

0.12

 mvn clean test -Dtest=CleanupTest#withoutLabelTest -Dxtf.version=0.12
2

0.13

 mvn clean test -Dtest=CleanupTest#withoutLabelTest -Dxtf.version=0.13
3

@pkremens
Copy link
Contributor Author

pkremens commented Sep 6, 2019

with xtf 0.13

List<ConfigMap> configMapList = Stream.of(
		new ConfigMapBuilder("keep-label-map").addLabel(KEEP_LABEL, null).build(),
		new ConfigMapBuilder("null-label-map").build(),
		new ConfigMapBuilder("arbitrary-label-map").build()
).collect(Collectors.toList());

openshift.configMaps().withoutLabel(KEEP_LABEL).list().getItems().size() == 3

openshift.configMaps().withLabel(KEEP_LABEL).list().getItems().size() == 1

openshift.configMaps().withLabelNotIn(KEEP_LABEL).list().getItems().size() = 2

withLabelNotIn seems to be the way to go here.

@pkremens
Copy link
Contributor Author

pkremens commented Sep 6, 2019

PR sent: #309

pkremens added a commit to pkremens/xtf that referenced this issue Sep 6, 2019
dsimansk added a commit that referenced this issue Sep 23, 2019
[core] [#306] Openshift.clean() doesn't take KEEP_LABEL into account
@Crumby
Copy link
Contributor

Crumby commented Sep 23, 2019

Fixed by #309

@Crumby Crumby closed this as completed Sep 23, 2019
@mchoma
Copy link
Contributor

mchoma commented Jan 24, 2020

Would be nice to create also openshift client issue.

Just note, With current implementation I have noticed xtf.cz/keep=true did not work for me. I have to use xtf.cz/keep=. But maybe it is how withLabelNotIn(String var1, String... var2) should work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants