Skip to content

Commit

Permalink
Merge pull request #39554 from xstefank/vcs-uri-config
Browse files Browse the repository at this point in the history
Make VCS URI annotation configurable
  • Loading branch information
geoand authored Mar 21, 2024
2 parents 3da6a27 + 870853f commit 886b78e
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,12 @@ public class KnativeConfig implements PlatformConfiguration {
@ConfigItem(defaultValue = "false")
boolean idempotent;

/**
* VCS URI annotation configuration.
*/
@ConfigItem
VCSUriConfig vcsUri;

public Optional<String> getPartOf() {
return partOf;
}
Expand Down Expand Up @@ -542,6 +548,11 @@ public boolean isIdempotent() {
return idempotent;
}

@Override
public VCSUriConfig getVCSUri() {
return vcsUri;
}

@Override
public RbacConfig getRbacConfig() {
return rbac;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -974,7 +974,7 @@ private static List<DecoratorBuildItem> createAnnotationDecorators(Optional<Proj

project.ifPresent(p -> {
ScmInfo scm = p.getScmInfo();
String vcsUrl = scm != null ? scm.getRemote().get("origin") : null;
String vcsUri = parseVCSUri(config.getVCSUri(), scm);
String commitId = scm != null ? scm.getCommit() : null;

// Dekorate uses its own annotations. Let's replace them with the quarkus ones.
Expand All @@ -988,10 +988,10 @@ private static List<DecoratorBuildItem> createAnnotationDecorators(Optional<Proj
result.add(new DecoratorBuildItem(target, new AddAnnotationDecorator(name,
new Annotation(QUARKUS_ANNOTATIONS_COMMIT_ID, commitId, new String[0]))));
}
if (vcsUrl != null) {
if (vcsUri != null) {
result.add(new DecoratorBuildItem(target,
new AddAnnotationDecorator(name,
new Annotation(QUARKUS_ANNOTATIONS_VCS_URL, Git.sanitizeRemoteUrl(vcsUrl), new String[0]))));
new Annotation(QUARKUS_ANNOTATIONS_VCS_URL, vcsUri, new String[0]))));
}

});
Expand Down Expand Up @@ -1192,4 +1192,11 @@ private static List<PolicyRule> toPolicyRulesList(Map<String, PolicyRuleConfig>
.build())
.collect(Collectors.toList());
}

private static String parseVCSUri(VCSUriConfig config, ScmInfo scm) {
if (config.enabled) {
return config.override.orElseGet(() -> scm != null ? Git.sanitizeRemoteUrl(scm.getRemote().get("origin")) : null);
}
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,12 @@ public class KubernetesConfig implements PlatformConfiguration {
@ConfigItem(defaultValue = "false")
boolean idempotent;

/**
* VCS URI annotation configuration.
*/
@ConfigItem
VCSUriConfig vcsUri;

/**
* Optionally set directory generated kubernetes resources will be written to. Default is `target/kubernetes`.
*/
Expand Down Expand Up @@ -600,6 +606,11 @@ public boolean isIdempotent() {
return idempotent;
}

@Override
public VCSUriConfig getVCSUri() {
return vcsUri;
}

public DeployStrategy getDeployStrategy() {
return deployStrategy;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,12 @@ public EnvVarsConfig getEnv() {
@ConfigItem(defaultValue = "false")
boolean idempotent;

/**
* VCS URI annotation configuration.
*/
@ConfigItem
VCSUriConfig vcsUri;

public Optional<String> getAppSecret() {
return this.appSecret;
}
Expand All @@ -605,6 +611,11 @@ public boolean isIdempotent() {
return idempotent;
}

@Override
public VCSUriConfig getVCSUri() {
return vcsUri;
}

public DeployStrategy getDeployStrategy() {
return deployStrategy;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,6 @@ default String getConfigName() {
SecurityContextConfig getSecurityContext();

boolean isIdempotent();

VCSUriConfig getVCSUri();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package io.quarkus.kubernetes.deployment;

import java.util.Optional;

import io.quarkus.runtime.annotations.ConfigGroup;
import io.quarkus.runtime.annotations.ConfigItem;

@ConfigGroup
public class VCSUriConfig {

/**
* Whether the vcs-uri annotation should be added to the generated configuration.
*/
@ConfigItem(defaultValue = "true")
boolean enabled;

/**
* Optional override of the vcs-uri annotation.
*/
@ConfigItem
Optional<String> override;
}

0 comments on commit 886b78e

Please sign in to comment.