io.fabric8.kubernetes.api.model.ObjectMeta Java Examples

The following examples show how to use io.fabric8.kubernetes.api.model.ObjectMeta. 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: AddBasicAuthSecretDecorator.java    From dekorate with Apache License 2.0 6 votes vote down vote up
@Override
public void visit(KubernetesListBuilder list) {
  ObjectMeta meta = getMandatoryDeploymentMetadata(list);
  String name = Strings.isNullOrEmpty(this.name) ? meta.getName() : this.name;

  Map<String, String> data = new HashMap<String, String>() {
    {
      put(USERNAME, username);
      put(PASSWORD, password);
    }
  };

  list.addToItems(new SecretBuilder()
                  .withNewMetadata()
                    .withName(name)
                  .withAnnotations(annotations)
                  .endMetadata()
      .withType(KUBERNETES_IO_BASIC_AUTH).addToStringData(data).build());
}
 
Example #2
Source File: ContainerResourceProvisionerTest.java    From che with Eclipse Public License 2.0 6 votes vote down vote up
@BeforeMethod
public void setup() {
  resourceProvisioner = new ContainerResourceProvisioner(1024, 512, "500m", "100m");
  container = new Container();
  container.setName(CONTAINER_NAME);
  when(k8sEnv.getMachines()).thenReturn(of(MACHINE_NAME, internalMachineConfig));
  when(internalMachineConfig.getAttributes())
      .thenReturn(
          of(
              MEMORY_LIMIT_ATTRIBUTE,
              RAM_LIMIT_VALUE,
              MEMORY_REQUEST_ATTRIBUTE,
              RAM_REQUEST_VALUE,
              CPU_LIMIT_ATTRIBUTE,
              CPU_LIMIT_VALUE,
              CPU_REQUEST_ATTRIBUTE,
              CPU_REQUEST_VALUE));
  final ObjectMeta podMetadata = mock(ObjectMeta.class);
  when(podMetadata.getName()).thenReturn(POD_NAME);
  final PodSpec podSpec = mock(PodSpec.class);
  when(podSpec.getContainers()).thenReturn(Collections.singletonList(container));
  when(k8sEnv.getPodsData()).thenReturn(of(POD_NAME, new PodData(podSpec, podMetadata)));
}
 
Example #3
Source File: AddBuilderImageStreamResourceDecorator.java    From dekorate with Apache License 2.0 6 votes vote down vote up
public void visit(KubernetesListBuilder list) {
  ObjectMeta meta = getMandatoryDeploymentMetadata(list);

  String repository = Images.getRepository(config.getBuilderImage());

  String name = !repository.contains("/")
    ? repository
    : repository.substring(repository.lastIndexOf("/") + 1);

  String dockerImageRepo = Images.removeTag(config.getBuilderImage());

  list.addToItems(new ImageStreamBuilder()
    .withNewMetadata()
    .withName(name)
    .withLabels(meta.getLabels())
    .endMetadata()
    .withNewSpec()
    .withDockerImageRepository(dockerImageRepo)
    .endSpec());
}
 
Example #4
Source File: ApplyDeploymentTriggerDecorator.java    From dekorate with Apache License 2.0 6 votes vote down vote up
@Override
public void andThenVisit(DeploymentConfigSpecFluent<?> deploymentConfigSpec, ObjectMeta resourceMeta) {
  DeploymentConfigSpecFluent.TriggersNested<?> target;

  if (deploymentConfigSpec.buildMatchingTrigger(predicate) != null)  {
    target = deploymentConfigSpec.editMatchingTrigger(predicate);
  } else {
    target = deploymentConfigSpec.addNewTrigger();
  }
  target.withType(IMAGECHANGE)
    .withNewImageChangeParams()
    .withAutomatic(true)
    .withContainerNames(containerName)
    .withNewFrom()
    .withKind(IMAGESTREAMTAG)
    .withName(imageStreamTag)
    .endFrom()
    .endImageChangeParams()
    .endTrigger();
}
 
