Search in sources :

Example 91 with Configuration

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

the class SuiteListener method start.

public void start(@Observes(precedence = 100) BeforeSuite event, Configuration configuration, Logger logger) {
    session = new Session(configuration.getSessionId(), configuration.getNamespace(), logger);
    session.init();
    sessionProducer.set(session);
    controlEvent.fire(new Start(session));
}
Also used : Start(io.fabric8.arquillian.kubernetes.event.Start)

Example 92 with Configuration

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

the class Configuration method fromMap.

public static Configuration fromMap(Map<String, String> map, KubernetesClient testKubernetesClient) {
    Configuration configuration = new Configuration();
    try {
        configuration.masterUrl = getStringProperty(KUBERNETES_MASTER, map, FALLBACK_CONFIG.getMasterUrl());
        configuration.environment = getStringProperty(FABRIC8_ENVIRONMENT, map, null);
        configuration.environmentInitEnabled = getBooleanProperty(ENVIRONMENT_INIT_ENABLED, map, true);
        configuration.environmentConfigUrl = getKubernetesConfigurationUrl(map);
        configuration.environmentDependencies = Strings.splitAndTrimAsList(getStringProperty(ENVIRONMENT_DEPENDENCIES, map, ""), "\\s+");
        configuration.namespaceLazyCreateEnabled = getBooleanProperty(NAMESPACE_LAZY_CREATE_ENABLED, map, DEFAULT_NAMESPACE_LAZY_CREATE_ENABLED);
        configuration.properties = map;
        String existingNamespace = getStringProperty(NAMESPACE_TO_USE, map, null);
        configuration.sessionId = UUID.randomUUID().toString();
        configuration.namespaceCleanupConfirmationEnabled = getBooleanProperty(NAMESPACE_CLEANUP_CONFIRM_ENABLED, map, false);
        configuration.deleteAllResourcesOnExit = getBooleanProperty(NAMESPACE_DELETE_ALL_RESOURCES_ON_EXIT, map, false);
        configuration.namespaceCleanupTimeout = getLongProperty(NAMESPACE_CLEANUP_TIMEOUT, map, DEFAULT_NAMESPACE_CLEANUP_TIMEOUT);
        configuration.waitTimeout = getLongProperty(WAIT_TIMEOUT, map, DEFAULT_WAIT_TIMEOUT);
        configuration.waitPollInterval = getLongProperty(WAIT_POLL_INTERVAL, map, DEFAULT_WAIT_POLL_INTERVAL);
        configuration.waitForServiceList = Strings.splitAndTrimAsList(getStringProperty(WAIT_FOR_SERVICE_LIST, map, ""), "\\s+");
        configuration.waitForServiceConnectionEnabled = getBooleanProperty(WAIT_FOR_SERVICE_CONNECTION_ENABLED, map, DEFAULT_WAIT_FOR_SERVICE_CONNECTION_ENABLED);
        configuration.waitForServiceConnectionTimeout = getLongProperty(WAIT_FOR_SERVICE_CONNECTION_TIMEOUT, map, DEFAULT_NAMESPACE_CLEANUP_TIMEOUT);
        configuration.ansiLoggerEnabled = getBooleanProperty(ANSI_LOGGER_ENABLED, map, true);
        configuration.kubernetesDomain = getStringProperty(KUBERNETES_DOMAIN, map, "");
        configuration.gofabric8Enabled = getBooleanProperty(GOFABRIC8_ENABLED, map, false);
        configuration.createNamespaceForTest = getBooleanProperty(CREATE_NAMESPACE_FOR_TEST, map, false);
        KubernetesClient kubernetesClient = getOrCreateKubernetesClient(configuration, testKubernetesClient);
        boolean failOnMissingEnvironmentNamespace = getBooleanProperty(FAIL_ON_MISSING_ENVIRONMENT_NAMESPACE, map, false);
        String defaultDevelopNamespace = existingNamespace;
        if (Strings.isNullOrBlank(defaultDevelopNamespace)) {
            defaultDevelopNamespace = kubernetesClient.getNamespace();
        }
        String developNamespace = getStringProperty(DEVELOPMENT_NAMESPACE, map, defaultDevelopNamespace);
        configuration.kubernetesClient = kubernetesClient;
        String environmentNamespace = findNamespaceForEnvironment(configuration.environment, map, kubernetesClient, developNamespace, failOnMissingEnvironmentNamespace);
        String providedNamespace = selectNamespace(environmentNamespace, existingNamespace);
        if (configuration.createNamespaceForTest) {
            configuration.namespace = NAMESPACE_PREFIX + configuration.sessionId;
        } else {
            String namespace = Strings.isNotBlank(providedNamespace) ? providedNamespace : developNamespace;
            ;
            if (Strings.isNullOrBlank(namespace)) {
                namespace = kubernetesClient.getNamespace();
                if (Strings.isNullOrBlank(namespace)) {
                    namespace = KubernetesHelper.defaultNamespace();
                }
            }
            configuration.namespace = namespace;
        }
        // We default to "cleanup=true" when generating namespace and "cleanup=false" when using existing namespace.
        configuration.namespaceCleanupEnabled = getBooleanProperty(NAMESPACE_CLEANUP_ENABLED, map, Strings.isNullOrBlank(providedNamespace));
    } catch (Throwable t) {
        if (t instanceof RuntimeException) {
            throw (RuntimeException) t;
        } else {
            throw new RuntimeException(t);
        }
    }
    return configuration;
}
Also used : KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient)

