Search in sources :

Example 1 with Job

use of io.fabric8.kubernetes.api.model.Job in project jointware by isdream.

the class KubernetesKeyValueStyleGeneratorTest method testKubernetesWithAllKind.

protected static void testKubernetesWithAllKind() throws Exception {
    info(KUBERNETES_KIND, KubernetesDocumentKeyValueStyleGenerator.class.getName(), new ServiceAccount());
    info(KUBERNETES_KIND, KubernetesDocumentKeyValueStyleGenerator.class.getName(), new ThirdPartyResource());
    info(KUBERNETES_KIND, KubernetesDocumentKeyValueStyleGenerator.class.getName(), new ResourceQuota());
    info(KUBERNETES_KIND, KubernetesDocumentKeyValueStyleGenerator.class.getName(), new Node());
    info(KUBERNETES_KIND, KubernetesDocumentKeyValueStyleGenerator.class.getName(), new ConfigMap());
    info(KUBERNETES_KIND, KubernetesDocumentKeyValueStyleGenerator.class.getName(), new NetworkPolicy());
    info(KUBERNETES_KIND, KubernetesDocumentKeyValueStyleGenerator.class.getName(), new CustomResourceDefinition());
    info(KUBERNETES_KIND, KubernetesDocumentKeyValueStyleGenerator.class.getName(), new Ingress());
    info(KUBERNETES_KIND, KubernetesDocumentKeyValueStyleGenerator.class.getName(), new Service());
    info(KUBERNETES_KIND, KubernetesDocumentKeyValueStyleGenerator.class.getName(), new Namespace());
    info(KUBERNETES_KIND, KubernetesDocumentKeyValueStyleGenerator.class.getName(), new Secret());
    info(KUBERNETES_KIND, KubernetesDocumentKeyValueStyleGenerator.class.getName(), new LimitRange());
    info(KUBERNETES_KIND, KubernetesDocumentKeyValueStyleGenerator.class.getName(), new Event());
    info(KUBERNETES_KIND, KubernetesDocumentKeyValueStyleGenerator.class.getName(), new PersistentVolume());
    info(KUBERNETES_KIND, KubernetesDocumentKeyValueStyleGenerator.class.getName(), new StatefulSet());
    info(KUBERNETES_KIND, KubernetesDocumentKeyValueStyleGenerator.class.getName(), new PersistentVolumeClaim());
    info(KUBERNETES_KIND, KubernetesDocumentKeyValueStyleGenerator.class.getName(), new DaemonSet());
    info(KUBERNETES_KIND, KubernetesDocumentKeyValueStyleGenerator.class.getName(), new HorizontalPodAutoscaler());
    info(KUBERNETES_KIND, KubernetesDocumentKeyValueStyleGenerator.class.getName(), new Pod());
    info(KUBERNETES_KIND, KubernetesDocumentKeyValueStyleGenerator.class.getName(), new ReplicaSet());
    info(KUBERNETES_KIND, KubernetesDocumentKeyValueStyleGenerator.class.getName(), new Job());
    info(KUBERNETES_KIND, KubernetesDocumentKeyValueStyleGenerator.class.getName(), new ReplicationController());
    info(KUBERNETES_KIND, KubernetesDocumentKeyValueStyleGenerator.class.getName(), new Deployment());
}
Also used : ServiceAccount(io.fabric8.kubernetes.api.model.ServiceAccount) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) Pod(io.fabric8.kubernetes.api.model.Pod) ThirdPartyResource(io.fabric8.kubernetes.api.model.extensions.ThirdPartyResource) NetworkPolicy(io.fabric8.kubernetes.api.model.extensions.NetworkPolicy) CustomResourceDefinition(io.fabric8.kubernetes.api.model.apiextensions.CustomResourceDefinition) Node(io.fabric8.kubernetes.api.model.Node) Ingress(io.fabric8.kubernetes.api.model.extensions.Ingress) Service(io.fabric8.kubernetes.api.model.Service) Deployment(io.fabric8.kubernetes.api.model.extensions.Deployment) Namespace(io.fabric8.kubernetes.api.model.Namespace) Secret(io.fabric8.kubernetes.api.model.Secret) LimitRange(io.fabric8.kubernetes.api.model.LimitRange) ResourceQuota(io.fabric8.kubernetes.api.model.ResourceQuota) ReplicationController(io.fabric8.kubernetes.api.model.ReplicationController) HorizontalPodAutoscaler(io.fabric8.kubernetes.api.model.HorizontalPodAutoscaler) Event(io.fabric8.kubernetes.api.model.Event) PersistentVolumeClaim(io.fabric8.kubernetes.api.model.PersistentVolumeClaim) DaemonSet(io.fabric8.kubernetes.api.model.extensions.DaemonSet) PersistentVolume(io.fabric8.kubernetes.api.model.PersistentVolume) StatefulSet(io.fabric8.kubernetes.api.model.extensions.StatefulSet) Job(io.fabric8.kubernetes.api.model.Job) KubernetesDocumentKeyValueStyleGenerator(com.github.isdream.chameleon.docs.KubernetesDocumentKeyValueStyleGenerator) ReplicaSet(io.fabric8.kubernetes.api.model.extensions.ReplicaSet)

Example 2 with Job

use of io.fabric8.kubernetes.api.model.Job in project fabric8-maven-plugin by fabric8io.

the class DefaultControllerEnricher method addMissingResources.

@Override
public void addMissingResources(KubernetesListBuilder builder) {
    final String name = getConfig(Config.name, MavenUtil.createDefaultResourceName(getProject()));
    final ResourceConfig config = new ResourceConfig.Builder().controllerName(name).imagePullPolicy(getConfig(Config.pullPolicy)).withReplicas(Configs.asInt(getConfig(Config.replicaCount))).build();
    final List<ImageConfiguration> images = getImages();
    // Check if at least a replica set is added. If not add a default one
    if (!KubernetesResourceUtil.checkForKind(builder, POD_CONTROLLER_KINDS)) {
        // At least one image must be present, otherwise the resulting config will be invalid
        if (!Lists.isNullOrEmpty(images)) {
            String type = getConfig(Config.type);
            if ("deployment".equalsIgnoreCase(type)) {
                log.info("Adding a default Deployment");
                builder.addToDeploymentItems(deployHandler.getDeployment(config, images));
            } else if ("statefulSet".equalsIgnoreCase(type)) {
                log.info("Adding a default StatefulSet");
                builder.addToStatefulSetItems(statefulSetHandler.getStatefulSet(config, images));
            } else if ("daemonSet".equalsIgnoreCase(type)) {
                log.info("Adding a default DaemonSet");
                builder.addToDaemonSetItems(daemonSetHandler.getDaemonSet(config, images));
            } else if ("replicaSet".equalsIgnoreCase(type)) {
                log.info("Adding a default ReplicaSet");
                builder.addToReplicaSetItems(rsHandler.getReplicaSet(config, images));
            } else if ("replicationController".equalsIgnoreCase(type)) {
                log.info("Adding a default ReplicationController");
                builder.addToReplicationControllerItems(rcHandler.getReplicationController(config, images));
            } else if ("job".equalsIgnoreCase(type)) {
                log.info("Adding a default Job");
                builder.addToJobItems(jobHandler.getJob(config, images));
            }
        }
    } else if (KubernetesResourceUtil.checkForKind(builder, "StatefulSet")) {
        final StatefulSetSpec spec = statefulSetHandler.getStatefulSet(config, images).getSpec();
        if (spec != null) {
            builder.accept(new TypedVisitor<StatefulSetBuilder>() {

                @Override
                public void visit(StatefulSetBuilder statefulSetBuilder) {
                    statefulSetBuilder.editOrNewSpec().editOrNewTemplate().editOrNewSpec().endSpec().endTemplate().endSpec();
                    mergeStatefulSetSpec(statefulSetBuilder, spec);
                }
            });
            if (spec.getTemplate() != null && spec.getTemplate().getSpec() != null) {
                final PodSpec podSpec = spec.getTemplate().getSpec();
                builder.accept(new TypedVisitor<PodSpecBuilder>() {

                    @Override
                    public void visit(PodSpecBuilder builder) {
                        KubernetesResourceUtil.mergePodSpec(builder, podSpec, name);
                    }
                });
            }
        }
    } else {
        final DeploymentSpec spec = deployHandler.getDeployment(config, images).getSpec();
        if (spec != null) {
            builder.accept(new TypedVisitor<DeploymentBuilder>() {

                @Override
                public void visit(DeploymentBuilder deploymentBuilder) {
                    deploymentBuilder.editOrNewSpec().editOrNewTemplate().editOrNewSpec().endSpec().endTemplate().endSpec();
                    mergeDeploymentSpec(deploymentBuilder, spec);
                }
            });
            if (spec.getTemplate() != null && spec.getTemplate().getSpec() != null) {
                final PodSpec podSpec = spec.getTemplate().getSpec();
                builder.accept(new TypedVisitor<PodSpecBuilder>() {

                    @Override
                    public void visit(PodSpecBuilder builder) {
                        KubernetesResourceUtil.mergePodSpec(builder, podSpec, name);
                    }
                });
            }
        }
    }
}
Also used : TypedVisitor(io.fabric8.kubernetes.api.builder.TypedVisitor) PodSpecBuilder(io.fabric8.kubernetes.api.model.PodSpecBuilder) StatefulSetSpec(io.fabric8.kubernetes.api.model.extensions.StatefulSetSpec) DeploymentSpec(io.fabric8.kubernetes.api.model.extensions.DeploymentSpec) PodSpec(io.fabric8.kubernetes.api.model.PodSpec) ImageConfiguration(io.fabric8.maven.docker.config.ImageConfiguration) StatefulSetBuilder(io.fabric8.kubernetes.api.model.extensions.StatefulSetBuilder) PodSpecBuilder(io.fabric8.kubernetes.api.model.PodSpecBuilder) KubernetesListBuilder(io.fabric8.kubernetes.api.model.KubernetesListBuilder) DeploymentBuilder(io.fabric8.kubernetes.api.model.extensions.DeploymentBuilder) ResourceConfig(io.fabric8.maven.core.config.ResourceConfig) StatefulSetBuilder(io.fabric8.kubernetes.api.model.extensions.StatefulSetBuilder) DeploymentBuilder(io.fabric8.kubernetes.api.model.extensions.DeploymentBuilder)