Example #5
Source File: AddApplicationResourceDecorator.java    From dekorate with Apache License 2.0 6 votes vote down vote up
public void visit(KubernetesListBuilder list) {
  ObjectMeta meta = getMandatoryDeploymentMetadata(list);
  list.addToItems(new ApplicationBuilder()
           .withNewMetadata()
           .withName(meta.getName())
           .withLabels(meta.getLabels())
           .endMetadata()
           .withNewSpec()
           .withNewSelector()
           .withMatchLabels(meta.getLabels())
           .endSelector()
           .withNewDescriptor()
           .withVersion(meta.getLabels().getOrDefault(Labels.VERSION, "latest"))
           .withOwners(Arrays.stream(config.getOwners()).map(AddApplicationResourceDecorator::adapt).collect(Collectors.toList()))
           .withLinks(Arrays.stream(config.getLinks()).map(AddApplicationResourceDecorator::adapt).collect(Collectors.toList()))
           .withMaintainers(Arrays.stream(config.getMaintainers()).map(AddApplicationResourceDecorator::adapt).collect(Collectors.toList()))
           .withIcons(Arrays.stream(config.getIcons()).map(AddApplicationResourceDecorator::adapt).collect(Collectors.toList()))
           .withKeywords(config.getKeywords())
           .withNotes(config.getNotes())
           .endDescriptor()
           .endSpec());
}
 
Example #6
Source File: KubernetesDiscoveryClientFilterTest.java    From spring-cloud-kubernetes with Apache License 2.0 6 votes vote down vote up
@Test
public void testFilteredServices() {
	List<String> springBootServiceNames = Arrays.asList("serviceA", "serviceB");
	List<Service> services = createSpringBootServiceByName(springBootServiceNames);

	// Add non spring boot service
	Service service = new Service();
	ObjectMeta objectMeta = new ObjectMeta();
	objectMeta.setName("ServiceNonSpringBoot");
	service.setMetadata(objectMeta);
	services.add(service);

	ServiceList serviceList = new ServiceList();
	serviceList.setItems(services);
	when(this.serviceOperation.list()).thenReturn(serviceList);
	when(this.kubernetesClient.services()).thenReturn(this.serviceOperation);

	when(this.properties.getFilter())
			.thenReturn("metadata.additionalProperties['spring-boot']");

	List<String> filteredServices = this.underTest.getServices();

	System.out.println("Filtered Services: " + filteredServices);
	assertThat(filteredServices).isEqualTo(springBootServiceNames);

}
 
Example #7
Source File: KubernetesService.java    From vault-crd with Apache License 2.0 6 votes vote down vote up
private ObjectMeta metaData(ObjectMeta resource, String compare) {
    ObjectMeta meta = new ObjectMeta();
    meta.setNamespace(resource.getNamespace());
    meta.setName(resource.getName());
    if (resource.getLabels() != null) {
        meta.setLabels(resource.getLabels());
    }

    HashMap<String, String> annotations = new HashMap<>();
    if (resource.getAnnotations() != null) {
        annotations.putAll(resource.getAnnotations());
    }
    annotations.put(crdName + LAST_UPDATE_ANNOTATION, LocalDateTime.now().toString());
    annotations.put(crdName + COMPARE_ANNOTATION, compare);
    meta.setAnnotations(annotations);
    return meta;
}
 
Example #8
Source File: MockKubernetesServerSupport.java    From kogito-runtimes with Apache License 2.0 6 votes vote down vote up
protected void createMockService(final String serviceName, final String ip, final Map<String, String> labels, final String namespace) {
    final ServiceSpec serviceSpec = new ServiceSpec();
    serviceSpec.setPorts(Collections.singletonList(new ServicePort("http", 0, 8080, "http", new IntOrString(8080))));
    serviceSpec.setClusterIP(ip);
    serviceSpec.setType("ClusterIP");
    serviceSpec.setSessionAffinity("ClientIP");

    final ObjectMeta metadata = new ObjectMeta();
    metadata.setName(serviceName);
    metadata.setNamespace(MOCK_NAMESPACE);
    metadata.setLabels(labels);

    final Service service = new Service("v1", "Service", metadata, serviceSpec, new ServiceStatus(new LoadBalancerStatus()));
    if (namespace != null) {
        this.server.getClient().inNamespace(namespace).services().create(service);
    } else {
        this.server.getClient().services().create(service);
    }

}
 
