Search in sources :

Example 1 with VaultConfigMountSet

use of com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.distributed.VaultConfigMountSet 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

ManagedInstance (com.google.api.services.compute.model.ManagedInstance)1 Metadata (com.google.api.services.compute.model.Metadata)1 RunningServiceDetails (com.netflix.spinnaker.halyard.deploy.spinnaker.v1.RunningServiceDetails)1 VaultServerService (com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.VaultServerService)1 VaultConfigMountSet (com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.distributed.VaultConfigMountSet)1 VaultConnectionDetails (com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.distributed.VaultConnectionDetails)1 ArrayList (java.util.ArrayList)1