Example 3 with Job

use of io.fabric8.kubernetes.api.model.Job in project fabric8 by fabric8io.

the class PipelineConfigurationParseTest method testLoadMutateAndLoadPipelineConfiguration.

@Test
public void testLoadMutateAndLoadPipelineConfiguration() throws Exception {
    ConfigMap configMap = loadTestConfigMap();
    PipelineConfiguration pipelineConfiguration = PipelineConfiguration.getPipelineConfiguration(configMap);
    pipelineConfiguration.setCdBranchPatterns(Arrays.asList("cd-1", "cd-2"));
    pipelineConfiguration.setCiBranchPatterns(Arrays.asList("ci-1", "ci-2"));
    pipelineConfiguration.setJobNameToKindMap(new HashMap<>());
    pipelineConfiguration.setJobNamesCD("job-cd");
    pipelineConfiguration.setJobNamesCI("job-ci");
    HashMap<String, List<String>> cdGitHostAndOrganisationToBranchPatterns = new HashMap<>();
    cdGitHostAndOrganisationToBranchPatterns.put("github.com/acme", Arrays.asList("release1"));
    cdGitHostAndOrganisationToBranchPatterns.put("github.com/another", Arrays.asList("release2"));
    pipelineConfiguration.setCdGitHostAndOrganisationToBranchPatterns(cdGitHostAndOrganisationToBranchPatterns);
    // reload the modified configuration
    configMap = pipelineConfiguration.createConfigMap();
    pipelineConfiguration = PipelineConfiguration.getPipelineConfiguration(configMap);
    assertThat(pipelineConfiguration.getCdBranchPatterns()).describedAs("getCdBranchPatterns()").contains("cd-1").contains("cd-2");
    assertThat(pipelineConfiguration.getCiBranchPatterns()).describedAs("getCiBranchPatterns()").contains("ci-1").contains("ci-2");
    assertThat(pipelineConfiguration.getJobNameToKindMap()).describedAs("getJobNameToKindMap()").containsEntry("job-cd", PipelineKind.CD).containsEntry("job-ci", PipelineKind.CI);
    assertThat(pipelineConfiguration.getCdGitHostAndOrganisationToBranchPatterns()).describedAs("getCdGitHostAndOrganisationToBranchPatterns()").containsEntry("github.com/acme", Arrays.asList("release1")).containsEntry("github.com/another", Arrays.asList("release2"));
}
Also used : ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) HashMap(java.util.HashMap) List(java.util.List) Test(org.junit.Test)

