Skip to content

Commit

Permalink
task: Rename api by server (#11)
Browse files Browse the repository at this point in the history
* Test arm64

* task: rename "api" resources by "server"

* restore "amd64"

* Rename classes
  • Loading branch information
carlosthe19916 authored Aug 1, 2024
1 parent b8c64a0 commit ddbd09e
Show file tree
Hide file tree
Showing 20 changed files with 109 additions and 109 deletions.
4 changes: 2 additions & 2 deletions src/main/java/org/trustify/operator/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
@ConfigMapping(prefix = "related.image")
public interface Config {

@WithName("api")
String apiImage();
@WithName("server")
String serverImage();

@WithName("db")
String dbImage();
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/org/trustify/operator/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ public class Constants {

//
public static final String TRUSTI_NAME = "trustify";
public static final String TRUSTI_API_NAME = "trustify-api";
public static final String TRUSTI_SERVER_NAME = "trustify-server";
public static final String TRUSTI_DB_NAME = "trustify-db";

//
public static final Map<String, String> DB_SELECTOR_LABELS = Map.of(
"trustify-operator/group", "db"
);
public static final Map<String, String> API_SELECTOR_LABELS = Map.of(
"trustify-operator/group", "api"
public static final Map<String, String> SERVER_SELECTOR_LABELS = Map.of(
"trustify-operator/group", "server"
);

//
Expand All @@ -32,12 +32,12 @@ public class Constants {
public static final String DB_DEPLOYMENT_SUFFIX = "-" + TRUSTI_DB_NAME + "-deployment";
public static final String DB_SERVICE_SUFFIX = "-" + TRUSTI_DB_NAME + "-service";

public static final String API_DEPLOYMENT_SUFFIX = "-" + TRUSTI_API_NAME + "-deployment";
public static final String API_SERVICE_SUFFIX = "-" + TRUSTI_API_NAME + "-service";
public static final String SERVER_DEPLOYMENT_SUFFIX = "-" + TRUSTI_SERVER_NAME + "-deployment";
public static final String SERVER_SERVICE_SUFFIX = "-" + TRUSTI_SERVER_NAME + "-service";


public static final String INGRESS_SUFFIX = "-" + TRUSTI_API_NAME + "-ingress";
public static final String INGRESS_SECURE_SUFFIX = "-" + TRUSTI_API_NAME + "-secure-ingress";
public static final String INGRESS_SUFFIX = "-" + TRUSTI_SERVER_NAME + "-ingress";
public static final String INGRESS_SECURE_SUFFIX = "-" + TRUSTI_SERVER_NAME + "-secure-ingress";

//
public static final String DB_SECRET_USERNAME = "username";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ public record TrustifySpec(
@JsonPropertyDescription("In this section you can configure features related to HTTP and HTTPS")
HttpSpec httpSpec,

@JsonProperty("apiResourceLimits")
@JsonPropertyDescription("In this section you can configure resource limits settings for the API.")
ResourcesLimitSpec apiResourceLimitSpec
@JsonProperty("serverResourceLimits")
@JsonPropertyDescription("In this section you can configure resource limits settings for the Server.")
ResourcesLimitSpec serverResourceLimitSpec
) {

public TrustifySpec() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public void setCondition(TrustifyStatusCondition condition) {
@JsonIgnore
public boolean isAvailable() {
return this.conditions.stream()
.anyMatch(item -> item.getType().equals(TrustifyStatusCondition.Successful) && Objects.equals(item.getStatus(), true));
.anyMatch(item -> item.getType().equals(TrustifyStatusCondition.SUCCESSFUL) && Objects.equals(item.getStatus(), true));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

@JsonInclude(JsonInclude.Include.NON_NULL)
public class TrustifyStatusCondition {
public static final String Successful = "Successful";
public static final String SUCCESSFUL = "Successful";
public static final String PROCESSING = "Processing";
public static final String DEGRADED = "Degraded";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.trustify.operator.cdrs.v2alpha1.api;
package org.trustify.operator.cdrs.v2alpha1.server;

import io.fabric8.kubernetes.api.model.*;
import io.fabric8.kubernetes.api.model.apps.*;
Expand All @@ -23,17 +23,17 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;

@KubernetesDependent(labelSelector = ApiDeployment.LABEL_SELECTOR, resourceDiscriminator = ApiDeploymentDiscriminator.class)
@KubernetesDependent(labelSelector = ServerDeployment.LABEL_SELECTOR, resourceDiscriminator = ServerDeploymentDiscriminator.class)
@ApplicationScoped
public class ApiDeployment extends CRUDKubernetesDependentResource<Deployment, Trustify>
public class ServerDeployment extends CRUDKubernetesDependentResource<Deployment, Trustify>
implements Matcher<Deployment, Trustify>, Condition<Deployment, Trustify> {

public static final String LABEL_SELECTOR = "app.kubernetes.io/managed-by=trustify-operator,component=api";
public static final String LABEL_SELECTOR = "app.kubernetes.io/managed-by=trustify-operator,component=server";

@Inject
Config config;

public ApiDeployment() {
public ServerDeployment() {
super(Deployment.class);
}

Expand All @@ -58,7 +58,7 @@ public Result<Deployment> match(Deployment actual, Trustify cr, Context<Trustify

@Override
public boolean isMet(DependentResource<Deployment, Trustify> dependentResource, Trustify primary, Context<Trustify> context) {
return context.getSecondaryResource(Deployment.class, new ApiDeploymentDiscriminator())
return context.getSecondaryResource(Deployment.class, new ServerDeploymentDiscriminator())
.map(deployment -> {
final var status = deployment.getStatus();
if (status != null) {
Expand All @@ -80,7 +80,7 @@ private Deployment newDeployment(Trustify cr, Context<Trustify> context, Trustif
.withName(getDeploymentName(cr))
.withNamespace(cr.getMetadata().getNamespace())
.withLabels(contextLabels)
.addToLabels("component", "api")
.addToLabels("component", "server")
.withAnnotations(Map.of("app.openshift.io/connects-to", """
[{"apiVersion": "apps/v1", "kind":"Deployment", "name": "%s"}]
""".formatted(DBDeployment.getDeploymentName(cr))
Expand All @@ -96,15 +96,15 @@ private DeploymentSpec getDeploymentSpec(Trustify cr, Context<Trustify> context,
final var contextLabels = (Map<String, String>) context.managedDependentResourceContext()
.getMandatory(Constants.CONTEXT_LABELS_KEY, Map.class);

Map<String, String> selectorLabels = Constants.API_SELECTOR_LABELS;
String image = config.apiImage();
Map<String, String> selectorLabels = Constants.SERVER_SELECTOR_LABELS;
String image = config.serverImage();
String imagePullPolicy = config.imagePullPolicy();

List<EnvVar> envVars = distConfigurator.getAllEnvVars();
List<Volume> volumes = distConfigurator.getAllVolumes();
List<VolumeMount> volumeMounts = distConfigurator.getAllVolumeMounts();

TrustifySpec.ResourcesLimitSpec resourcesLimitSpec = CRDUtils.getValueFromSubSpec(cr.getSpec(), TrustifySpec::apiResourceLimitSpec)
TrustifySpec.ResourcesLimitSpec resourcesLimitSpec = CRDUtils.getValueFromSubSpec(cr.getSpec(), TrustifySpec::serverResourceLimitSpec)
.orElse(null);

return new DeploymentSpecBuilder()
Expand All @@ -130,11 +130,11 @@ private DeploymentSpec getDeploymentSpec(Trustify cr, Context<Trustify> context,
.withImagePullSecrets(cr.getSpec().imagePullSecrets())
// .withServiceAccountName(Constants.TRUSTI_NAME)
.withContainers(new ContainerBuilder()
.withName(Constants.TRUSTI_API_NAME)
.withName(Constants.TRUSTI_SERVER_NAME)
.withImage(image)
.withImagePullPolicy(imagePullPolicy)
.withEnv(envVars)
.withCommand("/usr/local/bin/trustd", "api", "--devmode")
.withCommand("/usr/local/bin/trustd", "server", "--devmode")
.withPorts(
new ContainerPortBuilder()
.withName("http")
Expand Down Expand Up @@ -212,6 +212,6 @@ private DeploymentSpec getDeploymentSpec(Trustify cr, Context<Trustify> context,
}

public static String getDeploymentName(Trustify cr) {
return cr.getMetadata().getName() + Constants.API_DEPLOYMENT_SUFFIX;
return cr.getMetadata().getName() + Constants.SERVER_DEPLOYMENT_SUFFIX;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.trustify.operator.cdrs.v2alpha1.api;
package org.trustify.operator.cdrs.v2alpha1.server;

import io.fabric8.kubernetes.api.model.apps.Deployment;
import io.javaoperatorsdk.operator.api.reconciler.Context;
Expand All @@ -9,10 +9,10 @@

import java.util.Optional;

public class ApiDeploymentDiscriminator implements ResourceDiscriminator<Deployment, Trustify> {
public class ServerDeploymentDiscriminator implements ResourceDiscriminator<Deployment, Trustify> {
@Override
public Optional<Deployment> distinguish(Class<Deployment> resource, Trustify cr, Context<Trustify> context) {
String deploymentName = ApiDeployment.getDeploymentName(cr);
String deploymentName = ServerDeployment.getDeploymentName(cr);
ResourceID resourceID = new ResourceID(deploymentName, cr.getMetadata().getNamespace());
var informerEventSource = (InformerEventSource<Deployment, Trustify>) context.eventSourceRetriever().getResourceEventSourceFor(Deployment.class);
return informerEventSource.get(resourceID);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.trustify.operator.cdrs.v2alpha1.api;
package org.trustify.operator.cdrs.v2alpha1.server;

import io.fabric8.kubernetes.api.model.networking.v1.Ingress;
import io.fabric8.kubernetes.api.model.networking.v1.IngressTLS;
Expand All @@ -13,11 +13,11 @@

import java.util.Map;

@KubernetesDependent(labelSelector = ApiIngress.LABEL_SELECTOR, resourceDiscriminator = ApiIngressDiscriminator.class)
@KubernetesDependent(labelSelector = ServerIngress.LABEL_SELECTOR, resourceDiscriminator = ServerIngressDiscriminator.class)
@ApplicationScoped
public class ApiIngress extends ApiIngressBase {
public class ServerIngress extends ServerIngressBase {

public static final String LABEL_SELECTOR = "app.kubernetes.io/managed-by=trustify-operator,component=api,component-variant=http";
public static final String LABEL_SELECTOR = "app.kubernetes.io/managed-by=trustify-operator,component=server,component-variant=http";

@Override
@SuppressWarnings("unchecked")
Expand All @@ -27,7 +27,7 @@ protected Ingress desired(Trustify cr, Context<Trustify> context) {
context,
getIngressName(cr),
Map.of(
"component", "api",
"component", "server",
"component-variant", "http"
),
Map.of(
Expand All @@ -38,7 +38,7 @@ protected Ingress desired(Trustify cr, Context<Trustify> context) {

@Override
public boolean isMet(DependentResource<Ingress, Trustify> dependentResource, Trustify cr, Context<Trustify> context) {
return context.getSecondaryResource(Ingress.class, new ApiIngressDiscriminator())
return context.getSecondaryResource(Ingress.class, new ServerIngressDiscriminator())
.map(in -> {
final var status = in.getStatus();
if (status != null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.trustify.operator.cdrs.v2alpha1.api;
package org.trustify.operator.cdrs.v2alpha1.server;

import io.fabric8.kubernetes.api.model.GenericKubernetesResource;
import io.fabric8.kubernetes.api.model.networking.v1.Ingress;
Expand All @@ -21,12 +21,12 @@
import java.util.Map;
import java.util.Optional;

public abstract class ApiIngressBase extends CRUDKubernetesDependentResource<Ingress, Trustify> implements Condition<Ingress, Trustify> {
public abstract class ServerIngressBase extends CRUDKubernetesDependentResource<Ingress, Trustify> implements Condition<Ingress, Trustify> {

@Inject
KubernetesClient k8sClient;

public ApiIngressBase() {
public ServerIngressBase() {
super(Ingress.class);
}

Expand All @@ -38,7 +38,7 @@ protected Ingress newIngress(Trustify cr, Context<Trustify> context, String ingr
final var labels = (Map<String, String>) context.managedDependentResourceContext()
.getMandatory(Constants.CONTEXT_LABELS_KEY, Map.class);

var port = ApiService.getServicePort(cr);
var port = ServerService.getServicePort(cr);

String hostname = getHostname(cr);
IngressTLS ingressTLS = getIngressTLS(cr);
Expand All @@ -62,7 +62,7 @@ protected Ingress newIngress(Trustify cr, Context<Trustify> context, String ingr
.withPathType("Prefix")
.withNewBackend()
.withNewService()
.withName(ApiService.getServiceName(cr))
.withName(ServerService.getServiceName(cr))
.withNewPort()
.withNumber(port)
.endPort()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.trustify.operator.cdrs.v2alpha1.api;
package org.trustify.operator.cdrs.v2alpha1.server;

import io.fabric8.kubernetes.api.model.networking.v1.Ingress;
import io.javaoperatorsdk.operator.api.reconciler.Context;
Expand All @@ -9,10 +9,10 @@

import java.util.Optional;

public class ApiIngressDiscriminator implements ResourceDiscriminator<Ingress, Trustify> {
public class ServerIngressDiscriminator implements ResourceDiscriminator<Ingress, Trustify> {
@Override
public Optional<Ingress> distinguish(Class<Ingress> resource, Trustify cr, Context<Trustify> context) {
String ingressName = ApiIngress.getIngressName(cr);
String ingressName = ServerIngress.getIngressName(cr);
ResourceID resourceID = new ResourceID(ingressName, cr.getMetadata().getNamespace());
var informerEventSource = (InformerEventSource<Ingress, Trustify>) context.eventSourceRetriever().getResourceEventSourceFor(Ingress.class);
return informerEventSource.get(resourceID);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.trustify.operator.cdrs.v2alpha1.api;
package org.trustify.operator.cdrs.v2alpha1.server;

import io.fabric8.kubernetes.api.model.networking.v1.Ingress;
import io.fabric8.kubernetes.api.model.networking.v1.IngressTLS;
Expand All @@ -15,11 +15,11 @@
import java.util.Collections;
import java.util.Map;

@KubernetesDependent(labelSelector = ApiIngressSecure.LABEL_SELECTOR, resourceDiscriminator = ApiIngressSecureDiscriminator.class)
@KubernetesDependent(labelSelector = ServerIngressSecure.LABEL_SELECTOR, resourceDiscriminator = ServerIngressSecureDiscriminator.class)
@ApplicationScoped
public class ApiIngressSecure extends ApiIngressBase {
public class ServerIngressSecure extends ServerIngressBase {

public static final String LABEL_SELECTOR = "app.kubernetes.io/managed-by=trustify-operator,component=api,component-variant=https";
public static final String LABEL_SELECTOR = "app.kubernetes.io/managed-by=trustify-operator,component=server,component-variant=https";

@Override
@SuppressWarnings("unchecked")
Expand All @@ -29,7 +29,7 @@ protected Ingress desired(Trustify cr, Context<Trustify> context) {
context,
getIngressName(cr),
Map.of(
"component", "api",
"component", "server",
"component-variant", "https"
),
Collections.emptyMap()
Expand All @@ -38,7 +38,7 @@ protected Ingress desired(Trustify cr, Context<Trustify> context) {

@Override
public boolean isMet(DependentResource<Ingress, Trustify> dependentResource, Trustify primary, Context<Trustify> context) {
return context.getSecondaryResource(Ingress.class, new ApiIngressSecureDiscriminator())
return context.getSecondaryResource(Ingress.class, new ServerIngressSecureDiscriminator())
.map(in -> {
final var status = in.getStatus();
if (status != null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.trustify.operator.cdrs.v2alpha1.api;
package org.trustify.operator.cdrs.v2alpha1.server;

import io.fabric8.kubernetes.api.model.networking.v1.Ingress;
import io.javaoperatorsdk.operator.api.reconciler.Context;
Expand All @@ -9,10 +9,10 @@

import java.util.Optional;

public class ApiIngressSecureDiscriminator implements ResourceDiscriminator<Ingress, Trustify> {
public class ServerIngressSecureDiscriminator implements ResourceDiscriminator<Ingress, Trustify> {
@Override
public Optional<Ingress> distinguish(Class<Ingress> resource, Trustify cr, Context<Trustify> context) {
String ingressName = ApiIngressSecure.getIngressName(cr);
String ingressName = ServerIngressSecure.getIngressName(cr);
ResourceID resourceID = new ResourceID(ingressName, cr.getMetadata().getNamespace());
var informerEventSource = (InformerEventSource<Ingress, Trustify>) context.eventSourceRetriever().getResourceEventSourceFor(Ingress.class);
return informerEventSource.get(resourceID);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.trustify.operator.cdrs.v2alpha1.api;
package org.trustify.operator.cdrs.v2alpha1.server;

import io.fabric8.kubernetes.api.model.Service;
import io.fabric8.kubernetes.api.model.ServiceBuilder;
Expand All @@ -15,13 +15,13 @@

import java.util.Map;

@KubernetesDependent(labelSelector = ApiService.LABEL_SELECTOR, resourceDiscriminator = ApiServiceDiscriminator.class)
@KubernetesDependent(labelSelector = ServerService.LABEL_SELECTOR, resourceDiscriminator = ServerServiceDiscriminator.class)
@ApplicationScoped
public class ApiService extends CRUDKubernetesDependentResource<Service, Trustify> {
public class ServerService extends CRUDKubernetesDependentResource<Service, Trustify> {

public static final String LABEL_SELECTOR = "app.kubernetes.io/managed-by=trustify-operator,component=api";
public static final String LABEL_SELECTOR = "app.kubernetes.io/managed-by=trustify-operator,component=server";

public ApiService() {
public ServerService() {
super(Service.class);
}

Expand All @@ -40,7 +40,7 @@ private Service newService(Trustify cr, Context context) {
.withName(getServiceName(cr))
.withNamespace(cr.getMetadata().getNamespace())
.withLabels(labels)
.addToLabels("component", "api")
.addToLabels("component", "server")
.withOwnerReferences(CRDUtils.getOwnerReference(cr))
.endMetadata()
.withSpec(getServiceSpec(cr))
Expand All @@ -53,7 +53,7 @@ private ServiceSpec getServiceSpec(Trustify cr) {
.withPort(getServicePort(cr))
.withProtocol(Constants.SERVICE_PROTOCOL)
.endPort()
.withSelector(Constants.API_SELECTOR_LABELS)
.withSelector(Constants.SERVER_SELECTOR_LABELS)
.withType("ClusterIP")
.build();
}
Expand All @@ -63,7 +63,7 @@ public static int getServicePort(Trustify cr) {
}

public static String getServiceName(Trustify cr) {
return cr.getMetadata().getName() + Constants.API_SERVICE_SUFFIX;
return cr.getMetadata().getName() + Constants.SERVER_SERVICE_SUFFIX;
}

public static boolean isTlsConfigured(Trustify cr) {
Expand Down
Loading

0 comments on commit ddbd09e

Please sign in to comment.