Search in sources :

Example 1 with io.fabric8.crd.generator.visitor

use of io.fabric8.crd.generator.visitor in project fabric8-maven-plugin by fabric8io.

the class OpenshiftBuildService method checkOrCreatePullSecret.

private Boolean checkOrCreatePullSecret(BuildServiceConfig config, OpenShiftClient client, KubernetesListBuilder builder, String pullSecretName, ImageConfiguration imageConfig) throws MojoExecutionException, UnsupportedEncodingException {
    io.fabric8.maven.docker.service.BuildService.BuildContext dockerBuildContext = config.getDockerBuildContext();
    BuildImageConfiguration buildConfig = imageConfig.getBuildConfiguration();
    String fromImage;
    if (buildConfig.isDockerFileMode()) {
        fromImage = extractBaseFromDockerfile(buildConfig, dockerBuildContext);
    } else {
        fromImage = extractBaseFromConfiguration(buildConfig);
    }
    String pullRegistry = EnvUtil.firstRegistryOf(new ImageName(fromImage).getRegistry(), dockerBuildContext.getRegistryConfig().getRegistry(), dockerBuildContext.getRegistryConfig().getRegistry());
    if (pullRegistry != null) {
        RegistryService.RegistryConfig registryConfig = dockerBuildContext.getRegistryConfig();
        AuthConfig authConfig = registryConfig.getAuthConfigFactory().createAuthConfig(false, registryConfig.isSkipExtendedAuth(), registryConfig.getAuthConfig(), registryConfig.getSettings(), null, pullRegistry);
        if (authConfig != null) {
            JsonObject auths = new JsonObject();
            JsonObject auth = new JsonObject();
            JsonObject item = new JsonObject();
            String authString = authConfig.getUsername() + ":" + authConfig.getPassword();
            item.add("auth", new JsonPrimitive(Base64.encodeBase64String(authString.getBytes("UTF-8"))));
            auth.add(pullRegistry, item);
            auths.add("auths", auth);
            String credentials = Base64.encodeBase64String(auths.toString().getBytes("UTF-8"));
            Map<String, String> data = new HashMap<>();
            data.put(".dockerconfigjson", credentials);
            boolean hasPullSecret = client.secrets().withName(pullSecretName).get() != null;
            if (!hasPullSecret) {
                log.info("Creating Secret %s", hasPullSecret);
                builder.addNewSecretItem().withNewMetadata().withName(pullSecretName).endMetadata().withData(data).withType("kubernetes.io/dockerconfigjson").endSecretItem();
            } else {
                log.info("Adding to Secret %s", pullSecretName);
                return updateSecret(client, pullSecretName, data);
            }
            return true;
        } else {
            return false;
        }
    }
    return false;
}
Also used : BuildService(io.fabric8.maven.core.service.BuildService) JsonPrimitive(com.google.gson.JsonPrimitive) HashMap(java.util.HashMap) JsonObject(com.google.gson.JsonObject) AuthConfig(io.fabric8.maven.docker.access.AuthConfig) BuildImageConfiguration(io.fabric8.maven.docker.config.BuildImageConfiguration) ImageName(io.fabric8.maven.docker.util.ImageName) RegistryService(io.fabric8.maven.docker.service.RegistryService)

Example 2 with io.fabric8.crd.generator.visitor

use of io.fabric8.crd.generator.visitor in project fabric8-maven-plugin by fabric8io.

the class DeploymentConfigEnricher method convertFromExtensionsV1Beta1Deployment.

private DeploymentConfig convertFromExtensionsV1Beta1Deployment(HasMetadata item) {
    io.fabric8.kubernetes.api.model.extensions.Deployment resource = (io.fabric8.kubernetes.api.model.extensions.Deployment) item;
    DeploymentConfigBuilder builder = new DeploymentConfigBuilder();
    builder.withMetadata(resource.getMetadata());
    io.fabric8.kubernetes.api.model.extensions.DeploymentSpec spec = resource.getSpec();
    if (spec != null) {
        builder.withSpec(getDeploymentConfigSpec(spec.getReplicas(), spec.getRevisionHistoryLimit(), spec.getSelector(), spec.getTemplate(), spec.getStrategy() != null ? spec.getStrategy().getType() : null));
    }
    return builder.build();
}
Also used : DeploymentConfigBuilder(io.fabric8.openshift.api.model.DeploymentConfigBuilder) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment)

Example 3 with io.fabric8.crd.generator.visitor

use of io.fabric8.crd.generator.visitor in project fabric8-maven-plugin by fabric8io.

