本文整理汇总了Java中io.fabric8.kubernetes.api.model.Pod类的典型用法代码示例。如果您正苦于以下问题:Java Pod类的具体用法?Java Pod怎么用?Java Pod使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Pod类属于io.fabric8.kubernetes.api.model包,在下文中一共展示了Pod类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: fetchPods
import io.fabric8.kubernetes.api.model.Pod; //导入依赖的package包/类
private void fetchPods(KubernetesClient dockerClient) throws ParseException {
final Map<String, KubernetesNode> dockerNodeMap = nodes.stream().distinct().collect(toMap(KubernetesNode::getName, node -> node));
final List<Pod> pods = dockerClient.pods().inNamespace(Constants.KUBERNETES_NAMESPACE_KEY)
.withLabel(Constants.CREATED_BY_LABEL_KEY, Constants.PLUGIN_ID)
.list().getItems();
LOG.info("Running pods " + pods.size());
for (Pod pod : pods) {
final KubernetesPod kubernetesPod = new KubernetesPod(pod);
final KubernetesNode kubernetesNode = dockerNodeMap.get(kubernetesPod.getNodeName());
if (kubernetesNode != null) {
kubernetesNode.add(kubernetesPod);
}
}
}
示例2: unregisteredAfterTimeout
import io.fabric8.kubernetes.api.model.Pod; //导入依赖的package包/类
private KubernetesAgentInstances unregisteredAfterTimeout(PluginSettings settings, Agents knownAgents) throws Exception {
Period period = settings.getAutoRegisterPeriod();
KubernetesAgentInstances unregisteredInstances = new KubernetesAgentInstances();
KubernetesClient client = factory.kubernetes(settings);
for (String instanceName : instances.keySet()) {
if (knownAgents.containsAgentWithId(instanceName)) {
continue;
}
Pod pod = client.pods().inNamespace(Constants.KUBERNETES_NAMESPACE_KEY).withName(instanceName).get();
Date createdAt = getSimpleDateFormat().parse(pod.getMetadata().getCreationTimestamp());
DateTime dateTimeCreated = new DateTime(createdAt);
if (clock.now().isAfter(dateTimeCreated.plus(period))) {
unregisteredInstances.register(kubernetesInstanceFactory.fromKubernetesPod(pod));
}
}
return unregisteredInstances;
}
示例3: setUp
import io.fabric8.kubernetes.api.model.Pod; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
initMocks(this);
when(factory.kubernetes(any(PluginSettings.class))).thenReturn(mockedClient);
when(mockedClient.pods()).thenReturn(mockedOperation);
when(mockedOperation.inNamespace(KUBERNETES_NAMESPACE_KEY)).thenReturn(mockedNamespaceOperation);
when(mockedNamespaceOperation.create(any(Pod.class))).thenAnswer(new Answer<Pod>() {
@Override
public Pod answer(InvocationOnMock invocation) throws Throwable {
Object[] args = invocation.getArguments();
return (Pod) args[0];
}
});
agentInstances = new KubernetesAgentInstances(factory);
properties.put("foo", "bar");
properties.put("Image", "gocdcontrib/ubuntu-docker-elastic-agent");
instance = agentInstances.create(new CreateAgentRequest(UUID.randomUUID().toString(), properties, environment, new JobIdentifier(100L)), createSettings(), null);
}
示例4: setUp
import io.fabric8.kubernetes.api.model.Pod; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
initMocks(this);
when(factory.kubernetes(any(PluginSettings.class))).thenReturn(mockedClient);
when(mockedClient.pods()).thenReturn(mockedOperation);
when(mockedOperation.inNamespace(Constants.KUBERNETES_NAMESPACE_KEY)).thenReturn(mockedNamespaceOperation);
when(mockedNamespaceOperation.create(any(Pod.class))).thenAnswer(new Answer<Pod>() {
@Override
public Pod answer(InvocationOnMock invocation) throws Throwable {
Object[] args = invocation.getArguments();
return (Pod) args[0];
}
});
when(mockedNamespaceOperation.withName(anyString())).thenReturn(podResource);
when(podResource.get()).thenReturn(mockedPod);
objectMetadata = new ObjectMeta();
objectMetadata.setCreationTimestamp(getSimpleDateFormat().format(new Date()));
when(mockedPod.getMetadata()).thenReturn(objectMetadata);
}
示例5: onRequest
import io.fabric8.kubernetes.api.model.Pod; //导入依赖的package包/类
@Override
public SpeechletResponse onRequest(IntentRequest request, Session session) throws SpeechletException {
IntentContext<BaseOperation<Pod, PodList, ?, ?>> ctx = createContext(request.getIntent(), session);
String namespace = ctx.getVariable(Variable.Namespace, getKubernetesClient().getNamespace());
LOGGER.info("Listing all failing pods for namespace:" + namespace);
try {
List<String> pods = list(ctx)
.getItems()
.stream()
.filter(p -> FAILED_PHASE.equalsIgnoreCase(p.getStatus().getPhase()))
.map(d -> d.getMetadata().getName()).collect(Collectors.toList());
if (pods.isEmpty()) {
return newResponse("No failing pods found in namespace " + namespace);
} else {
return newResponse("The failing pods in namespace " + namespace + " are: " + join(pods, ","));
}
} catch (KubernetesClientException e) {
return newFailureNotice(e.getStatus().getMessage());
}
}
示例6: onRequest
import io.fabric8.kubernetes.api.model.Pod; //导入依赖的package包/类
@Override
public SpeechletResponse onRequest(IntentRequest request, Session session) throws SpeechletException {
IntentContext<BaseOperation<Pod, PodList, ?, ?>> ctx = createContext(request.getIntent(), session);
String namespace = ctx.getVariable(Variable.Namespace, getKubernetesClient().getNamespace());
LOGGER.info("Listing all pods for namespace:" + namespace);
try {
List<String> pods = list(ctx)
.getItems()
.stream()
.map(d -> d.getMetadata().getName()).collect(Collectors.toList());
if (pods.isEmpty()) {
return newResponse("No pods found in namespace " + namespace);
} else {
return newResponse("The available pods in namespace " + namespace + " are: " + join(pods, ","));
}
} catch (KubernetesClientException e) {
return newFailureNotice(e.getStatus().getMessage());
}
}
示例7: getLinesWithFoundPatternsInLogs
import io.fabric8.kubernetes.api.model.Pod; //导入依赖的package包/类
public static String[] getLinesWithFoundPatternsInLogs(Pod pod, Pattern... patterns) throws IOException {
String found[] = new String[patterns.length];
// TODO: use a method that don't require whole log in memory
StringReader stringReader = new StringReader(OpenShiftUtils.getInstance().getRuntimeLog(pod));
try (BufferedReader br = new BufferedReader(stringReader)) {
br.lines().forEach(line -> {
for (int i = 0; i < patterns.length; ++i) {
Pattern pattern = patterns[i];
if (pattern.matcher(line).find()) {
LOGGER.info("Found pattern {} on line '{}'", pattern, cleanLine(line));
found[i] = line;
}
}
});
}
return found;
}
示例8: assertLogsContainsOrNot
import io.fabric8.kubernetes.api.model.Pod; //导入依赖的package包/类
public static void assertLogsContainsOrNot(Collection<Pod> pods, String[] shouldFinds, String[] shouldNotFinds) throws IOException {
Pattern patterns[] = new Pattern[shouldFinds.length + shouldNotFinds.length];
for (int i = 0; i < shouldFinds.length; ++i) {
patterns[i] = Pattern.compile(shouldFinds[i]);
}
for (int i = 0; i < shouldNotFinds.length; ++i) {
patterns[shouldFinds.length + i] = Pattern.compile(shouldNotFinds[i]);
}
boolean found[] = findPatternsInLogs(pods, patterns);
for (int i = 0; i < patterns.length; ++i) {
if (i < shouldFinds.length) {
Assertions.assertThat(found[i]).as("Didn't find pattern '" + patterns[i].toString() + "' in pod " + formatPodLists(pods) + "logs").isEqualTo(true);
} else {
Assertions.assertThat(found[i]).as("Found pattern '" + patterns[i].toString() + "' in pod " + formatPodLists(pods) + "logs").isEqualTo(false);
}
}
}
示例9: getPodsByName
import io.fabric8.kubernetes.api.model.Pod; //导入依赖的package包/类
private KubernetesPod getPodsByName(String namespace, String name) throws VmidcException {
KubernetesPod resultPod = null;
try {
Pod pod = getKubernetesClient().pods().inNamespace(namespace).withName(name).get();
if (pod != null) {
resultPod = new KubernetesPod(pod.getMetadata().getName(), pod.getMetadata().getNamespace(), pod.getMetadata().getUid(),
pod.getSpec().getNodeName());
}
} catch (KubernetesClientException e) {
throw new VmidcException("Failed to get Pods");
}
return resultPod;
}
示例10: testGetPodsbyLabel_WhenK8sReturnsPodWithMatchingId_ReturnsPod
import io.fabric8.kubernetes.api.model.Pod; //导入依赖的package包/类
@Test
public void testGetPodsbyLabel_WhenK8sReturnsPodWithMatchingId_ReturnsPod() throws Exception {
// Arrange.
String name = UUID.randomUUID().toString();
String namespace = UUID.randomUUID().toString();
String uid = UUID.randomUUID().toString();
Pod pod = newPod(uid, namespace, name, UUID.randomUUID().toString());
mockPodsByName(namespace, name, pod);
// Act.
KubernetesPod result = this.service.getPodById(uid, namespace, name);
// Assert.
assertNotNull("The result should not be null.", result);
assertPodFields(pod, result);
}
示例11: newPod
import io.fabric8.kubernetes.api.model.Pod; //导入依赖的package包/类
private Pod newPod(String uid, String namespace, String name, String node) {
Pod pod = new Pod();
ObjectMeta objMeta = new ObjectMeta();
objMeta.setName(name);
objMeta.setNamespace(namespace);
objMeta.setUid(uid);
PodSpec spec = new PodSpec();
spec.setNodeName(node);
pod.setMetadata(objMeta);
pod.setSpec(spec);
return pod;
}
示例12: testGetPodsbyLabel_WhenK8sReturnsPods
import io.fabric8.kubernetes.api.model.Pod; //导入依赖的package包/类
private void testGetPodsbyLabel_WhenK8sReturnsPods(int podCount) throws Exception {
// Arrange.
String label = UUID.randomUUID().toString();
List<Pod> pods = new ArrayList<>();
for(int i = 0; i < podCount; i++) {
pods.add(newPod(UUID.randomUUID().toString(), UUID.randomUUID().toString(), UUID.randomUUID().toString(), UUID.randomUUID().toString()));
}
mockPodsByLabel(label, pods);
// Act.
List<KubernetesPod> result = this.service.getPodsByLabel(label);
// Assert.
assertNotNull("The result should not be null.", result);
assertPodsList(pods, result);
}
示例13: startNewInstance
import io.fabric8.kubernetes.api.model.Pod; //导入依赖的package包/类
@NotNull
@Override
public CloudInstance startNewInstance(@NotNull CloudImage cloudImage, @NotNull CloudInstanceUserData cloudInstanceUserData) throws QuotaException {
final KubeCloudImage kubeCloudImage = (KubeCloudImage) cloudImage;
BuildAgentPodTemplateProvider podTemplateProvider = myPodTemplateProviders.get(kubeCloudImage.getPodSpecMode());
try {
final Pod podTemplate = podTemplateProvider.getPodTemplate(cloudInstanceUserData, kubeCloudImage, myKubeClientParams);
final Pod newPod = myApiConnector.createPod(podTemplate);
myCurrentError = null;
final KubeCloudInstance newInstance = new CachingKubeCloudInstance(new KubeCloudInstanceImpl(kubeCloudImage, newPod, myApiConnector), myCache);
kubeCloudImage.populateInstances();
return newInstance;
} catch (KubeCloudException | KubernetesClientException ex){
myCurrentError = new CloudErrorInfo("Failed to start pod", ex.getMessage(), ex);
throw ex;
}
}
示例14: getLinesWithFoundPatternsInLogs
import io.fabric8.kubernetes.api.model.Pod; //导入依赖的package包/类
public static String[] getLinesWithFoundPatternsInLogs(Pod pod, Pattern... patterns) throws IOException {
String found[] = new String[patterns.length];
// TODO: use a method that don't require whole log in memory
StringReader stringReader = new StringReader(OpenshiftUtil.getInstance().getRuntimeLog(pod));
try (BufferedReader br = new BufferedReader(stringReader)) {
br.lines().forEach(line -> {
for (int i = 0; i < patterns.length; ++i) {
Pattern pattern = patterns[i];
if (pattern.matcher(line).find()) {
LOGGER.info("Found pattern {} on line '{}'", pattern, LogCleaner.cleanLine(line));
found[i] = line;
}
}
});
}
return found;
}
示例15: assertLogsContainsOrNot
import io.fabric8.kubernetes.api.model.Pod; //导入依赖的package包/类
/**
* Asserts logs contain (or not) given Pair<issue-id, pattern>, and report the assert as <issue> Didn't find pattern|Found pattern <pattern>
* @param pods
* @param shouldFinds Pair<issue-id, pattern>...
* @param shouldNotFinds Pair<issue-id, pattern>...
* @throws IOException
*/
public static void assertLogsContainsOrNot(Collection<Pod> pods, Tuple.Pair<String, String>[] shouldFinds, Tuple.Pair<String, String>[] shouldNotFinds) throws IOException {
Pattern patterns[] = new Pattern[shouldFinds.length + shouldNotFinds.length];
for (int i = 0; i < shouldFinds.length; ++i) {
patterns[i] = Pattern.compile(shouldFinds[i].getSecond());
}
for (int i = 0; i < shouldNotFinds.length; ++i) {
patterns[shouldFinds.length + i] = Pattern.compile(shouldNotFinds[i].getSecond());
}
boolean found[] = findPatternsInLogs(pods, patterns);
for (int i = 0; i < patterns.length; ++i) {
if (i < shouldFinds.length) {
Assertions.assertThat(found[i]).as(shouldFinds[i].getFirst() + " Didn't find pattern '" + patterns[i].toString() + "' in pod " + formatPodLists(pods) + "logs").isEqualTo(true);
} else {
Assertions.assertThat(found[i]).as(shouldNotFinds[i - shouldFinds.length].getFirst() + " Found pattern '" + patterns[i].toString() + "' in pod " + formatPodLists(pods) + "logs").isEqualTo(false);
}
}
}