Example #9
Source File: AddServiceMonitorResourceDecorator.java    From dekorate with Apache License 2.0 6 votes vote down vote up
public void visit(KubernetesListBuilder list) {
  ObjectMeta meta = getMandatoryDeploymentMetadata(list);
  list.addToItems(new ServiceMonitorBuilder()
                  .withNewMetadata()
                  .withName(meta.getName())
                  .withLabels(meta.getLabels())
                  .endMetadata()
                  .withNewSpec()
                  .withNewSelector()
                  .addToMatchLabels(meta.getLabels())
                  .endSelector()
                  .addNewEndpoint()
                  .withPort(config.getPort())
                  .withNewPath(config.getPath())
                  .withInterval(config.getInterval() + "s")
                  .withHonorLabels(config.isHonorLabels())
                  .endEndpoint()
                  .endSpec());
}
 
Example #10
Source File: KubernetesInternalRuntime.java    From che with Eclipse Public License 2.0 6 votes vote down vote up
private List<PodData> getAllInjectablePods(
    ObjectMeta toCreateMeta,
    List<Container> toCreateContainers,
    Map<String, Map<String, Pod>> injectables) {
  return toCreateContainers
      .stream()
      .map(c -> Names.machineName(toCreateMeta, c))
      .map(injectables::get)
      // we're only interested in pods for which we require injection
      .filter(Objects::nonNull)
      // now reduce to a map keyed by injected pod name so that if 2 pods require injection
      // of the same thing, we don't inject twice
      .flatMap(m -> m.entrySet().stream())
      // collect to map, ignoring duplicate entries
      .collect(toMap(Entry::getKey, Entry::getValue, (v1, v2) -> v1))
      // ok, we only have 1 of each injectable pods keyed by their names, so let's just get them
      // all and return as list
      .values()
      .stream()
      .map(PodData::new)
      .collect(Collectors.toList());
}
 
Example #11
Source File: KubernetesMockTest.java    From vxms with Apache License 2.0 6 votes vote down vote up
@Test
public void findServices() {
  final ObjectMeta build = new ObjectMetaBuilder().addToLabels("test", "test").build();
  final ServiceSpec spec =
      new ServiceSpecBuilder().addNewPort().and().withClusterIP("192.168.1.1").build();
  final Service service = new ServiceBuilder().withMetadata(build).withSpec(spec).build();
  server
      .expect()
      .withPath("/api/v1/namespaces/default/services")
      .andReturn(200, new ServiceListBuilder().addToItems().addToItems(service).build())
      .once();
  KubernetesClient client = this.client;
  final ServiceList list = client.services().inNamespace("default").list();
  assertNotNull(list);
  assertEquals("test", list.getItems().get(0).getMetadata().getLabels().get("test"));
  System.out.println(list.getItems().get(0).getSpec().getClusterIP());
}
 
Example #12
Source File: KnativeMetaDataSupport.java    From syndesis with Apache License 2.0 5 votes vote down vote up
private static List<String> listResources(CustomResourceDefinition crd) {
    try (OpenShiftClient client = new DefaultOpenShiftClient()) {
        return client.customResources(crd, KnativeResource.class, KnativeResourceList.class, KnativeResourceDoneable.class)
            .inNamespace(getTargetNamespace())
            .list()
            .getItems()
            .stream()
            .map(KnativeResource::getMetadata)
            .map(ObjectMeta::getName)
            .collect(Collectors.toList());
    }
}
 
Example #13
Source File: ReflectUtilsTest.java    From kubernetes-client with Apache License 2.0 5 votes vote down vote up
@Test
public void testDirectReflection () throws ReflectiveOperationException {
  ObjectMeta meta = new ObjectMeta();
  Foo foo = new Foo();
  foo.setMetadata(meta);
  assertSame(meta, ReflectUtils.objectMetadata(foo));
}
 
Example #14
Source File: OpenShiftUniqueNamesProvisionerTest.java    From che with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void provideUniquePodsNames() throws Exception {
  when(runtimeIdentity.getWorkspaceId()).thenReturn(WORKSPACE_ID);
  Pod pod = newPod();
  PodData podData = new PodData(pod.getSpec(), pod.getMetadata());
  doReturn(ImmutableMap.of(POD_NAME, podData)).when(osEnv).getPodsData();

  uniqueNamesProvisioner.provision(osEnv, runtimeIdentity);

  ObjectMeta podMetadata = pod.getMetadata();
  assertNotEquals(podMetadata.getName(), POD_NAME);
  assertEquals(podMetadata.getLabels().get(CHE_ORIGINAL_NAME_LABEL), POD_NAME);
}
 
