Search in sources :

Example 11 with Logger

use of io.fabric8.maven.docker.util.Logger in project fabric8-maven-plugin by fabric8io.

the class ResourceValidatorTest method testValidKubernetesResourcesDirectory.

@Test
public void testValidKubernetesResourcesDirectory() throws IOException, URISyntaxException {
    // Given
    URL fileUrl = ResourceValidatorTest.class.getResource("/validations/kubernetes");
    // When
    ResourceValidator resourceValidator = new ResourceValidator(Paths.get(fileUrl.toURI()).toFile(), ResourceClassifier.KUBERNETES, logger);
    int resources = resourceValidator.validate();
    // Then
    Assert.assertEquals(2, resources);
}
Also used : ResourceValidator(io.fabric8.maven.core.util.validator.ResourceValidator) URL(java.net.URL) Test(org.junit.Test)

Example 12 with Logger

use of io.fabric8.maven.docker.util.Logger in project fabric8-maven-plugin by fabric8io.

the class ResourceValidatorTest method testInvalidKubernetesPodSpec.

@Test
public void testInvalidKubernetesPodSpec() throws IOException, URISyntaxException {
    // Given
    URL fileUrl = ResourceValidatorTest.class.getResource("/validations/kubernetes-deploy-invalid.yml");
    // When
    ResourceValidator resourceValidator = new ResourceValidator(Paths.get(fileUrl.toURI()).toFile(), ResourceClassifier.KUBERNETES, logger);
    // Then
    thrown.expect(ConstraintViolationException.class);
    thrown.expect(Matchers.hasProperty("constraintViolations", IsCollectionWithSize.hasSize(2)));
    // On
    resourceValidator.validate();
}
Also used : ResourceValidator(io.fabric8.maven.core.util.validator.ResourceValidator) URL(java.net.URL) Test(org.junit.Test)

Example 13 with Logger

use of io.fabric8.maven.docker.util.Logger in project fabric8-maven-plugin by fabric8io.

the class ResourceValidatorTest method testValidOpenShiftResources.

@Test
public void testValidOpenShiftResources() throws IOException, URISyntaxException {
    // Given
    URL fileUrl = ResourceValidatorTest.class.getResource("/validations/openshift-deploymentconfig.yml");
    // When
    ResourceValidator resourceValidator = new ResourceValidator(Paths.get(fileUrl.toURI()).toFile(), ResourceClassifier.OPENSHIFT, logger);
    int resources = resourceValidator.validate();
    // Then
    Assert.assertEquals(1, resources);
}
Also used : ResourceValidator(io.fabric8.maven.core.util.validator.ResourceValidator) URL(java.net.URL) Test(org.junit.Test)

Example 14 with Logger

use of io.fabric8.maven.docker.util.Logger in project fabric8-maven-plugin by fabric8io.

the class ResourceValidatorTest method testValidOpenshiftResourcesDirectory.

@Test
public void testValidOpenshiftResourcesDirectory() throws IOException, URISyntaxException {
    // Given
    URL fileUrl = ResourceValidatorTest.class.getResource("/validations/openshift");
    // When
    ResourceValidator resourceValidator = new ResourceValidator(Paths.get(fileUrl.toURI()).toFile(), ResourceClassifier.OPENSHIFT, logger);
    int resources = resourceValidator.validate();
    // Then
    Assert.assertEquals(2, resources);
}
Also used : ResourceValidator(io.fabric8.maven.core.util.validator.ResourceValidator) URL(java.net.URL) Test(org.junit.Test)

Example 15 with Logger

use of io.fabric8.maven.docker.util.Logger in project fabric8-maven-plugin by fabric8io.

the class KubernetesClientUtil method withSelector.

public static FilterWatchListDeletable<Pod, PodList, Boolean, Watch, Watcher<Pod>> withSelector(NonNamespaceOperation<Pod, PodList, DoneablePod, PodResource<Pod, DoneablePod>> pods, LabelSelector selector, Logger log) {
    FilterWatchListDeletable<Pod, PodList, Boolean, Watch, Watcher<Pod>> answer = pods;
    Map<String, String> matchLabels = selector.getMatchLabels();
    if (matchLabels != null && !matchLabels.isEmpty()) {
        answer = answer.withLabels(matchLabels);
    }
    List<LabelSelectorRequirement> matchExpressions = selector.getMatchExpressions();
    if (matchExpressions != null) {
        for (LabelSelectorRequirement expression : matchExpressions) {
            String key = expression.getKey();
            List<String> values = expression.getValues();
            if (Strings.isNullOrBlank(key)) {
                log.warn("Ignoring empty key in selector expression %s", expression);
                continue;
            }
            if (values == null || values.isEmpty()) {
                log.warn("Ignoring empty values in selector expression %s", expression);
                continue;
            }
            String[] valuesArray = values.toArray(new String[values.size()]);
            String operator = expression.getOperator();
            switch(operator) {
                case "In":
                    answer = answer.withLabelIn(key, valuesArray);
                    break;
                case "NotIn":
                    answer = answer.withLabelNotIn(key, valuesArray);
                    break;
                default:
                    log.warn("Ignoring unknown operator %s in selector expression %s", operator, expression);
            }
        }
    }
    return answer;
}
Also used : PodList(io.fabric8.kubernetes.api.model.PodList) DoneablePod(io.fabric8.kubernetes.api.model.DoneablePod) Pod(io.fabric8.kubernetes.api.model.Pod) Watch(io.fabric8.kubernetes.client.Watch) LogWatch(io.fabric8.kubernetes.client.dsl.LogWatch) Watcher(io.fabric8.kubernetes.client.Watcher) LabelSelectorRequirement(io.fabric8.kubernetes.api.model.LabelSelectorRequirement)

Aggregations

Test (org.junit.Test)30 File (java.io.File)11 OpenShiftClient (io.fabric8.openshift.client.OpenShiftClient)10 IOException (java.io.IOException)9 ArrayList (java.util.ArrayList)9 URL (java.net.URL)8 GeneratorContext (io.fabric8.maven.generator.api.GeneratorContext)7 ProcessorConfig (io.fabric8.maven.core.config.ProcessorConfig)6 ResourceValidator (io.fabric8.maven.core.util.validator.ResourceValidator)6 ImageConfiguration (io.fabric8.maven.docker.config.ImageConfiguration)6 Logger (io.fabric8.maven.docker.util.Logger)6 Util.readAsString (io.fabric8.arquillian.utils.Util.readAsString)5 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)5 Pod (io.fabric8.kubernetes.api.model.Pod)5 OpenShiftMockServer (io.fabric8.openshift.client.server.mock.OpenShiftMockServer)5 Expectations (mockit.Expectations)5 Logger (io.fabric8.arquillian.kubernetes.log.Logger)4 Deployment (io.fabric8.kubernetes.api.model.extensions.Deployment)4 BuildService (io.fabric8.maven.core.service.BuildService)4 Fabric8ServiceException (io.fabric8.maven.core.service.Fabric8ServiceException)4