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;
}
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>>() {
});
}
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;
}
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>>() { });
*/
}
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;
}
Aggregations