Example #15
Source File: PodMergerTest.java    From che with Eclipse Public License 2.0 5 votes vote down vote up
private void verifyContainsAllFrom(ObjectMeta source, ObjectMeta toCheck) {
  assertTrue(source.getLabels().entrySet().containsAll(toCheck.getLabels().entrySet()));
  assertTrue(source.getAnnotations().entrySet().containsAll(toCheck.getAnnotations().entrySet()));
  assertTrue(
      source
          .getAdditionalProperties()
          .entrySet()
          .containsAll(toCheck.getAdditionalProperties().entrySet()));
}
 
Example #16
Source File: OpenShiftUniqueNamesProvisioner.java    From che with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void provision(OpenShiftEnvironment osEnv, RuntimeIdentity identity)
    throws InfrastructureException {
  super.provision(osEnv, identity);

  final Set<Route> routes = new HashSet<>(osEnv.getRoutes().values());
  osEnv.getRoutes().clear();
  for (Route route : routes) {
    final ObjectMeta routeMeta = route.getMetadata();
    putLabel(route, Constants.CHE_ORIGINAL_NAME_LABEL, routeMeta.getName());
    final String routeName = Names.generateName("route");
    routeMeta.setName(routeName);
    osEnv.getRoutes().put(routeName, route);
  }
}
 
Example #17
Source File: K8sNetworkPolicyManagerTest.java    From onos with Apache License 2.0 5 votes vote down vote up
private static NetworkPolicy createK8sNetworkPolicy(String uid, String name) {
    ObjectMeta meta = new ObjectMeta();
    meta.setUid(uid);
    meta.setName(name);

    NetworkPolicy networkPolicy = new NetworkPolicy();
    networkPolicy.setApiVersion("v1");
    networkPolicy.setKind("NetworkPolicy");
    networkPolicy.setMetadata(meta);

    return networkPolicy;
}
 
Example #18
Source File: KubernetesAgentInstancesTest.java    From kubernetes-elastic-agents with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldNotCreatePodsWhenOutstandingLimitOfPendingKubernetesPodsHasReached() throws IOException {
    //set maximum pending pod count to 1
    when(mockPluginSettings.getMaxPendingPods()).thenReturn(1);

    //pending kubernetes pod
    KubernetesInstance kubernetesInstance = new KubernetesInstance(new DateTime(), "test", "test-agent", new HashMap<>(), 100L, PodState.Pending);
    when(mockKubernetesInstanceFactory.create(mockCreateAgentRequest, mockPluginSettings, mockKubernetesClient, mockPluginRequest)).
            thenReturn(kubernetesInstance);
    testProperties.put("PodSpecType", "properties");

    //first create agent request
    KubernetesAgentInstances agentInstances = new KubernetesAgentInstances(factory, mockKubernetesInstanceFactory);
    JobIdentifier jobId = new JobIdentifier("test", 1L, "Test pipeline", "test name", "1", "test job", 100L);
    when(mockCreateAgentRequest.jobIdentifier()).thenReturn(jobId);
    agentInstances.create(mockCreateAgentRequest, mockPluginSettings, mockPluginRequest, consoleLogAppender);
    verify(mockKubernetesInstanceFactory, times(1)).create(any(), any(), any(), any());
    reset(mockKubernetesInstanceFactory);

    final Map<String, String> labels = new HashMap<>();
    labels.put(JOB_ID_LABEL_KEY, jobId.getJobId().toString());
    labels.put(Constants.KUBERNETES_POD_KIND_LABEL_KEY, Constants.KUBERNETES_POD_KIND_LABEL_VALUE);

    final Pod pod = mock(Pod.class);
    final ObjectMeta objectMeta = mock(ObjectMeta.class);
    when(pod.getMetadata()).thenReturn(objectMeta);
    when(objectMeta.getLabels()).thenReturn(labels);
    when(objectMeta.getName()).thenReturn("test-agent");
    when(podList.getItems()).thenReturn(Arrays.asList(pod));
    when(mockKubernetesInstanceFactory.fromKubernetesPod(pod)).thenReturn(kubernetesInstance);

    //second create agent request
    agentInstances.create(mockCreateAgentRequest, mockPluginSettings, mockPluginRequest, consoleLogAppender);
    verify(mockKubernetesInstanceFactory, times(0)).create(any(), any(), any(), any());
}
 
