diff --git a/src/main/java/io/kokuwa/maven/k3s/mojo/ApplyMojo.java b/src/main/java/io/kokuwa/maven/k3s/mojo/ApplyMojo.java index 9f4dcd0..6f2b9ee 100644 --- a/src/main/java/io/kokuwa/maven/k3s/mojo/ApplyMojo.java +++ b/src/main/java/io/kokuwa/maven/k3s/mojo/ApplyMojo.java @@ -136,9 +136,9 @@ public void execute() throws MojoExecutionException { var oldMissing = missing.getAndSet(newMissing); if (!newMissing.isEmpty()) { if (oldMissing.equals(newMissing)) { - log.debug("Still waiting for: " + missing); + log.debug("Still waiting for: {}", missing); } else { - log.info("Still waiting for: " + missing); + log.info("Still waiting for: {}", missing); } } } @@ -207,9 +207,9 @@ private Stream>> waitFor(Entry) () -> { try { - log.debug(kind + " " + representation + " ... waiting"); + log.debug("{} {} ... waiting", kind, representation); getDocker().exec(timeout.plusSeconds(10), tmp); - log.info(kind + " " + representation + " ... ready"); + log.info("{} {} ... ready", kind, representation); return true; } catch (MojoExecutionException e) { getDocker().exec("kubectl", "get", "--output=yaml", "--namespace=" + namespace, kind, name); diff --git a/src/main/java/io/kokuwa/maven/k3s/mojo/ImageMojo.java b/src/main/java/io/kokuwa/maven/k3s/mojo/ImageMojo.java index 5698049..cc4cb07 100644 --- a/src/main/java/io/kokuwa/maven/k3s/mojo/ImageMojo.java +++ b/src/main/java/io/kokuwa/maven/k3s/mojo/ImageMojo.java @@ -123,7 +123,7 @@ public void execute() throws MojoExecutionException { private boolean tar(Map> existingImages, Path tarFile) { if (!Files.isRegularFile(tarFile)) { - log.error("Tar not found: " + tarFile); + log.error("Tar not found: {}", tarFile); return false; } @@ -141,13 +141,12 @@ private boolean tar(Map> existingImages, Path tarFile) { .map(l -> l.get(labelChecksum)).filter(Objects::nonNull) .findAny().orElse(null); if (oldChecksum == null) { - log.debug("Tar " + tarFile + " does not exists in ctr."); + log.debug("Tar {} does not exists in ctr.", tarFile); } else if (oldChecksum.equals(newChecksum)) { - log.info("Tar " + tarFile + " present in ctr with checksum " + newChecksum + ", skip."); + log.info("Tar {} present in ctr with checksum {}, skip.", tarFile, newChecksum); return true; } else { - log.debug("Tar " + tarFile + " present in ctr with checksum " + oldChecksum + ", new is: " - + newChecksum); + log.debug("Tar {} present in ctr with checksum {}, new is: {}", tarFile, oldChecksum, newChecksum); } // import tar into ctr @@ -163,30 +162,30 @@ private boolean tar(Map> existingImages, Path tarFile) { getDocker().exec("ctr", "image", "label", matcher.group("image"), labelChecksum + "=" + newChecksum); } else { - log.warn("Tar " + tarFile + " import output cannot be parsed: " + output); + log.warn("Tar {} import output cannot be parsed: {}", tarFile, output); } } } catch (MojoExecutionException | IOException e) { - log.error("Failed to import tar: " + tarFile, e); + log.error("Failed to import tar: {}", tarFile, e); return false; } - log.info("Imported tar from " + tarFile); + log.info("Imported tar from {}", tarFile); return true; } private boolean ctr(Map> existingImages, String image) throws MojoExecutionException { if (existingImages.containsKey(image)) { - log.debug("Image " + image + " found in ctr, skip pulling"); + log.debug("Image {} found in ctr, skip pulling", image); return true; } - log.info("Image " + image + " not found, start pulling"); + log.info("Image {} not found, start pulling", image); // use crictl instead of cri, because crictl honors custom registry.yaml // see https://github.com/k3s-io/k3s/issues/5277 getDocker().exec(pullTimeout, "crictl", "pull", image); - log.info("Image " + image + " pulled"); + log.info("Image {} pulled", image); return true; } @@ -198,19 +197,19 @@ private boolean docker(Map> existingImages, String image) var digest = getDocker().getImage(image).map(ContainerImage::getDigest).orElse(null); if (dockerPullAlways || digest == null) { if (digest != null) { - log.debug("Image " + image + " found in docker, pull always ..."); + log.debug("Image {} found in docker, pull always ...", image); } else { - log.debug("Image " + image + " not found in docker, pulling ..."); + log.debug("Image {} not found in docker, pulling ...", image); } try { getDocker().pullImage(image, pullTimeout); } catch (MojoExecutionException e) { - log.error("Failed to pull docker image " + image, e); + log.error("Failed to pull docker image {}", image, e); return false; } digest = getDocker().getImage(image).map(ContainerImage::getDigest).orElse(null); } else { - log.debug("Image " + image + " found in docker"); + log.debug("Image {} found in docker", image); } // skip if image is already present in ctr @@ -219,13 +218,12 @@ private boolean docker(Map> existingImages, String image) var label = "k3s-maven-digest"; var oldDigest = existingImages.getOrDefault(normalizedImage, Map.of()).get(label); if (oldDigest == null) { - log.debug("Image " + image + " does not exists in ctr."); + log.debug("Image {} does not exists in ctr.", image); } else if (oldDigest.equals(digest)) { - log.info("Image " + image + " present in ctr with digest " + digest + ", skip."); + log.info("Image {} present in ctr with digest {}, skip.", image, digest); return true; } else { - log.debug( - "Image " + image + " present in ctr with digest " + oldDigest + ", new digest is: " + digest); + log.debug("Image {} present in ctr with digest {}, new digest is: {}", image, oldDigest, digest); } // move from docker to ctr @@ -239,11 +237,11 @@ private boolean docker(Map> existingImages, String image) getDocker().exec(pullTimeout, "ctr", "image", "import", destination.toString()); getDocker().exec("ctr", "image", "label", normalizedImage, label + "=" + digest); } catch (MojoExecutionException e) { - log.error("Failed to import tar " + source, e); + log.error("Failed to import tar {}", source, e); return false; } - log.info("Image " + image + " copied from docker deamon"); + log.info("Image {} copied from docker deamon", image); return true; } @@ -259,14 +257,14 @@ private boolean docker(Map> existingImages, String image) .filter(parts -> { var matches = parts.length == 7; if (!matches) { - log.warn("Unexpected output of `ctr image list`: " + List.of(parts)); + log.warn("Unexpected output of `ctr image list`: {}", List.of(parts)); } return matches; }) .map(parts -> Map.entry(parts[0], Stream.of(parts[6].split(",")).map(s -> s.split("=")) .filter(s -> !"io.cri-containerd.image".equals(s[0])) .collect(Collectors.toMap(s -> s[0], s -> s[1])))) - .peek(entry -> log.debug("Found ctr image: " + entry)) + .peek(entry -> log.debug("Found ctr image: {}", entry)) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); } diff --git a/src/main/java/io/kokuwa/maven/k3s/mojo/RestartMojo.java b/src/main/java/io/kokuwa/maven/k3s/mojo/RestartMojo.java index cfb5cc5..84bc98f 100644 --- a/src/main/java/io/kokuwa/maven/k3s/mojo/RestartMojo.java +++ b/src/main/java/io/kokuwa/maven/k3s/mojo/RestartMojo.java @@ -108,7 +108,7 @@ private Callable restart(String resoure) { var matcher = resourcePattern.matcher(resoure); if (!matcher.matches()) { - log.error("Failed to parse resoure: " + resoure); + log.error("Failed to parse resoure: {}", resoure); return () -> false; } @@ -119,10 +119,10 @@ private Callable restart(String resoure) { return () -> { try { getDocker().exec("kubectl", "rollout", "restart", kind, name, "--namespace=" + namespace); - log.info(kind + " " + namespace + "/" + name + " restarted"); + log.info("{} {}/{} restarted", kind, namespace, name); getDocker().exec("kubectl", "rollout", "status", kind, name, "--namespace=" + namespace, "--timeout=" + timeout.getSeconds() + "s"); - log.info(kind + " " + namespace + "/" + name + " restart finished"); + log.info("{} {}/{} restart finished", kind, namespace, name); return true; } catch (MojoExecutionException e) { getDocker().exec("kubectl", "get", "--output=yaml", "--namespace=" + namespace, kind, name); diff --git a/src/main/java/io/kokuwa/maven/k3s/mojo/RunMojo.java b/src/main/java/io/kokuwa/maven/k3s/mojo/RunMojo.java index e6f7b65..f2791bd 100644 --- a/src/main/java/io/kokuwa/maven/k3s/mojo/RunMojo.java +++ b/src/main/java/io/kokuwa/maven/k3s/mojo/RunMojo.java @@ -230,9 +230,9 @@ public void execute() throws MojoExecutionException { if (dnsResolverCheck) { try { var address = InetAddress.getByName(dnsResolverDomain).getHostAddress(); - log.debug("DNS resolved " + dnsResolverDomain + " to " + address + "."); + log.debug("DNS resolved {} to {}.", dnsResolverDomain, address); } catch (UnknownHostException e) { - log.warn("DNS was unable to resolve " + dnsResolverDomain + ". Custom domains may not work!"); + log.warn("DNS was unable to resolve {}. Custom domains may not work!", dnsResolverDomain); } } @@ -250,14 +250,14 @@ public void execute() throws MojoExecutionException { throw new MojoExecutionException("Container with id '" + container.id + "' found. Please remove that container or set 'k3s.failIfExists' to false."); } else if (replaceIfExists) { - log.info("Container with id '" + container.id + "' found, replacing"); + log.info("Container with id '{}' found, replacing", container.id); getDocker().removeContainer(); } else if (!container.isRunning()) { - log.warn("Container with id '" + container.id + "' found in stopped state, restart container"); + log.warn("Container with id '{}' found in stopped state, restart container", container.id); create = false; restart = true; } else { - log.warn("Container with id '" + container.id + "' found, skip creating"); + log.warn("Container with id '{}' found, skip creating", container.id); create = false; } } @@ -283,7 +283,7 @@ public void execute() throws MojoExecutionException { } getDocker().copyFromContainer("/etc/rancher/k3s/k3s.yaml", kubeconfig); - log.info("k3s ready: KUBECONFIG=" + kubeconfig + " kubectl get all --all-namespaces"); + log.info("k3s ready: KUBECONFIG={} kubectl get all --all-namespaces", kubeconfig); } private void createAndStartK3sContainer() throws MojoExecutionException { @@ -331,7 +331,7 @@ private void createAndStartK3sContainer() throws MojoExecutionException { if (disableTraefik) { command.add("--disable=traefik"); } - log.info("k3s " + command.stream().collect(Collectors.joining(" "))); + log.info("k3s {}", command.stream().collect(Collectors.joining(" "))); // create container diff --git a/src/main/java/io/kokuwa/maven/k3s/util/Await.java b/src/main/java/io/kokuwa/maven/k3s/util/Await.java index 1874b19..8bf6c30 100644 --- a/src/main/java/io/kokuwa/maven/k3s/util/Await.java +++ b/src/main/java/io/kokuwa/maven/k3s/util/Await.java @@ -70,13 +70,13 @@ public V until(Callable supplier, Function check) throws Mojo lastException = null; } catch (Exception e) { lastException = e; - log.debug("Await " + text + " failed with exception " + e.getMessage()); + log.debug("Await {} failed with exception {}", text, e.getMessage()); } wait(interval); } if (lastException != null) { - log.error("Await " + text + " had exception while waiting", lastException); + log.error("Await {} had exception while waiting", text, lastException); } onTimeout.run(); diff --git a/src/main/java/io/kokuwa/maven/k3s/util/Task.java b/src/main/java/io/kokuwa/maven/k3s/util/Task.java index c763856..6a19877 100644 --- a/src/main/java/io/kokuwa/maven/k3s/util/Task.java +++ b/src/main/java/io/kokuwa/maven/k3s/util/Task.java @@ -71,7 +71,7 @@ public List run() throws MojoExecutionException { public Task start() throws MojoExecutionException { - log.debug(">>> " + this); + log.debug(">>> {}", this); try { var builder = new ProcessBuilder(command); @@ -102,8 +102,8 @@ public Task waitFor() throws MojoExecutionException { public Task verify() throws MojoExecutionException { var exitCode = process.exitValue(); if (exitCode != 0) { - log.error(">>> " + this); - output.forEach(line -> log.error("<<< " + line)); + log.error(">>> {}", this); + output.forEach(line -> log.error("<<< {}", line)); throw new MojoExecutionException("Command failed with exit code " + exitCode + ": " + this); } return this; @@ -128,10 +128,10 @@ private void collectLogs(String stream, InputStream inputStream) { String line; while ((line = reader.readLine()) != null) { output.add(line); - log.debug("<<< [" + stream + "] " + line); + log.debug("<<< [{}] {}", stream, line); } } catch (IOException e) { - log.debug("Stream " + stream + " closed unexpected: " + e.getMessage()); + log.debug("Stream {} closed unexpected: {}", stream, e.getMessage()); } }); thread.start();