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;
}
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());
}
Aggregations