简体   繁体   中英

How to watch ConfigMap with sharedInformer

How to watch changes in configMaps using sharedInformer ? I tried something and I see in log that configMaps is watched but when I change some property in configMap I still see old value:

@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();
}

I was following this example

spring-cloud-kubernetes contributor here. This was fixed as part of this PR . It is on 3.0.x branch, and as such not yet released. But it will fairly soon.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM