Java Code Examples for io.fabric8.kubernetes.api.model.PodSpec#setServiceAccountName()
The following examples show how to use
io.fabric8.kubernetes.api.model.PodSpec#setServiceAccountName() .
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: KubernetesScheduler.java From spring-cloud-deployer-kubernetes with Apache License 2.0 | 6 votes |
protected CronJob createCronJob(ScheduleRequest scheduleRequest) { Map<String, String> labels = Collections.singletonMap(SPRING_CRONJOB_ID_KEY, scheduleRequest.getDefinition().getName()); Map<String, String> schedulerProperties = scheduleRequest.getSchedulerProperties(); String schedule = schedulerProperties.get(SchedulerPropertyKeys.CRON_EXPRESSION); Assert.hasText(schedule, "The property: " + SchedulerPropertyKeys.CRON_EXPRESSION + " must be defined"); PodSpec podSpec = createPodSpec(scheduleRequest); String taskServiceAccountName = this.deploymentPropertiesResolver.getTaskServiceAccountName(scheduleRequest.getSchedulerProperties()); if (StringUtils.hasText(taskServiceAccountName)) { podSpec.setServiceAccountName(taskServiceAccountName); } CronJob cronJob = new CronJobBuilder().withNewMetadata().withName(scheduleRequest.getScheduleName()) .withLabels(labels).endMetadata().withNewSpec().withSchedule(schedule).withNewJobTemplate() .withNewSpec().withNewTemplate().withSpec(podSpec).endTemplate().endSpec() .endJobTemplate().endSpec().build(); setImagePullSecret(scheduleRequest, cronJob); return this.client.batch().cronjobs().create(cronJob); }
Example 2
Source File: TillerInstaller.java From microbean-helm with Apache License 2.0 | 5 votes |
protected DeploymentSpec createDeploymentSpec(final int replicas, final Map<String, String> labels, final Map<String, String> nodeSelector, String serviceAccountName, final String imageName, final ImagePullPolicy imagePullPolicy, final int maxHistory, final String namespace, final boolean hostNetwork, final boolean tls, final boolean verifyTls) { final DeploymentSpec deploymentSpec = new DeploymentSpec(); deploymentSpec.setReplicas(Math.max(1, replicas)); final PodTemplateSpec podTemplateSpec = new PodTemplateSpec(); final ObjectMeta metadata = new ObjectMeta(); metadata.setLabels(normalizeLabels(labels)); podTemplateSpec.setMetadata(metadata); final PodSpec podSpec = new PodSpec(); serviceAccountName = normalizeServiceAccountName(serviceAccountName); podSpec.setServiceAccountName(serviceAccountName); podSpec.setContainers(Arrays.asList(this.createContainer(imageName, imagePullPolicy, maxHistory, namespace, tls, verifyTls))); podSpec.setHostNetwork(Boolean.valueOf(hostNetwork)); if (nodeSelector != null && !nodeSelector.isEmpty()) { podSpec.setNodeSelector(nodeSelector); } if (tls) { final Volume volume = new Volume(); volume.setName(DEFAULT_NAME + "-certs"); final SecretVolumeSource secretVolumeSource = new SecretVolumeSource(); secretVolumeSource.setSecretName(SECRET_NAME); volume.setSecret(secretVolumeSource); podSpec.setVolumes(Arrays.asList(volume)); } podTemplateSpec.setSpec(podSpec); deploymentSpec.setTemplate(podTemplateSpec); final LabelSelector selector = new LabelSelector(); selector.setMatchLabels(labels); deploymentSpec.setSelector(selector); return deploymentSpec; }