Search in sources :

Example 1 with ConfigSource

use of com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.ConfigSource in project halyard by spinnaker.

the class KubernetesV1DistributedService method buildContainer.

default KubernetesContainerDescription buildContainer(String name, ServiceSettings settings, List<ConfigSource> configSources, DeploymentEnvironment deploymentEnvironment, DeployKubernetesAtomicOperationDescription description) {
    KubernetesContainerDescription container = new KubernetesContainerDescription();
    KubernetesProbe readinessProbe = new KubernetesProbe();
    KubernetesHandler handler = new KubernetesHandler();
    int port = settings.getPort();
    String healthEndpoint = settings.getHealthEndpoint();
    if (healthEndpoint != null) {
        handler.setType(KubernetesHandlerType.HTTP);
        KubernetesHttpGetAction action = new KubernetesHttpGetAction();
        action.setPath(healthEndpoint);
        action.setPort(port);
        handler.setHttpGetAction(action);
    } else {
        handler.setType(KubernetesHandlerType.TCP);
        KubernetesTcpSocketAction action = new KubernetesTcpSocketAction();
        action.setPort(port);
        handler.setTcpSocketAction(action);
    }
    readinessProbe.setHandler(handler);
    container.setReadinessProbe(readinessProbe);
    applyCustomSize(container, deploymentEnvironment, name, description);
    KubernetesImageDescription imageDescription = KubernetesUtil.buildImageDescription(settings.getArtifactId());
    container.setImageDescription(imageDescription);
    container.setName(name);
    List<KubernetesContainerPort> ports = new ArrayList<>();
    KubernetesContainerPort containerPort = new KubernetesContainerPort();
    containerPort.setContainerPort(port);
    ports.add(containerPort);
    container.setPorts(ports);
    List<KubernetesVolumeMount> volumeMounts = new ArrayList<>();
    for (ConfigSource configSource : configSources) {
        KubernetesVolumeMount volumeMount = new KubernetesVolumeMount();
        volumeMount.setName(configSource.getId());
        volumeMount.setMountPath(configSource.getMountPath());
        volumeMounts.add(volumeMount);
    }
    container.setVolumeMounts(volumeMounts);
    List<KubernetesEnvVar> envVars = new ArrayList<>();
    settings.getEnv().forEach((k, v) -> {
        KubernetesEnvVar envVar = new KubernetesEnvVar();
        envVar.setName(k);
        envVar.setValue(v);
        envVars.add(envVar);
    });
    configSources.forEach(c -> {
        c.getEnv().entrySet().forEach(envEntry -> {
            KubernetesEnvVar envVar = new KubernetesEnvVar();
            envVar.setName(envEntry.getKey());
            envVar.setValue(envEntry.getValue());
            envVars.add(envVar);
        });
    });
    container.setEnvVars(envVars);
    return container;
}
Also used : ArrayList(java.util.ArrayList) KubernetesProbe(com.netflix.spinnaker.clouddriver.kubernetes.v1.deploy.description.servergroup.KubernetesProbe) KubernetesHandler(com.netflix.spinnaker.clouddriver.kubernetes.v1.deploy.description.servergroup.KubernetesHandler) KubernetesVolumeMount(com.netflix.spinnaker.clouddriver.kubernetes.v1.deploy.description.servergroup.KubernetesVolumeMount) KubernetesContainerDescription(com.netflix.spinnaker.clouddriver.kubernetes.v1.deploy.description.servergroup.KubernetesContainerDescription) ConfigSource(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.ConfigSource) KubernetesImageDescription(com.netflix.spinnaker.clouddriver.kubernetes.v1.deploy.description.servergroup.KubernetesImageDescription) KubernetesContainerPort(com.netflix.spinnaker.clouddriver.kubernetes.v1.deploy.description.servergroup.KubernetesContainerPort) KubernetesTcpSocketAction(com.netflix.spinnaker.clouddriver.kubernetes.v1.deploy.description.servergroup.KubernetesTcpSocketAction) KubernetesHttpGetAction(com.netflix.spinnaker.clouddriver.kubernetes.v1.deploy.description.servergroup.KubernetesHttpGetAction) KubernetesEnvVar(com.netflix.spinnaker.clouddriver.kubernetes.v1.deploy.description.servergroup.KubernetesEnvVar)

Example 2 with ConfigSource

use of com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.ConfigSource in project halyard by spinnaker.

the class KubernetesV1DistributedService method getServerGroupDescription.

