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

doc: Examples usage of internal class SerializationUtils #3915

Merged
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
10 changes: 8 additions & 2 deletions kubernetes-examples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,22 @@
</properties>

<dependencies>
<dependency>
<groupId>io.fabric8</groupId>
<artifactId>openshift-client-api</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>io.fabric8</groupId>
<artifactId>openshift-client</artifactId>
<scope>runtime</scope>
</dependency>

<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
import io.fabric8.kubernetes.api.model.ObjectMetaBuilder;
import io.fabric8.kubernetes.api.model.PodBuilder;
import io.fabric8.kubernetes.api.model.PodSpecBuilder;
import io.fabric8.kubernetes.client.DefaultKubernetesClient;
import io.fabric8.kubernetes.client.KubernetesClient;
import io.fabric8.kubernetes.client.KubernetesClientBuilder;

import java.util.UUID;
/**
Expand All @@ -31,8 +31,8 @@ public class BindingExample {

@SuppressWarnings("java:S106")
public static void main(String[] args) {
final String podName = "binding-example-" + UUID.randomUUID().toString();
try (final KubernetesClient client = new DefaultKubernetesClient()) {
final String podName = "binding-example-" + UUID.randomUUID();
try (final KubernetesClient client = new KubernetesClientBuilder().build()) {
final String namespace;
if (client.getConfiguration().getNamespace() != null) {
namespace = client.getConfiguration().getNamespace();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
import io.fabric8.kubernetes.api.model.apiextensions.v1.JSONSchemaPropsBuilder;
import io.fabric8.kubernetes.client.CustomResource;
import io.fabric8.kubernetes.client.CustomResourceList;
import io.fabric8.kubernetes.client.DefaultKubernetesClient;
import io.fabric8.kubernetes.client.KubernetesClient;
import io.fabric8.kubernetes.client.KubernetesClientBuilder;
import io.fabric8.kubernetes.client.KubernetesClientException;
import io.fabric8.kubernetes.client.Watcher;
import io.fabric8.kubernetes.client.WatcherException;
Expand All @@ -44,7 +44,7 @@ public class CRDExample {

private static final Logger logger = LoggerFactory.getLogger(CRDExample.class);

private static boolean logRootPaths = false;
private static final boolean LOG_ROOT_PATHS = false;

/**
* Example of Cluster and Namespaced scoped K8S Custom Resources.
Expand All @@ -63,7 +63,7 @@ public static void main(String[] args) {
namespace = args[0];
}
}
try (final KubernetesClient client = new DefaultKubernetesClient()) {
try (final KubernetesClient client = new KubernetesClientBuilder().build()) {
if (resourceNamespaced) {
if (namespace == null) {
namespace = client.getNamespace();
Expand All @@ -78,7 +78,7 @@ public static void main(String[] args) {
System.out.println("Creating cluster scoped resource");
}

if (logRootPaths) {
if (LOG_ROOT_PATHS) {
RootPaths rootPaths = client.rootPaths();
if (rootPaths != null) {
List<String> paths = rootPaths.getPaths();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@

import io.fabric8.kubernetes.api.model.apiextensions.v1beta1.CustomResourceDefinition;
import io.fabric8.kubernetes.api.model.apiextensions.v1beta1.CustomResourceDefinitionList;
import io.fabric8.kubernetes.client.DefaultKubernetesClient;
import io.fabric8.kubernetes.client.KubernetesClient;
import io.fabric8.kubernetes.client.KubernetesClientBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -27,7 +27,7 @@ public class CRDLoadExample {
private static final Logger logger = LoggerFactory.getLogger(CRDLoadExample.class);

public static void main(String[] args) {
try (final KubernetesClient client = new DefaultKubernetesClient()) {
try (final KubernetesClient client = new KubernetesClientBuilder().build()) {
// List all Custom resources.
logger.info("Listing all current Custom Resource Definitions :");
CustomResourceDefinitionList crdList = client.apiextensions().v1beta1().customResourceDefinitions().list();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
import io.fabric8.kubernetes.api.model.ConfigMapBuilder;
import io.fabric8.kubernetes.client.Config;
import io.fabric8.kubernetes.client.ConfigBuilder;
import io.fabric8.kubernetes.client.DefaultKubernetesClient;
import io.fabric8.kubernetes.client.KubernetesClient;
import io.fabric8.kubernetes.client.KubernetesClientBuilder;
import io.fabric8.kubernetes.client.dsl.Resource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -34,21 +34,20 @@ public class ConfigMapExample {

public static void main(String[] args) {
Config config = new ConfigBuilder().build();
KubernetesClient client = new DefaultKubernetesClient(config);
try (KubernetesClient client = new KubernetesClientBuilder().withConfig(config).build()) {

String namespace = null;
if (args.length > 0) {
namespace = args[0];
}
if (namespace == null) {
namespace = client.getNamespace();
}
if (namespace == null) {
namespace = "default";
}
String namespace = null;
if (args.length > 0) {
namespace = args[0];
}
if (namespace == null) {
namespace = client.getNamespace();
}
if (namespace == null) {
namespace = "default";
}

String name = "cheese";
try {
String name = "cheese";
Resource<ConfigMap> configMapResource = client.configMaps().inNamespace(namespace).withName(name);


Expand All @@ -60,8 +59,6 @@ public static void main(String[] args) {

logger.info("Upserted ConfigMap at {} data {}", configMap.getMetadata().getSelfLink(), configMap.getData());

} finally {
client.close();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
import io.fabric8.kubernetes.api.model.PodList;
import io.fabric8.kubernetes.client.Config;
import io.fabric8.kubernetes.client.ConfigBuilder;
import io.fabric8.kubernetes.client.DefaultKubernetesClient;
import io.fabric8.kubernetes.client.KubernetesClient;
import io.fabric8.kubernetes.client.KubernetesClientBuilder;
import io.fabric8.kubernetes.client.dsl.NonNamespaceOperation;
import io.fabric8.kubernetes.client.dsl.PodResource;
import org.slf4j.Logger;
Expand Down Expand Up @@ -57,7 +57,7 @@ public static void main(String[] args) {
builder.withOauthToken(args[1]);
}
Config config = builder.build();
try (final KubernetesClient client = new DefaultKubernetesClient(config)) {
try (final KubernetesClient client = new KubernetesClientBuilder().withConfig(config).build()) {
if (namespace == null) {
namespace = client.getNamespace();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
*/
package io.fabric8.kubernetes.examples;

