Search in sources :

Example 16 with V1ObjectMeta

use of io.kubernetes.client.models.V1ObjectMeta in project twister2 by DSC-SPIDAL.

the class KubernetesUtils method createStatefulSetObjectForJob.

/**
 * TBD: calculate containers per pod or issue error
 * when the numberOfContainers can not be divisible by the number of containersPerPod
 * @param jobName
 * @param resourceRequest
 * @return
 */
public static V1beta2StatefulSet createStatefulSetObjectForJob(String jobName, RequestedResources resourceRequest, long jobFileSize, Config config) {
    V1beta2StatefulSet statefulSet = new V1beta2StatefulSet();
    statefulSet.setApiVersion("apps/v1beta2");
    statefulSet.setKind("StatefulSet");
    // construct metadata and set for jobName setting
    V1ObjectMeta meta = new V1ObjectMeta();
    meta.setName(jobName);
    statefulSet.setMetadata(meta);
    // construct JobSpec and set
    V1beta2StatefulSetSpec setSpec = new V1beta2StatefulSetSpec();
    setSpec.serviceName(createServiceName(jobName));
    // pods will be started in parallel
    // by default they are started sequentially
    setSpec.setPodManagementPolicy("Parallel");
    // number of containers has to be divisible by the containersPerPod
    // all pods will have equal number of containers
    // all pods will be identical
    int containersPerPod = KubernetesContext.containersPerPod(config);
    if (resourceRequest.getNoOfContainers() % containersPerPod != 0) {
        LOG.log(Level.SEVERE, "Number of containers has to be divisible by containersPerPod.\n" + "Number of containers: " + resourceRequest.getNoOfContainers() + "\n" + "containersPerPod: " + containersPerPod + "\n" + "Aborting submission.");
        return null;
    }
    int numberOfPods = resourceRequest.getNoOfContainers() / containersPerPod;
    setSpec.setReplicas(numberOfPods);
    // add selector for the job
    V1LabelSelector selector = new V1LabelSelector();
    String serviceLabel = createServiceLabel(jobName);
    selector.putMatchLabelsItem("app", serviceLabel);
    setSpec.setSelector(selector);
    // construct the pod template
    V1PodTemplateSpec template = constructPodTemplate(resourceRequest.getContainer(), serviceLabel, jobFileSize, config);
    setSpec.setTemplate(template);
    statefulSet.setSpec(setSpec);
    return statefulSet;
}
Also used : V1beta2StatefulSet(io.kubernetes.client.models.V1beta2StatefulSet) V1beta2StatefulSetSpec(io.kubernetes.client.models.V1beta2StatefulSetSpec) V1ObjectMeta(io.kubernetes.client.models.V1ObjectMeta) IntOrString(io.kubernetes.client.custom.IntOrString) V1PodTemplateSpec(io.kubernetes.client.models.V1PodTemplateSpec) V1LabelSelector(io.kubernetes.client.models.V1LabelSelector)

Example 17 with V1ObjectMeta

use of io.kubernetes.client.models.V1ObjectMeta in project twister2 by DSC-SPIDAL.

the class KubernetesUtils method constructPodTemplate.

public static V1PodTemplateSpec constructPodTemplate(ResourceContainer reqContainer, String serviceLabel, long jobFileSize, Config config) {
    V1PodTemplateSpec template = new V1PodTemplateSpec();
    V1ObjectMeta templateMetaData = new V1ObjectMeta();
    HashMap<String, String> labels = new HashMap<String, String>();
    labels.put("app", serviceLabel);
    templateMetaData.setLabels(labels);
    template.setMetadata(templateMetaData);
    V1PodSpec podSpec = new V1PodSpec();
    podSpec.setTerminationGracePeriodSeconds(0L);
    V1Volume volume = new V1Volume();
    volume.setName(POD_SHARED_VOLUME_NAME);
    V1EmptyDirVolumeSource volumeSource = new V1EmptyDirVolumeSource();
    volumeSource.setMedium("Memory");
    volume.setEmptyDir(volumeSource);
    podSpec.setVolumes(Arrays.asList(volume));
    int containersPerPod = KubernetesContext.containersPerPod(config);
    int basePort = KubernetesContext.workerBasePort(config);
    ArrayList<V1Container> containers = new ArrayList<V1Container>();
    for (int i = 0; i < containersPerPod; i++) {
        containers.add(constructContainer(i, reqContainer, jobFileSize, basePort + 1, config));
    }
    podSpec.setContainers(containers);
    template.setSpec(podSpec);
    return template;
}
Also used : V1Container(io.kubernetes.client.models.V1Container) V1Volume(io.kubernetes.client.models.V1Volume) HashMap(java.util.HashMap) V1ObjectMeta(io.kubernetes.client.models.V1ObjectMeta) V1EmptyDirVolumeSource(io.kubernetes.client.models.V1EmptyDirVolumeSource) ArrayList(java.util.ArrayList) V1PodTemplateSpec(io.kubernetes.client.models.V1PodTemplateSpec) IntOrString(io.kubernetes.client.custom.IntOrString) V1PodSpec(io.kubernetes.client.models.V1PodSpec)

