@Test public void testConfigSourcesAbsentFailOnMissing() { try { KubernetesConfigSourceConfig config = defaultConfig(); config.enabled = true; config.namespace = Optional.of("demo"); List<String> configMaps = Lists.list("cm2"); config.configMaps = Optional.of(configMaps); config.failOnMissingConfig = true; KubernetesConfigBuildTimeConfig buildTimeConfig = new KubernetesConfigBuildTimeConfig(); KubernetesClient kubernetesClient = Mockito.mock(KubernetesClient.class); stubNamespacedConfigMap(kubernetesClient, null, "cm2"); KubernetesConfigSourceProvider kcsp = new KubernetesConfigSourceProvider(config, buildTimeConfig, kubernetesClient); Iterable<ConfigSource> configSources = kcsp.getConfigSources(null); fail("an exception should be raised"); } catch (RuntimeException expected) { } }
@Override public Iterable<ConfigSource> getConfigSources(ClassLoader forClassLoader) { if (!config.configMaps.isPresent() && !config.secrets.isPresent()) { log.debug("No ConfigMaps or Secrets were configured for config source lookup"); return Collections.emptyList(); } List<ConfigSource> result = new ArrayList<>(); if (config.enabled && config.configMaps.isPresent()) { result.addAll(getConfigMapConfigSources(config.configMaps.get())); } if (buildTimeConfig.secretsEnabled && config.secrets.isPresent()) { result.addAll(getSecretConfigSources(config.secrets.get())); } return result; }
KubernetesConfigSourceProvider implements ConfigSourceProvider { @Override public Iterable<ConfigSource> getConfigSources(ClassLoader forClassLoader) { if (!config.configMaps.isPresent() && !config.secrets.isPresent()) { log.debug("No ConfigMaps or Secrets were configured for config source lookup"); return Collections.emptyList(); } List<ConfigSource> result = new ArrayList<>(); if (config.enabled && config.configMaps.isPresent()) { result.addAll(getConfigMapConfigSources(config.configMaps.get())); } if (buildTimeConfig.secretsEnabled && config.secrets.isPresent()) { result.addAll(getSecretConfigSources(config.secrets.get())); } return result; } }
KubernetesConfigSourceProvider implements ConfigSourceProvider { @Override public Iterable<ConfigSource> getConfigSources(ClassLoader forClassLoader) { if (!config.configMaps.isPresent() && !config.secrets.isPresent()) { log.debug("No ConfigMaps or Secrets were configured for config source lookup"); return Collections.emptyList(); } List<ConfigSource> result = new ArrayList<>(); if (config.enabled && config.configMaps.isPresent()) { result.addAll(getConfigMapConfigSources(config.configMaps.get())); } if (buildTimeConfig.secretsEnabled && config.secrets.isPresent()) { result.addAll(getSecretConfigSources(config.secrets.get())); } return result; } KubernetesConfigSourceProvider(KubernetesConfigSourceConfig config, KubernetesConfigBuildTimeConfig buildTimeConfig,
            KubernetesClient client); }
KubernetesConfigSourceProvider implements ConfigSourceProvider { @Override public Iterable<ConfigSource> getConfigSources(ClassLoader forClassLoader) { if (!config.configMaps.isPresent() && !config.secrets.isPresent()) { log.debug("No ConfigMaps or Secrets were configured for config source lookup"); return Collections.emptyList(); } List<ConfigSource> result = new ArrayList<>(); if (config.enabled && config.configMaps.isPresent()) { result.addAll(getConfigMapConfigSources(config.configMaps.get())); } if (buildTimeConfig.secretsEnabled && config.secrets.isPresent()) { result.addAll(getSecretConfigSources(config.secrets.get())); } return result; } KubernetesConfigSourceProvider(KubernetesConfigSourceConfig config, KubernetesConfigBuildTimeConfig buildTimeConfig,
            KubernetesClient client); @Override Iterable<ConfigSource> getConfigSources(ClassLoader forClassLoader); }
KubernetesConfigSourceProvider implements ConfigSourceProvider { @Override public Iterable<ConfigSource> getConfigSources(ClassLoader forClassLoader) { if (!config.configMaps.isPresent() && !config.secrets.isPresent()) { log.debug("No ConfigMaps or Secrets were configured for config source lookup"); return Collections.emptyList(); } List<ConfigSource> result = new ArrayList<>(); if (config.enabled && config.configMaps.isPresent()) { result.addAll(getConfigMapConfigSources(config.configMaps.get())); } if (buildTimeConfig.secretsEnabled && config.secrets.isPresent()) { result.addAll(getSecretConfigSources(config.secrets.get())); } return result; } KubernetesConfigSourceProvider(KubernetesConfigSourceConfig config, KubernetesConfigBuildTimeConfig buildTimeConfig,
            KubernetesClient client); @Override Iterable<ConfigSource> getConfigSources(ClassLoader forClassLoader);  }