Example 4 with Job

use of io.fabric8.kubernetes.api.model.Job in project fabric8 by fabric8io.

the class JenkinsAsserts method assertWaitForNoRunningBuilds.

/**
 * Asserts that we can trigger the job defined by the given path
 */
public static void assertWaitForNoRunningBuilds(JenkinsServer jenkins, long timeMillis) throws Exception {
    LOG.info("Waiting for no running Jenkins jobs");
    Asserts.assertWaitFor(timeMillis, new Block() {

        @Override
        public void invoke() throws Exception {
            List<QueueItem> items = jenkins.getQueue().getItems();
            assertTrue("Waiting for build queue to be empty but has " + items.size(), items.isEmpty());
        }
    });
}
Also used : Block(io.fabric8.utils.Block) List(java.util.List) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException)

Example 5 with Job

use of io.fabric8.kubernetes.api.model.Job in project fabric8 by fabric8io.

the class JenkinsAsserts method assertWaitForJobPathExists.

/**
 * Waits for the given time period for the given job path to exist in Jenkins
 *
 * @return the job details
 */
public static JobWithDetails assertWaitForJobPathExists(final JenkinsServer jenkins, long timeMillis, String... jobPath) throws Exception {
    final AtomicReference<JobWithDetails> holder = new AtomicReference<>(null);
    LOG.info("Waiting for Jenkins job " + fullJobPath(jobPath));
    Asserts.assertWaitFor(timeMillis, new Block() {

        @Override
        public void invoke() throws Exception {
            holder.set(assertJobPathExists(jenkins, jobPath));
        }
    });
    return holder.get();
}
Also used : Block(io.fabric8.utils.Block) AtomicReference(java.util.concurrent.atomic.AtomicReference) JobWithDetails(com.offbytwo.jenkins.model.JobWithDetails) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)4 Job (io.fabric8.kubernetes.api.model.Job)3 Block (io.fabric8.utils.Block)3 URISyntaxException (java.net.URISyntaxException)3 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)2 ReplicationController (io.fabric8.kubernetes.api.model.ReplicationController)2 DaemonSet (io.fabric8.kubernetes.api.model.extensions.DaemonSet)2 Deployment (io.fabric8.kubernetes.api.model.extensions.Deployment)2 DeploymentSpec (io.fabric8.kubernetes.api.model.extensions.DeploymentSpec)2 ReplicaSet (io.fabric8.kubernetes.api.model.extensions.ReplicaSet)2 StatefulSet (io.fabric8.kubernetes.api.model.extensions.StatefulSet)2 StatefulSetSpec (io.fabric8.kubernetes.api.model.extensions.StatefulSetSpec)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Test (org.junit.Test)2 KubernetesDocumentKeyValueStyleGenerator (com.github.isdream.chameleon.docs.KubernetesDocumentKeyValueStyleGenerator)1 JobWithDetails (com.offbytwo.jenkins.model.JobWithDetails)1 Controller (io.fabric8.kubernetes.api.Controller)1 TypedVisitor (io.fabric8.kubernetes.api.builder.TypedVisitor)1 Event (io.fabric8.kubernetes.api.model.Event)1