Advertisement
frenky666

single statement

Jun 29th, 2022
707
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.88 KB | None | 0 0
  1.     kubernetesClient.apps().deployments()
  2.         .inNamespace(resource.getMetadata().getNamespace())
  3.         .createOrReplace(
  4.             new DeploymentBuilder()
  5.                 .withNewMetadata()
  6.                 .addToLabels(APP_NAME, name)
  7.                 .addToLabels(APP_INSTANCE, properties.getInstance())
  8.                 .addToLabels(APP_VERSION, properties.getVersion())
  9.                 .addToLabels(APP_MANAGED, "deus-operator")
  10.                 .endMetadata()
  11.  
  12.                 .withSpec(
  13.                     new DeploymentSpecBuilder()
  14.                         .withReplicas(resource.getSpec().getReplicas())
  15.                         .withNewSelector()
  16.                         .addToMatchLabels(APP_NAME, name)
  17.                         .addToMatchLabels(APP_INSTANCE, properties.getInstance())
  18.                         .endSelector()
  19.  
  20.                         .withTemplate(
  21.                             new PodTemplateSpecBuilder()
  22.                                 .withNewMetadata()
  23.                                 .addToLabels(APP_NAME, name)
  24.                                 .addToLabels(APP_INSTANCE, properties.getInstance())
  25.                                 .endMetadata()
  26.  
  27.                                 .withSpec(
  28.                                     new PodSpecBuilder()
  29.                                         // .withAffinity() // TODO
  30.  
  31.                                         .withContainers(
  32.                                             new ContainerBuilder()
  33.                                                 .withName(name)
  34.                                                 .withImage(Optional.ofNullable(properties.getRepository())
  35.                                                     .filter(StringUtils::isNotBlank)
  36.                                                     .map(s -> s + "/")
  37.                                                     .orElse("") + "deus/apache-iframe:" + properties.getImageVersion())
  38.                                                 .withPorts(
  39.                                                     new ContainerPortBuilder()
  40.                                                         .withName("apache-http")
  41.                                                         .withContainerPort(80)
  42.                                                         .build())
  43.                                                 .withVolumeMounts(
  44.                                                     add(
  45.                                                         resource.getSpec().getUrls().stream()
  46.                                                             .filter(urlDefinition ->
  47.                                                                 StringUtils.isNotBlank(urlDefinition.getName()))
  48.                                                             .filter(urlDefinition ->
  49.                                                                 NAME_PATTERN.matcher(urlDefinition.getName()).matches())
  50.                                                             .map(urlDefinition ->
  51.                                                                 new VolumeMountBuilder()
  52.                                                                     .withName(urlDefinition.getName())
  53.                                                                     .withMountPath("/usr/local/apache2/conf.d/" + urlDefinition.getName() + ".conf")
  54.                                                                     .withSubPath(urlDefinition.getName() + ".conf")
  55.                                                                     .build())
  56.                                                             .collect(Collectors.toList()),
  57.                                                         new VolumeMountBuilder()
  58.                                                             .withName("timezone")
  59.                                                             .withMountPath("/etc/localtime")
  60.                                                             .build())
  61.  
  62.                                                 )
  63.                                                 .build())
  64.  
  65.                                         .withVolumes(
  66.                                             add(
  67.                                                 resource.getSpec().getUrls().stream()
  68.                                                     .filter(urlDefinition ->
  69.                                                         StringUtils.isNotBlank(urlDefinition.getName()))
  70.                                                     .filter(urlDefinition ->
  71.                                                         NAME_PATTERN.matcher(urlDefinition.getName()).matches())
  72.                                                     .map(urlDefinition ->
  73.                                                         new VolumeBuilder()
  74.                                                             .withName(urlDefinition.getName())
  75.                                                             .withNewConfigMap()
  76.                                                             .withName(urlDefinition.getName())
  77.                                                             .addNewItem(urlDefinition.getName(), null, urlDefinition.getName() + ".conf")
  78.                                                             .endConfigMap()
  79.                                                             .build())
  80.                                                     .collect(Collectors.toList()),
  81.                                                 new VolumeBuilder()
  82.                                                     .withName("timezone")
  83.                                                     .withNewHostPath("/usr/share/zoneinfo/" + properties.getTimeZone(), null)
  84.                                                     .build())
  85.  
  86.                                         )
  87.                                         .build())
  88.                                 .build())
  89.                         .build())
  90.  
  91.                 .build());
  92.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement