### Compile and Run Kubernetes Client Java Examples Source: https://github.com/kubernetes-client/java/blob/master/examples/examples-release-latest/README.md Set the repository root, install the project with Maven, navigate to the examples directory, compile, and then execute the example using Maven. ```sh export REPO_ROOT=/path/to/client-java/repo cd ${REPO_ROOT}/ mvn install cd ${REPO_ROOT}/examples/examples-15 mvn compile mvn exec:java -Dexec.mainClass="io.kubernetes.client.examples.Example" ``` -------------------------------- ### Execute Java Example with Maven Source: https://github.com/kubernetes-client/java/wiki/3.-Code-Examples This command shows how to run a specific Java example class using Maven's exec plugin. Ensure you have Maven installed and the project configured. ```shell mvn exec:java -Dexec.mainClass="io.kubernetes.client.examples.Example" ``` -------------------------------- ### Java Kubernetes Client: CoordinationV1beta1Api Example Source: https://github.com/kubernetes-client/java/blob/master/kubernetes/docs/CoordinationV1beta1Api.md Demonstrates how to initialize the Kubernetes client, configure API key authentication, and set the base path for the CoordinationV1beta1Api. This setup is required before making any API calls. ```java // Import classes: import io.kubernetes.client.openapi.ApiClient; import io.kubernetes.client.openapi.ApiException; import io.kubernetes.client.openapi.Configuration; import io.kubernetes.client.openapi.auth.*; import io.kubernetes.client.openapi.models.*; import io.kubernetes.client.openapi.apis.CoordinationV1beta1Api; public class Example { public static void main(String[] args) { ApiClient defaultClient = Configuration.getDefaultApiClient(); defaultClient.setBasePath("http://localhost"); // Configure API key authorization: BearerToken ApiKeyAuth BearerToken = (ApiKeyAuth) defaultClient.getAuthentication("BearerToken"); BearerToken.setApiKey("YOUR API KEY"); // Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null) //BearerToken.setApiKeyPrefix("Token"); CoordinationV1beta1Api apiInstance = new CoordinationV1beta1Api(defaultClient); String namespace = "namespace_example"; // String String pretty = "pretty_example"; // String Boolean allowWatchBookmarks = true; // Boolean String _continue = "_continue_example"; // String String fieldSelector = "fieldSelector_example"; // String String labelSelector = "labelSelector_example"; // String Integer limit = 56; // Integer String resourceVersion = "resourceVersion_example"; // String } } ``` -------------------------------- ### Get Available API Resources - Java Source: https://github.com/kubernetes-client/java/blob/master/kubernetes/docs/BatchV1Api.md This example demonstrates how to retrieve a list of available API resources from the Kubernetes cluster using the BatchV1Api. It includes setup for API client authentication and error handling. ```java import io.kubernetes.client.openapi.ApiClient; import io.kubernetes.client.openapi.ApiException; import io.kubernetes.client.openapi.Configuration; import io.kubernetes.client.openapi.auth.*; import io.kubernetes.client.openapi.models.*; import io.kubernetes.client.openapi.apis.BatchV1Api; public class Example { public static void main(String[] args) { ApiClient defaultClient = Configuration.getDefaultApiClient(); defaultClient.setBasePath("http://localhost"); // Configure API key authorization: BearerToken ApiKeyAuth BearerToken = (ApiKeyAuth) defaultClient.getAuthentication("BearerToken"); BearerToken.setApiKey("YOUR API KEY"); // Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null) //BearerToken.setApiKeyPrefix("Token"); BatchV1Api apiInstance = new BatchV1Api(defaultClient); try { V1APIResourceList result = apiInstance.getAPIResources() .execute(); System.out.println(result); } catch (ApiException e) { System.err.println("Exception when calling BatchV1Api#getAPIResources"); System.err.println("Status code: " + e.getCode()); System.err.println("Reason: " + e.getResponseBody()); System.err.println("Response headers: " + e.getResponseHeaders()); e.printStackTrace(); } } } ``` -------------------------------- ### Kubernetes AdmissionregistrationV1beta1Api Example Source: https://github.com/kubernetes-client/java/blob/master/kubernetes/docs/AdmissionregistrationV1beta1Api.md Demonstrates how to configure the API client, set authentication, and prepare for API calls. Includes common parameters for listing resources. ```java // Import classes: import io.kubernetes.client.openapi.ApiClient; import io.kubernetes.client.openapi.ApiException; import io.kubernetes.client.openapi.Configuration; import io.kubernetes.client.openapi.auth.*; import io.kubernetes.client.openapi.models.*; import io.kubernetes.client.openapi.apis.AdmissionregistrationV1beta1Api; public class Example { public static void main(String[] args) { ApiClient defaultClient = Configuration.getDefaultApiClient(); defaultClient.setBasePath("http://localhost"); // Configure API key authorization: BearerToken ApiKeyAuth BearerToken = (ApiKeyAuth) defaultClient.getAuthentication("BearerToken"); BearerToken.setApiKey("YOUR API KEY"); // Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null) //BearerToken.setApiKeyPrefix("Token"); AdmissionregistrationV1beta1Api apiInstance = new AdmissionregistrationV1beta1Api(defaultClient); String pretty = "pretty_example"; // String | If 'true', then the output is pretty printed. Defaults to 'false' unless the user-agent indicates a browser or command-line HTTP tool (curl and wget). Boolean allowWatchBookmarks = true; // Boolean | allowWatchBookmarks requests watch events with type "BOOKMARK". Servers that do not implement bookmarks may ignore this flag and bookmarks are sent at the server's discretion. Clients should not assume bookmarks are returned at any specific interval, nor may they assume the server will send any BOOKMARK event during a session. If this is not a watch, this field is ignored. This field is not supported when watch is true. String _continue = "_continue_example"; // String | The continue option should be set when retrieving more results from the server. Since this value is server defined, clients may only use the continue value from a previous query result with identical query parameters (except for the value of continue) and the server may reject a continue value it does not recognize. If the specified continue value is no longer valid whether due to expiration (generally five to fifteen minutes) or a configuration change on the server, the server will respond with a 410 ResourceExpired error together with a continue token. If the client needs a consistent list, it must restart their list without the continue field. Otherwise, the client may send another list request with the token received with the 410 error, the server will respond with a list starting from the next key, but from the latest snapshot, which is inconsistent from the previous list results - objects that are created, modified, or deleted after the first list request will be included in the response, as long as their keys are after the "next key". This field is not supported when watch is true. Clients may start a watch from the last resourceVersion value returned by the server and not miss any modifications. String fieldSelector = "fieldSelector_example"; // String | A selector to restrict the list of returned objects by their fields. Defaults to everything. String labelSelector = "labelSelector_example"; // String | A selector to restrict the list of returned objects by their labels. Defaults to everything. Integer limit = 56; // Integer | limit is a maximum number of responses to return for a list call. If more items exist, the server will set the `continue` field on the list metadata to a value that can be used with the same initial query to retrieve the next set of results. Setting a limit may return fewer than the requested amount of items (up to zero items) in the event all requested objects are filtered out and clients should only use the presence of the continue field to determine whether more results are available. Servers may choose not to support the limit argument and will return all of the available results. If limit is specified and the continue field is empty, clients may assume that no more results are available. This field is not supported if watch is true. The server guarantees that the objects returned when using continue will be identical to issuing a single list call without a limit - that is, no objects created, modified, or deleted after the first request is issued will be included in any subsequent continued requests. This is sometimes referred to as a consistent snapshot, and ensures that a client that is using limit to receive smaller chunks of a very large result can ensure they see all possible objects. If objects are updated during a chunked list the version of the object that was present at the time the first list result was calculated is returned. String resourceVersion = "resourceVersion_example"; // String | resourceVersion sets a constraint on what resource versions a request may be served from. See https://kubernetes.io/docs/reference/using-api/api-concepts/#resource-versions for details. Defaults to unset } } ``` -------------------------------- ### Install Fluent Generator with Maven Source: https://github.com/kubernetes-client/java/blob/master/fluent-gen/README.md Execute this Maven command to install the fluent-gen module. Ensure your environment is clean before starting. ```bash mvn -Pfluent-gen install ``` -------------------------------- ### Initialize and Configure StoragemigrationV1beta1Api Client Source: https://github.com/kubernetes-client/java/blob/master/kubernetes/docs/StoragemigrationV1beta1Api.md Demonstrates setting up the Kubernetes client, configuring authentication with an API key, and instantiating the StoragemigrationV1beta1Api. Ensure to replace 'YOUR API KEY' with your actual token. ```java // Import classes: import io.kubernetes.client.openapi.ApiClient; import io.kubernetes.client.openapi.ApiException; import io.kubernetes.client.openapi.Configuration; import io.kubernetes.client.openapi.auth.*; import io.kubernetes.client.openapi.models.*; import io.kubernetes.client.openapi.apis.StoragemigrationV1beta1Api; public class Example { public static void main(String[] args) { ApiClient defaultClient = Configuration.getDefaultApiClient(); defaultClient.setBasePath("http://localhost"); // Configure API key authorization: BearerToken ApiKeyAuth BearerToken = (ApiKeyAuth) defaultClient.getAuthentication("BearerToken"); BearerToken.setApiKey("YOUR API KEY"); // Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null) //BearerToken.setApiKeyPrefix("Token"); StoragemigrationV1beta1Api apiInstance = new StoragemigrationV1beta1Api(defaultClient); String pretty = "pretty_example"; // String | If 'true', then the output is pretty printed. Defaults to 'false' unless the user-agent indicates a browser or command-line HTTP tool (curl and wget). String _continue = "_continue_example"; // String | The continue option should be set when retrieving more results from the server. Since this value is server defined, clients may only use the continue value from a previous query result with identical query parameters (except for the value of continue) and the server may reject a continue value it does not recognize. If the specified continue value is no longer valid whether due to expiration (generally five to fifteen minutes) or a configuration change on the server, the server will respond with a 410 ResourceExpired error together with a continue token. If the client needs a consistent list, it must restart their list without the continue field. Otherwise, the client may send another list request with the token received with the 410 error, the server will respond with a list starting from the next key, but from the latest snapshot, which is inconsistent from the previous list results - objects that are created, modified, or deleted after the first list request will be included in the response, as long as their keys are after the "next key". This field is not supported when watch is true. Clients may start a watch from the last resourceVersion value returned by the server and not miss any modifications. String dryRun = "dryRun_example"; // String | When present, indicates that modifications should not be persisted. An invalid or unrecognized dryRun directive will result in an error response and no further processing of the request. Valid values are: - All: all dry run stages will be processed String fieldSelector = "fieldSelector_example"; // String | A selector to restrict the list of returned objects by their fields. Defaults to everything. Integer gracePeriodSeconds = 56; // Integer | The duration in seconds before the object should be deleted. Value must be non-negative integer. The value zero indicates delete immediately. If this value is nil, the default grace period for the specified type will be used. Defaults to a per object value if not specified. zero means delete immediately. Boolean ignoreStoreReadErrorWithClusterBreakingPotential = true; // Boolean | if set to true, it will trigger an unsafe deletion of the resource in case the normal deletion flow fails with a corrupt object error. A resource is considered corrupt if it can not be retrieved from the underlying storage successfully because of a) its data can not be transformed e.g. decryption failure, or b) it fails to decode into an object. NOTE: unsafe deletion ignores finalizer constraints, skips precondition checks, and removes the object from the storage. WARNING: This may potentially break the cluster if the workload associated with the resource being unsafe-deleted relies on normal deletion flow. Use only if you REALLY know what you are doing. The default value is false, and the user must opt in to enable it String labelSelector = "labelSelector_example"; // String | A selector to restrict the list of returned objects by their labels. Defaults to everything. ``` -------------------------------- ### List StorageV1 Resources with Java Source: https://github.com/kubernetes-client/java/blob/master/kubernetes/docs/StorageV1Api.md This example shows how to initialize the Kubernetes client, configure API key authentication, and instantiate the StorageV1Api. It then demonstrates making a call to list storage resources with various query parameters for filtering and pagination. ```java // Import classes: import io.kubernetes.client.openapi.ApiClient; import io.kubernetes.client.openapi.ApiException; import io.kubernetes.client.openapi.Configuration; import io.kubernetes.client.openapi.auth.*; import io.kubernetes.client.openapi.models.*; import io.kubernetes.client.openapi.apis.StorageV1Api; public class Example { public static void main(String[] args) { ApiClient defaultClient = Configuration.getDefaultApiClient(); defaultClient.setBasePath("http://localhost"); // Configure API key authorization: BearerToken ApiKeyAuth BearerToken = (ApiKeyAuth) defaultClient.getAuthentication("BearerToken"); BearerToken.setApiKey("YOUR API KEY"); // Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null) //BearerToken.setApiKeyPrefix("Token"); StorageV1Api apiInstance = new StorageV1Api(defaultClient); String pretty = "pretty_example"; // String | If 'true', then the output is pretty printed. Defaults to 'false' unless the user-agent indicates a browser or command-line HTTP tool (curl and wget). Boolean allowWatchBookmarks = true; // Boolean | allowWatchBookmarks requests watch events with type "BOOKMARK". Servers that do not implement bookmarks may ignore this flag and bookmarks are sent at the server's discretion. Clients should not assume bookmarks are returned at any specific interval, nor may they assume the server will send any BOOKMARK event during a session. If this is not a watch, this field is ignored. String _continue = "_continue_example"; // String | The continue option should be set when retrieving more results from the server. Since this value is server defined, clients may only use the continue value from a previous query result with identical query parameters (except for the value of continue) and the server may reject a continue value it does not recognize. If the specified continue value is no longer valid whether due to expiration (generally five to fifteen minutes) or a configuration change on the server, the server will respond with a 410 ResourceExpired error together with a continue token. If the client needs a consistent list, it must restart their list without the continue field. Otherwise, the client may send another list request with the token received with the 410 error, the server will respond with a list starting from the next key, but from the latest snapshot, which is inconsistent from the previous list results - objects that are created, modified, or deleted after the first list request will be included in the response, as long as their keys are after the "next key". This field is not supported when watch is true. Clients may start a watch from the last resourceVersion value returned by the server and not miss any modifications. String fieldSelector = "fieldSelector_example"; // String | A selector to restrict the list of returned objects by their fields. Defaults to everything. String labelSelector = "labelSelector_example"; // String | A selector to restrict the list of returned objects by their labels. Defaults to everything. Integer limit = 56; // Integer | limit is a maximum number of responses to return for a list call. If more items exist, the server will set the `continue` field on the list metadata to a value that can be used with the same initial query to retrieve the next set of results. Setting a limit may return fewer than the requested amount of items (up to zero items) in the event all requested objects are filtered out and clients should only use the presence of the continue field to determine whether more results are available. Servers may choose not to support the limit argument and will return all of the available results. If limit is specified and the continue field is empty, clients may assume that no more results are available. This field is not supported if watch is true. The server guarantees that the objects returned when using continue will be identical to issuing a single list call without a limit - that is, no objects created, modified, or deleted after the first request is issued will be included in any subsequent continued requests. This is sometimes referred to as a consistent snapshot, and ensures that a client that is using limit to receive smaller chunks of a very large result can ensure they see all possible objects. If objects are updated during a chunked list the version of the object that was present at the time the first list result was calculated is returned. String resourceVersion = "resourceVersion_example"; // String | resourceVersion sets a constraint on what resource versions a request may be served from. See https://kubernetes.io/docs/reference/using-api/api-concepts/#resource-versions for details. Defaults to unset ``` -------------------------------- ### Kubernetes ResourceV1beta2Api Example Source: https://github.com/kubernetes-client/java/blob/master/kubernetes/docs/ResourceV1beta2Api.md Demonstrates setting up the API client, configuring authentication, and making a request to the ResourceV1beta2Api. Ensure you replace 'YOUR API KEY' with your actual token. ```java import io.kubernetes.client.openapi.ApiClient; import io.kubernetes.client.openapi.ApiException; import io.kubernetes.client.openapi.Configuration; import io.kubernetes.client.openapi.auth.*; import io.kubernetes.client.openapi.models.*; import io.kubernetes.client.openapi.apis.ResourceV1beta2Api; public class Example { public static void main(String[] args) { ApiClient defaultClient = Configuration.getDefaultApiClient(); defaultClient.setBasePath("http://localhost"); // Configure API key authorization: BearerToken ApiKeyAuth BearerToken = (ApiKeyAuth) defaultClient.getAuthentication("BearerToken"); BearerToken.setApiKey("YOUR API KEY"); // Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null) //BearerToken.setApiKeyPrefix("Token"); ResourceV1beta2Api apiInstance = new ResourceV1beta2Api(defaultClient); Boolean allowWatchBookmarks = true; // Boolean | allowWatchBookmarks requests watch events with type "BOOKMARK". Servers that do not implement bookmarks may ignore this flag and bookmarks are sent at the server's discretion. Clients should not assume bookmarks are returned at any specific interval, nor may they assume the server will send any BOOKMARK event during a session. If this is not a watch, this field is ignored. Clients may start a watch from the last resourceVersion value returned by the server and not miss any modifications. String _continue = "_continue_example"; // String | The continue option should be set when retrieving more results from the server. Since this value is server defined, clients may only use the continue value from a previous query result with identical query parameters (except for the value of continue) and the server may reject a continue value it does not recognize. If the specified continue value is no longer valid whether due to expiration (generally five to fifteen minutes) or a configuration change on the server, the server will respond with a 410 ResourceExpired error together with a continue token. If the client needs a consistent list, it must restart their list without the continue field. Otherwise, the client may send another list request with the token received with the 410 error, the server will respond with a list starting from the next key, but from the latest snapshot, which is inconsistent from the previous list results - objects that are created, modified, or deleted after the first list request will be included in the response, as long as their keys are after the "next key". This field is not supported when watch is true. Clients may start a watch from the last resourceVersion value returned by the server and not miss any modifications. String fieldSelector = "fieldSelector_example"; // String | A selector to restrict the list of returned objects by their fields. Defaults to everything. String labelSelector = "labelSelector_example"; // String | A selector to restrict the list of returned objects by their labels. Defaults to everything. Integer limit = 56; // Integer | limit is a maximum number of responses to return for a list call. If more items exist, the server will set the `continue` field on the list metadata to a value that can be used with the same initial query to retrieve the next set of results. Setting a limit may return fewer than the requested amount of items (up to zero items) in the event all requested objects are filtered out and clients should only use the presence of the continue field to determine whether more results are available. Servers may choose not to support the limit argument and will return all of the available results. If limit is specified and the continue field is empty, clients may assume that no more results are available. This field is not supported if watch is true. The server guarantees that the objects returned when using continue will be identical to issuing a single list call without a limit - that is, no objects created, modified, or deleted after the first request is issued will be included in any subsequent continued requests. This is sometimes referred to as a consistent snapshot, and ensures that a client that is using limit to receive smaller chunks of a very large result can ensure they see all possible objects. If objects are updated during a chunked list the version of the object that was present at the time the first list result was calculated is returned. String pretty = "pretty_example"; // String | If 'true', then the output is pretty printed. Defaults to 'false' unless the user-agent indicates a browser or command-line HTTP tool (curl and wget). String resourceVersion = "resourceVersion_example"; // String | resourceVersion sets a constraint on what resource versions a request may be served from. See https://kubernetes.io/docs/reference/using-api/api-concepts/#resource-versions for details. Defaults to unset try { // TODO: Warning - example is incomplete. // The following code is commented out because it is not a complete example. // V1beta2StatefulSetList result = apiInstance.listStatefulSetForAllNamespaces(allowWatchBookmarks, _continue, fieldSelector, labelSelector, limit, pretty, resourceVersion); // System.out.println(result.getItems()); } catch (ApiException e) { System.err.println("Exception when calling ResourceV1beta2Api#listStatefulSetForAllNamespaces"); System.err.println("Status code: " + e.getCode()); System.err.println("Reason: " + e.getResponseBody()); System.err.println("Response headers: " + e.getResponseHeaders()); e.printStackTrace(); } } } ``` -------------------------------- ### Read Namespaced ResourceClaimTemplate with Java Source: https://github.com/kubernetes-client/java/blob/master/kubernetes/docs/ResourceV1beta2Api.md This example shows how to fetch a ResourceClaimTemplate by its name and namespace. It requires proper API client setup and authentication. ```java import io.kubernetes.client.openapi.ApiClient; import io.kubernetes.client.openapi.ApiException; import io.kubernetes.client.openapi.Configuration; import io.kubernetes.client.openapi.auth.*; import io.kubernetes.client.openapi.models.*; import io.kubernetes.client.openapi.apis.ResourceV1beta2Api; public class Example { public static void main(String[] args) { ApiClient defaultClient = Configuration.getDefaultApiClient(); defaultClient.setBasePath("http://localhost"); // Configure API key authorization: BearerToken ApiKeyAuth BearerToken = (ApiKeyAuth) defaultClient.getAuthentication("BearerToken"); BearerToken.setApiKey("YOUR API KEY"); // Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null) //BearerToken.setApiKeyPrefix("Token"); ResourceV1beta2Api apiInstance = new ResourceV1beta2Api(defaultClient); String name = "name_example"; // String | name of the ResourceClaimTemplate String namespace = "namespace_example"; // String | object name and auth scope, such as for teams and projects String pretty = "pretty_example"; // String | If 'true', then the output is pretty printed. Defaults to 'false' unless the user-agent indicates a browser or command-line HTTP tool (curl and wget). try { V1beta2ResourceClaimTemplate result = apiInstance.readNamespacedResourceClaimTemplate(name, namespace) .pretty(pretty) .execute(); System.out.println(result); } catch (ApiException e) { System.err.println("Exception when calling ResourceV1beta2Api#readNamespacedResourceClaimTemplate"); System.err.println("Status code: " + e.getCode()); System.err.println("Reason: " + e.getResponseBody()); System.err.println("Response headers: " + e.getResponseHeaders()); e.printStackTrace(); } } } ``` -------------------------------- ### Read DeviceTaintRule Example Source: https://github.com/kubernetes-client/java/blob/master/kubernetes/docs/ResourceV1alpha3Api.md Demonstrates how to read a specific DeviceTaintRule using the ResourceV1alpha3Api. Includes setup for API client, authentication, and error handling. ```java import io.kubernetes.client.openapi.ApiClient; import io.kubernetes.client.openapi.ApiException; import io.kubernetes.client.openapi.Configuration; import io.kubernetes.client.openapi.auth.*; import io.kubernetes.client.openapi.models.*; import io.kubernetes.client.openapi.apis.ResourceV1alpha3Api; public class Example { public static void main(String[] args) { ApiClient defaultClient = Configuration.getDefaultApiClient(); defaultClient.setBasePath("http://localhost"); // Configure API key authorization: BearerToken ApiKeyAuth BearerToken = (ApiKeyAuth) defaultClient.getAuthentication("BearerToken"); BearerToken.setApiKey("YOUR API KEY"); // Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null) //BearerToken.setApiKeyPrefix("Token"); ResourceV1alpha3Api apiInstance = new ResourceV1alpha3Api(defaultClient); String name = "name_example"; // String | name of the DeviceTaintRule String pretty = "pretty_example"; // String | If 'true', then the output is pretty printed. Defaults to 'false' unless the user-agent indicates a browser or command-line HTTP tool (curl and wget). try { V1alpha3DeviceTaintRule result = apiInstance.readDeviceTaintRule(name) .pretty(pretty) .execute(); System.out.println(result); } catch (ApiException e) { System.err.println("Exception when calling ResourceV1alpha3Api#readDeviceTaintRule"); System.err.println("Status code: " + e.getCode()); System.err.println("Reason: " + e.getResponseBody()); System.err.println("Response headers: " + e.getResponseHeaders()); e.printStackTrace(); } } } ``` -------------------------------- ### Java Example: StoragemigrationV1beta1Api Client Source: https://github.com/kubernetes-client/java/blob/master/kubernetes/docs/StoragemigrationV1beta1Api.md Demonstrates how to initialize and configure the StoragemigrationV1beta1Api client in Java, including setting the base path and API key authentication. This is useful for making authenticated requests to the Kubernetes API. ```java // Import classes: import io.kubernetes.client.openapi.ApiClient; import io.kubernetes.client.openapi.ApiException; import io.kubernetes.client.openapi.Configuration; import io.kubernetes.client.openapi.auth.*; import io.kubernetes.client.openapi.models.*; import io.kubernetes.client.openapi.apis.StoragemigrationV1beta1Api; public class Example { public static void main(String[] args) { ApiClient defaultClient = Configuration.getDefaultApiClient(); defaultClient.setBasePath("http://localhost"); // Configure API key authorization: BearerToken ApiKeyAuth BearerToken = (ApiKeyAuth) defaultClient.getAuthentication("BearerToken"); BearerToken.setApiKey("YOUR API KEY"); // Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null) //BearerToken.setApiKeyPrefix("Token"); StoragemigrationV1beta1Api apiInstance = new StoragemigrationV1beta1Api(defaultClient); String pretty = "pretty_example"; // String | If 'true', then the output is pretty printed. Defaults to 'false' unless the user-agent indicates a browser or command-line HTTP tool (curl and wget). Boolean allowWatchBookmarks = true; // Boolean | allowWatchBookmarks requests watch events with type "BOOKMARK". Servers that do not implement bookmarks may ignore this flag and bookmarks are sent at the server's discretion. Clients should not assume bookmarks are returned at any specific interval, nor may they assume the server will send any BOOKMARK event during a session. If this is not a watch, this field is ignored. String _continue = "_continue_example"; // String | The continue option should be set when retrieving more results from the server. Since this value is server defined, clients may only use the continue value from a previous query result with identical query parameters (except for the value of continue) and the server may reject a continue value it does not recognize. If the specified continue value is no longer valid whether due to expiration (generally five to fifteen minutes) or a configuration change on the server, the server will respond with a 410 ResourceExpired error together with a continue token. If the client needs a consistent list, it must restart their list without the continue field. Otherwise, the client may send another list request with the token received with the 410 error, the server will respond with a list starting from the next key, but from the latest snapshot, which is inconsistent from the previous list results - objects that are created, modified, or deleted after the first list request will be included in the response, as long as their keys are after the "next key". This field is not supported when watch is true. Clients may start a watch from the last resourceVersion value returned by the server and not miss any modifications. String fieldSelector = "fieldSelector_example"; // String | A selector to restrict the list of returned objects by their fields. Defaults to everything. String labelSelector = "labelSelector_example"; // String | A selector to restrict the list of returned objects by their labels. Defaults to everything. Integer limit = 56; // Integer | limit is a maximum number of responses to return for a list call. If more items exist, the server will set the `continue` field on the list metadata to a value that can be used with the same initial query to retrieve the next set of results. Setting a limit may return fewer than the requested amount of items (up to zero items) in the event all requested objects are filtered out and clients should only use the presence of the continue field to determine whether more results are available. Servers may choose not to support the limit argument and will return all of the available results. If limit is specified and the continue field is empty, clients may assume that no more results are available. This field is not supported if watch is true. The server guarantees that the objects returned when using continue will be identical to issuing a single list call without a limit - that is, no objects created, modified, or deleted after the first request is issued will be included in any subsequent continued requests. This is sometimes referred to as a consistent snapshot, and ensures that a client that is using limit to receive smaller chunks of a very large result can ensure they see all possible objects. If objects are updated during a chunked list the version of the object that was present at the time the first list result was calculated is returned. String resourceVersion = "resourceVersion_example"; // String | resourceVersion sets a constraint on what resource versions a request may be served from. See https://kubernetes.io/docs/reference/using-api/api-concepts/#resource-versions for details. Defaults to unset ``` -------------------------------- ### Kubernetes Java Client ResourceV1beta2Api Example Source: https://github.com/kubernetes-client/java/blob/master/kubernetes/docs/ResourceV1beta2Api.md Demonstrates setting up the ApiClient, configuring authentication, and initializing the ResourceV1beta2Api client. This example shows how to set the base path and API key for authentication. ```java import io.kubernetes.client.openapi.ApiClient; import io.kubernetes.client.openapi.ApiException; import io.kubernetes.client.openapi.Configuration; import io.kubernetes.client.openapi.auth.*; import io.kubernetes.client.openapi.models.*; import io.kubernetes.client.openapi.apis.ResourceV1beta2Api; public class Example { public static void main(String[] args) { ApiClient defaultClient = Configuration.getDefaultApiClient(); defaultClient.setBasePath("http://localhost"); // Configure API key authorization: BearerToken ApiKeyAuth BearerToken = (ApiKeyAuth) defaultClient.getAuthentication("BearerToken"); BearerToken.setApiKey("YOUR API KEY"); // Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null) //BearerToken.setApiKeyPrefix("Token"); ResourceV1beta2Api apiInstance = new ResourceV1beta2Api(defaultClient); String pretty = "pretty_example"; // String | If 'true', then the output is pretty printed. Defaults to 'false' unless the user-agent indicates a browser or command-line HTTP tool (curl and wget). String _continue = "_continue_example"; // String | The continue option should be set when retrieving more results from the server. Since this value is server defined, clients may only use the continue value from a previous query result with identical query parameters (except for the value of continue) and the server may reject a continue value it does not recognize. If the specified continue value is no longer valid whether due to expiration (generally five to fifteen minutes) or a configuration change on the server, the server will respond with a 410 ResourceExpired error together with a continue token. If the client needs a consistent list, it must restart their list without the continue field. Otherwise, the client may send another list request with the token received with the 410 error, the server will respond with a list starting from the next key, but from the latest snapshot, which is inconsistent from the previous list results - objects that are created, modified, or deleted after the first list request will be included in the response, as long as their keys are after the "next key". This field is not supported when watch is true. Clients may start a watch from the last resourceVersion value returned by the server and not miss any modifications. String dryRun = "dryRun_example"; // String | When present, indicates that modifications should not be persisted. An invalid or unrecognized dryRun directive will result in an error response and no further processing of the request. Valid values are: - All: all dry run stages will be processed String fieldSelector = "fieldSelector_example"; // String | A selector to restrict the list of returned objects by their fields. Defaults to everything. Integer gracePeriodSeconds = 56; // Integer | The duration in seconds before the object should be deleted. Value must be non-negative integer. The value zero indicates delete immediately. If this value is nil, the default grace period for the specified type will be used. Defaults to a per object value if not specified. zero means delete immediately. Boolean ignoreStoreReadErrorWithClusterBreakingPotential = true; // Boolean | if set to true, it will trigger an unsafe deletion of the resource in case the normal deletion flow fails with a corrupt object error. A resource is considered corrupt if it can not be retrieved from the underlying storage successfully because of a) its data can not be transformed e.g. decryption failure, or b) it fails to decode into an object. NOTE: unsafe deletion ignores finalizer constraints, skips precondition checks, and removes the object from the storage. WARNING: This may potentially break the cluster if the workload associated with the resource being unsafe-deleted relies on normal deletion flow. Use only if you REALLY know what you are doing. The default value is false, and the user must opt in to enable it String labelSelector = "labelSelector_example"; // String | A selector to restrict the list of returned objects by their labels. Defaults to everything. ``` -------------------------------- ### Java Kubernetes ApiregistrationV1Api Example Source: https://github.com/kubernetes-client/java/blob/master/kubernetes/docs/ApiregistrationV1Api.md Demonstrates how to configure the ApiClient, set authentication, and instantiate the ApiregistrationV1Api client. This is a common setup for interacting with Kubernetes APIs. ```java import io.kubernetes.client.openapi.ApiClient; import io.kubernetes.client.openapi.ApiException; import io.kubernetes.client.openapi.Configuration; import io.kubernetes.client.openapi.auth.*; import io.kubernetes.client.openapi.models.*; import io.kubernetes.client.openapi.apis.ApiregistrationV1Api; public class Example { public static void main(String[] args) { ApiClient defaultClient = Configuration.getDefaultApiClient(); defaultClient.setBasePath("http://localhost"); // Configure API key authorization: BearerToken ApiKeyAuth BearerToken = (ApiKeyAuth) defaultClient.getAuthentication("BearerToken"); BearerToken.setApiKey("YOUR API KEY"); // Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null) //BearerToken.setApiKeyPrefix("Token"); ApiregistrationV1Api apiInstance = new ApiregistrationV1Api(defaultClient); String pretty = "pretty_example"; // String | If 'true', then the output is pretty printed. Defaults to 'false' unless the user-agent indicates a browser or command-line HTTP tool (curl and wget). String _continue = "_continue_example"; // String | The continue option should be set when retrieving more results from the server. Since this value is server defined, clients may only use the continue value from a previous query result with identical query parameters (except for the value of continue) and the server may reject a continue value it does not recognize. If the specified continue value is no longer valid whether due to expiration (generally five to fifteen minutes) or a configuration change on the server, the server will respond with a 410 ResourceExpired error together with a continue token. If the client needs a consistent list, it must restart their list without the continue field. Otherwise, the client may send another list request with the token received with the 410 error, the server will respond with a list starting from the next key, but from the latest snapshot, which is inconsistent from the previous list results - objects that are created, modified, or deleted after the first list request will be included in the response, as long as their keys are after the "next key". This field is not supported when watch is true. Clients may start a watch from the last resourceVersion value returned by the server and not miss any modifications. String dryRun = "dryRun_example"; // String | When present, indicates that modifications should not be persisted. An invalid or unrecognized dryRun directive will result in an error response and no further processing of the request. Valid values are: - All: all dry run stages will be processed String fieldSelector = "fieldSelector_example"; // String | A selector to restrict the list of returned objects by their fields. Defaults to everything. Integer gracePeriodSeconds = 56; // Integer | The duration in seconds before the object should be deleted. Value must be non-negative integer. The value zero indicates delete immediately. If this value is nil, the default grace period for the specified type will be used. Defaults to a per object value if not specified. zero means delete immediately. Boolean ignoreStoreReadErrorWithClusterBreakingPotential = true; // Boolean | if set to true, it will trigger an unsafe deletion of the resource in case the normal deletion flow fails with a corrupt object error. A resource is considered corrupt if it can not be retrieved from the underlying storage successfully because of a) its data can not be transformed e.g. decryption failure, or b) it fails to decode into an object. NOTE: unsafe deletion ignores finalizer constraints, skips precondition checks, and removes the object from the storage. WARNING: This may potentially break the cluster if the workload associated with the resource being unsafe-deleted relies on normal deletion flow. Use only if you REALLY know what you are doing. The default value is false, and the user must opt in to enable it String labelSelector = "labelSelector_example"; // String | A selector to restrict the list of returned objects by their labels. Defaults to everything. ``` -------------------------------- ### Read Namespaced ResourceClaimTemplate (Java) Source: https://github.com/kubernetes-client/java/blob/master/kubernetes/docs/ResourceV1Api.md This example shows how to fetch a ResourceClaimTemplate by its name and namespace. It includes setup for API key authentication and basic error handling. ```java import io.kubernetes.client.openapi.ApiClient; import io.kubernetes.client.openapi.ApiException; import io.kubernetes.client.openapi.Configuration; import io.kubernetes.client.openapi.auth.*; import io.kubernetes.client.openapi.models.*; import io.kubernetes.client.openapi.apis.ResourceV1Api; public class Example { public static void main(String[] args) { ApiClient defaultClient = Configuration.getDefaultApiClient(); defaultClient.setBasePath("http://localhost"); // Configure API key authorization: BearerToken ApiKeyAuth BearerToken = (ApiKeyAuth) defaultClient.getAuthentication("BearerToken"); BearerToken.setApiKey("YOUR API KEY"); // Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null) //BearerToken.setApiKeyPrefix("Token"); ResourceV1Api apiInstance = new ResourceV1Api(defaultClient); String name = "name_example"; // String | name of the ResourceClaimTemplate String namespace = "namespace_example"; // String | object name and auth scope, such as for teams and projects String pretty = "pretty_example"; // String | If 'true', then the output is pretty printed. Defaults to 'false' unless the user-agent indicates a browser or command-line HTTP tool (curl and wget). try { V1ResourceClaimTemplate result = apiInstance.readNamespacedResourceClaimTemplate(name, namespace) .pretty(pretty) .execute(); System.out.println(result); } catch (ApiException e) { System.err.println("Exception when calling ResourceV1Api#readNamespacedResourceClaimTemplate"); System.err.println("Status code: " + e.getCode()); System.err.println("Reason: " + e.getResponseBody()); System.err.println("Response headers: " + e.getResponseHeaders()); e.printStackTrace(); } } } ``` -------------------------------- ### Get API Group Information Source: https://github.com/kubernetes-client/java/blob/master/kubernetes/docs/ApiregistrationApi.md Demonstrates how to retrieve information about an API group using the ApiregistrationApi. Includes setup for API client, authentication, and error handling. ```java import io.kubernetes.client.openapi.ApiClient; import io.kubernetes.client.openapi.ApiException; import io.kubernetes.client.openapi.Configuration; import io.kubernetes.client.openapi.auth.*; import io.kubernetes.client.openapi.models.*; import io.kubernetes.client.openapi.apis.ApiregistrationApi; public class Example { public static void main(String[] args) { ApiClient defaultClient = Configuration.getDefaultApiClient(); defaultClient.setBasePath("http://localhost"); // Configure API key authorization: BearerToken ApiKeyAuth BearerToken = (ApiKeyAuth) defaultClient.getAuthentication("BearerToken"); BearerToken.setApiKey("YOUR API KEY"); // Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null) //BearerToken.setApiKeyPrefix("Token"); ApiregistrationApi apiInstance = new ApiregistrationApi(defaultClient); try { V1APIGroup result = apiInstance.getAPIGroup() .execute(); System.out.println(result); } catch (ApiException e) { System.err.println("Exception when calling ApiregistrationApi#getAPIGroup"); System.err.println("Status code: " + e.getCode()); System.err.println("Reason: " + e.getResponseBody()); System.err.println("Response headers: " + e.getResponseHeaders()); e.printStackTrace(); } } } ```