default Map<String, Object> getServerGroupDescription(AccountDeploymentDetails<KubernetesAccount> details, SpinnakerRuntimeSettings runtimeSettings, List<ConfigSource> configSources) {
    DeployKubernetesAtomicOperationDescription description = new DeployKubernetesAtomicOperationDescription();
    SpinnakerMonitoringDaemonService monitoringService = getMonitoringDaemonService();
    ServiceSettings settings = runtimeSettings.getServiceSettings(getService());
    DeploymentEnvironment deploymentEnvironment = details.getDeploymentConfiguration().getDeploymentEnvironment();
    String accountName = details.getAccount().getName();
    String namespace = getNamespace(settings);
    String name = getServiceName();
    Names parsedName = Names.parseName(name);
    description.setNamespace(namespace);
    description.setAccount(accountName);
    description.setApplication(parsedName.getApp());
    description.setStack(parsedName.getStack());
    description.setFreeFormDetails(parsedName.getDetail());
    List<KubernetesVolumeSource> volumeSources = new ArrayList<>();
    for (ConfigSource configSource : configSources) {
        KubernetesVolumeSource volumeSource = new KubernetesVolumeSource();
        volumeSource.setName(configSource.getId());
        volumeSource.setType(KubernetesVolumeSourceType.Secret);
        KubernetesSecretVolumeSource secretVolumeSource = new KubernetesSecretVolumeSource();
        secretVolumeSource.setSecretName(configSource.getId());
        volumeSource.setSecret(secretVolumeSource);
        volumeSources.add(volumeSource);
    }
    description.setVolumeSources(volumeSources);
    description.setPodAnnotations(settings.getKubernetes().getPodAnnotations());
    List<String> loadBalancers = new ArrayList<>();
    loadBalancers.add(name);
    description.setLoadBalancers(loadBalancers);
    List<KubernetesContainerDescription> containers = new ArrayList<>();
    ServiceSettings serviceSettings = runtimeSettings.getServiceSettings(getService());
    KubernetesContainerDescription container = buildContainer(name, serviceSettings, configSources, deploymentEnvironment, description);
    containers.add(container);
    ServiceSettings monitoringSettings = runtimeSettings.getServiceSettings(monitoringService);
    if (monitoringSettings.getEnabled() && serviceSettings.getMonitored()) {
        serviceSettings = runtimeSettings.getServiceSettings(monitoringService);
        container = buildContainer(monitoringService.getServiceName(), serviceSettings, configSources, deploymentEnvironment, description);
        containers.add(container);
    }
    description.setContainers(containers);
    return getObjectMapper().convertValue(description, new TypeReference<Map<String, Object>>() {
    });
}
Also used : DeploymentEnvironment(com.netflix.spinnaker.halyard.config.model.v1.node.DeploymentEnvironment) DeployKubernetesAtomicOperationDescription(com.netflix.spinnaker.clouddriver.kubernetes.v1.deploy.description.servergroup.DeployKubernetesAtomicOperationDescription) ServiceSettings(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.ServiceSettings) ArrayList(java.util.ArrayList) KubernetesVolumeSource(com.netflix.spinnaker.clouddriver.kubernetes.v1.deploy.description.servergroup.KubernetesVolumeSource) Names(com.netflix.frigga.Names) ConfigSource(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.ConfigSource) KubernetesContainerDescription(com.netflix.spinnaker.clouddriver.kubernetes.v1.deploy.description.servergroup.KubernetesContainerDescription) KubernetesSecretVolumeSource(com.netflix.spinnaker.clouddriver.kubernetes.v1.deploy.description.servergroup.KubernetesSecretVolumeSource) SpinnakerMonitoringDaemonService(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.SpinnakerMonitoringDaemonService) Map(java.util.Map) HashMap(java.util.HashMap)

Example 3 with ConfigSource

use of com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.ConfigSource in project halyard by spinnaker.

the class DistributedService method buildDeployServerGroupPipeline.