Example #19
Source File: K8sNamespaceManagerTest.java    From onos with Apache License 2.0 5 votes vote down vote up
private static Namespace createK8sNamespace(String uid, String name) {
    ObjectMeta meta = new ObjectMeta();
    meta.setUid(uid);
    meta.setName(name);

    Namespace namespace = new Namespace();
    namespace.setApiVersion("v1");
    namespace.setKind("Namespace");
    namespace.setMetadata(meta);

    return namespace;
}
 
Example #20
Source File: AddImagePullSecretDecorator.java    From dekorate with Apache License 2.0 5 votes vote down vote up
public void andThenVisit(PodSpecFluent<?> podSpec, ObjectMeta resourceMeta) {
  if (Strings.isNotNullOrEmpty(imagePullSecret) && !podSpec.hasMatchingImagePullSecret(r -> imagePullSecret.equals(r.getName()))) {
     podSpec.addNewImagePullSecret()
       .withName(imagePullSecret)
     .endImagePullSecret();
  }
}
 
Example #21
Source File: ReflectUtilsTest.java    From kubernetes-client with Apache License 2.0 5 votes vote down vote up
@Test
public void testInstanceOf() throws ReflectiveOperationException {
  ObjectMeta meta = new ObjectMeta();
  Baz baz = new Baz();
  baz.setMetadata(meta);
  assertSame(meta, ReflectUtils.objectMetadata(baz));
}
 
Example #22
Source File: OpenShiftPreviewUrlExposerTest.java    From che with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void shouldNotProvisionWhenServiceAndRouteFound() throws InternalInfrastructureException {
  final int PORT = 8080;
  final String SERVER_PORT_NAME = "server-" + PORT;

  CommandImpl command =
      new CommandImpl("a", "a", "a", new PreviewUrlImpl(PORT, null), Collections.emptyMap());

  Service service = new Service();
  ObjectMeta serviceMeta = new ObjectMeta();
  serviceMeta.setName("servicename");
  service.setMetadata(serviceMeta);
  ServiceSpec serviceSpec = new ServiceSpec();
  serviceSpec.setPorts(
      singletonList(new ServicePort(SERVER_PORT_NAME, null, PORT, "TCP", new IntOrString(PORT))));
  service.setSpec(serviceSpec);

  Route route = new Route();
  RouteSpec routeSpec = new RouteSpec();
  routeSpec.setPort(new RoutePort(new IntOrString(SERVER_PORT_NAME)));
  routeSpec.setTo(new RouteTargetReference("routekind", "servicename", 1));
  route.setSpec(routeSpec);

  Map<String, Service> services = new HashMap<>();
  services.put("servicename", service);
  Map<String, Route> routes = new HashMap<>();
  routes.put("routename", route);

  OpenShiftEnvironment env =
      OpenShiftEnvironment.builder()
          .setCommands(singletonList(new CommandImpl(command)))
          .setServices(services)
          .setRoutes(routes)
          .build();

  assertEquals(env.getRoutes().size(), 1);
  previewUrlEndpointsProvisioner.expose(env);
  assertEquals(env.getRoutes().size(), 1);
}
 
Example #23
Source File: EndpointPathDecorator.java    From dekorate with Apache License 2.0 5 votes vote down vote up
@Override
public void andThenVisit(ServiceMonitorBuilder serviceMonitor, ObjectMeta resourceMeta) {
    serviceMonitor.accept(new TypedVisitor<EndpointBuilder>() {
      @Override
      public void visit(EndpointBuilder endpoint) {
       if (port.equals(endpoint.getPort())) {
         endpoint.withPath(path);
       }
      }
    });
}
 
