use of io.stackgres.common.crd.sgdbops.StackGresDbOps in project stackgres by ongres.
the class ClusterEventResourceTest method setup.
@BeforeAll
public static void setup() {
StackGresDbOps dbOps = new StackGresDbOps();
dbOps.setMetadata(new ObjectMeta());
dbOps.getMetadata().setNamespace("test-namespace");
dbOps.getMetadata().setName("test-operation");
dbOps.getMetadata().setUid("1");
dbOps.setSpec(new StackGresDbOpsSpec());
dbOps.getSpec().setSgCluster("test");
DbOpsScanner dbOpsScanner = Mockito.mock(DbOpsScanner.class);
Mockito.when(dbOpsScanner.getResources(ArgumentMatchers.any())).thenReturn(ImmutableList.of(dbOps));
QuarkusMock.installMockForType(dbOpsScanner, DbOpsScanner.class);
}
use of io.stackgres.common.crd.sgdbops.StackGresDbOps in project stackgres by ongres.
the class DbOpsTransformer method toCustomResource.
@Override
public StackGresDbOps toCustomResource(DbOpsDto source, StackGresDbOps original) {
StackGresDbOps transformation = Optional.ofNullable(original).orElseGet(StackGresDbOps::new);
transformation.setMetadata(getCustomResourceMetadata(source, original));
transformation.setSpec(getCustomResourceSpec(source.getSpec()));
return transformation;
}
use of io.stackgres.common.crd.sgdbops.StackGresDbOps 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;
}
}
use of io.stackgres.common.crd.sgdbops.StackGresDbOps in project stackgres by ongres.
the class DbOpsRequiredResourcesGenerator method getRequiredResources.
@Override
public List<HasMetadata> getRequiredResources(StackGresDbOps config) {
final ObjectMeta metadata = config.getMetadata();
final String dbOpsName = metadata.getName();
final String dbOpsNamespace = metadata.getNamespace();
final StackGresDbOpsSpec spec = config.getSpec();
final StackGresCluster cluster = clusterFinder.findByNameAndNamespace(spec.getSgCluster(), dbOpsNamespace).orElseThrow(() -> new IllegalArgumentException("SGDbOps " + dbOpsNamespace + "/" + dbOpsName + " have a non existent SGCluster " + spec.getSgCluster()));
StackGresDbOpsContext context = ImmutableStackGresDbOpsContext.builder().source(config).cluster(cluster).build();
final List<ResourceGenerator<StackGresDbOpsContext>> resourceGenerators = generators.getResourceGenerators(context);
final List<HasMetadata> resources = resourceGenerators.stream().flatMap(generator -> generator.generateResource(context)).collect(Collectors.toUnmodifiableList());
List<Decorator<StackGresDbOpsContext>> decorators = decoratorDiscoverer.discoverDecorator(context);
decorators.forEach(decorator -> decorator.decorate(context, resources));
return resources;
}
use of io.stackgres.common.crd.sgdbops.StackGresDbOps in project stackgres by ongres.
the class DbOpsSecurityUpgradeJob method createJob.
@Override
public Job createJob(StackGresDbOpsContext context) {
StackGresDbOps dbOps = context.getSource();
String namespace = dbOps.getMetadata().getNamespace();
final Map<String, String> labels = dbOpsLabelFactory.dbOpsPodLabels(context.getSource());
return new JobBuilder().withNewMetadata().withNamespace(namespace).withName(jobName(dbOps, "security-upgrade")).withLabels(labels).endMetadata().withNewSpec().withBackoffLimit(0).withCompletions(1).withParallelism(1).withNewTemplate().withNewMetadata().withNamespace(namespace).withName(jobName(dbOps)).withLabels(labels).endMetadata().withNewSpec().withSecurityContext(podSecurityFactory.createResource(context)).withRestartPolicy("Never").withServiceAccountName(DbOpsRole.roleName(context)).withContainers(new ContainerBuilder().withName("security-upgrade").withImagePullPolicy("IfNotPresent").withImage(String.format(IMAGE_NAME, StackGresProperty.OPERATOR_IMAGE_VERSION.getString())).addToEnv(new EnvVarBuilder().withName(OperatorProperty.OPERATOR_NAME.getEnvironmentVariableName()).withValue(OperatorProperty.OPERATOR_NAME.getString()).build(), new EnvVarBuilder().withName(OperatorProperty.OPERATOR_NAMESPACE.getEnvironmentVariableName()).withValue(OperatorProperty.OPERATOR_NAMESPACE.getString()).build(), new EnvVarBuilder().withName("JOB_NAMESPACE").withValue(namespace).build(), new EnvVarBuilder().withName(StackGresProperty.OPERATOR_VERSION.getEnvironmentVariableName()).withValue(StackGresProperty.OPERATOR_VERSION.getString()).build(), new EnvVarBuilder().withName("CRD_UPGRADE").withValue(Boolean.FALSE.toString()).build(), new EnvVarBuilder().withName("CONVERSION_WEBHOOKS").withValue(Boolean.FALSE.toString()).build(), new EnvVarBuilder().withName("DATABASE_OPERATION_JOB").withValue(Boolean.TRUE.toString()).build(), new EnvVarBuilder().withName("DATABASE_OPERATION_CR_NAME").withValue(dbOps.getMetadata().getName()).build(), new EnvVarBuilder().withName("SERVICE_ACCOUNT").withNewValueFrom().withNewFieldRef().withFieldPath("spec.serviceAccountName").endFieldRef().endValueFrom().build(), new EnvVarBuilder().withName("POD_NAME").withNewValueFrom().withNewFieldRef().withFieldPath("metadata.name").endFieldRef().endValueFrom().build(), new EnvVarBuilder().withName("APP_OPTS").withValue(System.getenv("APP_OPTS")).build(), new EnvVarBuilder().withName("JAVA_OPTS").withValue(System.getenv("JAVA_OPTS")).build(), new EnvVarBuilder().withName("DEBUG_JOBS").withValue(System.getenv("DEBUG_OPERATOR")).build(), new EnvVarBuilder().withName("DEBUG_JOBS_SUSPEND").withValue(System.getenv("DEBUG_OPERATOR_SUSPEND")).build(), new EnvVarBuilder().withName("DBOPS_LOCK_TIMEOUT").withValue(OperatorProperty.LOCK_TIMEOUT.getString()).build(), new EnvVarBuilder().withName("DBOPS_LOCK_POLL_INTERVAL").withValue(OperatorProperty.LOCK_POLL_INTERVAL.getString()).build()).build()).endSpec().endTemplate().endSpec().build();
}
Aggregations