Skip to content

OpenShiftAssistant : add a scale method with applicationName  #1052

Closed
@dcdh

Description

@dcdh

In my test I need to scale down (0) some pods (like postgresql or other) to test the behavior of my application when infrastructure is in failure.

Currently, the scale method use the applicationName used to deploy an application in the OpenShiftAssistant.

So I have tried to inject multiple OpenShiftAssistant in my test (using @ArquillianResource) and deploy for each OpenShiftAssistant the application and next call on the desired one the scale method. However it doesn't worked because the same object is injected. So the applicationName used by the scale method refer to the last application launched.

A workaround is to define this method in test:

public void scale(final int replicas, final String applicationName) {
		final OpenShiftClient client = openShiftAssistant.getClient();
		final String namespace = client.getNamespace();
		client
			.deploymentConfigs()
			.inNamespace(namespace)
			.withName(applicationName)
			.scale(replicas);

		// ideally, we'd look at deployment config's status.availableReplicas field,
		// but that's only available since OpenShift 3.5
		await().atMost(5, TimeUnit.MINUTES)
			.until(() -> {
				final List<Pod> pods = client
						.pods()
						.inNamespace(namespace)
						.withLabel("deploymentconfig", applicationName)
						.list()
						.getItems();
				try {
					return pods.size() == replicas && pods.stream()
							.allMatch(Readiness::isPodReady);
				} catch (final IllegalStateException e) {
					// the 'Ready' condition can be missing sometimes, in which case Readiness.isPodReady throws an exception
					// here, we'll swallow that exception in hope that the 'Ready' condition will appear later
					return false;
				}
			});
	}

So I guess, the better way would be to add in OpenShiftAssistant and KubernetesAssistant this kind of method:

public void scale(final int replicas, final String applicationName) {
...
}

Regards,
Damien

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions