Search in sources :

Example 6 with LabelsBuilder

use of com.redhat.service.smartevents.shard.operator.utils.LabelsBuilder in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class BridgeIngressServiceImpl method fetchOrCreateBridgeIngressService.

@Override
public Service fetchOrCreateBridgeIngressService(BridgeIngress bridgeIngress, Deployment deployment) {
    Service expected = templateProvider.loadBridgeIngressServiceTemplate(bridgeIngress);
    // Specs
    expected.getSpec().setSelector(new LabelsBuilder().withAppInstance(deployment.getMetadata().getName()).build());
    // The service must have a label to link with a supposed ServiceMonitor: https://prometheus-operator.dev/docs/operator/troubleshooting/#overview-of-servicemonitor-tagging-and-related-elements
    if (expected.getMetadata().getLabels() == null) {
        expected.getMetadata().setLabels(new HashMap<>());
    }
    expected.getMetadata().getLabels().putAll(new LabelsBuilder().withAppInstance(deployment.getMetadata().getName()).buildWithDefaults());
    Service existing = kubernetesClient.services().inNamespace(bridgeIngress.getMetadata().getNamespace()).withName(bridgeIngress.getMetadata().getName()).get();
    if (existing == null || !expected.getSpec().getSelector().equals(existing.getSpec().getSelector()) || !expected.getMetadata().getLabels().equals(existing.getMetadata().getLabels())) {
        return kubernetesClient.services().inNamespace(bridgeIngress.getMetadata().getNamespace()).createOrReplace(expected);
    }
    return existing;
}
Also used : LabelsBuilder(com.redhat.service.smartevents.shard.operator.utils.LabelsBuilder) Service(io.fabric8.kubernetes.api.model.Service)

Example 7 with LabelsBuilder

use of com.redhat.service.smartevents.shard.operator.utils.LabelsBuilder in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class ServiceMonitorServiceImpl method ensureLabels.

private void ensureLabels(final ServiceMonitor serviceMonitor, final Service service, final String component) {
    serviceMonitor.getSpec().getSelector().setMatchLabels(new LabelsBuilder().withAppInstance(service.getMetadata().getName()).build());
    serviceMonitor.getMetadata().setLabels(new LabelsBuilder().withAppInstance(service.getMetadata().getName()).withComponent(component).buildWithDefaults());
}
Also used : LabelsBuilder(com.redhat.service.smartevents.shard.operator.utils.LabelsBuilder)

Aggregations

LabelsBuilder (com.redhat.service.smartevents.shard.operator.utils.LabelsBuilder)7 When (io.cucumber.java.en.When)2 EnvVar (io.fabric8.kubernetes.api.model.EnvVar)2 EnvVarBuilder (io.fabric8.kubernetes.api.model.EnvVarBuilder)2 ObjectMetaBuilder (io.fabric8.kubernetes.api.model.ObjectMetaBuilder)2 Secret (io.fabric8.kubernetes.api.model.Secret)2 SecretBuilder (io.fabric8.kubernetes.api.model.SecretBuilder)2 Service (io.fabric8.kubernetes.api.model.Service)2 Deployment (io.fabric8.kubernetes.api.model.apps.Deployment)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 InputStream (java.io.InputStream)2 ArrayList (java.util.ArrayList)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 BridgeExecutor (com.redhat.service.smartevents.shard.operator.resources.BridgeExecutor)1 BridgeIngress (com.redhat.service.smartevents.shard.operator.resources.BridgeIngress)1