use of io.fabric8.kubernetes.api.model.extensions.DeploymentBuilder in project jkube by eclipse.
the class ServiceAccountEnricher method create.
@Override
public void create(PlatformMode mode, KubernetesListBuilder builder) {
Map<String, String> deploymentToSaPair = new HashMap<>();
List<ServiceAccount> serviceAccounts = new ArrayList<>();
// Check XML config and see if there are any service accounts specified
ResourceConfig xmlResourceConfig = getConfiguration().getResource();
if (xmlResourceConfig != null && xmlResourceConfig.getServiceAccounts() != null) {
for (ServiceAccountConfig serviceAccountConfig : xmlResourceConfig.getServiceAccounts()) {
if (serviceAccountConfig.getName() != null) {
serviceAccounts.add(createServiceAccount(builder, serviceAccountConfig.getName()));
}
if (serviceAccountConfig.getDeploymentRef() != null) {
deploymentToSaPair.put(serviceAccountConfig.getDeploymentRef(), serviceAccountConfig.getName());
}
}
}
// If any service account is referenced in deployment spec, then
// create sa on fly.
builder.accept(new TypedVisitor<DeploymentBuilder>() {
@Override
public void visit(DeploymentBuilder deploymentBuilder) {
String serviceAccountName = getServiceAccountNameFromSpec(deploymentBuilder);
if (serviceAccountName != null && getServiceAccountFromList(builder, serviceAccountName) == null) {
serviceAccounts.add(createServiceAccount(builder, serviceAccountName));
}
if (deploymentToSaPair.containsKey(deploymentBuilder.buildMetadata().getName())) {
deploymentBuilder.editSpec().editTemplate().editSpec().withServiceAccountName(deploymentToSaPair.get(deploymentBuilder.buildMetadata().getName())).endSpec().endTemplate().endSpec();
}
}
});
builder.addAllToServiceAccountItems(serviceAccounts);
}
use of io.fabric8.kubernetes.api.model.extensions.DeploymentBuilder in project jkube by eclipse.
the class ImageEnricherTest method checkEnrichDeployment.
@Test
public void checkEnrichDeployment() throws Exception {
KubernetesListBuilder builder = new KubernetesListBuilder().addToItems(new DeploymentBuilder().build());
imageEnricher.create(PlatformMode.kubernetes, builder);
assertCorrectlyGeneratedResources(builder.build(), "Deployment", "MY_KEY", "MY_VALUE");
}
use of io.fabric8.kubernetes.api.model.extensions.DeploymentBuilder in project jkube by eclipse.
the class ImageEnricherTest method create_whenEnvironmentVariableAbsent_thenAddsEnvironmentVariable.
@Test
public void create_whenEnvironmentVariableAbsent_thenAddsEnvironmentVariable() throws JsonProcessingException {
// Given
KubernetesListBuilder builder = new KubernetesListBuilder().addToItems(new DeploymentBuilder().build());
// When
imageEnricher.create(PlatformMode.kubernetes, builder);
// Then
assertCorrectlyGeneratedResources(builder.build(), "Deployment", "MY_KEY", "MY_VALUE");
}
use of io.fabric8.kubernetes.api.model.extensions.DeploymentBuilder in project jkube by eclipse.
the class MavenIssueManagementEnricherTest method testMavenIssueManagementOnlyUrl.
@Test
public void testMavenIssueManagementOnlyUrl() {
final JavaProject project = JavaProject.builder().build();
project.setIssueManagementUrl("https://github.com/fabric8org.eclipse.jkube-maven-plugin/issues/");
// Setup mock behaviour
new Expectations() {
{
{
context.getProject();
result = project;
}
}
};
MavenIssueManagementEnricher enricher = new MavenIssueManagementEnricher(context);
KubernetesListBuilder builder = new KubernetesListBuilder().withItems(new DeploymentBuilder().withNewMetadata().withName("foo").endMetadata().build());
enricher.create(PlatformMode.kubernetes, builder);
Map<String, String> scmAnnotations = builder.buildFirstItem().getMetadata().getAnnotations();
assertNotNull(scmAnnotations);
assertTrue(scmAnnotations.isEmpty());
}
use of io.fabric8.kubernetes.api.model.extensions.DeploymentBuilder in project jkube by eclipse.
the class MavenIssueManagementEnricherTest method testMavenIssueManagementAll.
@Test
public void testMavenIssueManagementAll() {
final JavaProject project = JavaProject.builder().build();
project.setIssueManagementUrl("https://github.com/reactiverse/vertx-maven-plugin/issues/");
project.setIssueManagementSystem("GitHub");
// Setup mock behaviour
new Expectations() {
{
{
context.getProject();
result = project;
}
}
};
MavenIssueManagementEnricher enricher = new MavenIssueManagementEnricher(context);
KubernetesListBuilder builder = new KubernetesListBuilder().withItems(new DeploymentBuilder().withNewMetadata().withName("foo").endMetadata().build());
enricher.create(PlatformMode.kubernetes, builder);
Map<String, String> scmAnnotations = builder.buildFirstItem().getMetadata().getAnnotations();
assertNotNull(scmAnnotations);
Assert.assertEquals(2, scmAnnotations.size());
assertEquals("GitHub", scmAnnotations.get(JKubeAnnotations.ISSUE_SYSTEM.value()));
assertEquals("https://github.com/reactiverse/vertx-maven-plugin/issues/", scmAnnotations.get(JKubeAnnotations.ISSUE_TRACKER_URL.value()));
}
Aggregations