Skip to content
Permalink
Browse files

feat: first draft.

  • Loading branch information...
iocanel committed Nov 15, 2018
1 parent 450dd61 commit d3487201168715c175a3cdb2de21ec21c4ebffeb
Showing with 6,527 additions and 0 deletions.
  1. +7 −0 .editorconfig
  2. +80 −0 .gitignore
  3. +43 −0 annotations/istio-annotations/pom.xml
  4. +65 −0 annotations/istio-annotations/src/main/java/io/ap4k/istio/Istio.java
  5. +113 −0 annotations/istio-annotations/src/main/java/io/ap4k/istio/IstioGenerator.java
  6. +53 −0 annotations/istio-annotations/src/main/java/io/ap4k/istio/IstioProxy.java
  7. +23 −0 annotations/istio-annotations/src/main/java/io/ap4k/istio/annotation/Istio.java
  8. +111 −0 annotations/istio-annotations/src/main/java/io/ap4k/istio/annotation/ProxyConfig.java
  9. +47 −0 annotations/istio-annotations/src/main/java/io/ap4k/istio/processor/IstioAnnotationProcessor.java
  10. +1 −0 ...ions/istio-annotations/src/main/resources/META-INF/services/javax.annotation.processing.Processor
  11. +71 −0 annotations/kubernetes-annotations/pom.xml
  12. +24 −0 annotations/kubernetes-annotations/src/main/java/io/ap4k/kubernetes/KubernetesGenerator.java
  13. +102 −0 annotations/kubernetes-annotations/src/main/java/io/ap4k/kubernetes/KubernetesResources.java
  14. +48 −0 ...ernetes-annotations/src/main/java/io/ap4k/kubernetes/processor/KubernetesAnnotationProcessor.java
  15. +1 −0 ...kubernetes-annotations/src/main/resources/META-INF/services/javax.annotation.processing.Processor
  16. +2 −0 annotations/openshift-annotations/build.sh
  17. +76 −0 annotations/openshift-annotations/pom.xml
  18. +17 −0 annotations/openshift-annotations/src/main/java/io/ap4k/openshift/Constants.java
  19. +31 −0 annotations/openshift-annotations/src/main/java/io/ap4k/openshift/OpenshiftGenerator.java
  20. +218 −0 annotations/openshift-annotations/src/main/java/io/ap4k/openshift/OpenshiftResources.java
  21. +154 −0 ...ations/openshift-annotations/src/main/java/io/ap4k/openshift/annotation/OpenshiftApplication.java
  22. +31 −0 annotations/openshift-annotations/src/main/java/io/ap4k/openshift/annotation/SourceToImage.java
  23. +100 −0 ...openshift-annotations/src/main/java/io/ap4k/openshift/processor/OpenshiftAnnotationProcessor.java
  24. +21 −0 ...tions/openshift-annotations/src/main/java/io/ap4k/openshift/visitor/ApplySourceToImageConfig.java
  25. +1 −0 .../openshift-annotations/src/main/resources/META-INF/services/javax.annotation.processing.Processor
  26. +18 −0 annotations/openshift-annotations/src/test/java/io/ap4k/openshift/config/OpenshiftConfigTest.java
  27. +24 −0 annotations/pom.xml
  28. +51 −0 annotations/servicecatalog-annotations/pom.xml
  29. +4 −0 annotations/servicecatalog-annotations/src/main/java/io/ap4k/servicecatalog/Constants.java
  30. +67 −0 ...ions/servicecatalog-annotations/src/main/java/io/ap4k/servicecatalog/ServiceCatalogGenerator.java
  31. +31 −0 ...tations/servicecatalog-annotations/src/main/java/io/ap4k/servicecatalog/annotation/Parameter.java
  32. +30 −0 ...ns/servicecatalog-annotations/src/main/java/io/ap4k/servicecatalog/annotation/ServiceCatalog.java
  33. +71 −0 ...cecatalog-annotations/src/main/java/io/ap4k/servicecatalog/annotation/ServiceCatalogInstance.java
  34. +25 −0 .../servicecatalog-annotations/src/main/java/io/ap4k/servicecatalog/config/ServiceCatalogConfig.java
  35. +24 −0 ...ecatalog-annotations/src/main/java/io/ap4k/servicecatalog/config/ServiceCatalogConfigAdapter.java
  36. +47 −0 ...annotations/src/main/java/io/ap4k/servicecatalog/processor/ServiceCatalogAnnotationProcessor.java
  37. +1 −0 ...icecatalog-annotations/src/main/resources/META-INF/services/javax.annotation.processing.Processor
  38. +80 −0 core/pom.xml
  39. +103 −0 core/src/main/java/io/ap4k/AbstractKubernetesGenerator.java
  40. +5 −0 core/src/main/java/io/ap4k/Ap4k.java
  41. +39 −0 core/src/main/java/io/ap4k/Configurations.java
  42. +15 −0 core/src/main/java/io/ap4k/Generator.java
  43. +105 −0 core/src/main/java/io/ap4k/Resources.java
  44. +93 −0 core/src/main/java/io/ap4k/Session.java
  45. +23 −0 core/src/main/java/io/ap4k/annotation/Annotation.java
  46. +27 −0 core/src/main/java/io/ap4k/annotation/AwsElasticBlockStoreVolume.java
  47. +31 −0 core/src/main/java/io/ap4k/annotation/AzureDiskVolume.java
  48. +20 −0 core/src/main/java/io/ap4k/annotation/AzureFileVolume.java
  49. +30 −0 core/src/main/java/io/ap4k/annotation/ConfigMapVolume.java
  50. +27 −0 core/src/main/java/io/ap4k/annotation/Env.java
  51. +29 −0 core/src/main/java/io/ap4k/annotation/GitRepoVolume.java
  52. +24 −0 core/src/main/java/io/ap4k/annotation/ImagePullPolicy.java
  53. +143 −0 core/src/main/java/io/ap4k/annotation/KubernetesApplication.java
  54. +23 −0 core/src/main/java/io/ap4k/annotation/Label.java
  55. +28 −0 core/src/main/java/io/ap4k/annotation/Mount.java
  56. +22 −0 core/src/main/java/io/ap4k/annotation/PersistentVolumeClaimVolume.java
  57. +43 −0 core/src/main/java/io/ap4k/annotation/Port.java
  58. +59 −0 core/src/main/java/io/ap4k/annotation/Probe.java
  59. +30 −0 core/src/main/java/io/ap4k/annotation/SecretVolume.java
  60. +26 −0 core/src/main/java/io/ap4k/annotation/ServiceType.java
  61. +47 −0 core/src/main/java/io/ap4k/config/ConfigKey.java
  62. +72 −0 core/src/main/java/io/ap4k/config/Configuration.java
  63. +48 −0 core/src/main/java/io/ap4k/config/ConfigurationSupplier.java
  64. +71 −0 core/src/main/java/io/ap4k/config/visitors/AddPortToConfig.java
  65. +99 −0 core/src/main/java/io/ap4k/processor/AbstractAnnotationProcessor.java
  66. +28 −0 core/src/main/java/io/ap4k/project/ApplyProjectInfo.java
  67. +42 −0 core/src/main/java/io/ap4k/project/BazelInfo.java
  68. +40 −0 core/src/main/java/io/ap4k/project/BazelInfoReader.java
  69. +52 −0 core/src/main/java/io/ap4k/project/BuildInfo.java
  70. +46 −0 core/src/main/java/io/ap4k/project/BuildInfoReader.java
  71. +41 −0 core/src/main/java/io/ap4k/project/GenericInfo.java
  72. +40 −0 core/src/main/java/io/ap4k/project/GenericReader.java
  73. +41 −0 core/src/main/java/io/ap4k/project/GradleBuildInfo.java
  74. +40 −0 core/src/main/java/io/ap4k/project/GradleInfoReader.java
  75. +41 −0 core/src/main/java/io/ap4k/project/LeiningenBuildInfo.java
  76. +40 −0 core/src/main/java/io/ap4k/project/LeiningenInfoReader.java
  77. +151 −0 core/src/main/java/io/ap4k/project/MavenInfo.java
  78. +63 −0 core/src/main/java/io/ap4k/project/MavenInfoReader.java
  79. +39 −0 core/src/main/java/io/ap4k/project/Project.java
  80. +90 −0 core/src/main/java/io/ap4k/project/ProjectFactory.java
  81. +41 −0 core/src/main/java/io/ap4k/project/SbtBuildInfo.java
  82. +40 −0 core/src/main/java/io/ap4k/project/SbtInfoReader.java
  83. +74 −0 core/src/main/java/io/ap4k/utils/Images.java
  84. +51 −0 core/src/main/java/io/ap4k/utils/Labels.java
  85. +54 −0 core/src/main/java/io/ap4k/utils/Strings.java
  86. +92 −0 core/src/main/java/io/ap4k/visitor/AbstractAddProbe.java
  87. +55 −0 core/src/main/java/io/ap4k/visitor/AddAnnotation.java
  88. +27 −0 core/src/main/java/io/ap4k/visitor/AddAwsElasticBlockStoreVolume.java
  89. +30 −0 core/src/main/java/io/ap4k/visitor/AddAzureDiskVolume.java
  90. +27 −0 core/src/main/java/io/ap4k/visitor/AddAzureFileVolume.java
  91. +27 −0 core/src/main/java/io/ap4k/visitor/AddConfigMapVolume.java
  92. +110 −0 core/src/main/java/io/ap4k/visitor/AddEnvVar.java
  93. +55 −0 core/src/main/java/io/ap4k/visitor/AddLabel.java
  94. +33 −0 core/src/main/java/io/ap4k/visitor/AddLivenessProbe.java
  95. +26 −0 core/src/main/java/io/ap4k/visitor/AddMount.java
  96. +60 −0 core/src/main/java/io/ap4k/visitor/AddPort.java
  97. +25 −0 core/src/main/java/io/ap4k/visitor/AddPvcVolume.java
  98. +33 −0 core/src/main/java/io/ap4k/visitor/AddReadinessProbe.java
  99. +27 −0 core/src/main/java/io/ap4k/visitor/AddSecretVolume.java
  100. +59 −0 core/src/main/java/io/ap4k/visitor/AddService.java
  101. +46 −0 core/src/main/java/io/ap4k/visitor/ContainerVisitor.java
  102. +26 −0 core/src/main/java/io/ap4k/visitor/FluentVisitor.java
  103. +37 −0 core/src/main/java/io/ap4k/visitor/VolumeMountVisitor.java
  104. +36 −0 core/src/main/java/io/ap4k/visitor/VolumeVisitor.java
  105. +4 −0 core/src/main/resources/META-INF/services/io.ap4k.project.BuildInfoReader
  106. +38 −0 core/src/main/resources/templates/fluent-visitor.vm
  107. +31 −0 core/src/test/java/io/ap4k/visitor/AddAnnotationTest.java
  108. +28 −0 core/src/test/java/io/ap4k/visitor/AddVolumeTest.java
  109. +28 −0 examples/istio-example/pom.xml
  110. +26 −0 examples/istio-example/src/main/java/io/ap4k/examples/istio/Main.java
  111. +4 −0 examples/kubernetes-example/Dockerfile
  112. +56 −0 examples/kubernetes-example/pom.xml
  113. +47 −0 examples/kubernetes-example/readme.md
  114. +13 −0 examples/kubernetes-example/src/main/java/io/ap4k/examples/kubernetes/Controller.java
  115. +35 −0 examples/kubernetes-example/src/main/java/io/ap4k/examples/kubernetes/Main.java
  116. +4 −0 examples/openshift-example/Dockerfile
  117. +7 −0 examples/openshift-example/build.sh
  118. +63 −0 examples/openshift-example/pom.xml
  119. +14 −0 examples/openshift-example/readme.md
  120. +13 −0 examples/openshift-example/src/main/java/io/ap4k/examples/openshift/Controller.java
  121. +33 −0 examples/openshift-example/src/main/java/io/ap4k/examples/openshift/Main.java
  122. +26 −0 examples/pom.xml
  123. +36 −0 examples/service-catalog-example/pom.xml
  124. +2 −0 examples/service-catalog-example/service-catalog-example.iml
  125. +29 −0 examples/service-catalog-example/src/main/java/io/ap4k/examples/svcat/Main.java
  126. +58 −0 examples/spring-boot-on-kubernetes-example/pom.xml
  127. +13 −0 ...es/spring-boot-on-kubernetes-example/src/main/java/io/ap4k/example/sbonkubernetes/Controller.java
  128. +35 −0 examples/spring-boot-on-kubernetes-example/src/main/java/io/ap4k/example/sbonkubernetes/Main.java
  129. +71 −0 frameworks/micronaut/pom.xml
  130. +49 −0 frameworks/micronaut/src/main/java/io/ap4k/micronaut/MicronautProcessor.java
  131. +1 −0 frameworks/micronaut/src/main/resources/META-INF/services/javax.annotation.processing.Processor
  132. +22 −0 frameworks/pom.xml
  133. +71 −0 frameworks/spring-boot/pom.xml
  134. +49 −0 frameworks/spring-boot/src/main/java/io/ap4k/spring/SpringBootProcessor.java
  135. +1 −0 frameworks/spring-boot/src/main/resources/META-INF/services/javax.annotation.processing.Processor
  136. +12 −0 frameworks/spring-boot/src/test/java/io/ap4k/spring/SpringBootTest.java
  137. +72 −0 frameworks/thorntail/pom.xml
  138. +49 −0 frameworks/thorntail/src/main/java/io/ap4k/thorntail/ThrorntailProcessor.java
  139. +1 −0 frameworks/thorntail/src/main/resources/META-INF/services/javax.annotation.processing.Processor
  140. +13 −0 header.txt
  141. +110 −0 pom.xml
  142. +283 −0 readme.md
@@ -0,0 +1,7 @@
root = true

[*]
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 2
@@ -0,0 +1,80 @@
# Created by .ignore support plugin (hsz.mobi)
### Maven template
target/
pom.xml.tag
pom.xml.releaseBackup
pom.xml.versionsBackup
pom.xml.next
release.properties
dependency-reduced-pom.xml
buildNumber.properties
.mvn/timing.properties

# Eclipse
.project
.settings/
.classpath

### Java template
*.class

# Package Files #
*.jar
*.war
*.ear

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*


### JetBrains template
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion

*.iml

## Directory-based project format:
.idea/
# if you remove the above rule, at least ignore the following:

# User-specific stuff:
# .idea/workspace.xml
# .idea/tasks.xml
# .idea/dictionaries

# Sensitive or high-churn files:
# .idea/dataSources.ids
# .idea/dataSources.xml
# .idea/sqlDataSources.xml
# .idea/dynamic.xml
# .idea/uiDesigner.xml

# Gradle:
# .idea/gradle.xml
# .idea/libraries

# Mongo Explorer plugin:
# .idea/mongoSettings.xml

## File-based project format:
*.ipr
*.iws

## Plugin-specific files:

# IntelliJ
/out/

# mpeltonen/sbt-idea plugin
.idea_modules/

