Skip to content

Commit

Permalink
fix: fix labels on k8s objects + remove required imageName from conta…
Browse files Browse the repository at this point in the history
…iner
  • Loading branch information
matteo-s committed May 7, 2024
1 parent 5ffba49 commit 1e5c907
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,9 @@ protected Map<String, String> buildLabels(T runnable) {
"app.kubernetes.io/instance",
"dhcore-" + runnable.getId(),
"app.kubernetes.io/version",
version,
"app.kubernetes.io/component",
"dhcore-k8s",
runnable.getId(),
"app.kubernetes.io/part-of",
"dhcore",
"dhcore-" + runnable.getFramework() + "-" + runnable.getId(),
"app.kubernetes.io/managed-by",
"dhcore"
);
Expand All @@ -146,11 +144,14 @@ protected List<V1EnvVar> buildEnv(T runnable) {
V1Secret secret = buildRunSecret(runnable);
List<V1EnvVar> runSecretEnvs = new LinkedList<>();
if (secret != null && secret.getStringData() != null && !secret.getStringData().isEmpty()) {
Map<String, Set<String>> runSecretKeys = Collections.singletonMap(secret.getMetadata().getName(), secret.getStringData().keySet());
Map<String, Set<String>> runSecretKeys = Collections.singletonMap(
secret.getMetadata().getName(),
secret.getStringData().keySet()
);
runSecretEnvs.addAll(k8sBuilderHelper.geEnvVarsFromSecrets(runSecretKeys));
runSecretEnvs.add(new V1EnvVar().name("DH_RUN_SECRET_NAME").value(secret.getMetadata().getName()));
}

// function specific envs
List<V1EnvVar> functionEnvs = runnable
.getEnvs()
Expand Down Expand Up @@ -281,10 +282,20 @@ protected List<String> buildArgs(T runnable) {

protected V1Secret buildRunSecret(T runnable) {
if (runnable.getCredentials() != null) {
return k8sSecretHelper.convertAuthentication(
V1Secret secret = k8sSecretHelper.convertAuthentication(
k8sSecretHelper.getSecretName(runnable.getRuntime(), runnable.getTask(), runnable.getId()),
runnable.getCredentials()
);

//attach labels
Map<String, String> labels = buildLabels(runnable);
labels
.entrySet()
.forEach(e -> {
secret.getMetadata().putLabelsItem(e.getKey(), e.getValue());
});

return secret;
}

return null;
Expand All @@ -298,6 +309,7 @@ protected void storeRunSecret(V1Secret secret) throws K8sFrameworkException {
throw new K8sFrameworkException(e.getMessage());
}
}

protected void cleanRunSecret(T runnable) {
String secretName = k8sSecretHelper.getSecretName(runnable.getRuntime(), runnable.getTask(), runnable.getId());
try {
Expand All @@ -306,5 +318,4 @@ protected void cleanRunSecret(T runnable) {
log.warn("Failed to delete secret {}", secretName, e);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public V1Service build(K8sServeRunnable runnable) throws K8sFrameworkException {

//build service spec
V1ServiceSpec serviceSpec = new V1ServiceSpec().type(type).ports(ports).selector(labels);
V1ObjectMeta serviceMetadata = new V1ObjectMeta().name(serviceName);
V1ObjectMeta serviceMetadata = new V1ObjectMeta().name(serviceName).labels(labels);

return new V1Service().metadata(serviceMetadata).spec(serviceSpec);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ public V1Job build(K8sKanikoRunnable runnable) throws K8sFrameworkException {
Optional<List<ContextRef>> contextRefsOpt = Optional.ofNullable(runnable.getContextRefs());
Optional<List<ContextSource>> contextSourcesOpt = Optional.ofNullable(runnable.getContextSources());
V1ConfigMap configMap = new V1ConfigMap()
.metadata(new V1ObjectMeta().name("init-config-map-" + runnable.getId()))
.metadata(new V1ObjectMeta().name("init-config-map-" + runnable.getId()).labels(labels))
.data(
MapUtils.mergeMultipleMaps(
Map.of("Dockerfile", runnable.getDockerFile()),
Expand Down Expand Up @@ -298,6 +298,7 @@ public V1Job build(K8sKanikoRunnable runnable) throws K8sFrameworkException {
);

// Check if config map already exist. if not, create it
//TODO move creation to run NOT build!
try {
coreV1Api.readNamespacedConfigMap(
Objects.requireNonNull(configMap.getMetadata()).getName(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
@SpecType(runtime = ContainerRuntime.RUNTIME, kind = ContainerRuntime.RUNTIME, entity = EntityName.FUNCTION)
public class FunctionContainerSpec extends FunctionBaseSpec {

@NotBlank
@Schema(description = "Container image name")
private String image;

Expand Down

0 comments on commit 1e5c907

Please sign in to comment.