Java Code Examples for io.fabric8.kubernetes.api.model.ObjectMeta#getNamespace()

The following examples show how to use io.fabric8.kubernetes.api.model.ObjectMeta#getNamespace() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: KubernetesHelper.java    From jkube with Eclipse Public License 2.0 5 votes vote down vote up
public static String getNamespace(ObjectMeta entity) {
    if (entity != null) {
        return entity.getNamespace();
    } else {
        return null;
    }
}
 
Example 2
Source File: KubernetesComputer.java    From kubernetes-plugin with Apache License 2.0 5 votes vote down vote up
@Exported
public List<Event> getPodEvents() throws KubernetesAuthException, IOException {
    if(!Jenkins.get().hasPermission(Jenkins.ADMINISTER)) {
        LOGGER.log(Level.FINE, " Computer {0} getPodEvents, lack of admin permission, returning empty list", this);
        return Collections.emptyList();
    }

    KubernetesSlave slave = getNode();
    if(slave != null) {
        KubernetesCloud cloud = slave.getKubernetesCloud();
        KubernetesClient client = cloud.connect();

        String namespace = StringUtils.defaultIfBlank(slave.getNamespace(), client.getNamespace());

        Pod pod = client.pods().inNamespace(namespace).withName(getName()).get();
        if(pod != null) {
            ObjectMeta podMeta = pod.getMetadata();
            String podNamespace = podMeta.getNamespace();

            Map<String, String> fields = new HashMap<>();
            fields.put("involvedObject.uid", podMeta.getUid());
            fields.put("involvedObject.name", podMeta.getName());
            fields.put("involvedObject.namespace", podNamespace);

            EventList eventList = client.events().inNamespace(podNamespace).withFields(fields).list();
            if(eventList != null) {
                return eventList.getItems();
            }
        }
    }

    return Collections.emptyList();
}
 
Example 3
Source File: DynamicPVCWorkspaceVolume.java    From kubernetes-plugin with Apache License 2.0 5 votes vote down vote up
@Override
public PersistentVolumeClaim createVolume(KubernetesClient client, ObjectMeta podMetaData){
    String namespace = podMetaData.getNamespace();
    String podId = podMetaData.getName();
    LOGGER.log(Level.FINE, "Adding workspace volume from pod: {0}/{1}", new Object[] { namespace, podId });
    OwnerReference ownerReference = new OwnerReferenceBuilder().
            withApiVersion("v1").
            withKind("Pod").
            withBlockOwnerDeletion(true).
            withController(true).
            withName(podMetaData.getName()).
            withUid(podMetaData.getUid()).build();

     PersistentVolumeClaim pvc = new PersistentVolumeClaimBuilder()
            .withNewMetadata()
            .withName("pvc-" + podMetaData.getName())
            .withOwnerReferences(ownerReference)
            .withLabels(DEFAULT_POD_LABELS)
            .endMetadata()
            .withNewSpec()
            .withAccessModes(getAccessModesOrDefault())
            .withNewResources()
            .withRequests(getResourceMap())
            .endResources()
            .withStorageClassName(getStorageClassNameOrDefault())
            .endSpec()
            .build();
     pvc = client.persistentVolumeClaims().inNamespace(podMetaData.getNamespace()).create(pvc);
     LOGGER.log(INFO, "Created PVC: {0}/{1}", new Object[] { namespace, pvc.getMetadata().getName() });
     return pvc;
}
 
Example 4
Source File: KubernetesResourceUtil.java    From kubernetes-client with Apache License 2.0 5 votes vote down vote up
/**
 * Null safe get operation for getting namespace from Kubernetes Resource's MetaData
 *
 * @param entity Kubernetes Resource
 * @return returns namespace as plain string
 */
public static String getNamespace(ObjectMeta entity) {
  if (entity != null) {
    return entity.getNamespace();
  } else {
    return null;
  }
}