Example 18 with V1ObjectMeta

use of io.kubernetes.client.models.V1ObjectMeta in project incubator-heron by apache.

the class AppsV1beta1Controller method createStatefulSet.

private V1beta1StatefulSet createStatefulSet(Resource containerResource, int numberOfInstances) {
    final String topologyName = getTopologyName();
    final Config runtimeConfiguration = getRuntimeConfiguration();
    final V1beta1StatefulSet statefulSet = new V1beta1StatefulSet();
    // setup stateful set metadata
    final V1ObjectMeta objectMeta = new V1ObjectMeta();
    objectMeta.name(topologyName);
    statefulSet.metadata(objectMeta);
    // create the stateful set spec
    final V1beta1StatefulSetSpec statefulSetSpec = new V1beta1StatefulSetSpec();
    statefulSetSpec.serviceName(topologyName);
    statefulSetSpec.setReplicas(Runtime.numContainers(runtimeConfiguration).intValue());
    // Parallel pod management tells the StatefulSet controller to launch or terminate
    // all Pods in parallel, and not to wait for Pods to become Running and Ready or completely
    // terminated prior to launching or terminating another Pod.
    statefulSetSpec.setPodManagementPolicy("Parallel");
    // add selector match labels "app=heron" and "topology=topology-name"
    // so the we know which pods to manage
    final V1LabelSelector selector = new V1LabelSelector();
    selector.matchLabels(getMatchLabels(topologyName));
    statefulSetSpec.selector(selector);
    // create a pod template
    final V1PodTemplateSpec podTemplateSpec = new V1PodTemplateSpec();
    // set up pod meta
    final V1ObjectMeta templateMetaData = new V1ObjectMeta().labels(getLabels(topologyName));
    templateMetaData.annotations(getPrometheusAnnotations());
    podTemplateSpec.setMetadata(templateMetaData);
    final List<String> command = getExecutorCommand("$" + ENV_SHARD_ID);
    podTemplateSpec.spec(getPodSpec(command, containerResource, numberOfInstances));
    statefulSetSpec.setTemplate(podTemplateSpec);
    statefulSet.spec(statefulSetSpec);
    return statefulSet;
}
Also used : Config(com.twitter.heron.spi.common.Config) V1ObjectMeta(io.kubernetes.client.models.V1ObjectMeta) V1PodTemplateSpec(io.kubernetes.client.models.V1PodTemplateSpec) V1LabelSelector(io.kubernetes.client.models.V1LabelSelector) V1beta1StatefulSet(io.kubernetes.client.models.V1beta1StatefulSet) V1beta1StatefulSetSpec(io.kubernetes.client.models.V1beta1StatefulSetSpec)

Example 19 with V1ObjectMeta

use of io.kubernetes.client.models.V1ObjectMeta in project java by kubernetes-client.

the class YamlTest method testLoad.

