use of io.fabric8.crd.generator.decorator.Decorator in project kubernetes-client by fabric8io.
the class Resources method applyConstraints.
public List<Decorator> applyConstraints(Set<Decorator> decorators) {
List<Decorator> result = new ArrayList<>();
Decorator[] array = decorators.toArray(new Decorator[decorators.size()]);
// But hey, let's have an upper limit of 5 just to prevent infinite loops
for (int i = 0; i < 10 && bubbleSort(array); i++) {
System.out.println("Sorting again:" + (i + 1));
}
for (Decorator d : array) {
result.add(d);
}
return result;
}
use of io.fabric8.crd.generator.decorator.Decorator in project quarkus by quarkusio.
the class ContainerAdapter method adapt.
public static Container adapt(io.dekorate.kubernetes.config.Container container) {
String name = container.getName();
if (Strings.isNullOrEmpty(name)) {
name = Images.getName(container.getImage());
}
ContainerBuilder builder = new ContainerBuilder().withName(name).withImage(container.getImage()).withWorkingDir(container.getWorkingDir()).withCommand(container.getCommand()).withArgs(container.getArguments());
for (Env env : container.getEnvVars()) {
builder.accept(new AddEnvVarDecorator(ANY, name, env));
}
for (Port port : container.getPorts()) {
// this was changed to use our patched port decorator
builder.accept(new AddPortDecorator(ANY, name, port));
}
for (Mount mount : container.getMounts()) {
builder.accept(new AddMountDecorator(ANY, name, mount));
}
builder.accept(new ApplyImagePullPolicyDecorator(name, container.getImagePullPolicy()));
builder.accept(new AddLivenessProbeDecorator(name, container.getLivenessProbe()));
builder.accept(new AddReadinessProbeDecorator(name, container.getReadinessProbe()));
return builder.build();
}
use of io.fabric8.crd.generator.decorator.Decorator in project quarkus by quarkusio.
the class S2iUtils method waitForImageStreamTags.
/**
* Wait for the references ImageStreamTags to become available.
*
* @param client The openshift client used to check the status of the ImageStream
* @param items A list of items, possibly referencing image stream tags.
* @param amount The max amount of time to wait.
* @param timeUnit The time unit of the time to wait.
* @return True if the items became available false otherwise.
*/
public static boolean waitForImageStreamTags(OpenShiftClient client, Collection<HasMetadata> items, long amount, TimeUnit timeUnit) {
if (items == null || items.isEmpty()) {
return true;
}
final List<String> tags = new ArrayList<>();
new KubernetesListBuilder().withItems(new ArrayList<>(items)).accept(new Decorator<SourceBuildStrategyFluent>() {
@Override
public void visit(SourceBuildStrategyFluent strategy) {
ObjectReference from = strategy.buildFrom();
if (from.getKind().equals("ImageStreamTag")) {
tags.add(from.getName());
}
}
}).build();
boolean tagsMissing = true;
long started = System.currentTimeMillis();
long elapsed = 0;
while (tagsMissing && elapsed < timeUnit.toMillis(amount) && !Thread.interrupted()) {
tagsMissing = false;
for (String tag : tags) {
ImageStreamTag t = client.imageStreamTags().withName(tag).get();
if (t == null) {
tagsMissing = true;
}
}
if (tagsMissing) {
try {
Thread.sleep(1000);
elapsed = System.currentTimeMillis() - started;
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}
}
return !tagsMissing;
}
use of io.fabric8.crd.generator.decorator.Decorator in project stackgres by ongres.
the class ClusterRequiredResourcesGenerator method getRequiredResources.
@Override
public List<HasMetadata> getRequiredResources(StackGresCluster config) {
final ObjectMeta metadata = config.getMetadata();
final String clusterName = metadata.getName();
final String clusterNamespace = metadata.getNamespace();
final StackGresClusterSpec spec = config.getSpec();
final StackGresClusterConfiguration clusterConfiguration = spec.getConfiguration();
final StackGresPostgresConfig clusterPgConfig = postgresConfigFinder.findByNameAndNamespace(clusterConfiguration.getPostgresConfig(), clusterNamespace).orElseThrow(() -> new IllegalArgumentException("SGCluster " + clusterNamespace + "/" + clusterName + " have a non existent SGPostgresConfig postgresconf"));
final StackGresProfile clusterProfile = profileFinder.findByNameAndNamespace(spec.getResourceProfile(), clusterNamespace).orElseThrow(() -> new IllegalArgumentException("SGCluster " + clusterNamespace + "/" + clusterName + " have a non existent " + StackGresProfile.KIND + " " + spec.getResourceProfile()));
final Optional<StackGresBackupConfig> backupConfig = Optional.ofNullable(clusterConfiguration.getBackupConfig()).flatMap(backupConfigName -> backupConfigFinder.findByNameAndNamespace(backupConfigName, clusterNamespace));
final Optional<StackGresPoolingConfig> clusterPooling = Optional.ofNullable(clusterConfiguration.getConnectionPoolingConfig()).flatMap(poolingConfigName -> poolingConfigFinder.findByNameAndNamespace(poolingConfigName, clusterNamespace));
Optional<StackGresClusterRestore> restoreConfig = Optional.ofNullable(config.getSpec().getInitData()).map(StackGresClusterInitData::getRestore);
final Optional<StackGresBackup> restoreBackup;
if (restoreConfig.isEmpty()) {
restoreBackup = Optional.empty();
} else {
restoreBackup = restoreConfig.map(restore -> {
final List<StackGresBackup> backups = backupScanner.getResources();
return backups.stream().filter(backup -> backup.getMetadata().getUid().equals(restore.getFromBackup().getUid())).peek(backup -> {
Preconditions.checkNotNull(backup.getStatus(), "Backup is " + BackupPhase.RUNNING.label());
Preconditions.checkNotNull(backup.getStatus().getProcess(), "Backup is " + BackupPhase.RUNNING.label());
Preconditions.checkArgument(backup.getStatus().getProcess().getStatus().equals(BackupPhase.COMPLETED.label()), "Backup is " + backup.getStatus().getProcess().getStatus());
}).findFirst().orElseThrow(() -> new IllegalArgumentException("SGCluster " + clusterNamespace + "/" + clusterName + " have an invalid restore backup Uid"));
});
}
StackGresClusterContext context = ImmutableStackGresClusterContext.builder().source(config).postgresConfig(clusterPgConfig).stackGresProfile(clusterProfile).backupConfig(backupConfig).poolingConfig(clusterPooling).restoreBackup(restoreBackup).prometheus(getPrometheus(config)).internalScripts(List.of(getPostgresExporterInitScript())).databaseCredentials(secretFinder.findByNameAndNamespace(clusterName, clusterNamespace)).build();
final List<ResourceGenerator<StackGresClusterContext>> resourceGenerators = generators.getResourceGenerators(context);
final List<HasMetadata> resources = resourceGenerators.stream().flatMap(generator -> generator.generateResource(context)).collect(Collectors.toUnmodifiableList());
List<Decorator<StackGresClusterContext>> decorators = decoratorDiscoverer.discoverDecorator(context);
decorators.forEach(decorator -> decorator.decorate(context, resources));
return resources;
}
use of io.fabric8.crd.generator.decorator.Decorator in project stackgres by ongres.
the class DbOpsDeployedResourceScanner method getDeployedResources.
@Override
public List<HasMetadata> getDeployedResources(StackGresDbOps config) {
try (KubernetesClient client = clientFactory.create()) {
final Map<String, String> genericLabels = labelFactory.genericLabels(config);
Stream<HasMetadata> inNamespace = IN_NAMESPACE_RESOURCE_OPERATIONS.values().stream().flatMap(resourceOperationGetter -> resourceOperationGetter.apply(client).inNamespace(config.getMetadata().getNamespace()).withLabels(genericLabels).list().getItems().stream());
List<HasMetadata> deployedResources = inNamespace.filter(resource -> resource.getMetadata().getOwnerReferences().stream().anyMatch(ownerReference -> ownerReference.getKind().equals(StackGresDbOps.KIND) && ownerReference.getName().equals(config.getMetadata().getName()) && ownerReference.getUid().equals(config.getMetadata().getUid()))).collect(Collectors.toUnmodifiableList());
deployedResources.forEach(resource -> {
Instance<DeployedResourceDecorator> decorator = decorators.select(new ReconciliationScopeLiteral(StackGresDbOps.class, resource.getKind()));
if (decorator.isResolvable()) {
decorator.get().decorate(resource);
}
});
return deployedResources;
}
}
Aggregations