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));
}
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);
}
}
}
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;
}
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();
}
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;
}
Aggregations