Skip to content

Commit 3e3c5fa

Browse files
committed
Correct for git names used as Docker image tags and cleanup repos where we are deleting the last tag
1 parent b485ed6 commit 3e3c5fa

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed

new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/Operator.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@ public static String getImageName() {
7070
String branchName = "";
7171
if (!BUILD_ID.isEmpty()) {
7272
branchName = BRANCH_NAME_FROM_JENKINS;
73+
// Ensure that the branch name can be used as a part of Docker tag by replacing illegal characters
74+
branchName = branchName.codePoints()
75+
.map(cp -> Character.isLetterOrDigit(cp) ? cp : '-')
76+
.collect(StringBuilder::new, StringBuilder::appendCodePoint, StringBuilder::append)
77+
.toString();
7378
} else {
7479
CommandParams params = Command.defaultCommandParams()
7580
.command("git branch | grep \\* | cut -d ' ' -f2-")

new-integration-tests/src/test/java/oracle/weblogic/kubernetes/extensions/ImageBuilders.java

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,15 @@
1010
import java.util.Collection;
1111
import java.util.Collections;
1212
import java.util.HashMap;
13+
import java.util.Iterator;
1314
import java.util.List;
1415
import java.util.Map;
1516
import java.util.concurrent.CountDownLatch;
1617
import java.util.concurrent.atomic.AtomicBoolean;
1718

19+
import com.fasterxml.jackson.core.JsonProcessingException;
20+
import com.fasterxml.jackson.databind.JsonNode;
21+
import com.fasterxml.jackson.databind.ObjectMapper;
1822
import oracle.weblogic.kubernetes.TestConstants;
1923
import oracle.weblogic.kubernetes.actions.impl.Operator;
2024
import oracle.weblogic.kubernetes.utils.ExecCommand;
@@ -243,7 +247,65 @@ private void deleteImageOcir(String token, String imageName) {
243247
}
244248
if (result != null) {
245249
logger.info("result.stdout: \n{0}", result.stdout());
250+
String stdout = result.stdout();
251+
logger.info("result.stdout: \n{0}", stdout);
246252
logger.info("result.stderr: \n{0}", result.stderr());
253+
254+
// check if delete was successful and respond if tag couldn't be deleted because there is only one image
255+
if (!stdout.isEmpty()) {
256+
ObjectMapper mapper = new ObjectMapper();
257+
try {
258+
JsonNode root = mapper.readTree(stdout);
259+
JsonNode errors = root.path("errors");
260+
if (errors != null) {
261+
Iterator<JsonNode> it = errors.elements();
262+
while (it.hasNext()) {
263+
JsonNode entry = it.next();
264+
if (entry != null) {
265+
JsonNode code = entry.path("code");
266+
if (code != null) {
267+
if ("SEMANTIC_VALIDATION_ERROR".equals(code.asText())) {
268+
// The delete of the tag failed because there is only one tag remaining in the
269+
// repository
270+
// Note: there are probably other semantic validation errors, but I don't think
271+
// it's worth
272+
// checking now because our use cases are fairly simple
273+
274+
int colonIdx = imageAndTag.indexOf(':');
275+
String repo = imageAndTag.substring(0, colonIdx);
276+
277+
// Delete the repository
278+
curlCmd =
279+
"curl -skL -X \"DELETE\" -H \"Authorization: Bearer "
280+
+ token
281+
+ "\" \"https://"
282+
+ registry
283+
+ "/20180419/docker/repos/"
284+
+ tenancy
285+
+ "/"
286+
+ repo
287+
+ "\"";
288+
logger.info("About to invoke: " + curlCmd);
289+
result = null;
290+
try {
291+
result = ExecCommand.exec(curlCmd, true);
292+
} catch (Exception e) {
293+
logger.info("Got exception while running command: {0}", curlCmd);
294+
logger.info(e.toString());
295+
}
296+
if (result != null) {
297+
logger.info("result.stdout: \n{0}", result.stdout());
298+
logger.info("result.stderr: \n{0}", result.stderr());
299+
}
300+
}
301+
}
302+
}
303+
}
304+
}
305+
} catch (JsonProcessingException e) {
306+
logger.info("Got exception, parsing failed with errors " + e.getMessage());
307+
}
308+
}
247309
}
248310
}
249311

0 commit comments

Comments
 (0)