Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IBMMQ] Wait until openshift namespace annotations are present #1293

Merged
merged 1 commit into from
Jan 8, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
}
}
Loading