@Test
public void testLoad() {
    String[] kinds = new String[] { "Pod", "Deployment", "ClusterRole", "APIService", "Scale" };
    String[] apiVersions = new String[] { "v1", "v1beta2", "v1alpha1", "v1beta1", "extensions/v1beta1" };
    String[] classNames = new String[] { "V1Pod", "V1beta2Deployment", "V1alpha1ClusterRole", "V1beta1APIService", "ExtensionsV1beta1Scale" };
    for (int i = 0; i < kinds.length; i++) {
        String kind = kinds[i];
        String className = classNames[i];
        try {
            String input = "kind: " + kind + "\n" + "apiVersion: " + apiVersions[i] + "\n" + "metadata:\n" + "  name: foo";
            Object obj = Yaml.load(new StringReader(input));
            Method m = obj.getClass().getMethod("getMetadata");
            V1ObjectMeta metadata = (V1ObjectMeta) m.invoke(obj);
            assertEquals("foo", metadata.getName());
            assertEquals(className, obj.getClass().getSimpleName());
        } catch (Exception ex) {
            assertNull("Unexpected exception: " + ex.toString(), ex);
        }
    }
}
Also used : V1ObjectMeta(io.kubernetes.client.models.V1ObjectMeta) StringReader(java.io.StringReader) Method(java.lang.reflect.Method) Test(org.junit.Test)

Example 20 with V1ObjectMeta

use of io.kubernetes.client.models.V1ObjectMeta in project weblogic-kubernetes-operator by oracle.

the class DomainStatusUpdater method doDomainUpdate.

private static NextAction doDomainUpdate(Domain dom, DomainPresenceInfo info, Packet packet, Step conflictStep, Step next) {
    V1ObjectMeta meta = dom.getMetadata();
    NextAction na = new NextAction();
    CallBuilderFactory factory = ContainerResolver.getInstance().getContainer().getSPI(CallBuilderFactory.class);
    na.invoke(factory.create().replaceDomainAsync(meta.getName(), meta.getNamespace(), dom, new ResponseStep<Domain>(next) {

        @Override
        public NextAction onFailure(Packet packet, ApiException e, int statusCode, Map<String, List<String>> responseHeaders) {
            if (statusCode == CallBuilder.NOT_FOUND) {
                // Just ignore update
                return doNext(packet);
            }
            return super.onFailure(conflictStep, packet, e, statusCode, responseHeaders);
        }

        @Override
        public NextAction onSuccess(Packet packet, Domain result, int statusCode, Map<String, List<String>> responseHeaders) {
            info.setDomain(result);
            return doNext(packet);
        }
    }), packet);
    return na;
}
Also used : Packet(oracle.kubernetes.operator.work.Packet) V1ObjectMeta(io.kubernetes.client.models.V1ObjectMeta) CallBuilderFactory(oracle.kubernetes.operator.helpers.CallBuilderFactory) Domain(oracle.kubernetes.weblogic.domain.v1.Domain) NextAction(oracle.kubernetes.operator.work.NextAction) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map) TreeMap(java.util.TreeMap) ResponseStep(oracle.kubernetes.operator.helpers.ResponseStep) ApiException(io.kubernetes.client.ApiException)

Aggregations

V1ObjectMeta (io.kubernetes.client.models.V1ObjectMeta)36 Test (org.junit.Test)12 V1Service (io.kubernetes.client.models.V1Service)10 ApiException (io.kubernetes.client.ApiException)7 CallBuilderFactory (oracle.kubernetes.operator.helpers.CallBuilderFactory)6 V1beta1Ingress (io.kubernetes.client.models.V1beta1Ingress)5 DomainPresenceInfo (oracle.kubernetes.operator.helpers.DomainPresenceInfo)4 IntOrString (io.kubernetes.client.custom.IntOrString)3 V1PodTemplateSpec (io.kubernetes.client.models.V1PodTemplateSpec)3 HashMap (java.util.HashMap)3 Domain (oracle.kubernetes.weblogic.domain.v1.Domain)3 DomainSpec (oracle.kubernetes.weblogic.domain.v1.DomainSpec)3 V1LabelSelector (io.kubernetes.client.models.V1LabelSelector)2 V1Namespace (io.kubernetes.client.models.V1Namespace)2 V1Secret (io.kubernetes.client.models.V1Secret)2 V1ServicePort (io.kubernetes.client.models.V1ServicePort)2 V1ServiceSpec (io.kubernetes.client.models.V1ServiceSpec)2 Method (java.lang.reflect.Method)2 ArrayList (java.util.ArrayList)2 ServerKubernetesObjects (oracle.kubernetes.operator.helpers.ServerKubernetesObjects)2