# JIRA plugin
atlassian-ide-plugin.xml

# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties


# meghanada
.meghanada
@@ -0,0 +1,43 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>annotations</artifactId>
<groupId>io.ap4k</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<groupId>io.ap4k</groupId>
<artifactId>istio-annotations</artifactId>
<name>AP4K :: Annotations :: Istio</name>

<dependencies>
<dependency>
<groupId>io.ap4k</groupId>
<artifactId>ap4k-core</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>io.sundr</groupId>
<artifactId>builder-annotations</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>${version.maven-compiler-plugin}</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<annotationProcessors>
<processor>io.sundr.builder.internal.processor.BuildableProcessor</processor>
</annotationProcessors>
</configuration>
</plugin>
</plugins>
</build>
</project>
@@ -0,0 +1,65 @@
/**
* Copyright (C) 2018 Ioannis Canellos
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
**/
package io.ap4k.istio;

import io.ap4k.config.ConfigKey;
import io.ap4k.config.Configuration;
import io.ap4k.istio.annotation.ProxyConfig;

import java.util.HashMap;

public class Istio {

public static final ConfigKey<String> CLUSTER_NAME = new ConfigKey<>("CLUSTER_NAME", String.class);

public static final ConfigKey<Integer> V = new ConfigKey<>("V", Integer.class, 2);
public static final ConfigKey<String> CONFIG_PATH = new ConfigKey<>("CONFIG_PATH", String.class, "/etc/istio/proxy");
public static final ConfigKey<String> BINARY_PATH = new ConfigKey<>("BINARY_PATH", String.class, "/usr/local/bin/envoy");

public static final ConfigKey<String> DISCOVERY_ADDRESS = new ConfigKey<>("DISCOVERY_ADDRESS", String.class);
public static final ConfigKey<Long> DISCOVERY_REFRESH_DELAY = new ConfigKey<>("DISCOVERY_REFRESH_DELAY", Long.class, 1L);

public static final ConfigKey<String> ZIPKIN_ADDRESS = new ConfigKey<>("ZIPKIN_ADDRESS", String.class);
public static final ConfigKey<String> STATSD_UDP_ADDRESS = new ConfigKey<>("STATSD_UDP_ADDRESS", String.class);

public static final ConfigKey<Long> CONNECT_TIMEOUT = new ConfigKey<>("CONNECT_TIMEOUT", Long.class, 10L);
public static final ConfigKey<Long> PARENT_SHUTDOWN_DURATION = new ConfigKey<>("PARENT_SHUTDOWN_DURATION", Long.class, 1L);
public static final ConfigKey<Long> DRAIN_DURATION = new ConfigKey<>("DRAIN_DURATION", Long.class , 45L);

public static final ConfigKey<Integer> PROXY_ADMIN_PORT = new ConfigKey<>("PROXY_ADMIN_PORT", Integer.class, 15000);

public static final ConfigKey<String> CONTROL_PLANE_AUTH_POLICY = new ConfigKey<>("PROXY_ADMIN_PORT", String.class);

public static final ConfigKey<String> ISTIO_VERSION = new ConfigKey<>("ISTIO_VERSION", String.class);

public static Configuration read(ProxyConfig proxyConfig) {
Configuration result = new Configuration(null, new HashMap<>());
result.put(CLUSTER_NAME, proxyConfig.serviceCluster());
result.put(CONFIG_PATH, proxyConfig.configPath());
result.put(BINARY_PATH, proxyConfig.binaryPath());
result.put(DISCOVERY_ADDRESS, proxyConfig.discoveryAddress());
result.put(ZIPKIN_ADDRESS, proxyConfig.zipkinAddress());
result.put(STATSD_UDP_ADDRESS, proxyConfig.statsdUdpAddress());
result.put(DRAIN_DURATION, proxyConfig.drainDuration());
result.put(PARENT_SHUTDOWN_DURATION, proxyConfig.parentShutdownDuration());
result.put(PROXY_ADMIN_PORT, proxyConfig.proxyAdminPort());
result.put(CONTROL_PLANE_AUTH_POLICY, proxyConfig.controlPlaneAuthPolicy());
return result;
}

}
@@ -0,0 +1,113 @@
package io.ap4k.istio;

import io.ap4k.Generator;
import io.ap4k.Resources;
import io.ap4k.annotation.ImagePullPolicy;
import io.ap4k.istio.config.IstioConfig;
import io.ap4k.visitor.ContainerVisitor;
import io.ap4k.visitor.VolumeMountVisitor;
import io.ap4k.visitor.VolumeVisitor;
import io.fabric8.kubernetes.api.builder.TypedVisitor;
import io.fabric8.kubernetes.api.model.PodSpecBuilder;

public class IstioGenerator implements Generator<IstioConfig> {

private static final String DEV_TERMINATION_LOG = "/dev/termination-log";
private static final String FILE = "File";

private static final String ISTIO_PROXY = "istio-proxy";
private static final Long ISTIO_PROXY_USER = 1337L;

private static final String ISTIO_SYSTEM = "istio-system";

private static final String ISTIO_INIT = "istio-init";
private static final String[] ISTIO_INIT_ARGS = {"-p", "15001", "-u", "1337"};

private static final String ENABLE_CORE_DUMP = "enable-core-dump";
private static final String[] CORE_DUMP_ARGS = {"-c", "sysctl -w kernel.core_pattern=/etc/istio/proxy/core.%e.%p.%t && ulimit -c unlimited"};


private static final String POD_NAME = "POD_NAME";
private static final String POD_NAMESPACE = "POD_NAMESPACE";
private static final String INSTANCE_IP = "INSTANCE_IP";

private static final String METADATA_NAME = "metadata.name";
private static final String METADATA_NAMESPACE = "metadata.namespace";
private static final String STATUS_PODIP = "status.podIp";

private final Resources resources;

public IstioGenerator(Resources resources) {
this.resources = resources;
}

@Override
public void generate(IstioConfig config) {
//Containers
resources.accept(createIstioInit(config));
resources.accept(createIstioProxy(config));
//Volumes
resources.accept(VolumeVisitor.createNew()
.withName("istio-envoy")
.withNewEmptyDir()
.withMedium("Memory")
.endEmptyDir());
resources.accept(VolumeVisitor.createNew()
.withName("istio-certs")
.withNewSecret()
.withSecretName("istio.default")
.withDefaultMode(420)
.endSecret());
//Mounts
resources.accept(VolumeMountVisitor.createNew()
.withName("istio-envoy")
.withMountPath("/etc/istio/proxy"));
resources.accept(VolumeMountVisitor.createNew()
.withName("istio-certs")
.withMountPath("/etc/certs"));
}

@Override
public Class<? extends IstioConfig> getType() {
return IstioConfig.class;
}


/**
* Create a visitor that adds an istio proxy container to all pods.
* @param config The istio config.
* @return A visitor that adds the init container.
*/
private TypedVisitor<PodSpecBuilder> createIstioProxy(IstioConfig config) {
return ContainerVisitor.createNew()
.withName(ISTIO_PROXY)
.withImage(config.getProxyConfig().getProxyImage())
.withArgs(IstioProxy.getArguments(config))
.withTerminationMessagePath(DEV_TERMINATION_LOG)
.addNewEnv().withName(POD_NAME).withNewValueFrom().withNewFieldRef(null, METADATA_NAME).endValueFrom().endEnv()
.addNewEnv().withName(POD_NAMESPACE).withNewValueFrom().withNewFieldRef(null, METADATA_NAMESPACE).endValueFrom().endEnv()
.addNewEnv().withName(INSTANCE_IP).withNewValueFrom().withNewFieldRef(null, STATUS_PODIP).endValueFrom().endEnv()
.withNewSecurityContext()
.withPrivileged(true)
.withRunAsUser(ISTIO_PROXY_USER)
.withReadOnlyRootFilesystem(false)
.endSecurityContext()
.done();
}

/**
* Create a visitor that adds an istio init container to all pods.
* @param config The istio config.
* @return A visitor that adds the init container.
*/
private TypedVisitor<PodSpecBuilder> createIstioInit(IstioConfig config) {
return ContainerVisitor.createNewInit()
.withName(ISTIO_INIT)
.withImage(config.getProxyConfig().getInitImage())
.withImagePullPolicy(ImagePullPolicy.IfNotPresent.name())
.withTerminationMessagePath(DEV_TERMINATION_LOG)
.withTerminationMessagePolicy(FILE)
.withArgs("-p", "15001", "-u", "1337")
.done();
}
}
@@ -0,0 +1,53 @@
package io.ap4k.istio;

