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

Log usage of unstable api #1010

Merged
merged 1 commit into from
Feb 15, 2018
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -7,6 +7,7 @@
New Feature
* Added support for StorageClass - https://github.com/fabric8io/kubernetes-client/pull/978
* Added support for PodSecurityPolicy - https://github.com/fabric8io/kubernetes-client/pull/992
* The client now warns when using Kubernetes alpha or beta resources - https://github.com/fabric8io/kubernetes-client/pull/1010

Improvements
* Fixed issue of SecurityContextConstraints not working - https://github.com/fabric8io/kubernetes-client/pull/982
Original file line number Diff line number Diff line change
@@ -20,6 +20,7 @@
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;

import io.fabric8.kubernetes.client.internal.VersionUsageUtils;
import io.fabric8.kubernetes.client.utils.Serialization;
import okhttp3.MediaType;
import okhttp3.OkHttpClient;
@@ -373,6 +374,7 @@ protected <T> T handleResponse(OkHttpClient client, Request.Builder requestBuild
* @throws IOException
*/
protected <T> T handleResponse(OkHttpClient client, Request.Builder requestBuilder, Class<T> type, Map<String, String> parameters) throws ExecutionException, InterruptedException, KubernetesClientException, IOException {
VersionUsageUtils.log(this.resourceT, this.apiVersion);
Request request = requestBuilder.build();
Response response = client.newCall(request).execute();
try (ResponseBody body = response.body()) {
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/**
* Copyright (C) 2015 Red Hat, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
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);
}

}