Search in sources :

Example 1 with ReconciliationScopeLiteral

use of io.stackgres.operator.conciliation.ReconciliationScopeLiteral 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;
    }
}
Also used : KubernetesResourceList(io.fabric8.kubernetes.api.model.KubernetesResourceList) MixedOperation(io.fabric8.kubernetes.client.dsl.MixedOperation) ReconciliationOperations(io.stackgres.operator.conciliation.ReconciliationOperations) Role(io.fabric8.kubernetes.api.model.rbac.Role) Function(java.util.function.Function) StackGresDbOps(io.stackgres.common.crd.sgdbops.StackGresDbOps) Inject(javax.inject.Inject) RoleBinding(io.fabric8.kubernetes.api.model.rbac.RoleBinding) Resource(io.fabric8.kubernetes.client.dsl.Resource) DeployedResourceDecorator(io.stackgres.operator.conciliation.DeployedResourceDecorator) Map(java.util.Map) LabelFactoryForDbOps(io.stackgres.common.LabelFactoryForDbOps) KubernetesClientFactory(io.stackgres.common.KubernetesClientFactory) Any(javax.enterprise.inject.Any) Job(io.fabric8.kubernetes.api.model.batch.v1.Job) Instance(javax.enterprise.inject.Instance) ReconciliationScopeLiteral(io.stackgres.operator.conciliation.ReconciliationScopeLiteral) ImmutableMap(com.google.common.collect.ImmutableMap) Collectors(java.util.stream.Collectors) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) DeployedResourcesScanner(io.stackgres.operator.conciliation.DeployedResourcesScanner) List(java.util.List) Stream(java.util.stream.Stream) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) ApplicationScoped(javax.enterprise.context.ApplicationScoped) ServiceAccount(io.fabric8.kubernetes.api.model.ServiceAccount) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) ReconciliationScopeLiteral(io.stackgres.operator.conciliation.ReconciliationScopeLiteral) StackGresDbOps(io.stackgres.common.crd.sgdbops.StackGresDbOps) DeployedResourceDecorator(io.stackgres.operator.conciliation.DeployedResourceDecorator)

Example 2 with ReconciliationScopeLiteral

use of io.stackgres.operator.conciliation.ReconciliationScopeLiteral in project stackgres by ongres.

the class BackupDeployedResourceScanner method getDeployedResources.

@Override
public List<HasMetadata> getDeployedResources(StackGresBackup 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(StackGresBackup.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(StackGresBackup.class, resource.getKind()));
            if (decorator.isResolvable()) {
                decorator.get().decorate(resource);
            }
        });
        return deployedResources;
    }
}
Also used : ReconciliationScopeLiteral(io.stackgres.operator.conciliation.ReconciliationScopeLiteral) KubernetesResourceList(io.fabric8.kubernetes.api.model.KubernetesResourceList) MixedOperation(io.fabric8.kubernetes.client.dsl.MixedOperation) LabelFactoryForBackup(io.stackgres.common.LabelFactoryForBackup) ImmutableMap(com.google.common.collect.ImmutableMap) StackGresBackup(io.stackgres.common.crd.sgbackup.StackGresBackup) ReconciliationOperations(io.stackgres.operator.conciliation.ReconciliationOperations) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) Inject(javax.inject.Inject) DeployedResourcesScanner(io.stackgres.operator.conciliation.DeployedResourcesScanner) List(java.util.List) Resource(io.fabric8.kubernetes.client.dsl.Resource) Stream(java.util.stream.Stream) DeployedResourceDecorator(io.stackgres.operator.conciliation.DeployedResourceDecorator) Map(java.util.Map) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) KubernetesClientFactory(io.stackgres.common.KubernetesClientFactory) ApplicationScoped(javax.enterprise.context.ApplicationScoped) Any(javax.enterprise.inject.Any) Job(io.fabric8.kubernetes.api.model.batch.v1.Job) Instance(javax.enterprise.inject.Instance) StackGresBackup(io.stackgres.common.crd.sgbackup.StackGresBackup) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) ReconciliationScopeLiteral(io.stackgres.operator.conciliation.ReconciliationScopeLiteral) DeployedResourceDecorator(io.stackgres.operator.conciliation.DeployedResourceDecorator)

