-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #983: log usage of unstable api
- Loading branch information
1 parent
89a2c83
commit a1f03da
Showing
2 changed files
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
kubernetes-client/src/main/java/io/fabric8/kubernetes/client/internal/VersionUsageUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package io.fabric8.kubernetes.client.internal; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.util.concurrent.ConcurrentHashMap; | ||
|
||
/** | ||
* Utility class to monitor alhpa/beta version usage and log. | ||
*/ | ||
public final class VersionUsageUtils { | ||
|
||
private static final Logger LOG = LoggerFactory.getLogger(VersionUsageUtils.class); | ||
|
||
private static ConcurrentHashMap<String, Boolean> UNSTABLE_TYPES = new ConcurrentHashMap<>(); | ||
|
||
private static final boolean LOG_EACH_USAGE = false; | ||
|
||
private VersionUsageUtils() { | ||
} | ||
|
||
public static void log(String type, String version) { | ||
if (type == null || version == null) { | ||
return; | ||
} | ||
|
||
if (isUnstable(version)) { | ||
if (LOG_EACH_USAGE || UNSTABLE_TYPES.putIfAbsent(type + "-" + version, true) == null) { | ||
alert(type, version); | ||
} | ||
} | ||
} | ||
|
||
private static boolean isUnstable(String version) { | ||
String lowerCaseVersion = version.toLowerCase(); | ||
return lowerCaseVersion.contains("beta") || lowerCaseVersion.contains("alpha"); | ||
} | ||
|
||
private static void alert(String type, String version) { | ||
LOG.warn("The client is using resource type '{}' with unstable version '{}'", type, version); | ||
} | ||
|
||
} |