Skip to content

Commit

Permalink
fix: fix k8s labels
Browse files Browse the repository at this point in the history
  • Loading branch information
matteo-s committed May 10, 2024
1 parent 6117fbb commit b774509
Showing 1 changed file with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import io.kubernetes.client.openapi.models.V1Toleration;
import io.kubernetes.client.openapi.models.V1Volume;
import io.kubernetes.client.openapi.models.V1VolumeMount;
import it.smartcommunitylabdhub.commons.config.ApplicationProperties;
import it.smartcommunitylabdhub.commons.infrastructure.Framework;
import it.smartcommunitylabdhub.commons.models.enums.State;
import it.smartcommunitylabdhub.framework.k8s.exceptions.K8sFrameworkException;
Expand Down Expand Up @@ -42,6 +43,8 @@ public abstract class K8sBaseFramework<T extends K8sRunnable, K extends Kubernet

protected final CoreV1Api coreV1Api;

protected ApplicationProperties applicationProperties;

protected String namespace;
protected String registrySecret;

Expand All @@ -54,6 +57,11 @@ protected K8sBaseFramework(ApiClient apiClient) {
coreV1Api = new CoreV1Api(apiClient);
}

@Autowired
public void setApplicationProperties(ApplicationProperties applicationProperties) {
this.applicationProperties = applicationProperties;
}

@Autowired
public void setNamespace(@Value("${kubernetes.namespace}") String namespace) {
this.namespace = namespace;
Expand Down Expand Up @@ -123,13 +131,13 @@ protected Map<String, String> buildLabels(T runnable) {
// Create labels for job
Map<String, String> labels = Map.of(
"app.kubernetes.io/instance",
"dhcore-" + runnable.getId(),
applicationProperties.getName() + "-" + runnable.getId(),
"app.kubernetes.io/version",
runnable.getId(),
"app.kubernetes.io/part-of",
"dhcore-" + runnable.getFramework() + "-" + runnable.getId(),
"dhcore-" + runnable.getProject() + "-" + runnable.getId(),
"app.kubernetes.io/managed-by",
"dhcore"
applicationProperties.getName() + "-" + applicationProperties.getVersion()
);
if (runnable.getLabels() != null && !runnable.getLabels().isEmpty()) {
labels = new HashMap<>(labels);
Expand Down

0 comments on commit b774509

Please sign in to comment.