use of io.fabric8.maven.docker.config.CopyConfiguration.Entry in project fabric8 by fabric8io.
the class SessionListener method generateSecrets.
private Set<Secret> generateSecrets(KubernetesClient client, Session session, ObjectMeta meta) {
Set<Secret> secrets = new HashSet<>();
Map<String, String> annotations = meta.getAnnotations();
if (annotations != null && !annotations.isEmpty()) {
for (Map.Entry<String, String> entry : annotations.entrySet()) {
String key = entry.getKey();
String value = entry.getValue();
if (SecretKeys.isSecretKey(key)) {
SecretKeys keyType = SecretKeys.fromValue(key);
for (String name : Secrets.getNames(value)) {
Map<String, String> data = new HashMap<>();
Secret secret = null;
try {
secret = client.secrets().inNamespace(session.getNamespace()).withName(name).get();
} catch (Exception e) {
// ignore - probably doesn't exist
}
if (secret == null) {
for (String c : Secrets.getContents(value, name)) {
data.put(c, keyType.generate());
}
secret = client.secrets().inNamespace(session.getNamespace()).createNew().withNewMetadata().withName(name).endMetadata().withData(data).done();
secrets.add(secret);
}
}
}
}
}
return secrets;
}
use of io.fabric8.maven.docker.config.CopyConfiguration.Entry in project fabric8 by fabric8io.
the class ConfigMaps method createConfigMapAnnotations.
private static Map<String, String> createConfigMapAnnotations(Session session, String status) {
Map<String, String> annotations = new HashMap<>();
File dir = Util.getProjectBaseDir(session);
String gitUrl = Util.findGitUrl(session, dir);
annotations.put(Annotations.Tests.SESSION_ID, session.getId());
annotations.put(Annotations.Tests.TEST_SESSION_STATUS, status);
if (Strings.isNotBlank(gitUrl)) {
annotations.put(Annotations.Builds.GIT_URL, gitUrl);
}
// lets see if there's a maven generated set of pom properties
File pomProperties = new File(dir, "target/maven-archiver/pom.properties");
if (pomProperties.isFile()) {
try {
Properties properties = new Properties();
properties.load(new FileInputStream(pomProperties));
Map<String, String> map = PropertiesHelper.toMap(properties);
for (Map.Entry<String, String> entry : map.entrySet()) {
String key = entry.getKey();
String value = entry.getValue();
if (Strings.isNotBlank(key) && Strings.isNotBlank(value)) {
annotations.put(Annotations.Project.PREFIX + key, value);
}
}
} catch (IOException e) {
session.getLogger().warn("Failed to load " + pomProperties + " file to annotate the namespace: " + e);
}
}
return annotations;
}
use of io.fabric8.maven.docker.config.CopyConfiguration.Entry in project fabric8 by fabric8io.
the class KubernetesConfigAdminBridge method updateConfig.
// **********************
// ConfigAdmin
// **********************
private void updateConfig(ConfigMap map) {
Long ver = Long.parseLong(map.getMetadata().getResourceVersion());
String pid = map.getMetadata().getLabels().get(pidLabel);
String[] p = parsePid(pid);
try {
final Configuration config = getConfiguration(configAdmin.get(), pid, p[0], p[1]);
final Map<String, String> configMapData = map.getData();
if (configMapData == null) {
LOGGER.debug("Ignoring configuration pid={}, (empty)", config.getPid());
return;
}
final Dictionary<String, Object> props = config.getProperties();
final Hashtable<String, Object> configAdmCfg = props != null ? new Hashtable<String, Object>() : null;
Hashtable<String, Object> configMapCfg = new Hashtable<>();
/*
* If there is a key named as pid + ".cfg" (as the pid file on karaf)
* it will be used as source of configuration instead of the content
* of the data field. The name of the key can be changed by setting
* the key fabric8.config.pid.cfg
*
* i.e.
* apiVersion: v1
* data:
* org.ops4j.pax.logging.cfg: |+
* log4j.rootLogger=DEBUG, out
*/
String pidCfg = configMapData.get(FABRIC8_CONFIG_PID_CFG);
if (pidCfg == null) {
pidCfg = pid + ".cfg";
}
String cfgString = configMapData.get(pidCfg);
if (Utils.isNotNullOrEmpty(cfgString)) {
java.util.Properties cfg = new java.util.Properties();
cfg.load(new StringReader(cfgString));
for (Map.Entry<Object, Object> entry : cfg.entrySet()) {
configMapCfg.put((String) entry.getKey(), entry.getValue());
}
} else {
for (Map.Entry<String, String> entry : map.getData().entrySet()) {
configMapCfg.put(entry.getKey(), entry.getValue());
}
}
/*
* Configure if mete-data should be added to the Config Admin or not
*/
boolean meta = configMapData.containsKey(FABRIC8_CONFIG_META) ? Boolean.valueOf(configMapData.get(FABRIC8_CONFIG_META)) : configMeta;
/*
* Configure if ConfigMap data should be merge with ConfigAdmin or it
* should override it.
*/
boolean merge = configMapData.containsKey(FABRIC8_CONFIG_MERGE) ? Boolean.valueOf(configMapData.get(FABRIC8_CONFIG_MERGE)) : configMerge;
if (configAdmCfg != null) {
Long oldVer = (Long) props.get(FABRIC8_K8S_META_RESOURCE_VERSION);
if (oldVer != null && (oldVer >= ver)) {
LOGGER.debug("Ignoring configuration pid={}, oldVersion={} newVersion={} (no changes)", config.getPid(), oldVer, ver);
return;
}
for (Enumeration<String> e = props.keys(); e.hasMoreElements(); ) {
String key = e.nextElement();
Object val = props.get(key);
configAdmCfg.put(key, val);
}
}
if (shouldUpdate(configAdmCfg, configMapCfg)) {
LOGGER.debug("Updating configuration pid={}", config.getPid());
if (meta) {
configMapCfg.put(FABRIC8_PID, pid);
configMapCfg.put(FABRIC8_K8S_META_RESOURCE_VERSION, ver);
configMapCfg.put(FABRIC8_K8S_META_NAME, map.getMetadata().getName());
configMapCfg.put(FABRIC8_K8S_META_NAMESPACE, map.getMetadata().getNamespace());
}
if (merge && configAdmCfg != null) {
for (Map.Entry<String, Object> entry : configMapCfg.entrySet()) {
// Do not override ConfigAdmin meta data
if (!CM_META_KEYS.contains(entry.getKey())) {
configAdmCfg.put(entry.getKey(), entry.getValue());
}
}
configMapCfg = configAdmCfg;
}
config.update(configMapCfg);
} else {
LOGGER.debug("Ignoring configuration pid={} (no changes)", config.getPid());
}
} catch (Exception e) {
LOGGER.warn("", e);
}
}
use of io.fabric8.maven.docker.config.CopyConfiguration.Entry in project fabric8 by fabric8io.
the class YamlTest method testParseYaml.
@Test
public void testParseYaml() throws Exception {
String basedir = System.getProperty("basedir", ".");
File file = new File(basedir, "src/test/resources/fabric8.yml");
assertThat(file).exists();
ProjectConfig config = ProjectConfigs.parseProjectConfig(file);
System.out.println("Parsed: " + config);
assertThat(config.getChatRoom()).isEqualTo("myroom");
assertThat(config.getIssueProjectName()).isEqualTo("foo");
assertThat(config.getPipeline()).isEqualTo("maven/CanaryReleaseThenStage.groovy");
LinkedHashMap<String, String> environments = config.getEnvironments();
// lets assert that things are in the correct order...
List<Pair<String, String>> expectedEnvironents = Arrays.asList(new Pair<String, String>("Testing", "gogsadmin-james4-testing"), new Pair<String, String>("Staging", "gogsadmin-james4-staging"), new Pair<String, String>("Production", "gogsadmin-james4-prod"));
int idx = 0;
Set<Map.Entry<String, String>> entries = environments.entrySet();
for (Map.Entry<String, String> entry : entries) {
String key = entry.getKey();
String value = entry.getValue();
System.out.println("Found environment " + key + " = " + value);
Pair<String, String> actual = new Pair<>(key, value);
assertTrue("Too many entries - found unexpected value: " + actual, expectedEnvironents.size() > idx);
Pair<String, String> expected = expectedEnvironents.get(idx++);
assertEquals("environment " + idx, expected, actual);
}
}
use of io.fabric8.maven.docker.config.CopyConfiguration.Entry in project strimzi by strimzi.
the class TopicSerialization method topicConfigFromConfigMapString.
@SuppressWarnings("unchecked")
private static Map<String, String> topicConfigFromConfigMapString(ConfigMap cm) {
Map<String, String> mapData = cm.getData();
String value = mapData.get(CM_KEY_CONFIG);
Map<?, ?> result;
if (value == null || value.isEmpty()) {
result = Collections.emptyMap();
} else {
try {
ObjectMapper mapper = objectMapper();
result = mapper.readValue(new StringReader(value) {
@Override
public String toString() {
return "'config' key of 'data' section of ConfigMap '" + cm.getMetadata().getName() + "' in namespace '" + cm.getMetadata().getNamespace() + "'";
}
}, Map.class);
} catch (IOException e) {
throw new InvalidConfigMapException(cm, "ConfigMap's 'data' section has invalid key '" + CM_KEY_CONFIG + "': " + (e.getMessage() != null ? e.getMessage() : e.toString()));
}
}
Set<String> supportedConfigs = getSupportedTopicConfigs();
for (Map.Entry<?, ?> entry : result.entrySet()) {
Object key = entry.getKey();
String msg = null;
if (!(key instanceof String)) {
msg = "The must be of type String, not of type " + key.getClass();
}
Object v = entry.getValue();
if (v == null) {
msg = "The value corresponding to the key must have a String value, not null";
} else if (!(v instanceof String)) {
msg = "The value corresponding to the key must have a String value, not a value of type " + v.getClass();
}
if (!supportedConfigs.contains(key)) {
msg = "The allowed configs keys are " + supportedConfigs;
}
if (msg != null) {
throw new InvalidConfigMapException(cm, "ConfigMap's 'data' section has invalid key '" + CM_KEY_CONFIG + "': The key '" + key + "' of the topic config is invalid: " + msg);
}
}
return (Map<String, String>) result;
}
Aggregations