default Map<String, Object> buildDeployServerGroupPipeline(AccountDeploymentDetails<A> details, SpinnakerRuntimeSettings runtimeSettings, List<ConfigSource> configSources, Integer maxRemaining, boolean scaleDown) {
    String accountName = details.getAccount().getName();
    String region = runtimeSettings.getServiceSettings(getService()).getLocation();
    Map<String, Object> deployDescription = getServerGroupDescription(details, runtimeSettings, configSources);
    deployDescription.put("name", "deploy");
    Map<String, String> source = new HashMap<>();
    RunningServiceDetails runningServiceDetails = getRunningServiceDetails(details, runtimeSettings);
    if (runningServiceDetails.getLatestEnabledVersion() == null) {
        throw new HalException(Problem.Severity.FATAL, "No prior server group to clone for " + getServiceName());
    }
    source.put("account", accountName);
    source.put("credentials", accountName);
    source.put("serverGroupName", getVersionedName(runningServiceDetails.getLatestEnabledVersion()));
    source.put("region", region);
    source.put("namespace", region);
    deployDescription.put("source", source);
    deployDescription.put("interestingHealthProviders", getHealthProviders());
    deployDescription.put("type", AtomicOperations.CLONE_SERVER_GROUP);
    deployDescription.put("cloudProvider", getProviderType().getId());
    deployDescription.put("refId", "deployredblack");
    deployDescription.put("region", getRegion(runtimeSettings.getServiceSettings(getService())));
    deployDescription.put("strategy", "redblack");
    if (maxRemaining != null) {
        deployDescription.put("maxRemainingAsgs", maxRemaining + "");
    }
    deployDescription.put("scaleDown", scaleDown + "");
    if (scaleDown) {
        deployDescription.put("allowShrinkDownActive", "true");
    }
    List<Map<String, Object>> stages = new ArrayList<>();
    stages.add(deployDescription);
    Map<String, Object> pipeline = new HashMap<>();
    pipeline.put("stages", stages);
    pipeline.put("application", "spin");
    pipeline.put("name", "Deploy/Upgrade " + getServiceName());
    pipeline.put("description", "Auto-generated by Halyard");
    return pipeline;
}
Also used : HashMap(java.util.HashMap) RunningServiceDetails(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.RunningServiceDetails) HalException(com.netflix.spinnaker.halyard.core.error.v1.HalException) ArrayList(java.util.ArrayList) HashMap(java.util.HashMap) Map(java.util.Map)

Example 4 with ConfigSource

use of com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.ConfigSource in project halyard by spinnaker.

the class GoogleDistributedService method getServerGroupDescription.

@Override
default Map<String, Object> getServerGroupDescription(AccountDeploymentDetails<GoogleAccount> details, SpinnakerRuntimeSettings runtimeSettings, List<ConfigSource> configSources) {
    GoogleAccount account = details.getAccount();
    RunningServiceDetails runningServiceDetails = getRunningServiceDetails(details, runtimeSettings);
    Integer version = runningServiceDetails.getLatestEnabledVersion();
    if (version == null) {
        version = 0;
    } else {
        version++;
    }
    Names name = Names.parseName(getServiceName());
    String app = name.getApp();
    String stack = name.getStack();
    String detail = name.getDetail();
    String network = GoogleProviderUtils.getNetworkName();
    Map<String, String> metadata = getMetadata(details, runtimeSettings, configSources, version).stream().reduce(new HashMap<String, String>(), (h1, item) -> {
        h1.put(item.getKey(), item.getValue());
        return h1;
    }, (h1, h2) -> {
        h1.putAll(h2);
        return h1;
    });
    String serviceAccountEmail = GoogleProviderUtils.defaultServiceAccount(details);
    List<String> scopes = getScopes();
    String accountName = account.getName();
    Map<String, Object> deployDescription = new HashMap<>();
    deployDescription.put("application", app);
    deployDescription.put("stack", stack);
    deployDescription.put("freeFormDetails", detail);
    deployDescription.put("network", network);
    deployDescription.put("instanceMetadata", metadata);
    deployDescription.put("serviceAccountEmail", serviceAccountEmail);
    deployDescription.put("authScopes", scopes);
    deployDescription.put("accountName", accountName);
    deployDescription.put("account", accountName);
    return deployDescription;
/* TODO(lwander): Google's credential class cannot be serialized as-is, making this type of construction impossible
    BasicGoogleDeployDescription deployDescription = new BasicGoogleDeployDescription();
    deployDescription.setApplication(app);
    deployDescription.setStack(stack);
    deployDescription.setFreeFormDetails(detail);

    deployDescription.setNetwork(network);
    deployDescription.setInstanceMetadata(metadata);
    deployDescription.setServiceAccountEmail(serviceAccountEmail);
    deployDescription.setAuthScopes(scopes);
    // Google's credentials constructor prevents us from neatly creating a deploy description with only a name supplied
    String jsonKey = null;
    if (!StringUtils.isEmpty(account.getJsonPath())) {
      try {
        jsonKey = IOUtils.toString(new FileInputStream(account.getJsonPath()));
      } catch (IOException e) {
        throw new RuntimeException("Unvalidated json path found during deployment: " + e.getMessage(), e);
      }
    }

    deployDescription.setCredentials(new GoogleNamedAccountCredentials.Builder()
        .name(account.getName())
        .jsonKey(jsonKey)
        .project(account.getProject())
        .build()
    );

    return new ObjectMapper().convertValue(deployDescription, new TypeReference<Map<String, Object>>() { });
    */
}
Also used : Names(com.netflix.frigga.Names) GoogleAccount(com.netflix.spinnaker.halyard.config.model.v1.providers.google.GoogleAccount) HashMap(java.util.HashMap) RunningServiceDetails(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.RunningServiceDetails)

Example 5 with ConfigSource

