Skip to content

Informer the network is disconnected, how to report an error #896

@ZP-AlwaysWin

Description

@ZP-AlwaysWin

When I use the java-client Informer function, even if the network is disconnected, the client has no way to detect it. Is there any way to make the network disconnected and notify the client in time?

The code example is as follows

public class InformerStatefulSets7 {
    public static void main(String[] args)  {
        /**/
        ApiClient apiClient = null;
        try {
            ClassPathResource resource = new ClassPathResource("kubectl.conf");
            InputStream inputStream = resource.getInputStream();
            Reader input = new InputStreamReader(inputStream);

            KubeConfig kubeConfig = KubeConfig.loadKubeConfig(input);
            apiClient = ClientBuilder.kubeconfig(kubeConfig).build();
           apiClient.getHttpClient().newBuilder().pingInterval(100, TimeUnit.MILLISECONDS);
        } catch (Exception e) {
            e.printStackTrace();
        }
        
        SharedInformerFactory factory = new SharedInformerFactory();

        AppsV1Api appsV1Api = new AppsV1Api(apiClient);

        // StatefulSet informer
        SharedIndexInformer<V1StatefulSet> statefulSetInformer =
                factory.sharedIndexInformerFor(
                        (CallGeneratorParams params) -> {
                            try {
                                return appsV1Api.listNamespacedStatefulSetCall(
                                        "default",
                                        null,
                                        null,
                                        null,
                                        null,
                                        null,
                                        null,
                                        params.resourceVersion,
                                        params.timeoutSeconds,
                                        params.watch,
                                        null);
                            } catch (ApiException e) {
                                e.printStackTrace();
                                return null;
                            }

                        },
                        V1StatefulSet.class,
                        V1StatefulSetList.class);

        statefulSetInformer.addEventHandlerWithResyncPeriod(
                new ResourceEventHandler<V1StatefulSet>() {
                    @Override
                    public void onAdd(V1StatefulSet statefulSet) {
                        System.out.printf("%s StatefulSet added!\n", statefulSet.getMetadata().getName());
                    }

                    @Override
                    public void onUpdate(V1StatefulSet oldStatefulSet, V1StatefulSet newStatefulSet) {
                        System.out.printf("%s StatefulSet update!\n", newStatefulSet.getMetadata().getName());
                        System.out.println(newStatefulSet);
                    }

                    @Override
                    public void onDelete(V1StatefulSet statefulSet, boolean deletedFinalStateUnknown) {
                        System.out.printf("%s StatefulSet delete!\n", statefulSet.getMetadata().getName());
                        System.out.println(statefulSet);
                    }
                },1000);

        statefulSetInformer.run();
        
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    lifecycle/rottenDenotes an issue or PR that has aged beyond stale and will be auto-closed.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions