use of org.eclipse.jkube.kit.config.resource.ResourceConfig in project jkube by eclipse.
the class KubernetesClientUtilTest method resolveFallbackNamespace_whenNamespaceProvidedViaResourceConfiguration_shouldReturnProvidedNamespace.
@Test
public void resolveFallbackNamespace_whenNamespaceProvidedViaResourceConfiguration_shouldReturnProvidedNamespace() {
// Given
ResourceConfig resourceConfig = ResourceConfig.builder().namespace("ns1").build();
// When
String resolvedNamespace = KubernetesClientUtil.resolveFallbackNamespace(resourceConfig, null);
// Then
assertThat(resolvedNamespace).isEqualTo(resourceConfig.getNamespace());
}
use of org.eclipse.jkube.kit.config.resource.ResourceConfig in project jkube by eclipse.
the class KubernetesClientUtilTest method applicableNamespace_whenNamespaceProvidedViaResourceConfiguration_shouldReturnProvidedNamespace.
@Test
public void applicableNamespace_whenNamespaceProvidedViaResourceConfiguration_shouldReturnProvidedNamespace() {
// Given
ResourceConfig resourceConfig = ResourceConfig.builder().namespace("ns1").build();
// When
String resolvedNamespace = KubernetesClientUtil.applicableNamespace(null, null, resourceConfig, null);
// Then
assertThat(resolvedNamespace).isEqualTo("ns1");
}
use of org.eclipse.jkube.kit.config.resource.ResourceConfig in project jkube by eclipse.
the class KubernetesUndeployServiceTest method undeployWithManifestShouldDeleteEntitiesInMultipleNamespaces.
@Test
public void undeployWithManifestShouldDeleteEntitiesInMultipleNamespaces(@Mocked File file) throws Exception {
// Given
final ResourceConfig resourceConfig = ResourceConfig.builder().build();
final ConfigMap configMap = new ConfigMapBuilder().withNewMetadata().withName("cm1").withNamespace("ns1").endMetadata().build();
final Pod pod = new PodBuilder().withNewMetadata().withName("MrPoddington").withNamespace("ns2").endMetadata().build();
final Service service = new Service();
// @formatter:off
new Expectations() {
{
file.exists();
result = true;
file.isFile();
result = true;
kubernetesHelper.loadResources(file);
result = Arrays.asList(configMap, pod, service);
kubernetesHelper.getNamespace(configMap);
result = "ns1";
kubernetesHelper.getNamespace(pod);
result = "ns2";
KubernetesHelper.getDefaultNamespace();
result = "default";
}
};
// @formatter:on
// When
kubernetesUndeployService.undeploy(null, resourceConfig, file);
// Then
// @formatter:off
new Verifications() {
{
kubernetesHelper.getKind((HasMetadata) any);
times = 3;
jKubeServiceHub.getClient().resource(pod).inNamespace("ns2").withPropagationPolicy(DeletionPropagation.BACKGROUND).delete();
times = 1;
jKubeServiceHub.getClient().resource(service).inNamespace("default").withPropagationPolicy(DeletionPropagation.BACKGROUND).delete();
times = 1;
jKubeServiceHub.getClient().resource(configMap).inNamespace("ns1").withPropagationPolicy(DeletionPropagation.BACKGROUND).delete();
times = 1;
}
};
// @formatter:on
}
use of org.eclipse.jkube.kit.config.resource.ResourceConfig in project jkube by eclipse.
the class KubernetesUndeployTask method run.
@Override
public void run() {
try {
ResourceConfig resources = ResourceConfig.toBuilder(kubernetesExtension.resources).namespace(Optional.ofNullable(kubernetesExtension.getNamespaceOrNull()).map(String::trim).filter(s -> !s.isEmpty()).orElse(null)).build();
final File environmentResourceDir = ResourceUtil.getFinalResourceDir(resolveResourceSourceDirectory(), kubernetesExtension.getResourceEnvironmentOrNull());
jKubeServiceHub.getUndeployService().undeploy(environmentResourceDir, resources, findManifestsToUndeploy().toArray(new File[0]));
} catch (IOException e) {
throw new IllegalStateException(e.getMessage(), e);
}
}
use of org.eclipse.jkube.kit.config.resource.ResourceConfig 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);
}
Aggregations