the class OpenshiftBuildServiceTest method init.

@Before
public void init() throws Exception {
    final File dockerFile = new File(baseDir, "Docker.tar");
    dockerFile.getParentFile().mkdirs();
    dockerFile.createNewFile();
    imageStreamFile.delete();
    new Expectations() {

        {
            dockerServiceHub.getArchiveService();
            result = archiveService;
            archiveService.createDockerBuildArchive(withAny(ImageConfiguration.class.cast(null)), withAny(MojoParameters.class.cast(null)));
            result = dockerFile;
            minTimes = 0;
            project.getArtifact();
            result = "myapp";
            minTimes = 0;
            dockerMojoParameters.getProject();
            result = project;
            minTimes = 0;
        }
    };
    image = new ImageConfiguration.Builder().name(projectName).buildConfig(new BuildImageConfiguration.Builder().from(projectName).build()).build();
    final io.fabric8.maven.docker.service.BuildService.BuildContext context = new io.fabric8.maven.docker.service.BuildService.BuildContext.Builder().registryConfig(new RegistryService.RegistryConfig.Builder().build()).build();
    defaultConfig = new BuildService.BuildServiceConfig.Builder().buildDirectory(baseDir).buildRecreateMode(BuildRecreateMode.none).dockerBuildContext(context).s2iBuildNameSuffix("-s2i-suffix2").openshiftBuildStrategy(OpenShiftBuildStrategy.s2i).dockerMojoParameters(dockerMojoParameters);
    defaultConfigSecret = new BuildService.BuildServiceConfig.Builder().buildDirectory(baseDir).buildRecreateMode(BuildRecreateMode.none).dockerBuildContext(context).s2iBuildNameSuffix("-s2i-suffix2").openshiftPullSecret("pullsecret-fabric8").openshiftBuildStrategy(OpenShiftBuildStrategy.s2i).dockerMojoParameters(dockerMojoParameters);
}
Also used : Expectations(mockit.Expectations) BuildService(io.fabric8.maven.core.service.BuildService) BuildStrategyBuilder(io.fabric8.openshift.api.model.BuildStrategyBuilder) NamedTagEventListBuilder(io.fabric8.openshift.api.model.NamedTagEventListBuilder) ImageStreamStatusBuilder(io.fabric8.openshift.api.model.ImageStreamStatusBuilder) BuildBuilder(io.fabric8.openshift.api.model.BuildBuilder) KubernetesListBuilder(io.fabric8.kubernetes.api.model.KubernetesListBuilder) ImageStreamBuilder(io.fabric8.openshift.api.model.ImageStreamBuilder) BuildConfigBuilder(io.fabric8.openshift.api.model.BuildConfigBuilder) BuildImageConfiguration(io.fabric8.maven.docker.config.BuildImageConfiguration) BuildContext(io.fabric8.maven.docker.service.BuildService.BuildContext) File(java.io.File) Before(org.junit.Before)

Example 4 with io.fabric8.crd.generator.visitor

use of io.fabric8.crd.generator.visitor in project fabric8-maven-plugin by fabric8io.

the class OpenshiftBuildServiceTest method testDockerBuild.

