Search in sources :

Example 1 with ResourceConfig

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());
}
Also used : ResourceConfig(org.eclipse.jkube.kit.config.resource.ResourceConfig) Test(org.junit.Test)

Example 2 with ResourceConfig

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");
}
Also used : ResourceConfig(org.eclipse.jkube.kit.config.resource.ResourceConfig) Test(org.junit.Test)

Example 3 with ResourceConfig

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
}
Also used : Expectations(mockit.Expectations) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) Pod(io.fabric8.kubernetes.api.model.Pod) ConfigMapBuilder(io.fabric8.kubernetes.api.model.ConfigMapBuilder) PodBuilder(io.fabric8.kubernetes.api.model.PodBuilder) Service(io.fabric8.kubernetes.api.model.Service) ResourceConfig(org.eclipse.jkube.kit.config.resource.ResourceConfig) Verifications(mockit.Verifications) Test(org.junit.Test)

Example 4 with ResourceConfig

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);
    }
}
Also used : ResourceUtil(org.eclipse.jkube.kit.common.util.ResourceUtil) Inject(javax.inject.Inject) List(java.util.List) KubernetesExtension(org.eclipse.jkube.gradle.plugin.KubernetesExtension) ResourceConfig(org.eclipse.jkube.kit.config.resource.ResourceConfig) Optional(java.util.Optional) IOException(java.io.IOException) File(java.io.File) ArrayList(java.util.ArrayList) ResourceConfig(org.eclipse.jkube.kit.config.resource.ResourceConfig) IOException(java.io.IOException) File(java.io.File)

Example 5 with ResourceConfig

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);
}
Also used : ServiceAccount(io.fabric8.kubernetes.api.model.ServiceAccount) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ServiceAccountConfig(org.eclipse.jkube.kit.config.resource.ServiceAccountConfig) ResourceConfig(org.eclipse.jkube.kit.config.resource.ResourceConfig) DeploymentBuilder(io.fabric8.kubernetes.api.model.apps.DeploymentBuilder)

Aggregations

ResourceConfig (org.eclipse.jkube.kit.config.resource.ResourceConfig)69 Test (org.junit.Test)60 KubernetesListBuilder (io.fabric8.kubernetes.api.model.KubernetesListBuilder)17 Properties (java.util.Properties)10 ImageConfiguration (org.eclipse.jkube.kit.config.image.ImageConfiguration)9 PodTemplateSpec (io.fabric8.kubernetes.api.model.PodTemplateSpec)7 VolumeConfig (org.eclipse.jkube.kit.config.resource.VolumeConfig)7 ArrayList (java.util.ArrayList)5 Expectations (mockit.Expectations)5 File (java.io.File)4 IngressRulePathResourceConfig (org.eclipse.jkube.kit.config.resource.IngressRulePathResourceConfig)4 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)3 Service (io.fabric8.kubernetes.api.model.Service)3 IOException (java.io.IOException)3 List (java.util.List)3 Optional (java.util.Optional)3 KitLogger (org.eclipse.jkube.kit.common.KitLogger)3 JKubeServiceHub (org.eclipse.jkube.kit.config.service.JKubeServiceHub)3 ConfigMapBuilder (io.fabric8.kubernetes.api.model.ConfigMapBuilder)2 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)2