Skip to content

Commit

Permalink
Add labels to server imageStreams based on layer and fps
Browse files Browse the repository at this point in the history
  • Loading branch information
jfdenise committed Mar 13, 2024
1 parent 84d8a5f commit 2004f81
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@
import java.util.TreeMap;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import org.jboss.galleon.api.GalleonBuilder;
import org.jboss.galleon.api.Provisioning;
import org.jboss.galleon.api.config.GalleonConfigurationWithLayers;
import org.jboss.galleon.api.config.GalleonFeaturePackConfig;
import org.jboss.galleon.api.config.GalleonProvisioningConfig;
import org.jboss.galleon.config.ConfigId;
import org.jboss.galleon.util.IoUtils;
import org.jboss.galleon.util.ZipUtils;
import org.wildfly.glow.AddOn;
Expand Down Expand Up @@ -277,6 +283,47 @@ private static String bytesToHex(byte[] hash) {
return hexString.toString();
}

static Map<String, String> createLabels(Path provisioning) throws Exception {
GalleonBuilder provider = new GalleonBuilder();
Path dir = provisioning.getParent().resolve("tmpHome");
Files.createDirectory(dir);
StringBuilder layers = new StringBuilder();
StringBuilder excludedLayers = new StringBuilder();
StringBuilder fps = new StringBuilder();
Map<String, String> labels = new HashMap<>();
try (Provisioning p = provider.newProvisioningBuilder(provisioning).setInstallationHome(dir).build()) {
GalleonProvisioningConfig config = provider.newProvisioningBuilder(provisioning).setInstallationHome(dir).build().loadProvisioningConfig(provisioning);
GalleonConfigurationWithLayers cl = config.getDefinedConfig(new ConfigId("standalone", "standalone.xml"));
for(String s : cl.getIncludedLayers()) {
labels.put("org.wildfly.glow.layer."+s,"");
}
for(String s : cl.getExcludedLayers()) {
labels.put("org.wildfly.glow.excluded.layer."+s,"");
}
for (GalleonFeaturePackConfig gfpc : config.getFeaturePackDeps()) {
if (fps.length() != 0) {
fps.append("_");
}
String producerName = gfpc.getLocation().getProducerName();
producerName = producerName.replaceAll("::zip", "");
int i = producerName.indexOf(":");
if(i > 0) {
producerName = producerName.substring(i+1);
}
producerName = producerName.replaceAll(":", "-");
labels.put("org.wildfly.glow.feature-pack."+producerName,"");
}
}
return labels;
}

private static String format(String label) {
if (label.length() > 63) {
label = label.substring(0, 56);
label += ".trunc";
}
return label;
}
static String doServerImageBuild(GlowMessageWriter writer, Path target, OpenShiftClient osClient) throws Exception {
Path provisioning = target.resolve("galleon").resolve("provisioning.xml");
byte[] content = Files.readAllBytes(provisioning);
Expand All @@ -302,6 +349,7 @@ static String doServerImageBuild(GlowMessageWriter writer, Path target, OpenShif
Files.createDirectories(stepOne);
IoUtils.copy(target.resolve("galleon"), stepOne.resolve("galleon"));
ZipUtils.zip(stepOne, file);
stream = stream.toBuilder().editOrNewMetadata().withLabels(createLabels(provisioning)).endMetadata().build();
osClient.imageStreams().resource(stream).createOr(NonDeletingOperation::update);
Files.write(target.resolve(serverImageName + "-image-stream.yaml"), Serialization.asYaml(stream).getBytes());
BuildConfigBuilder builder = new BuildConfigBuilder();
Expand Down
4 changes: 4 additions & 0 deletions openshift-deployment/api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
<groupId>${project.groupId}</groupId>
<artifactId>wildfly-glow-core</artifactId>
</dependency>
<dependency>
<groupId>org.jboss.galleon</groupId>
<artifactId>galleon-api</artifactId>
</dependency>
<dependency>
<groupId>io.fabric8</groupId>
<artifactId>openshift-client</artifactId>
Expand Down

0 comments on commit 2004f81

Please sign in to comment.