Example 93 with Configuration

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

the class Controller method applyReplicationController.

public void applyReplicationController(ReplicationController replicationController, String sourceName) throws Exception {
    String namespace = getNamespace();
    String id = getName(replicationController);
    Objects.notNull(id, "No name for " + replicationController + " " + sourceName);
    if (isServicesOnlyMode()) {
        LOG.debug("Only processing Services right now so ignoring ReplicationController: " + namespace + ":" + id);
        return;
    }
    ReplicationController old = kubernetesClient.replicationControllers().inNamespace(namespace).withName(id).get();
    if (isRunning(old)) {
        if (UserConfigurationCompare.configEqual(replicationController, old)) {
            LOG.info("ReplicationController has not changed so not doing anything");
        } else {
            ReplicationControllerSpec newSpec = replicationController.getSpec();
            ReplicationControllerSpec oldSpec = old.getSpec();
            if (rollingUpgrade) {
                LOG.info("Rolling upgrade of the ReplicationController: " + namespace + "/" + id);
                // lets preserve the number of replicas currently running in the environment we are about to upgrade
                if (rollingUpgradePreserveScale && newSpec != null && oldSpec != null) {
                    Integer replicas = oldSpec.getReplicas();
                    if (replicas != null) {
                        newSpec.setReplicas(replicas);
                    }
                }
                LOG.info("rollingUpgradePreserveScale " + rollingUpgradePreserveScale + " new replicas is " + (newSpec != null ? newSpec.getReplicas() : "<null>"));
                kubernetesClient.replicationControllers().inNamespace(namespace).withName(id).rolling().replace(replicationController);
            } else if (isRecreateMode()) {
                LOG.info("Deleting ReplicationController: " + id);
                kubernetesClient.replicationControllers().inNamespace(namespace).withName(id).delete();
                doCreateReplicationController(replicationController, namespace, sourceName);
            } else {
                LOG.info("Updating ReplicationController from " + sourceName + " namespace " + namespace + " name " + getName(replicationController));
                try {
                    Object answer = kubernetesClient.replicationControllers().inNamespace(namespace).withName(id).replace(replicationController);
                    logGeneratedEntity("Updated replicationController: ", namespace, replicationController, answer);
                    if (deletePodsOnReplicationControllerUpdate) {
                        kubernetesClient.pods().inNamespace(namespace).withLabels(newSpec.getSelector()).delete();
                        LOG.info("Deleting any pods for the replication controller to ensure they use the new configuration");
                    } else {
                        LOG.info("Warning not deleted any pods so they could well be running with the old configuration!");
                    }
                } catch (Exception e) {
                    onApplyError("Failed to update ReplicationController from " + sourceName + ". " + e + ". " + replicationController, e);
                }
            }
        }
    } else {
        if (!isAllowCreate()) {
            LOG.warn("Creation disabled so not creating a ReplicationController from " + sourceName + " namespace " + namespace + " name " + getName(replicationController));
        } else {
            doCreateReplicationController(replicationController, namespace, sourceName);
        }
    }
}
Also used : ReplicationController(io.fabric8.kubernetes.api.model.ReplicationController) JSONObject(org.json.JSONObject) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException) FileNotFoundException(java.io.FileNotFoundException) OpenShiftNotAvailableException(io.fabric8.openshift.client.OpenShiftNotAvailableException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IOException(java.io.IOException) ReplicationControllerSpec(io.fabric8.kubernetes.api.model.ReplicationControllerSpec)

Example 94 with Configuration

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

the class ApmAgent method initialize.

/**
 * @return false if already initialized, else true if is actually initialized
 */
public boolean initialize(final Instrumentation instrumentation, String args) throws Exception {
    boolean result;
    if ((result = initialized.compareAndSet(false, true))) {
        this.instrumentation = instrumentation;
        PropertyUtils.setProperties(configuration, args);
        configuration.addChangeListener(this);
        apmAgentContext.initialize();
        ApmConfiguration.STRATEGY theStrategy = configuration.getStrategyImpl();
        switch(theStrategy) {
            case TRACE:
                this.strategy = new TraceStrategy(apmAgentContext, instrumentation);
                LOG.debug("Using Trace strategy");
                break;
            default:
                this.strategy = new SamplingStrategy(apmAgentContext);
                LOG.debug("Using Sampling strategy");
        }
        this.strategy.initialize();
        // add shutdown hook
        Thread cleanup = new Thread() {

            @Override
            public void run() {
                try {
                    ApmAgent apmAgent = ApmAgent.INSTANCE;
                    apmAgent.shutDown();
                } catch (Exception e) {
                    LOG.warn("Failed to run shutdown hook due " + e.getMessage(), e);
                }
            }
        };
        Runtime.getRuntime().addShutdownHook(cleanup);
    }
    return result;
}
Also used : TraceStrategy(io.fabric8.apmagent.strategy.trace.TraceStrategy) SamplingStrategy(io.fabric8.apmagent.strategy.sampling.SamplingStrategy)

Example 95 with Configuration

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

the class DevOpsConnector method execute.

/**
 * For a given project this operation will try to update the associated DevOps resources
 *
 * @throws Exception
 */
public void execute() throws Exception {
    loadConfigFile();
    KubernetesClient kubernetes = getKubernetes();
    String name = projectName;
    if (Strings.isNullOrBlank(name)) {
        if (projectConfig != null) {
            name = projectConfig.getBuildName();
        }
        if (Strings.isNullOrBlank(name)) {
            name = jenkinsJob;
        }
        if (Strings.isNullOrBlank(name)) {
            name = ProjectRepositories.createBuildName(username, repoName);
            if (projectConfig != null) {
                projectConfig.setBuildName(name);
            }
        }
    }
    if (Strings.isNullOrBlank(projectName)) {
        projectName = name;
    }
    Map<String, String> labels = new HashMap<>();
    labels.put("user", username);
    labels.put("repo", repoName);
    getLog().info("build name " + name);
    taiga = null;
    taigaProject = null;
    try {
        taiga = createTaiga();
        taigaProject = createTaigaProject(taiga);
    } catch (Exception e) {
        getLog().error("Failed to load or lazily create the Taiga project: " + e, e);
    }
    getLog().info("taiga " + taiga);
    LetsChatClient letschat = null;
    try {
        letschat = createLetsChat();
    } catch (Exception e) {
        getLog().error("Failed to load or lazily create the LetsChat client: " + e, e);
    }
    getLog().info("letschat " + letschat);
    /*
         * Create Gerrit Git to if isGerritReview is enabled
         */
    if (projectConfig != null && projectConfig.hasCodeReview()) {
        try {
            createGerritRepo(repoName, gerritUser, gerritPwd, gerritGitInitialCommit, gerritGitRepoDesription);
        } catch (Exception e) {
            getLog().error("Failed to create GerritGit repo : " + e, e);
        }
    }
    Map<String, String> annotations = new HashMap<>();
    jenkinsJobUrl = null;
    String jenkinsUrl = null;
    try {
        jenkinsUrl = getJenkinsServiceUrl(true);
        if (Strings.isNotBlank(jenkinsUrl)) {
            if (Strings.isNotBlank(jenkinsMonitorView)) {
                String url = URLUtils.pathJoin(jenkinsUrl, "/view", jenkinsMonitorView);
                annotationLink(annotations, "fabric8.link.jenkins.monitor/", url, "Monitor");
            }
            if (Strings.isNotBlank(jenkinsPipelineView)) {
                String url = URLUtils.pathJoin(jenkinsUrl, "/view", jenkinsPipelineView);
                annotationLink(annotations, "fabric8.link.jenkins.pipeline/", url, "Pipeline");
            }
            if (Strings.isNotBlank(name)) {
                jenkinsJobUrl = URLUtils.pathJoin(jenkinsUrl, "/job", name);
                annotationLink(annotations, "fabric8.link.jenkins.job/", jenkinsJobUrl, "Job");
            }
        }
    } catch (Exception e) {
        getLog().warn("Could not find the Jenkins URL!: " + e, e);
    }
    getLog().info("jenkins " + jenkinsUrl);
    if (!annotationLink(annotations, "fabric8.link.issues/", issueTrackerUrl, issueTrackerLabel)) {
        String taigaLink = getProjectPageLink(taiga, taigaProject, this.taigaProjectLinkPage);
        annotationLink(annotations, "fabric8.link.taiga/", taigaLink, taigaProjectLinkLabel);
    }
    if (!annotationLink(annotations, "fabric8.link.team/", teamUrl, teamLabel)) {
        String taigaTeamLink = getProjectPageLink(taiga, taigaProject, this.taigaTeamLinkPage);
        annotationLink(annotations, "fabric8.link.taiga.team/", taigaTeamLink, taigaTeamLinkLabel);
    }
    annotationLink(annotations, "fabric8.link.releases/", releasesUrl, releasesLabel);
    String chatRoomLink = getChatRoomLink(letschat);
    annotationLink(annotations, "fabric8.link.letschat.room/", chatRoomLink, letschatRoomLinkLabel);
    annotationLink(annotations, "fabric8.link.repository.browse/", repositoryBrowseLink, repositoryBrowseLabel);
    ProjectConfigs.defaultEnvironments(projectConfig, namespace);
    String consoleUrl = getServiceUrl(ServiceNames.FABRIC8_CONSOLE, namespace, fabric8ConsoleNamespace);
    if (projectConfig != null) {
        Map<String, String> environments = projectConfig.getEnvironments();
        updateEnvironmentConfigMap(environments, kubernetes, annotations, consoleUrl);
    }
    addLink("Git", getGitUrl());
    Controller controller = createController();
    OpenShiftClient openShiftClient = controller.getOpenShiftClientOrJenkinshift();
    BuildConfig buildConfig = null;
    if (openShiftClient != null) {
        try {
            buildConfig = openShiftClient.buildConfigs().withName(projectName).get();
        } catch (Exception e) {
            log.error("Failed to load build config for " + namespace + "/" + projectName + ". " + e, e);
        }
        log.info("Loaded build config for " + namespace + "/" + projectName + " " + buildConfig);
    }
    // if we have loaded a build config then lets assume its correct!
    boolean foundExistingGitUrl = false;
    if (buildConfig != null) {
        BuildConfigSpec spec = buildConfig.getSpec();
        if (spec != null) {
            BuildSource source = spec.getSource();
            if (source != null) {
                GitBuildSource git = source.getGit();
                if (git != null) {
                    gitUrl = git.getUri();
                    log.info("Loaded existing BuildConfig git url: " + gitUrl);
                    foundExistingGitUrl = true;
                }
                LocalObjectReference sourceSecret = source.getSourceSecret();
                if (sourceSecret != null) {
                    gitSourceSecretName = sourceSecret.getName();
                }
            }
        }
        if (!foundExistingGitUrl) {
            log.warn("Could not find a git url in the loaded BuildConfig: " + buildConfig);
        }
        log.info("Loaded gitSourceSecretName: " + gitSourceSecretName);
    }
    log.info("gitUrl is: " + gitUrl);
    if (buildConfig == null) {
        buildConfig = new BuildConfig();
    }
    ObjectMeta metadata = getOrCreateMetadata(buildConfig);
    metadata.setName(projectName);
    metadata.setLabels(labels);
    putAnnotations(metadata, annotations);
    Map<String, String> currentAnnotations = metadata.getAnnotations();
    if (!currentAnnotations.containsKey(Annotations.Builds.GIT_CLONE_URL)) {
        currentAnnotations.put(Annotations.Builds.GIT_CLONE_URL, gitUrl);
    }
    String localGitUrl = getLocalGitUrl();
    if (!currentAnnotations.containsKey(Annotations.Builds.LOCAL_GIT_CLONE_URL) && Strings.isNotBlank(localGitUrl)) {
        currentAnnotations.put(Annotations.Builds.LOCAL_GIT_CLONE_URL, localGitUrl);
    }
    // lets switch to the local git URL to avoid DNS issues in forge or jenkins
    if (Strings.isNotBlank(localGitUrl)) {
        gitUrl = localGitUrl;
    }
    Builds.configureDefaultBuildConfig(buildConfig, name, gitUrl, foundExistingGitUrl, buildImageStream, buildImageTag, s2iCustomBuilderImage, secret, jenkinsUrl);
    try {
        getLog().info("About to apply build config: " + new JSONObject(KubernetesHelper.toJson(buildConfig)).toString(4));
        controller.applyBuildConfig(buildConfig, "maven");
        getLog().info("Created build configuration for " + name + " in namespace: " + controller.getNamespace() + " at " + kubernetes.getMasterUrl());
    } catch (Exception e) {
        getLog().error("Failed to create BuildConfig for " + KubernetesHelper.toJson(buildConfig) + ". " + e, e);
    }
    this.jenkinsJobName = name;
    if (isRegisterWebHooks()) {
        registerWebHooks();
        getLog().info("webhooks done");
    }
    if (modifiedConfig) {
        if (basedir == null) {
            getLog().error("Could not save updated " + ProjectConfigs.FILE_NAME + " due to missing basedir");
        } else {
            try {
                ProjectConfigs.saveToFolder(basedir, projectConfig, true);
                getLog().info("Updated " + ProjectConfigs.FILE_NAME);
            } catch (IOException e) {
                getLog().error("Could not save updated " + ProjectConfigs.FILE_NAME + ": " + e, e);
            }
        }
    }
}
Also used : ObjectMeta(io.fabric8.kubernetes.api.model.ObjectMeta) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) HashMap(java.util.HashMap) IOException(java.io.IOException) Controller(io.fabric8.kubernetes.api.Controller) GitBuildSource(io.fabric8.openshift.api.model.GitBuildSource) SAXException(org.xml.sax.SAXException) WebApplicationException(javax.ws.rs.WebApplicationException) AuthenticationException(org.apache.http.auth.AuthenticationException) ConnectException(java.net.ConnectException) MalformedChallengeException(org.apache.http.auth.MalformedChallengeException) HttpResponseException(org.apache.http.client.HttpResponseException) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) BuildSource(io.fabric8.openshift.api.model.BuildSource) GitBuildSource(io.fabric8.openshift.api.model.GitBuildSource) JSONObject(org.json.JSONObject) OpenShiftClient(io.fabric8.openshift.client.OpenShiftClient) LocalObjectReference(io.fabric8.kubernetes.api.model.LocalObjectReference) BuildConfig(io.fabric8.openshift.api.model.BuildConfig) LetsChatClient(io.fabric8.letschat.LetsChatClient) BuildConfigSpec(io.fabric8.openshift.api.model.BuildConfigSpec)

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