Example 3 with ReconciliationScopeLiteral

use of io.stackgres.operator.conciliation.ReconciliationScopeLiteral in project stackgres by ongres.

the class ClusterDeployedResourceScanner method getDeployedResources.

@Override
public List<HasMetadata> getDeployedResources(StackGresCluster config) {
    try (KubernetesClient client = clientFactory.create()) {
        final Map<String, String> genericClusterLabels = labelFactory.genericLabels(config);
        Stream<HasMetadata> inNamespace = IN_NAMESPACE_RESOURCE_OPERATIONS.values().stream().flatMap(resourceOperationGetter -> resourceOperationGetter.apply(client).inNamespace(config.getMetadata().getNamespace()).withLabels(genericClusterLabels).list().getItems().stream());
        Stream<HasMetadata> anyNamespace = ANY_NAMESPACE_RESOURCE_OPERATIONS.values().stream().flatMap(resourceOperationGetter -> resourceOperationGetter.apply(client, genericClusterLabels).stream());
        List<HasMetadata> deployedResources = Stream.concat(inNamespace, anyNamespace).filter(resource1 -> resource1.getMetadata().getOwnerReferences().stream().anyMatch(ownerReference -> ownerReference.getKind().equals(StackGresCluster.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(StackGresCluster.class, resource.getKind()));
            if (decorator.isResolvable()) {
                decorator.get().decorate(resource);
            }
        });
        return deployedResources;
    }
}
Also used : ReconciliationScopeLiteral(io.stackgres.operator.conciliation.ReconciliationScopeLiteral) StackGresCluster(io.stackgres.common.crd.sgcluster.StackGresCluster) ReconciliationOperations(io.stackgres.operator.conciliation.ReconciliationOperations) LabelFactoryForCluster(io.stackgres.common.LabelFactoryForCluster) Collectors(java.util.stream.Collectors) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) Inject(javax.inject.Inject) DeployedResourcesScanner(io.stackgres.operator.conciliation.DeployedResourcesScanner) List(java.util.List) Stream(java.util.stream.Stream) DeployedResourceDecorator(io.stackgres.operator.conciliation.DeployedResourceDecorator) Map(java.util.Map) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) KubernetesClientFactory(io.stackgres.common.KubernetesClientFactory) ApplicationScoped(javax.enterprise.context.ApplicationScoped) Any(javax.enterprise.inject.Any) Instance(javax.enterprise.inject.Instance) StackGresCluster(io.stackgres.common.crd.sgcluster.StackGresCluster) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) ReconciliationScopeLiteral(io.stackgres.operator.conciliation.ReconciliationScopeLiteral) DeployedResourceDecorator(io.stackgres.operator.conciliation.DeployedResourceDecorator)

Aggregations

HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)3 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)3 KubernetesClientFactory (io.stackgres.common.KubernetesClientFactory)3 DeployedResourceDecorator (io.stackgres.operator.conciliation.DeployedResourceDecorator)3 DeployedResourcesScanner (io.stackgres.operator.conciliation.DeployedResourcesScanner)3 ReconciliationOperations (io.stackgres.operator.conciliation.ReconciliationOperations)3 ReconciliationScopeLiteral (io.stackgres.operator.conciliation.ReconciliationScopeLiteral)3 List (java.util.List)3 Map (java.util.Map)3 Collectors (java.util.stream.Collectors)3 Stream (java.util.stream.Stream)3 ApplicationScoped (javax.enterprise.context.ApplicationScoped)3 Any (javax.enterprise.inject.Any)3 Instance (javax.enterprise.inject.Instance)3 Inject (javax.inject.Inject)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 KubernetesResourceList (io.fabric8.kubernetes.api.model.KubernetesResourceList)2 Job (io.fabric8.kubernetes.api.model.batch.v1.Job)2 MixedOperation (io.fabric8.kubernetes.client.dsl.MixedOperation)2 Resource (io.fabric8.kubernetes.client.dsl.Resource)2