Search in sources :

Example 1 with Config

use of io.fabric8.openshift.api.model.operator.v1.Config in project universa by UniversaBlockchain.

the class PostgresLedgerTest method paymentSaveTest.

@Test
public void paymentSaveTest() throws Exception {
    try (PooledDb db = (PooledDb) ledger.getDb()) {
        try (PreparedStatement statement = db.statement("delete from payments_summary;")) {
            statement.executeUpdate();
        }
    }
    NodeStats stats = new NodeStats();
    Config config = new Config();
    stats.init(ledger, config);
    ZonedDateTime now = ZonedDateTime.now();
    ZonedDateTime dateTime = now.minusDays(now.getDayOfMonth() - 1).minusMonths(1);
    while (dateTime.isBefore(ZonedDateTime.now().plusSeconds(1))) {
        ledger.savePayment(100, dateTime);
        ledger.savePayment(100, dateTime);
        dateTime = dateTime.plusDays(1);
    }
    stats.collect(ledger, config);
// assertEquals(stats.todayPaidAmount,200);
// assertEquals(stats.yesterdayPaidAmount,200);
// assertEquals(stats.thisMonthPaidAmount,200*now.getDayOfMonth());
// assertEquals(stats.lastMonthPaidAmount,200*now.minusMonths(1).getMonth().length(now.getYear() % 4 == 0));
}
Also used : NodeStats(com.icodici.universa.node2.NodeStats) PooledDb(com.icodici.db.PooledDb) ZonedDateTime(java.time.ZonedDateTime) Config(com.icodici.universa.node2.Config) PreparedStatement(java.sql.PreparedStatement) Test(org.junit.Test)

Example 2 with Config

use of io.fabric8.openshift.api.model.operator.v1.Config in project fabric8-maven-plugin by fabric8io.

the class OpenshiftBuildService method build.

@Override
public void build(ImageConfiguration imageConfig) throws Fabric8ServiceException {
    String buildName = null;
    try {
        ImageName imageName = new ImageName(imageConfig.getName());
        File dockerTar = createBuildArchive(imageConfig);
        KubernetesListBuilder builder = new KubernetesListBuilder();
        // Check for buildconfig / imagestream / pullSecret and create them if necessary
        String openshiftPullSecret = config.getOpenshiftPullSecret();
        Boolean usePullSecret = checkOrCreatePullSecret(config, client, builder, openshiftPullSecret, imageConfig);
        if (usePullSecret) {
            buildName = updateOrCreateBuildConfig(config, client, builder, imageConfig, openshiftPullSecret);
        } else {
            buildName = updateOrCreateBuildConfig(config, client, builder, imageConfig, null);
        }
        checkOrCreateImageStream(config, client, builder, getImageStreamName(imageName));
        applyResourceObjects(config, client, builder);
        // Start the actual build
        Build build = startBuild(client, dockerTar, buildName);
        // Wait until the build finishes
        waitForOpenShiftBuildToComplete(client, build);
        // Create a file with generated image streams
        addImageStreamToFile(getImageStreamFile(config), imageName, client);
    } catch (Fabric8ServiceException e) {
        throw e;
    } catch (Exception ex) {
        // Log additional details in case of any IOException
        if (ex != null && ex.getCause() instanceof IOException) {
            log.error("Build for %s failed: %s", buildName, ex.getCause().getMessage());
            logBuildFailure(client, buildName);
        } else {
            throw new Fabric8ServiceException("Unable to build the image using the OpenShift build service", ex);
        }
    }
}
Also used : KubernetesListBuilder(io.fabric8.kubernetes.api.model.KubernetesListBuilder) ImageName(io.fabric8.maven.docker.util.ImageName) Fabric8ServiceException(io.fabric8.maven.core.service.Fabric8ServiceException) Build(io.fabric8.openshift.api.model.Build) IOException(java.io.IOException) File(java.io.File) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Fabric8ServiceException(io.fabric8.maven.core.service.Fabric8ServiceException) IOException(java.io.IOException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException)

Example 3 with Config

use of io.fabric8.openshift.api.model.operator.v1.Config 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 4 with Config

