如何使用sharedinformer观看configmap

vlju58qv  于 2021-06-30  发布在  Java
关注(0)|答案(0)|浏览(234)

如何使用sharedinformer查看configmaps中的更改?我尝试了一些方法,在日志中看到configmaps被监视,但当我更改configmap中的某些属性时,仍然看到旧值:

@PostConstruct
public void watch() {
    SharedInformerFactory sharedInformerFactory = client.informers();
    SharedIndexInformer<ConfigMap> configMapInformer = sharedInformerFactory.sharedIndexInformerFor(ConfigMap.class,
            ConfigMapList.class, 10 * 1000L);
    configMapInformer.addEventHandler(new ResourceEventHandler<ConfigMap>() {
        @Override
        public void onAdd(ConfigMap configMap) {
            System.out.println("ConfigMap " + configMap.getMetadata().getName() + " got added");
        }

        @Override
        public void onUpdate(ConfigMap oldConfigMap, ConfigMap newConfigMap) {
            System.out.println("ConfigMap " + oldConfigMap.getMetadata().getName() + " got updated");
        }

        @Override
        public void onDelete(ConfigMap configMap, boolean deletedFinalStateUnknown) {
            System.out.println("ConfigMap " + configMap.getMetadata().getName() + " got deleted");
        }
    });

    sharedInformerFactory.startAllRegisteredInformers();
}

我在学这个例子

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题