Search in sources :

Example 6 with ConfigMapList

use of io.fabric8.kubernetes.api.model.ConfigMapList in project strimzi by strimzi.

the class K8sImplTest method testList.

@Test
public void testList(TestContext context) {
    Async async = context.async();
    KubernetesClient mockClient = mock(KubernetesClient.class);
    MixedOperation<ConfigMap, ConfigMapList, DoneableConfigMap, Resource<ConfigMap, DoneableConfigMap>> mockConfigMaps = mock(MixedOperation.class);
    when(mockClient.configMaps()).thenReturn(mockConfigMaps);
    when(mockConfigMaps.withLabels(any())).thenReturn(mockConfigMaps);
    when(mockConfigMaps.inNamespace(any())).thenReturn(mockConfigMaps);
    when(mockConfigMaps.list()).thenReturn(new ConfigMapListBuilder().addNewItem().withKind("ConfigMap").withNewMetadata().withName("unrelated").withLabels(Collections.singletonMap("foo", "bar")).endMetadata().withData(Collections.singletonMap("foo", "bar")).endItem().addNewItem().endItem().build());
    K8sImpl k8s = new K8sImpl(vertx, mockClient, new LabelPredicate("foo", "bar"), "default");
    k8s.listMaps(ar -> {
        List<ConfigMap> list = ar.result();
        context.assertFalse(list.isEmpty());
        async.complete();
    });
}
Also used : ConfigMapList(io.fabric8.kubernetes.api.model.ConfigMapList) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) DoneableConfigMap(io.fabric8.kubernetes.api.model.DoneableConfigMap) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) Async(io.vertx.ext.unit.Async) Resource(io.fabric8.kubernetes.client.dsl.Resource) ConfigMapListBuilder(io.fabric8.kubernetes.api.model.ConfigMapListBuilder) DoneableConfigMap(io.fabric8.kubernetes.api.model.DoneableConfigMap) Test(org.junit.Test)

Example 7 with ConfigMapList

use of io.fabric8.kubernetes.api.model.ConfigMapList in project fabric8 by fabric8io.

the class KubernetesConfigAdminBridge method activate.

// ***********************
// Lifecycle
// ***********************
@Activate
void activate() {
    enabled = getSystemPropertyOrEnvVar(FABRIC8_CM_BRIDGE_ENABLED, enabled);
    pidLabel = getSystemPropertyOrEnvVar(FABRIC8_PID_LABEL, pidLabel);
    configMerge = getSystemPropertyOrEnvVar(FABRIC8_CONFIG_MERGE, configMerge);
    configMeta = getSystemPropertyOrEnvVar(FABRIC8_CONFIG_META, configMeta);
    configWatch = getSystemPropertyOrEnvVar(FABRIC8_CONFIG_WATCH, configWatch);
    filters = new HashMap<>();
    String filterList = getSystemPropertyOrEnvVar(FABRIC8_PID_FILTERS);
    if (!Utils.isNullOrEmpty(filterList)) {
        for (String filter : filterList.split(",")) {
            String[] kv = filter.split("=");
            if (kv.length == 2) {
                Set<String> orConditions = new HashSet<>();
                for (String orCondition : kv[1].split(";")) {
                    orConditions.add(orCondition.trim());
                }
                filters.put(kv[0].trim(), orConditions);
            }
        }
    }
    if (enabled) {
        synchronized (lock) {
            watchConfigMapList();
            ConfigMapList list = getConfigMapList();
            if (list != null) {
                for (ConfigMap map : list.getItems()) {
                    updateConfig(map);
                }
            }
        }
    }
}
Also used : ConfigMapList(io.fabric8.kubernetes.api.model.ConfigMapList) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) HashSet(java.util.HashSet) Activate(org.apache.felix.scr.annotations.Activate)

Example 8 with ConfigMapList

use of io.fabric8.kubernetes.api.model.ConfigMapList in project fabric8 by jboss-fuse.

the class KubernetesConfigAdminBridge method watchConfigMapList.

private void watchConfigMapList() {
    if (configWatch) {
        KubernetesClient client = kubernetesClient.get();
        if (client != null) {
            FilterWatchListDeletable<ConfigMap, ConfigMapList, Boolean, Watch, Watcher<ConfigMap>> configMapsSelector = client.configMaps().withLabel(pidLabel);
            for (String key : filters.keySet()) {
                configMapsSelector.withLabelIn(key, filters.get(key).toArray(new String[filters.get(key).size()]));
            }
            watch = configMapsSelector.watch(this);
        } else {
            throw new RuntimeException("KubernetesClient not set");
        }
    }
}
Also used : ConfigMapList(io.fabric8.kubernetes.api.model.ConfigMapList) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) Watch(io.fabric8.kubernetes.client.Watch) Watcher(io.fabric8.kubernetes.client.Watcher)

Aggregations

ConfigMapList (io.fabric8.kubernetes.api.model.ConfigMapList)8 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)7 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)4 DoneableConfigMap (io.fabric8.kubernetes.api.model.DoneableConfigMap)3 Resource (io.fabric8.kubernetes.client.dsl.Resource)3 Watch (io.fabric8.kubernetes.client.Watch)2 Watcher (io.fabric8.kubernetes.client.Watcher)2 HashSet (java.util.HashSet)2 Activate (org.apache.felix.scr.annotations.Activate)2 ConfigMapListBuilder (io.fabric8.kubernetes.api.model.ConfigMapListBuilder)1 DoneableEndpoints (io.fabric8.kubernetes.api.model.DoneableEndpoints)1 DoneablePersistentVolumeClaim (io.fabric8.kubernetes.api.model.DoneablePersistentVolumeClaim)1 DoneablePod (io.fabric8.kubernetes.api.model.DoneablePod)1 DoneableService (io.fabric8.kubernetes.api.model.DoneableService)1 Endpoints (io.fabric8.kubernetes.api.model.Endpoints)1 EndpointsList (io.fabric8.kubernetes.api.model.EndpointsList)1 KubernetesResource (io.fabric8.kubernetes.api.model.KubernetesResource)1 PersistentVolumeClaim (io.fabric8.kubernetes.api.model.PersistentVolumeClaim)1 PersistentVolumeClaimList (io.fabric8.kubernetes.api.model.PersistentVolumeClaimList)1 Pod (io.fabric8.kubernetes.api.model.Pod)1