Skip to content

Commit

Permalink
[IBMMQ] Wait until openshift namespace annotations are present
Browse files Browse the repository at this point in the history
  • Loading branch information
avano committed Jan 8, 2025
1 parent 100d44b commit 860bd90
Showing 1 changed file with 29 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.util.List;
import java.util.Map;
import java.util.concurrent.ThreadLocalRandom;
import java.util.function.BooleanSupplier;
import java.util.function.Predicate;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -113,10 +114,9 @@ public void create() {
* What this does it gets the uid interval from the namespace annotation and generates a random uid from that range and "hardcodes" that id
* in the deployment config and changes the auth configuration
*/
final List<Long> uidRange =
Arrays.stream(OpenshiftClient.get().namespaces().withName(OpenshiftClient.get().getNamespace()).get().getMetadata()
.getAnnotations().get("openshift.io/sa.scc.uid-range").split("/")).map(Long::parseLong).toList();
uid = ThreadLocalRandom.current().nextLong(uidRange.get(0), uidRange.get(0) + uidRange.get(1));
UidSupplier supplier = new UidSupplier();
WaitUtils.waitFor(supplier, "Waiting for uid-range openshift annotation");
uid = supplier.getUid();

createMqscConfigMap();

Expand Down Expand Up @@ -261,4 +261,29 @@ private int microshiftClientPort() {
.filter(servicePort -> name().equals(servicePort.getName()))
.findFirst().get().getNodePort();
}

/**
* In some cases the code was quick enough and the annotations were empty, so moved the uid-range logic into a separate supplier.
*/
private static final class UidSupplier implements BooleanSupplier {
private long uid;

@Override
public boolean getAsBoolean() {
Map<String, String> annotations = OpenshiftClient.get().namespaces().withName(OpenshiftClient.get().getNamespace()).get().getMetadata()
.getAnnotations();

if (annotations == null || annotations.isEmpty()) {
return false;
}

final List<Long> uidRange = Arrays.stream(annotations.get("openshift.io/sa.scc.uid-range").split("/")).map(Long::parseLong).toList();
uid = ThreadLocalRandom.current().nextLong(uidRange.get(0), uidRange.get(0) + uidRange.get(1));
return true;
}

public long getUid() {
return uid;
}
}
}

0 comments on commit 860bd90

Please sign in to comment.