use of io.fabric8.kubernetes.api.model.PodCondition in project strimzi by strimzi.
the class ResourceManager method logCurrentResourceStatus.
/**
* Log actual status of custom resource with pods.
* @param customResource - Kafka, KafkaConnect etc. - every resource that HasMetadata and HasStatus (Strimzi status)
*/
public static <T extends CustomResource<? extends Spec, ? extends Status>> void logCurrentResourceStatus(T customResource) {
if (customResource != null) {
List<String> printWholeCR = Arrays.asList(KafkaConnector.RESOURCE_KIND, KafkaTopic.RESOURCE_KIND, KafkaUser.RESOURCE_KIND);
String kind = customResource.getKind();
String name = customResource.getMetadata().getName();
if (printWholeCR.contains(kind)) {
LOGGER.info(customResource);
} else {
List<String> log = new ArrayList<>(asList(kind, " status:\n", "\nConditions:\n"));
if (customResource.getStatus() != null) {
List<Condition> conditions = customResource.getStatus().getConditions();
if (conditions != null) {
for (Condition condition : customResource.getStatus().getConditions()) {
if (condition.getMessage() != null) {
log.add("\tType: " + condition.getType() + "\n");
log.add("\tMessage: " + condition.getMessage() + "\n");
}
}
}
log.add("\nPods with conditions and messages:\n\n");
for (Pod pod : kubeClient().namespace(customResource.getMetadata().getNamespace()).listPodsByPrefixInName(name)) {
log.add(pod.getMetadata().getName() + ":");
for (PodCondition podCondition : pod.getStatus().getConditions()) {
if (podCondition.getMessage() != null) {
log.add("\n\tType: " + podCondition.getType() + "\n");
log.add("\tMessage: " + podCondition.getMessage() + "\n");
} else {
log.add("\n\tType: <EMPTY>\n");
log.add("\tMessage: <EMPTY>\n");
}
}
log.add("\n\n");
}
LOGGER.info("{}", String.join("", log).strip());
}
}
}
}
use of io.fabric8.kubernetes.api.model.PodCondition in project strimzi by strimzi.
the class DeploymentUtils method logCurrentDeploymentStatus.
/**
* Log actual status of deployment with pods
* @param deployment - every Deployment, that HasMetadata and has status (fabric8 status)
*/
public static void logCurrentDeploymentStatus(Deployment deployment, String namespaceName) {
if (deployment != null) {
String kind = deployment.getKind();
String name = deployment.getMetadata().getName();
List<String> log = new ArrayList<>(asList("\n", kind, " status:\n", "\nConditions:\n"));
for (DeploymentCondition deploymentCondition : deployment.getStatus().getConditions()) {
log.add("\tType: " + deploymentCondition.getType() + "\n");
log.add("\tMessage: " + deploymentCondition.getMessage() + "\n");
}
if (kubeClient(namespaceName).listPodsByPrefixInName(name).size() != 0) {
log.add("\nPods with conditions and messages:\n\n");
for (Pod pod : kubeClient(namespaceName).listPodsByPrefixInName(name)) {
log.add(pod.getMetadata().getName() + ":");
for (PodCondition podCondition : pod.getStatus().getConditions()) {
if (podCondition.getMessage() != null) {
log.add("\n\tType: " + podCondition.getType() + "\n");
log.add("\tMessage: " + podCondition.getMessage() + "\n");
}
}
log.add("\n\n");
}
LOGGER.info("{}", String.join("", log));
}
LOGGER.info("{}", String.join("", log));
}
}
use of io.fabric8.kubernetes.api.model.PodCondition in project cloud-pipeline by epam.
the class AutoscaleManagerTest method setUp.
@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
autoscaleManager = new AutoscaleManager(pipelineRunManager, executorService, clusterManager, nodesManager, kubernetesManager, preferenceManager, TEST_KUBE_NAMESPACE);
when(executorService.getExecutorService()).thenReturn(new CurrentThreadExecutorService());
// Mock preferences
when(preferenceManager.getPreference(SystemPreferences.CLUSTER_NODEUP_RETRY_COUNT)).thenReturn(2);
when(preferenceManager.getPreference(SystemPreferences.CLUSTER_SPOT_MAX_ATTEMPTS)).thenReturn(1);
when(preferenceManager.getPreference(SystemPreferences.CLUSTER_SPOT)).thenReturn(true);
when(preferenceManager.getPreference(SystemPreferences.CLUSTER_MAX_SIZE)).thenReturn(1);
when(preferenceManager.getPreference(SystemPreferences.CLUSTER_NODEUP_MAX_THREADS)).thenReturn(1);
when(preferenceManager.getPreference(SystemPreferences.CLUSTER_MIN_SIZE)).thenReturn(SystemPreferences.CLUSTER_MIN_SIZE.getDefaultValue());
when(preferenceManager.getPreference(SystemPreferences.CLUSTER_RANDOM_SCHEDULING)).thenReturn(SystemPreferences.CLUSTER_RANDOM_SCHEDULING.getDefaultValue());
when(preferenceManager.getPreference(SystemPreferences.CLUSTER_HIGH_NON_BATCH_PRIORITY)).thenReturn(SystemPreferences.CLUSTER_HIGH_NON_BATCH_PRIORITY.getDefaultValue());
when(kubernetesManager.getKubernetesClient(any(Config.class))).thenReturn(kubernetesClient);
// Mock no nodes in cluster
NonNamespaceOperation<Node, NodeList, DoneableNode, Resource<Node, DoneableNode>> mockNodes = new KubernetesTestUtils.MockNodes().mockWithLabel(KubernetesConstants.RUN_ID_LABEL).mockWithoutLabel(KubernetesConstants.PAUSED_NODE_LABEL).mockNodeList(Collections.emptyList()).and().getMockedEntity();
when(kubernetesClient.nodes()).thenReturn(mockNodes);
// Mock one unsceduled pod
Pod unscheduledPipelinePod = new Pod();
ObjectMeta metadata = new ObjectMeta();
metadata.setLabels(Collections.singletonMap(KubernetesConstants.RUN_ID_LABEL, TEST_RUN_ID.toString()));
unscheduledPipelinePod.setMetadata(metadata);
PodStatus status = new PodStatus();
status.setPhase("Pending");
PodCondition condition = new PodCondition();
condition.setReason(KubernetesConstants.POD_UNSCHEDULABLE);
status.setConditions(Collections.singletonList(condition));
unscheduledPipelinePod.setStatus(status);
PipelineRun testRun = new PipelineRun();
testRun.setStatus(TaskStatus.RUNNING);
testRun.setPipelineRunParameters(Collections.emptyList());
RunInstance spotInstance = new RunInstance();
spotInstance.setSpot(true);
testRun.setInstance(spotInstance);
when(pipelineRunManager.loadPipelineRun(Mockito.eq(TEST_RUN_ID))).thenReturn(testRun);
when(clusterManager.fillInstance(any(RunInstance.class))).thenAnswer(invocation -> invocation.getArguments()[0]);
MixedOperation<Pod, PodList, DoneablePod, PodResource<Pod, DoneablePod>> mockPods = new KubernetesTestUtils.MockPods().mockNamespace(TEST_KUBE_NAMESPACE).mockWithLabel("type", "pipeline").mockWithLabel(KubernetesConstants.RUN_ID_LABEL).mockPodList(Collections.singletonList(unscheduledPipelinePod)).and().getMockedEntity();
when(kubernetesClient.pods()).thenReturn(mockPods);
}
Aggregations