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

add example mock "kubectl get configmap xx -o json" #639

Closed
wants to merge 5 commits into from
Closed
Changes from 2 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package io.kubernetes.client.examples;

import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.squareup.okhttp.Response;
import io.kubernetes.client.ApiClient;
import io.kubernetes.client.ApiException;
import io.kubernetes.client.Configuration;
import io.kubernetes.client.apis.CoreV1Api;
import io.kubernetes.client.util.Config;
import java.io.IOException;

/**
* A simple example of how to use the Java API
*
* <p>Easiest way to run this: mvn exec:java
* -Dexec.mainClass="io.kubernetes.client.examples.CopyExample"
*
* <p>From inside $REPO_DIR/examples
*
* <p>mock "kubectl get configamp configmap-name -o json"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's the point of adding this example? i don't think this example worth a new file..

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hi @yue9944882
I use java-client to work for pass platform, I need to get xxx.json to change, mock kubectl get resourcename -o json。but Under the existing examples,I don't konw how to do it. Stand in the user's Perspective ,I add example。

It's up to you to decide.

Best Wishes

*/
public class KubectlJsonExample {

public static void main(String[] args) throws ApiException, IOException {

ApiClient client = Config.defaultClient();
Configuration.setDefaultApiClient(client);

CoreV1Api api = new CoreV1Api();
com.squareup.okhttp.Call call =
api.readNamespacedConfigMapCall("configmap-name", "default", null, null, null, null, null);

Response response = call.execute();

if (!response.isSuccessful()) {
return;
}

String body = response.body().string();

JsonObject returnData = new JsonParser().parse(body).getAsJsonObject();

System.out.println(returnData);
}
}