import io.fabric8.kubernetes.client.AutoAdaptableKubernetesClient;
import io.fabric8.kubernetes.client.Config;
import io.fabric8.kubernetes.client.ConfigBuilder;
import io.fabric8.kubernetes.client.KubernetesClient;
import io.fabric8.kubernetes.client.KubernetesClientBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -37,7 +37,7 @@ public static void main(String[] args) {
.withPassword("developer")
.withNamespace("myproject")
.build();
try (final KubernetesClient client = new AutoAdaptableKubernetesClient(config)) {
try (final KubernetesClient client = new KubernetesClientBuilder().withConfig(config).build()) {

logger.info("Received pods {}", client.pods().list());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public static void main(String[] args) {

log("Using master with url ", master);
Config config = new ConfigBuilder().withMasterUrl(master).build();
try(final KubernetesClient client = new DefaultKubernetesClient(config)) {
try(final KubernetesClient client = new KubernetesClientBuilder().withConfig(config).build()) {
final String namespace = client.getNamespace();

CronJob cronJob1 = new CronJobBuilder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@

import io.fabric8.kubernetes.api.model.HasMetadata;
import io.fabric8.kubernetes.api.model.ObjectMeta;
import io.fabric8.kubernetes.client.DefaultKubernetesClient;
import io.fabric8.kubernetes.client.KubernetesClient;
import io.fabric8.kubernetes.client.KubernetesClientBuilder;
import io.fabric8.kubernetes.client.informers.ResourceEventHandler;
import io.fabric8.kubernetes.client.informers.SharedIndexInformer;
import io.fabric8.kubernetes.client.informers.SharedInformerFactory;
Expand All @@ -33,7 +33,7 @@ public class CustomResourceInformerExample {
private static final Logger logger = LoggerFactory.getLogger(CustomResourceInformerExample.class);

public static void main(String[] args) {
try (KubernetesClient client = new DefaultKubernetesClient()) {
try (KubernetesClient client = new KubernetesClientBuilder().build()) {
SharedInformerFactory sharedInformerFactory = client.informers();
SharedIndexInformer<Dummy> podInformer = sharedInformerFactory.sharedIndexInformerForCustomResource(Dummy.class, 60 * 1000L);
logger.info("Informer factory initialized.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
import io.fabric8.kubernetes.api.model.apiextensions.v1.JSONSchemaPropsBuilder;
import io.fabric8.kubernetes.client.CustomResource;
import io.fabric8.kubernetes.client.CustomResourceList;
import io.fabric8.kubernetes.client.DefaultKubernetesClient;
import io.fabric8.kubernetes.client.KubernetesClient;
import io.fabric8.kubernetes.client.KubernetesClientBuilder;
import io.fabric8.kubernetes.client.dsl.NonNamespaceOperation;
import io.fabric8.kubernetes.client.dsl.Resource;
import io.fabric8.kubernetes.client.dsl.base.CustomResourceDefinitionContext;
Expand All @@ -35,7 +35,7 @@ public class CustomResourceV1Example {

@SuppressWarnings("java:S106")
public static void main(String... args) {
try (KubernetesClient kc = new DefaultKubernetesClient()) {
try (KubernetesClient kc = new KubernetesClientBuilder().build()) {
// @formatter:off
final CustomResourceDefinition crd = CustomResourceDefinitionContext.v1CRDFromCustomResourceType(Show.class)
.editSpec().editVersion(0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
package io.fabric8.kubernetes.examples;

import io.fabric8.kubernetes.api.model.NamespaceBuilder;
import io.fabric8.kubernetes.client.DefaultKubernetesClient;
import io.fabric8.kubernetes.client.KubernetesClient;
import io.fabric8.kubernetes.client.KubernetesClientBuilder;
import io.fabric8.kubernetes.client.KubernetesClientException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -29,7 +29,7 @@ public class DeleteExamples {
private static final String NAMESPACE = "this-is-a-test";

public static void main(String[] args) {
try(KubernetesClient client = new DefaultKubernetesClient()) {
try(KubernetesClient client = new KubernetesClientBuilder().build()) {
try {
logger.info("Create namespace: {}", client.namespaces().create(
new NamespaceBuilder().withNewMetadata().withName(NAMESPACE).endMetadata().build()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
import io.fabric8.kubernetes.api.model.ServiceAccountBuilder;
import io.fabric8.kubernetes.api.model.apps.Deployment;
import io.fabric8.kubernetes.api.model.apps.DeploymentBuilder;
import io.fabric8.kubernetes.client.DefaultKubernetesClient;
import io.fabric8.kubernetes.client.KubernetesClient;
import io.fabric8.kubernetes.client.KubernetesClientBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -34,7 +34,7 @@ public class DeploymentExamples {
private static final String NAMESPACE = "this-is-a-test";

public static void main(String[] args) {
try (KubernetesClient client = new DefaultKubernetesClient()) {
try (KubernetesClient client = new KubernetesClientBuilder().build()) {
// Create a namespace for all our stuff
Namespace ns = new NamespaceBuilder().withNewMetadata().withName(NAMESPACE).addToLabels("this", "rocks").endMetadata().build();
logger.info("Created namespace: {}", client.namespaces().createOrReplace(ns));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
package io.fabric8.kubernetes.examples;

import io.fabric8.kubernetes.api.model.GenericKubernetesResource;
import io.fabric8.kubernetes.client.DefaultKubernetesClient;
import io.fabric8.kubernetes.client.KubernetesClient;
import io.fabric8.kubernetes.client.KubernetesClientBuilder;
import io.fabric8.kubernetes.client.dsl.base.CustomResourceDefinitionContext;
import io.fabric8.kubernetes.client.informers.ResourceEventHandler;
import io.fabric8.kubernetes.client.informers.SharedIndexInformer;
Expand All @@ -40,7 +40,7 @@ public class DynamicSharedIndexInformerExample {
private static final Logger logger = LoggerFactory.getLogger(DynamicSharedIndexInformerExample.class.getSimpleName());

public static void main(String[] args) {
try (KubernetesClient client = new DefaultKubernetesClient()) {
try (KubernetesClient client = new KubernetesClientBuilder().build()) {
SharedInformerFactory informerFactory = client.informers();
CustomResourceDefinitionContext context = new CustomResourceDefinitionContext.Builder()
.withGroup("demo.fabric8.io")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
import io.fabric8.kubernetes.api.model.NamespaceBuilder;
import io.fabric8.kubernetes.api.model.Service;
import io.fabric8.kubernetes.api.model.apps.Deployment;
import io.fabric8.kubernetes.client.DefaultKubernetesClient;
import io.fabric8.kubernetes.client.KubernetesClient;
import io.fabric8.kubernetes.client.KubernetesClientBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -37,7 +37,7 @@ public class EndpointsExample {
private static final String NAMESPACE = "endpoints-example";

public static void main(String[] args) {
try (KubernetesClient client = new DefaultKubernetesClient()) {
try (KubernetesClient client = new KubernetesClientBuilder().build()) {
Namespace ns = new NamespaceBuilder().withNewMetadata().withName(NAMESPACE).addToLabels("this", "rocks").endMetadata().build();
logger.info("Created namespace: {}", client.namespaces().createOrReplace(ns));
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
*/
package io.fabric8.kubernetes.examples;

import io.fabric8.kubernetes.client.DefaultKubernetesClient;
import io.fabric8.kubernetes.client.KubernetesClient;
import io.fabric8.kubernetes.client.KubernetesClientBuilder;
import io.fabric8.kubernetes.client.dsl.ExecListener;
import io.fabric8.kubernetes.client.dsl.ExecWatch;

Expand All @@ -40,8 +40,8 @@ public static void main(String[] args) throws InterruptedException {
}

try (
KubernetesClient client = new DefaultKubernetesClient();
ExecWatch watch = newExecWatch(client, namespace, podName)
KubernetesClient client = new KubernetesClientBuilder().build();
ExecWatch ignore = newExecWatch(client, namespace, podName)
) {
Thread.sleep(10 * 1000L);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
*/
package io.fabric8.kubernetes.examples;

import io.fabric8.kubernetes.client.DefaultKubernetesClient;
import io.fabric8.kubernetes.client.KubernetesClient;
import io.fabric8.kubernetes.client.KubernetesClientBuilder;
import io.fabric8.kubernetes.client.dsl.ExecListener;
import io.fabric8.kubernetes.client.dsl.ExecWatch;

Expand Down Expand Up @@ -46,8 +46,8 @@ public static void main(String[] args) throws InterruptedException {
}

try (
KubernetesClient client = new DefaultKubernetesClient();
ExecWatch watch = newExecWatch(client, namespace, podName, columns, lines);
KubernetesClient client = new KubernetesClientBuilder().build();
ExecWatch ignore = newExecWatch(client, namespace, podName, columns, lines);
) {
Thread.sleep(10 * 1000L);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
*/
package io.fabric8.kubernetes.examples;

import io.fabric8.kubernetes.client.DefaultKubernetesClient;
import io.fabric8.kubernetes.client.KubernetesClient;
import io.fabric8.kubernetes.client.KubernetesClientBuilder;
import io.fabric8.kubernetes.client.dsl.ExecListener;
import io.fabric8.kubernetes.client.dsl.ExecWatch;
import io.fabric8.kubernetes.client.utils.InputStreamPumper;
Expand Down Expand Up @@ -48,7 +48,7 @@ public static void main(String[] args) throws InterruptedException {
}

ScheduledExecutorService executorService = Executors.newScheduledThreadPool(20);
try (KubernetesClient client = new DefaultKubernetesClient()) {
try (KubernetesClient client = new KubernetesClientBuilder().build()) {
for (int i = 0; i < 10; System.out.println("i=" + i), i++) {
ExecWatch watch = null;
CompletableFuture<?> pump = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@

import io.fabric8.kubernetes.client.Config;
import io.fabric8.kubernetes.client.ConfigBuilder;
import io.fabric8.kubernetes.client.DefaultKubernetesClient;
import io.fabric8.kubernetes.client.KubernetesClient;
import io.fabric8.kubernetes.client.KubernetesClientBuilder;
import io.fabric8.kubernetes.client.KubernetesClientException;
import io.fabric8.kubernetes.client.dsl.ExecWatch;
import io.fabric8.kubernetes.client.utils.InputStreamPumper;
Expand All @@ -43,7 +43,7 @@ public static void main(String[] args) {
Config config = new ConfigBuilder().withMasterUrl(master).build();
ExecutorService executorService = Executors.newSingleThreadExecutor();
try (
KubernetesClient client = new DefaultKubernetesClient(config);
KubernetesClient client = new KubernetesClientBuilder().withConfig(config).build();
ExecWatch watch = client.pods().withName(podName)
.redirectingInput()
.redirectingOutput()
Expand Down
Loading