import io.ap4k.istio.config.IstioConfig;
import io.ap4k.utils.Strings;

import java.util.ArrayList;
import java.util.List;

public class IstioProxy {

/**
* Get the istio proxy arguments for the specified configuration.
* @param config The istio config.
* @return An array containing all arguments.
*/
public static String[] getArguments(IstioConfig config) {
List<String> result = new ArrayList<>();
if (Strings.isNotNullOrEmpty(config.getProxyConfig().getServiceCluster())) {
result.add(String.format("--serviceCluster %s", config.getProxyConfig().getServiceCluster()));
}
if (Strings.isNotNullOrEmpty(config.getProxyConfig().getConfigPath())) {
result.add(String.format("--configPath %s", config.getProxyConfig().getConfigPath()));
}
if (Strings.isNotNullOrEmpty(config.getProxyConfig().getBinaryPath())) {
result.add(String.format("--binaryPath %s", config.getProxyConfig().getBinaryPath()));
}
if (Strings.isNotNullOrEmpty(config.getProxyConfig().getDiscoveryAddress())) {
result.add(String.format("--discoveryAddress %s", config.getProxyConfig().getDiscoveryAddress()));
}
if (config.getProxyConfig().getDiscoveryRefershDelay() > 0) {
result.add(String.format("--discoveryRefreshDelay %sm0s", config.getProxyConfig().getDiscoveryRefershDelay()));
}
if (Strings.isNotNullOrEmpty(config.getProxyConfig().getZipkinAddress())) {
result.add(String.format("--zipkinAddress %s", config.getProxyConfig().getZipkinAddress()));
}
if (config.getProxyConfig().getParentShutdownDuration() > 0) {
result.add(String.format("--parentShutdownDuration %sm0s", config.getProxyConfig().getParentShutdownDuration()));
}
if (config.getProxyConfig().getDrainDuration() > 0) {
result.add(String.format("--drainDuration %sm0s", config.getProxyConfig().getDrainDuration()));
}
if (config.getProxyConfig().getConnectTimeout() > 0) {
result.add(String.format("--connectTimeout %sm0s", config.getProxyConfig().getConnectTimeout()));
}
if (config.getProxyConfig().getParentShutdownDuration() > 0) {
result.add(String.format("--parentShutdownDuration %sm0s", config.getProxyConfig().getParentShutdownDuration()));
}
if (Strings.isNotNullOrEmpty(config.getProxyConfig().getControlPlaneAuthPolicy())) {
result.add(String.format("--controlPlaneAuthPolicy %s", config.getProxyConfig().getControlPlaneAuthPolicy()));
}
return result.toArray(new String[result.size()]);
}
}
@@ -0,0 +1,23 @@
package io.ap4k.istio.annotation;

import io.ap4k.config.Configuration;
import io.sundr.builder.annotations.Adapter;
import io.sundr.builder.annotations.Buildable;
import io.sundr.builder.annotations.Pojo;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;


@Buildable(builderPackage = "io.fabric8.kubernetes.api.builder")
@Pojo(name = "IstioConfig", superClass = Configuration.class, relativePath = "../config", withStaticAdapterMethod = false, adapter = @Adapter(relativePath = "../adapt"))
@Target({ElementType.CONSTRUCTOR, ElementType.TYPE})
@Retention(RetentionPolicy.SOURCE)
public @interface Istio {

String version() default "1.0.0";

ProxyConfig proxyConfig() default @ProxyConfig();
}

0 comments on commit d348720

Please sign in to comment.
You can’t perform that action at this time.