use of com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.ConfigSource in project halyard by spinnaker.

the class GoogleDistributedService method getMetadata.

default List<Metadata.Items> getMetadata(AccountDeploymentDetails<GoogleAccount> details, SpinnakerRuntimeSettings runtimeSettings, List<ConfigSource> configSources, Integer version) {
    List<Metadata.Items> metadataItems = new ArrayList<>();
    String deploymentName = details.getDeploymentName();
    Metadata.Items items = new Metadata.Items().setKey("startup-script").setValue(getStartupScript());
    metadataItems.add(items);
    items = new Metadata.Items().setKey("ssh-keys").setValue(GoogleProviderUtils.getSshPublicKey());
    metadataItems.add(items);
    if (!configSources.isEmpty()) {
        DaemonTaskHandler.message("Mounting config in vault server");
        GoogleVaultServerService vaultService = getVaultServerService();
        VaultServerService.Vault vault = vaultService.connectToPrimaryService(details, runtimeSettings);
        String secretName = secretName("config-mounts", version);
        VaultConfigMountSet mountSet = VaultConfigMountSet.fromConfigSources(configSources);
        secretName = vaultService.writeVaultConfigMountSet(deploymentName, vault, secretName, mountSet);
        VaultConnectionDetails connectionDetails = buildConnectionDetails(details, runtimeSettings, secretName);
        DaemonTaskHandler.message("Placing vault connection details into instance metadata");
        items = new Metadata.Items().setKey("vault_address").setValue(connectionDetails.getAddress());
        metadataItems.add(items);
        items = new Metadata.Items().setKey("vault_token").setValue(connectionDetails.getToken());
        metadataItems.add(items);
        items = new Metadata.Items().setKey("vault_secret").setValue(connectionDetails.getSecret());
        metadataItems.add(items);
    }
    GoogleConsulServerService consulServerService = getConsulServerService();
    RunningServiceDetails consulServerDetails = consulServerService.getRunningServiceDetails(details, runtimeSettings);
    Integer latestConsulVersion = consulServerDetails.getLatestEnabledVersion();
    if (latestConsulVersion != null) {
        List<RunningServiceDetails.Instance> instances = consulServerDetails.getInstances().get(latestConsulVersion);
        String instancesValue = String.join(" ", instances.stream().map(RunningServiceDetails.Instance::getId).collect(Collectors.toList()));
        items = new Metadata.Items().setKey(// TODO(lwander) change to consul_members for consistency w/ vault
        "consul-members").setValue(instancesValue);
        DaemonTaskHandler.message("Placing consul connection details into instance metadata");
        metadataItems.add(items);
    }
    return metadataItems;
}
Also used : ManagedInstance(com.google.api.services.compute.model.ManagedInstance) ArrayList(java.util.ArrayList) Metadata(com.google.api.services.compute.model.Metadata) VaultConfigMountSet(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.distributed.VaultConfigMountSet) VaultConnectionDetails(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.distributed.VaultConnectionDetails) RunningServiceDetails(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.RunningServiceDetails) VaultServerService(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.VaultServerService)

Aggregations

ArrayList (java.util.ArrayList)10 ConfigSource (com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.ConfigSource)8 ServiceSettings (com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.ServiceSettings)8 HashMap (java.util.HashMap)8 Map (java.util.Map)8 SpinnakerRuntimeSettings (com.netflix.spinnaker.halyard.deploy.spinnaker.v1.SpinnakerRuntimeSettings)6 KubernetesImageDescription (com.netflix.spinnaker.clouddriver.kubernetes.v1.deploy.description.servergroup.KubernetesImageDescription)5 HalException (com.netflix.spinnaker.halyard.core.error.v1.HalException)5 Profile (com.netflix.spinnaker.halyard.deploy.spinnaker.v1.profile.Profile)5 HashSet (java.util.HashSet)5 List (java.util.List)5 Collectors (java.util.stream.Collectors)5 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4 Names (com.netflix.frigga.Names)4 KubernetesUtil (com.netflix.spinnaker.clouddriver.kubernetes.v1.deploy.KubernetesUtil)4 KubernetesContainerDescription (com.netflix.spinnaker.clouddriver.kubernetes.v1.deploy.description.servergroup.KubernetesContainerDescription)4 DeploymentEnvironment (com.netflix.spinnaker.halyard.config.model.v1.node.DeploymentEnvironment)4 KubernetesAccount (com.netflix.spinnaker.halyard.config.model.v1.providers.kubernetes.KubernetesAccount)4 AccountDeploymentDetails (com.netflix.spinnaker.halyard.deploy.deployment.v1.AccountDeploymentDetails)4 ArtifactService (com.netflix.spinnaker.halyard.deploy.services.v1.ArtifactService)4