Search in sources :

Example 96 with Configuration

use of io.fabric8.maven.core.model.Configuration in project fabric8 by fabric8io.

the class BuildConfigHelper method importNewGitProject.

public static CreateGitProjectResults importNewGitProject(KubernetesClient kubernetesClient, UserDetails userDetails, File basedir, String namespace, String projectName, String origin, String message, boolean apply, boolean useLocalGitAddress) throws GitAPIException, JsonProcessingException {
    GitUtils.disableSslCertificateChecks();
    InitCommand initCommand = Git.init();
    initCommand.setDirectory(basedir);
    Git git = initCommand.call();
    LOG.info("Initialised an empty git configuration repo at {}", basedir.getAbsolutePath());
    PersonIdent personIdent = userDetails.createPersonIdent();
    String user = userDetails.getUser();
    String address = userDetails.getAddress();
    String internalAddress = userDetails.getInternalAddress();
    String branch = userDetails.getBranch();
    // lets create the repository
    GitRepoClient repoClient = userDetails.createRepoClient();
    CreateRepositoryDTO createRepository = new CreateRepositoryDTO();
    createRepository.setName(projectName);
    String fullName = null;
    RepositoryDTO repository = repoClient.createRepository(createRepository);
    if (repository != null) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Got repository: " + toJson(repository));
        }
        fullName = repository.getFullName();
    }
    if (Strings.isNullOrBlank(fullName)) {
        fullName = user + "/" + projectName;
    }
    String htmlUrl = URLUtils.pathJoin(resolveToRoot(address), user, projectName);
    String localCloneUrl = URLUtils.pathJoin(resolveToRoot(internalAddress), user, projectName + ".git");
    String cloneUrl = htmlUrl + ".git";
    String defaultCloneUrl = cloneUrl;
    // lets default to using the local git clone URL
    if (useLocalGitAddress && Strings.isNotBlank(internalAddress)) {
        defaultCloneUrl = localCloneUrl;
    }
    // now lets import the code and publish
    GitUtils.configureBranch(git, branch, origin, defaultCloneUrl);
    GitUtils.addDummyFileToEmptyFolders(basedir);
    LOG.info("About to git commit and push to: " + defaultCloneUrl + " and remote name " + origin);
    GitUtils.doAddCommitAndPushFiles(git, userDetails, personIdent, branch, origin, message, true);
    Map<String, String> annotations = new HashMap<>();
    annotations.put(Annotations.Builds.GIT_CLONE_URL, cloneUrl);
    annotations.put(Annotations.Builds.LOCAL_GIT_CLONE_URL, localCloneUrl);
    BuildConfig buildConfig;
    if (apply) {
        buildConfig = createAndApplyBuildConfig(kubernetesClient, namespace, projectName, defaultCloneUrl, annotations);
    } else {
        buildConfig = createBuildConfig(kubernetesClient, namespace, projectName, defaultCloneUrl, annotations);
    }
    return new CreateGitProjectResults(buildConfig, fullName, htmlUrl, localCloneUrl, cloneUrl);
}
Also used : Git(org.eclipse.jgit.api.Git) CreateRepositoryDTO(io.fabric8.repo.git.CreateRepositoryDTO) PersonIdent(org.eclipse.jgit.lib.PersonIdent) HashMap(java.util.HashMap) InitCommand(org.eclipse.jgit.api.InitCommand) GitRepoClient(io.fabric8.repo.git.GitRepoClient) BuildConfig(io.fabric8.openshift.api.model.BuildConfig) RepositoryDTO(io.fabric8.repo.git.RepositoryDTO) CreateRepositoryDTO(io.fabric8.repo.git.CreateRepositoryDTO)

Example 97 with Configuration

use of io.fabric8.maven.core.model.Configuration 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);
    }
}
Also used : Configuration(org.osgi.service.cm.Configuration) Hashtable(java.util.Hashtable) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException) StringReader(java.io.StringReader) HashMap(java.util.HashMap) Map(java.util.Map) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap)

Example 98 with Configuration

use of io.fabric8.maven.core.model.Configuration in project fabric8 by fabric8io.

the class KubernetesConfigAdminBridge method deleteConfig.

private void deleteConfig(ConfigMap map) {
    String pid = map.getMetadata().getLabels().get(pidLabel);
    String[] p = parsePid(pid);
    try {
        Map<String, String> configMapData = map.getData();
        Configuration config = getConfiguration(configAdmin.get(), pid, p[0], p[1]);
        if (configMapData != null) {
            boolean merge = configMapData.containsKey(FABRIC8_CONFIG_MERGE) ? Boolean.valueOf(configMapData.get(FABRIC8_CONFIG_MERGE)) : configMerge;
            if (!merge) {
                LOGGER.debug("Delete configuration {}", config.getPid());
                config.delete();
            }
        }
    } catch (Exception e) {
        LOGGER.warn("", e);
    }
}
Also used : Configuration(org.osgi.service.cm.Configuration) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException)

Example 99 with Configuration

use of io.fabric8.maven.core.model.Configuration in project strimzi by strimzi.

the class OpenShiftTemplatesTest method testStrimziPersistentWithCustomParameters.

@Test
public void testStrimziPersistentWithCustomParameters() throws IOException {
    String clusterName = "test-persistent-with-custom-parameters";
    oc.newApp("strimzi-persistent", map("CLUSTER_NAME", clusterName, "ZOOKEEPER_HEALTHCHECK_DELAY", "30", "ZOOKEEPER_HEALTHCHECK_TIMEOUT", "10", "KAFKA_HEALTHCHECK_DELAY", "30", "KAFKA_HEALTHCHECK_TIMEOUT", "10", "KAFKA_DEFAULT_REPLICATION_FACTOR", "2", "KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR", "5", "KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR", "5", "ZOOKEEPER_VOLUME_CAPACITY", "2Gi", "KAFKA_VOLUME_CAPACITY", "2Gi"));
    // TODO Add assertions to check that Kafka brokers have a custom configuration
    ConfigMap cm = client.configMaps().inNamespace(NAMESPACE).withName(clusterName).get();
    assertNotNull(cm);
    Map<String, String> cmData = cm.getData();
    assertEquals("30", cmData.get("zookeeper-healthcheck-delay"));
    assertEquals("10", cmData.get("zookeeper-healthcheck-timeout"));
    assertEquals("30", cmData.get("kafka-healthcheck-delay"));
    assertEquals("10", cmData.get("kafka-healthcheck-timeout"));
    assertEquals("2", cmData.get("KAFKA_DEFAULT_REPLICATION_FACTOR"));
    assertEquals("5", cmData.get("KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR"));
    assertEquals("5", cmData.get("KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR"));
    assertEquals("2Gi", mapper.readTree(cmData.get("kafka-storage")).get("size").asText());
    assertEquals("2Gi", mapper.readTree(cmData.get("zookeeper-storage")).get("size").asText());
}
Also used : ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) Test(org.junit.Test)

Example 100 with Configuration

use of io.fabric8.maven.core.model.Configuration in project fabric8-maven-plugin by fabric8io.

the class DefaultControllerEnricherTest method enrichAndAssert.

protected void enrichAndAssert(int sizeOfObjects, int replicaCount) throws com.fasterxml.jackson.core.JsonProcessingException {
    // Setup a sample docker build configuration
    final BuildImageConfiguration buildConfig = new BuildImageConfiguration.Builder().ports(Arrays.asList("8080")).build();
    final TreeMap controllerConfig = new TreeMap();
    controllerConfig.put("replicaCount", String.valueOf(replicaCount));
    setupExpectations(buildConfig, controllerConfig);
    // Enrich
    DefaultControllerEnricher controllerEnricher = new DefaultControllerEnricher(context);
    KubernetesListBuilder builder = new KubernetesListBuilder();
    controllerEnricher.create(PlatformMode.kubernetes, builder);
    // Validate that the generated resource contains
    KubernetesList list = builder.build();
    assertEquals(sizeOfObjects, list.getItems().size());
    String json = ResourceUtil.toJson(list.getItems().get(0));
    assertThat(json, JsonPathMatchers.isJson());
    assertThat(json, JsonPathMatchers.hasJsonPath("$.spec.replicas", Matchers.equalTo(replicaCount)));
}
Also used : KubernetesListBuilder(io.fabric8.kubernetes.api.model.KubernetesListBuilder) KubernetesListBuilder(io.fabric8.kubernetes.api.model.KubernetesListBuilder) KubernetesList(io.fabric8.kubernetes.api.model.KubernetesList) TreeMap(java.util.TreeMap) BuildImageConfiguration(io.fabric8.maven.docker.config.BuildImageConfiguration)

Aggregations

ParallelTest (io.strimzi.test.annotations.ParallelTest)142 Kafka (io.strimzi.api.kafka.model.Kafka)138 KafkaBuilder (io.strimzi.api.kafka.model.KafkaBuilder)132 HashMap (java.util.HashMap)97 IOException (java.io.IOException)86 IntOrString (io.fabric8.kubernetes.api.model.IntOrString)83 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)80 Map (java.util.Map)79 StatefulSet (io.fabric8.kubernetes.api.model.apps.StatefulSet)76 ArrayList (java.util.ArrayList)76 List (java.util.List)70 TopologySpreadConstraint (io.fabric8.kubernetes.api.model.TopologySpreadConstraint)66 GenericKafkaListenerBuilder (io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerBuilder)66 Matchers.containsString (org.hamcrest.Matchers.containsString)58 Service (io.fabric8.kubernetes.api.model.Service)55 Collectors (java.util.stream.Collectors)55 Container (io.fabric8.kubernetes.api.model.Container)54 PersistentVolumeClaim (io.fabric8.kubernetes.api.model.PersistentVolumeClaim)50 Quantity (io.fabric8.kubernetes.api.model.Quantity)48 File (java.io.File)47