Skip to content

Commit cbee7eb

Browse files
Merge pull request redhat-appstudio#796 from stuartwdouglas/STONEBLD-1579
STONEBLD-1579 Generate Java Kube classes
2 parents 4dc27c0 + 06ab166 commit cbee7eb

39 files changed

+904
-1065
lines changed

Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ generate-crds:
5959
"$(CONTROLLER_GEN)" "$(CRD_OPTIONS)" rbac:roleName=manager-role webhook paths=./pkg/apis/jvmbuildservice/v1alpha1 output:crd:artifacts:config=deploy/crds/base
6060

6161
generate: generate-crds generate-deepcopy-client
62+
cp deploy/crds/base/* java-components/resource-model/src/main/resources/crds
6263

6364
verify-generate-deepcopy-client: generate-deepcopy-client
6465
hack/verify-codegen.sh

java-components/build-request-processor/src/main/java/com/redhat/hacbs/container/analyser/deploy/DeployCommand.java

+6-3
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
import com.redhat.hacbs.container.analyser.deploy.containerregistry.ContainerRegistryDeployer;
3232
import com.redhat.hacbs.container.results.ResultsUpdater;
3333
import com.redhat.hacbs.recipies.util.FileUtil;
34-
import com.redhat.hacbs.resources.model.v1alpha1.Contaminant;
34+
import com.redhat.hacbs.resources.model.v1alpha1.dependencybuildstatus.Contaminates;
3535
import com.redhat.hacbs.resources.util.HashUtil;
3636

3737
import io.quarkus.logging.Log;
@@ -228,9 +228,12 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO
228228
}
229229
if (taskRun != null) {
230230

231-
List<Contaminant> newContaminates = new ArrayList<>();
231+
List<Contaminates> newContaminates = new ArrayList<>();
232232
for (var i : contaminatedGavs.entrySet()) {
233-
newContaminates.add(new Contaminant(i.getKey(), new ArrayList<>(i.getValue())));
233+
Contaminates contaminates = new Contaminates();
234+
contaminates.setContaminatedArtifacts(new ArrayList<>(i.getValue()));
235+
contaminates.setGav(i.getKey());
236+
newContaminates.add(contaminates);
234237
}
235238
String serialisedContaminants = new ObjectMapper().writeValueAsString(newContaminates);
236239
Log.infof("Updating results %s with contaminants %s and deployed resources %s",

java-components/cache/src/main/java/com/redhat/hacbs/artifactcache/artifactwatch/ScmLookup.java

+12-7
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@
1717
import com.redhat.hacbs.artifactcache.services.RecipeManager;
1818
import com.redhat.hacbs.recipies.GAV;
1919
import com.redhat.hacbs.resources.model.v1alpha1.ArtifactBuild;
20+
import com.redhat.hacbs.resources.model.v1alpha1.ArtifactBuildStatus;
2021
import com.redhat.hacbs.resources.model.v1alpha1.ModelConstants;
21-
import com.redhat.hacbs.resources.model.v1alpha1.ScmInfo;
22+
import com.redhat.hacbs.resources.model.v1alpha1.artifactbuildstatus.Scm;
2223

2324
import io.fabric8.kubernetes.client.KubernetesClient;
2425
import io.fabric8.kubernetes.client.KubernetesClientException;
@@ -60,8 +61,9 @@ void setup() {
6061
public void onAdd(ArtifactBuild newObj) {
6162

6263
for (var i = 0; i < 3; ++i) { //retry loop
63-
if (newObj.getStatus().getState() == null || Objects.equals(newObj.getStatus().getState(), "")
64-
|| Objects.equals(newObj.getStatus().getState(), ArtifactBuild.NEW)) {
64+
if (newObj.getStatus() == null || newObj.getStatus().getState() == null
65+
|| Objects.equals(newObj.getStatus().getState(), "")
66+
|| Objects.equals(newObj.getStatus().getState(), ModelConstants.ARTIFACT_BUILD_NEW)) {
6567
try {
6668
try {
6769
if (newObj.getMetadata().getAnnotations() != null
@@ -74,20 +76,23 @@ public void onAdd(ArtifactBuild newObj) {
7476
return; //the update should trigger the watch again
7577
}
7678
var result = recipeManager.locator().resolveTagInfo(GAV.parse(newObj.getSpec().getGav()));
77-
ScmInfo scm = new ScmInfo();
79+
Scm scm = new Scm();
7880
scm.setScmType("git");
7981
scm.setScmURL(result.getRepoInfo().getUri());
8082
scm.setCommitHash(result.getHash());
8183
scm.setPath(result.getRepoInfo().getPath());
82-
scm.setPrivateRepo(result.getRepoInfo().isPrivateRepo());
84+
scm.set_private(result.getRepoInfo().isPrivateRepo());
8385
scm.setTag(result.getTag());
86+
if (newObj.getStatus() == null) {
87+
newObj.setStatus(new ArtifactBuildStatus());
88+
}
8489
newObj.getStatus().setScm(scm);
8590
newObj.getStatus().setMessage("");
86-
newObj.getStatus().setState(ArtifactBuild.DISCOVERING);
91+
newObj.getStatus().setState(ModelConstants.ARTIFACT_BUILD_DISCOVERING);
8792
} catch (Exception e) {
8893
Log.errorf(e, "Failed to update rebuilt object");
8994
newObj.getStatus().setMessage(e.getMessage());
90-
newObj.getStatus().setState(ArtifactBuild.MISSING);
95+
newObj.getStatus().setState(ModelConstants.ARTIFACT_BUILD_MISSING);
9196
// Not setting status label to missing here but will be handled in artifactbuild.go Reconcile
9297
// operator loop that calls updateLabel.
9398
}

java-components/cache/src/main/java/com/redhat/hacbs/artifactcache/services/RemoteRepositoryManager.java

+22-4
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import com.redhat.hacbs.artifactcache.artifactwatch.RebuiltArtifacts;
1818
import com.redhat.hacbs.artifactcache.services.client.maven.MavenClient;
1919
import com.redhat.hacbs.artifactcache.services.client.ociregistry.OCIRegistryRepositoryClient;
20-
import com.redhat.hacbs.resources.model.v1alpha1.ImageRegistry;
20+
import com.redhat.hacbs.resources.model.v1alpha1.jbsconfigstatus.ImageRegistry;
2121

2222
import io.quarkus.logging.Log;
2323
import io.quarkus.runtime.Startup;
@@ -80,11 +80,11 @@ void setup() throws IOException, GitAPIException {
8080
if (sharedRegistries.isPresent()) {
8181
String[] registries = sharedRegistries.get().split(";", -1);
8282
for (int i = 0; i < registries.length; i++) {
83-
ImageRegistry registry = ImageRegistry.parseRegistry(registries[i]);
83+
ImageRegistry registry = parseRegistry(registries[i]);
8484
String name = "shared-rebuilt-" + i;
8585

8686
Repository rebuiltRepo = new Repository(name,
87-
"http" + (registry.isInsecure() ? "" : "s") + "://" +
87+
"http" + (registry.getInsecure() ? "" : "s") + "://" +
8888
registry.getHost() + ":" + registry.getPort() + "/" +
8989
registry.getRepository() + "/"
9090
+ registry.getPrependTag(),
@@ -96,7 +96,7 @@ void setup() throws IOException, GitAPIException {
9696
// TODO: How to pass token through
9797
Optional.empty(),
9898
Optional.of(registry.getPrependTag()),
99-
registry.isInsecure(),
99+
registry.getInsecure(),
100100
rebuiltArtifacts,
101101
storageManager));
102102

@@ -195,4 +195,22 @@ private List<Repository> createSystemRepository(String repo) {
195195
return ret;
196196
}
197197

198+
static ImageRegistry parseRegistry(String registry) {
199+
ImageRegistry result = new ImageRegistry();
200+
// This represents a comma-separated sequence in the *same* order as defined in
201+
// ImageRegistry in pkg/apis/jvmbuildservice/v1alpha1/jbsconfig_types.go
202+
String[] splitRegistry = registry.split(",", -1);
203+
if (splitRegistry.length != 6) {
204+
throw new RuntimeException("Invalid registry format");
205+
}
206+
result.setHost(splitRegistry[0]);
207+
result.setPort(splitRegistry[1]);
208+
result.setOwner(splitRegistry[2]);
209+
result.setRepository(splitRegistry[3]);
210+
result.setInsecure(Boolean.parseBoolean(splitRegistry[4]));
211+
result.setPrependTag(splitRegistry[5]);
212+
213+
return result;
214+
}
215+
198216
}

java-components/cli/src/main/java/io/github/redhatappstudio/jvmbuild/cli/artifacts/ArtifactListCommand.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package io.github.redhatappstudio.jvmbuild.cli.artifacts;
22

3-
import com.redhat.hacbs.resources.model.v1alpha1.ArtifactBuild;
3+
import com.redhat.hacbs.resources.model.v1alpha1.ModelConstants;
44

55
import picocli.CommandLine;
66

@@ -24,10 +24,11 @@ public void run() {
2424
}
2525
var e = it.next();
2626
String state = e.getValue().getStatus().getState();
27-
boolean buildFailed = state.equals(ArtifactBuild.FAILED) || state.equals(ArtifactBuild.MISSING);
27+
boolean buildFailed = state.equals(ModelConstants.ARTIFACT_BUILD_FAILED)
28+
|| state.equals(ModelConstants.ARTIFACT_BUILD_MISSING);
2829
if (failed && !buildFailed) {
2930
it.remove();
30-
} else if (building && (buildFailed || state.equals(ArtifactBuild.COMPLETE))) {
31+
} else if (building && (buildFailed || state.equals(ModelConstants.ARTIFACT_BUILD_COMPLETE))) {
3132
it.remove();
3233
} else {
3334
nameLongest = Math.max(nameLongest, e.getKey().length());

java-components/cli/src/main/java/io/github/redhatappstudio/jvmbuild/cli/artifacts/ArtifactRebuildCommand.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import java.util.function.UnaryOperator;
55

66
import com.redhat.hacbs.resources.model.v1alpha1.ArtifactBuild;
7+
import com.redhat.hacbs.resources.model.v1alpha1.ModelConstants;
78

89
import io.fabric8.kubernetes.client.KubernetesClient;
910
import io.quarkus.arc.Arc;
@@ -32,9 +33,9 @@ public void run() {
3233
}
3334
var client = Arc.container().instance(KubernetesClient.class).get();
3435
for (var ab : client.resources(ArtifactBuild.class).list().getItems()) {
35-
if (!ab.getStatus().getState().equals(ArtifactBuild.COMPLETE)) {
36+
if (!ab.getStatus().getState().equals(ModelConstants.ARTIFACT_BUILD_COMPLETE)) {
3637
if (missing) {
37-
if (!ab.getStatus().getState().equals(ArtifactBuild.MISSING)) {
38+
if (!ab.getStatus().getState().equals(ModelConstants.ARTIFACT_BUILD_MISSING)) {
3839
continue;
3940
}
4041
}

java-components/cli/src/main/java/io/github/redhatappstudio/jvmbuild/cli/artifacts/ArtifactSummaryCommand.java

+7-10
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
package io.github.redhatappstudio.jvmbuild.cli.artifacts;
22

3-
import static com.redhat.hacbs.resources.model.v1alpha1.ArtifactBuild.COMPLETE;
4-
import static com.redhat.hacbs.resources.model.v1alpha1.ArtifactBuild.FAILED;
5-
import static com.redhat.hacbs.resources.model.v1alpha1.ArtifactBuild.MISSING;
6-
73
import java.util.HashMap;
84
import java.util.Map;
95
import java.util.concurrent.atomic.AtomicInteger;
106

117
import com.redhat.hacbs.resources.model.v1alpha1.ArtifactBuild;
8+
import com.redhat.hacbs.resources.model.v1alpha1.ModelConstants;
129

1310
import io.fabric8.kubernetes.client.KubernetesClient;
1411
import io.quarkus.arc.Arc;
@@ -22,13 +19,13 @@ public void run() {
2219
var client = Arc.container().instance(KubernetesClient.class).get();
2320
var list = client.resources(ArtifactBuild.class).list().getItems();
2421
Map<String, AtomicInteger> counts = new HashMap<>();
25-
counts.put(COMPLETE, new AtomicInteger());
26-
counts.put(MISSING, new AtomicInteger());
27-
counts.put(FAILED, new AtomicInteger());
22+
counts.put(ModelConstants.ARTIFACT_BUILD_COMPLETE, new AtomicInteger());
23+
counts.put(ModelConstants.ARTIFACT_BUILD_MISSING, new AtomicInteger());
24+
counts.put(ModelConstants.ARTIFACT_BUILD_FAILED, new AtomicInteger());
2825
list.forEach(s -> counts.computeIfAbsent(s.getStatus().getState(), (k) -> new AtomicInteger()).incrementAndGet());
29-
System.out.println("Complete:\t" + counts.remove(COMPLETE).get());
30-
System.out.println("Missing:\t" + counts.remove(MISSING).get());
31-
System.out.println("Failed:\t\t" + counts.remove(FAILED).get());
26+
System.out.println("Complete:\t" + counts.remove(ModelConstants.ARTIFACT_BUILD_COMPLETE).get());
27+
System.out.println("Missing:\t" + counts.remove(ModelConstants.ARTIFACT_BUILD_MISSING).get());
28+
System.out.println("Failed:\t\t" + counts.remove(ModelConstants.ARTIFACT_BUILD_FAILED).get());
3229
for (var e : counts.entrySet()) {
3330
System.out.println(e.getKey().substring("ArtifactBuild".length()) + ":\t" + e.getValue().get());
3431
}

java-components/cli/src/main/java/io/github/redhatappstudio/jvmbuild/cli/artifacts/MissingArtifactBuildCompleter.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import java.util.stream.Collectors;
44

55
import com.redhat.hacbs.resources.model.v1alpha1.ArtifactBuild;
6+
import com.redhat.hacbs.resources.model.v1alpha1.ModelConstants;
67

78
import io.fabric8.kubernetes.client.KubernetesClient;
89
import io.github.redhatappstudio.jvmbuild.cli.RequestScopedCompleter;
@@ -15,7 +16,8 @@ public class MissingArtifactBuildCompleter extends RequestScopedCompleter {
1516
@Override
1617
public Iterable<String> completionCandidates(KubernetesClient client) {
1718
return client.resources(ArtifactBuild.class).list().getItems().stream()
18-
.filter(s -> s.getStatus().getState().equals(ArtifactBuild.MISSING)).map(s -> s.getMetadata().getName())
19+
.filter(s -> s.getStatus().getState().equals(ModelConstants.ARTIFACT_BUILD_MISSING))
20+
.map(s -> s.getMetadata().getName())
1921
.collect(Collectors.toList());
2022
}
2123

java-components/cli/src/main/java/io/github/redhatappstudio/jvmbuild/cli/artifacts/MissingGavCompleter.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import java.util.stream.Collectors;
44

55
import com.redhat.hacbs.resources.model.v1alpha1.ArtifactBuild;
6+
import com.redhat.hacbs.resources.model.v1alpha1.ModelConstants;
67

78
import io.fabric8.kubernetes.client.KubernetesClient;
89
import io.github.redhatappstudio.jvmbuild.cli.RequestScopedCompleter;
@@ -15,7 +16,8 @@ public class MissingGavCompleter extends RequestScopedCompleter {
1516
@Override
1617
protected Iterable<String> completionCandidates(KubernetesClient client) {
1718
return client.resources(ArtifactBuild.class).list().getItems().stream()
18-
.filter(s -> s.getStatus().getState().equals(ArtifactBuild.MISSING)).map(s -> s.getSpec().getGav())
19+
.filter(s -> s.getStatus().getState().equals(ModelConstants.ARTIFACT_BUILD_MISSING))
20+
.map(s -> s.getSpec().getGav())
1921
.collect(Collectors.toList());
2022
}
2123
}

java-components/cli/src/main/java/io/github/redhatappstudio/jvmbuild/cli/builds/BuildCompleter.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import java.util.Set;
1010

1111
import com.redhat.hacbs.resources.model.v1alpha1.DependencyBuild;
12-
import com.redhat.hacbs.resources.model.v1alpha1.ScmInfo;
12+
import com.redhat.hacbs.resources.model.v1alpha1.dependencybuildspec.Scm;
1313

1414
import io.fabric8.kubernetes.client.KubernetesClient;
1515
import io.github.redhatappstudio.jvmbuild.cli.RequestScopedCompleter;
@@ -28,7 +28,7 @@ public static Map<String, DependencyBuild> createNames() {
2828
Set<String> doubleUps = new HashSet<>();
2929
Map<String, DependencyBuild> names = new HashMap<>();
3030
for (var i : builds) {
31-
ScmInfo scm = i.getSpec().getScm();
31+
var scm = i.getSpec().getScm();
3232
String full = createFullName(scm);
3333
try {
3434
URI uri = new URI(scm.getScmURL());
@@ -56,7 +56,7 @@ public static Map<String, DependencyBuild> createNames() {
5656
return names;
5757
}
5858

59-
private static String createFullName(ScmInfo scm) {
59+
private static String createFullName(Scm scm) {
6060
String full = scm.getScmURL() + "@" + scm.getTag();
6161
if (scm.getPath() != null && scm.getPath().length() > 1) {
6262
full = full + ":" + scm.getPath();

java-components/cli/src/main/java/io/github/redhatappstudio/jvmbuild/cli/settings/SetupRebuildsCommand.java

+6-5
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import jakarta.inject.Inject;
77

88
import com.redhat.hacbs.resources.model.v1alpha1.JBSConfig;
9+
import com.redhat.hacbs.resources.model.v1alpha1.ModelConstants;
910

1011
import io.fabric8.kubernetes.client.KubernetesClient;
1112
import picocli.CommandLine;
@@ -19,10 +20,10 @@ public class SetupRebuildsCommand implements Runnable {
1920
@Override
2021
public void run() {
2122

22-
var resource = client.resources(JBSConfig.class).withName(JBSConfig.NAME);
23+
var resource = client.resources(JBSConfig.class).withName(ModelConstants.JBS_CONFIG_NAME);
2324
JBSConfig config = resource.get();
2425
if (config != null) {
25-
if (config.getSpec().isEnableRebuilds()) {
26+
if (Boolean.TRUE.equals(config.getSpec().getEnableRebuilds())) {
2627
System.out.println("Rebuilds are already enabled for this namespace");
2728
return;
2829
}
@@ -31,7 +32,7 @@ public void run() {
3132
resource.patch(config);
3233
} else {
3334
config = new JBSConfig();
34-
config.getMetadata().setName(JBSConfig.NAME);
35+
config.getMetadata().setName(ModelConstants.JBS_CONFIG_NAME);
3536
config.getSpec().setEnableRebuilds(true);
3637
config.getSpec().setRequireArtifactVerification(true);
3738
client.resource(config).create();
@@ -44,9 +45,9 @@ public void run() {
4445
} catch (InterruptedException e) {
4546
throw new RuntimeException(e);
4647
}
47-
var obj = client.resources(JBSConfig.class).withName(JBSConfig.NAME).get();
48+
var obj = client.resources(JBSConfig.class).withName(ModelConstants.JBS_CONFIG_NAME).get();
4849
System.out.println(Objects.toString(obj.getStatus().getMessage(), "Working..."));
49-
if (obj.getStatus().isRebuildsPossible()) {
50+
if (Boolean.TRUE.equals(obj.getStatus().getRebuildsPossible())) {
5051
System.out.println("Rebuilds setup successfully");
5152
return;
5253
}

0 commit comments

Comments
 (0)