in teamcity-kubernetes-plugin-server/src/main/java/jetbrains/buildServer/clouds/kubernetes/KubeCloudClient.java [86:118]
public CloudInstance startNewInstance(@NotNull CloudImage cloudImage, @NotNull CloudInstanceUserData cloudInstanceUserData) throws QuotaException {
final KubeCloudImage kubeCloudImage = (KubeCloudImage)cloudImage;
BuildAgentPodTemplateProvider podTemplateProvider = myPodTemplateProviders.get(kubeCloudImage.getPodSpecMode());
final String instanceName = myNameGenerator.generateNewVmName(kubeCloudImage);
final Pod podTemplate = podTemplateProvider.getPodTemplate(instanceName, cloudInstanceUserData, kubeCloudImage, myApiConnector);
final PersistentVolumeClaim pvc = podTemplateProvider.getPVC(instanceName, kubeCloudImage);
if (pvc != null){
KubeTeamCityLabels.addCustomLabel(podTemplate, KubeTeamCityLabels.POD_PVC_NAME, pvc.getMetadata().getName());
}
KubeCloudInstance instance = new KubeCloudInstanceImpl(kubeCloudImage, podTemplate);
kubeCloudImage.addStartedInstance(instance);
myExecutorService.submit(() -> {
Pod newPod = null;
PersistentVolumeClaim newPVC = null;
try {
if (pvc !=null){
newPVC = myApiConnector.createPVC(pvc);
}
newPod = myApiConnector.createPod(podTemplate);
instance.updateState(newPod);
} catch (KubeCloudException | KubernetesClientException ex){
LOG.warnAndDebugDetails("An error occurred while starting new instance", ex);
if (newPod == null && newPVC != null && newPVC.getMetadata() != null) {
LOG.warn("a PVC '" + newPVC.getMetadata().getName() +"' was created as a part of the POD '"+podTemplate.getMetadata().getName()+"' creation. Pod failed to create (see above). Will now delete the PVC as well.");
myApiConnector.deletePVC(newPVC.getMetadata().getName());
}
instance.setStatus(InstanceStatus.ERROR);
instance.setError(new CloudErrorInfo("Instance cannot be started", ex.getMessage(), ex));
throw ex;
}
});
return instance;
}