use of io.fabric8.openshift.api.model.operator.v1.Config in project fabric8-maven-plugin by fabric8io.

the class DeploymentConfigHandler method createDeploymentConfigSpec.

private DeploymentConfigSpec createDeploymentConfigSpec(ResourceConfig config, List<ImageConfiguration> images, Long openshiftDeployTimeoutSeconds, Boolean imageChangeTrigger, Boolean enableAutomaticTrigger, Boolean isOpenshiftBuildStrategy, List<String> generatedContainers) {
    DeploymentConfigSpecBuilder specBuilder = new DeploymentConfigSpecBuilder();
    PodTemplateSpec podTemplateSpec = podTemplateHandler.getPodTemplate(config, images);
    specBuilder.withReplicas(config.getReplicas()).withTemplate(podTemplateSpec).addNewTrigger().withType("ConfigChange").endTrigger();
    if (openshiftDeployTimeoutSeconds != null && openshiftDeployTimeoutSeconds > 0) {
        specBuilder.withNewStrategy().withType("Rolling").withNewRollingParams().withTimeoutSeconds(openshiftDeployTimeoutSeconds).endRollingParams().endStrategy();
    }
    return specBuilder.build();
}
Also used : DeploymentConfigSpecBuilder(io.fabric8.openshift.api.model.DeploymentConfigSpecBuilder) PodTemplateSpec(io.fabric8.kubernetes.api.model.PodTemplateSpec)

Example 5 with Config

use of io.fabric8.openshift.api.model.operator.v1.Config in project fabric8-maven-plugin by fabric8io.

the class ContainerHandler method getContainers.

List<Container> getContainers(ResourceConfig config, List<ImageConfiguration> images) {
    List<Container> ret = new ArrayList<>();
    for (ImageConfiguration imageConfig : images) {
        if (imageConfig.getBuildConfiguration() != null) {
            Probe livenessProbe = probeHandler.getProbe(config.getLiveness());
            Probe readinessProbe = probeHandler.getProbe(config.getReadiness());
            Container container = new ContainerBuilder().withName(KubernetesResourceUtil.extractContainerName(this.groupArtifactVersion, imageConfig)).withImage(getImageName(imageConfig)).withImagePullPolicy(getImagePullPolicy(config)).withEnv(getEnvVars(config)).withSecurityContext(createSecurityContext(config)).withPorts(getContainerPorts(imageConfig)).withVolumeMounts(getVolumeMounts(config)).withLivenessProbe(livenessProbe).withReadinessProbe(readinessProbe).build();
            ret.add(container);
        }
    }
    return ret;
}
Also used : Container(io.fabric8.kubernetes.api.model.Container) ContainerBuilder(io.fabric8.kubernetes.api.model.ContainerBuilder) BuildImageConfiguration(io.fabric8.maven.docker.config.BuildImageConfiguration) ImageConfiguration(io.fabric8.maven.docker.config.ImageConfiguration) ArrayList(java.util.ArrayList) Probe(io.fabric8.kubernetes.api.model.Probe)

Aggregations

Test (org.junit.Test)280 Test (org.junit.jupiter.api.Test)264 Map (java.util.Map)212 HashMap (java.util.HashMap)210 List (java.util.List)199 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)187 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)172 Reconciliation (io.strimzi.operator.common.Reconciliation)158 ArrayList (java.util.ArrayList)142 ResourceOperatorSupplier (io.strimzi.operator.cluster.operator.resource.ResourceOperatorSupplier)134 Config (io.fabric8.kubernetes.client.Config)133 Vertx (io.vertx.core.Vertx)129 Kafka (io.strimzi.api.kafka.model.Kafka)124 PlatformFeaturesAvailability (io.strimzi.operator.PlatformFeaturesAvailability)124 Future (io.vertx.core.Future)119 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)119 Checkpoint (io.vertx.junit5.Checkpoint)118 File (java.io.File)117 KafkaVersionTestUtils (io.strimzi.operator.cluster.KafkaVersionTestUtils)106 IOException (java.io.IOException)105