Example #24
Source File: KubernetesHelper.java    From jkube with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Returns the resource version for the entity or null if it does not have one
 *
 * @param entity entity as HasMetadata object
 * @return resource version as string value
 */
public static String getResourceVersion(HasMetadata entity) {
    if (entity != null) {
        ObjectMeta metadata = entity.getMetadata();
        if (metadata != null) {
            String resourceVersion = metadata.getResourceVersion();
            if (StringUtils.isNotBlank(resourceVersion)) {
                return resourceVersion;
            }
        }
    }
    return null;
}
 
Example #25
Source File: KubernetesAppDeployerIntegrationTests.java    From spring-cloud-deployer-kubernetes with Apache License 2.0 5 votes vote down vote up
private Secret randomSecret() {
	Map<String, String> secretData = new HashMap<>();
	secretData.put("d-" + UUID.randomUUID().toString().substring(0, 5), "dmFsdWUx");
	secretData.put("d-" + UUID.randomUUID().toString().substring(0, 5), "dmFsdWUy");

	Secret secret = new Secret();
	secret.setData(secretData);

	ObjectMeta objectMeta = new ObjectMeta();
	objectMeta.setName("secret-" + UUID.randomUUID().toString().substring(0, 5));

	secret.setMetadata(objectMeta);

	return kubernetesClient.secrets().create(secret);
}
 
Example #26
Source File: KubernetesDeployments.java    From che with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Starts the specified Pod via a Deployment.
 *
 * @param pod pod to deploy
 * @return created pod
 * @throws InfrastructureException when any exception occurs
 */
public Pod deploy(Pod pod) throws InfrastructureException {
  putLabel(pod, CHE_WORKSPACE_ID_LABEL, workspaceId);
  // Since we use the pod's metadata as the deployment's metadata
  // This is used to identify the pod in CreateWatcher.
  String originalName = pod.getMetadata().getName();
  putLabel(pod, CHE_DEPLOYMENT_NAME_LABEL, originalName);

  ObjectMeta metadata = pod.getMetadata();
  PodSpec podSpec = pod.getSpec();
  podSpec.setRestartPolicy("Always"); // Only allowable value

  Deployment deployment =
      new DeploymentBuilder()
          .withMetadata(metadata)
          .withNewSpec()
          .withNewSelector()
          .withMatchLabels(metadata.getLabels())
          .endSelector()
          .withReplicas(1)
          .withNewTemplate()
          .withMetadata(metadata)
          .withSpec(podSpec)
          .endTemplate()
          .endSpec()
          .build();
  return createDeployment(deployment, workspaceId);
}
 
Example #27
Source File: AppService.java    From jhipster-operator with Apache License 2.0 5 votes vote down vote up
public <T extends CustomService> T owns(Application application, T service) {

        if (application != null) {
            //Set OwnerReferences: the Application Owns the MicroService
            List<OwnerReference> ownerReferencesFromApp = createOwnerReferencesFromApp(application);
            ObjectMeta objectMetaMicroService = service.getMetadata();
            objectMetaMicroService.setOwnerReferences(ownerReferencesFromApp);
            service.setMetadata(objectMetaMicroService);


        }

        return service;
    }
 
Example #28
Source File: TillerInstaller.java    From microbean-helm with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #29
Source File: AddDockerImageStreamResourceDecorator.java    From dekorate with Apache License 2.0 5 votes vote down vote up
public void visit(KubernetesListBuilder list) {
  ObjectMeta meta = getMandatoryDeploymentMetadata(list);

  list.addToItems(new ImageStreamBuilder()
    .withNewMetadata()
      .withName(config.getName())
    .withLabels(meta.getLabels())
    .endMetadata()
    .withNewSpec()
      .withDockerImageRepository(dockerImageRepository)
    .endSpec());
}
 
Example #30
Source File: AddOutputImageStreamResourceDecorator.java    From dekorate with Apache License 2.0 5 votes vote down vote up
public void visit(KubernetesListBuilder list) {
  ObjectMeta meta = getMandatoryDeploymentMetadata(list);

  list.addToItems(new ImageStreamBuilder()
    .withNewMetadata()
    .withName(config.getName())
    .withLabels(meta.getLabels())
    .endMetadata()
    .withNewSpec()
    .endSpec());
}