@Test
public void testDockerBuild() throws Exception {
    retryInMockServer(() -> {
        final io.fabric8.maven.docker.service.BuildService.BuildContext context = new io.fabric8.maven.docker.service.BuildService.BuildContext.Builder().registryConfig(new RegistryService.RegistryConfig.Builder().build()).build();
        BuildService.BuildServiceConfig.Builder dockerConfig = new BuildService.BuildServiceConfig.Builder().buildDirectory(baseDir).dockerBuildContext(context).buildRecreateMode(BuildRecreateMode.none).s2iBuildNameSuffix("-docker").openshiftBuildStrategy(OpenShiftBuildStrategy.docker).dockerMojoParameters(dockerMojoParameters);
        BuildService.BuildServiceConfig config = dockerConfig.build();
        WebServerEventCollector<OpenShiftMockServer> collector = createMockServer(config, true, 50, false, false);
        OpenShiftMockServer mockServer = collector.getMockServer();
        DefaultOpenShiftClient client = (DefaultOpenShiftClient) mockServer.createOpenShiftClient();
        OpenshiftBuildService service = new OpenshiftBuildService(client, logger, dockerServiceHub, config);
        service.build(image);
        assertTrue(mockServer.getRequestCount() > 8);
        collector.assertEventsRecordedInOrder("build-config-check", "new-build-config", "pushed");
        assertEquals("{\"apiVersion\":\"build.openshift.io/v1\",\"kind\":\"BuildConfig\",\"metadata\":{\"name\":\"myapp-docker\"},\"spec\":{\"output\":{\"to\":{\"kind\":\"ImageStreamTag\",\"name\":\"myapp:latest\"}},\"source\":{\"type\":\"Binary\"},\"strategy\":{\"dockerStrategy\":{\"from\":{\"kind\":\"DockerImage\",\"name\":\"myapp\"}},\"type\":\"Docker\"}}}", collector.getBodies().get(1));
        collector.assertEventsNotRecorded("patch-build-config");
    });
}
Also used : BuildService(io.fabric8.maven.core.service.BuildService) BuildStrategyBuilder(io.fabric8.openshift.api.model.BuildStrategyBuilder) NamedTagEventListBuilder(io.fabric8.openshift.api.model.NamedTagEventListBuilder) ImageStreamStatusBuilder(io.fabric8.openshift.api.model.ImageStreamStatusBuilder) BuildBuilder(io.fabric8.openshift.api.model.BuildBuilder) KubernetesListBuilder(io.fabric8.kubernetes.api.model.KubernetesListBuilder) ImageStreamBuilder(io.fabric8.openshift.api.model.ImageStreamBuilder) BuildConfigBuilder(io.fabric8.openshift.api.model.BuildConfigBuilder) DefaultOpenShiftClient(io.fabric8.openshift.client.DefaultOpenShiftClient) BuildContext(io.fabric8.maven.docker.service.BuildService.BuildContext) OpenShiftMockServer(io.fabric8.openshift.client.server.mock.OpenShiftMockServer) Test(org.junit.Test)

Example 5 with io.fabric8.crd.generator.visitor

use of io.fabric8.crd.generator.visitor in project fabric8-maven-plugin by fabric8io.

the class DockerBuildServiceTest method testSuccessfulBuild.

@Test
public void testSuccessfulBuild() throws Exception {
    final BuildService.BuildContext context = new BuildService.BuildContext.Builder().build();
    final io.fabric8.maven.core.service.BuildService.BuildServiceConfig config = new io.fabric8.maven.core.service.BuildService.BuildServiceConfig.Builder().dockerBuildContext(context).imagePullManager(new ImagePullManager(new TestCacheStore(), ImagePullPolicy.Always.name(), AutoPullMode.ALWAYS.name())).build();
    final String imageName = "image-name";
    final ImageConfiguration image = new ImageConfiguration.Builder().name(imageName).buildConfig(new BuildImageConfiguration.Builder().from("from").build()).build();
    DockerBuildService service = new DockerBuildService(hub, config);
    service.build(image);
    new VerificationsInOrder() {

        {
            buildService.buildImage(image, config.getImagePullManager(), context);
            buildService.tagImage(imageName, image);
        }
    };
}
Also used : BuildService(io.fabric8.maven.docker.service.BuildService) ImagePullManager(io.fabric8.maven.docker.service.ImagePullManager) VerificationsInOrder(mockit.VerificationsInOrder) BuildImageConfiguration(io.fabric8.maven.docker.config.BuildImageConfiguration) ImageConfiguration(io.fabric8.maven.docker.config.ImageConfiguration) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)48 ParallelTest (io.strimzi.test.annotations.ParallelTest)42 IntOrString (io.fabric8.kubernetes.api.model.IntOrString)40 PodDisruptionBudget (io.fabric8.kubernetes.api.model.policy.v1.PodDisruptionBudget)38 File (java.io.File)32 Kafka (io.strimzi.api.kafka.model.Kafka)28 HashMap (java.util.HashMap)28 FabricService (io.fabric8.api.FabricService)26 KafkaBuilder (io.strimzi.api.kafka.model.KafkaBuilder)26 IOException (java.io.IOException)26 Container (io.fabric8.kubernetes.api.model.Container)20 Test (org.junit.jupiter.api.Test)20 Service (io.fabric8.kubernetes.api.model.Service)19 PersistentVolumeClaim (io.fabric8.kubernetes.api.model.PersistentVolumeClaim)18 KafkaVersionTestUtils (io.strimzi.operator.cluster.KafkaVersionTestUtils)18 ResourceUtils (io.strimzi.operator.cluster.ResourceUtils)18 Reconciliation (io.strimzi.operator.common.Reconciliation)18 Labels (io.strimzi.operator.common.model.Labels)18 CoreMatchers.is (org.hamcrest.CoreMatchers.is)18 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)18