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

Update Reaper watchers across multiple clouds and config updates #1170

Merged
merged 1 commit into from
Jun 10, 2022
Merged
Show file tree
Hide file tree
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
12 changes: 12 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,18 @@
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.fabric8</groupId>
<artifactId>kubernetes-server-mock</artifactId>
<version>5.12.1</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
import edu.umd.cs.findbugs.annotations.NonNull;
import org.jenkinsci.plugins.kubernetes.auth.KubernetesAuthException;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.NoExternalUse;
Expand Down Expand Up @@ -63,8 +64,15 @@ static KubernetesClient createClient(KubernetesCloud cloud) throws KubernetesAut
return c.getClient();
}

private static int getValidity(KubernetesCloud cloud) {
Object cloudObjects[] = { cloud.getServerUrl(), cloud.getNamespace(), cloud.getServerCertificate(),
/**
* Compute the hash of connection properties of the given cloud. This hash can be used to determine if a cloud
* was updated and a new connection is needed.
* @param cloud cloud to compute validity hash for
* @return client validity hash code
*/
@Restricted(NoExternalUse.class)
public static int getValidity(@NonNull KubernetesCloud cloud) {
Object[] cloudObjects = { cloud.getServerUrl(), cloud.getNamespace(), cloud.getServerCertificate(),
cloud.getCredentialsId(), cloud.isSkipTlsVerify(), cloud.getConnectTimeout(), cloud.getReadTimeout(),
cloud.getMaxRequestsPerHostStr(), cloud.isUseJenkinsProxy() };
return Arrays.hashCode(cloudObjects);
Expand Down Expand Up @@ -93,7 +101,13 @@ public static void invalidate(String displayName) {
clients.invalidate(displayName);
}

@Extension
@Restricted(NoExternalUse.class) // testing only
public static void invalidateAll() {
clients.invalidateAll();
}

// set ordinal to 1 so it runs ahead of Reaper
@Extension(ordinal = 1)
public static class SaveableListenerImpl extends SaveableListener {
@Override
public void onChange(Saveable o, XmlFile file) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.csanchez.jenkins.plugins.kubernetes;

import edu.umd.cs.findbugs.annotations.NonNull;
import hudson.Functions;
import hudson.model.TaskListener;
import io.fabric8.kubernetes.api.model.Event;
Expand All @@ -19,18 +20,22 @@ class TaskListenerEventWatcher implements Watcher<Event> {
private final String name;
private final TaskListener listener;

public TaskListenerEventWatcher(String name, TaskListener listener) {
public TaskListenerEventWatcher(@NonNull String name, @NonNull TaskListener listener) {
this.name = name;
this.listener = listener;
}

@Override
public void eventReceived(Action action, Event event) {
PrintStream logger = listener.getLogger();
// Messages can have multiple lines
String[] lines = event.getMessage().split("\n");
for (String line : lines) {
logger.printf("[%s][%s/%s][%s] %s%n", event.getType(), event.getInvolvedObject().getNamespace(), event.getInvolvedObject().getName(), event.getReason(), line);
// ignore bookmark actions
// event may be null if Error action
if (action != Action.BOOKMARK && event != null) {
PrintStream logger = listener.getLogger();
// Messages can have multiple lines
String[] lines = event.getMessage().split("\n");
for (String line : lines) {
logger.printf("[%s][%s/%s][%s] %s%n", event.getType(), event.getInvolvedObject().getNamespace(), event.getInvolvedObject().getName(), event.getReason(), line);
}
}
}

Expand Down
Loading