use of com.netflix.spinnaker.halyard.config.model.v1.node.DeploymentEnvironment in project halyard by spinnaker.
the class LocalGitService method prepArtifactCommand.
default String prepArtifactCommand(DeploymentDetails deploymentDetails) {
Map<String, Object> bindings = new HashMap<>();
String artifactName = getArtifact().getName();
bindings.put("artifact", artifactName);
// TODO(lwander): make configurable
bindings.put("repo", artifactName);
bindings.put("version", getArtifactCommit(deploymentDetails.getDeploymentName()));
bindings.put("git-root", getGitRoot());
DeploymentEnvironment env = deploymentDetails.getDeploymentConfiguration().getDeploymentEnvironment();
DeploymentEnvironment.GitConfig gitConfig = env.getGitConfig();
boolean update = env.getUpdateVersions();
bindings.put("update", update ? "true" : "");
bindings.put("origin", gitConfig.getOriginUser());
bindings.put("upstream", gitConfig.getUpstreamUser());
TemplatedResource prepResource = new StringReplaceJarResource("/git/prep-component.sh");
prepResource.setBindings(bindings);
return prepResource.toString();
}
use of com.netflix.spinnaker.halyard.config.model.v1.node.DeploymentEnvironment in project halyard by spinnaker.
the class DeploymentEnvironmentService method setDeploymentEnvironment.
public void setDeploymentEnvironment(String deploymentName, DeploymentEnvironment newDeploymentEnvironment) {
DeploymentConfiguration deploymentConfiguration = deploymentService.getDeploymentConfiguration(deploymentName);
deploymentConfiguration.setDeploymentEnvironment(newDeploymentEnvironment);
}
use of com.netflix.spinnaker.halyard.config.model.v1.node.DeploymentEnvironment in project halyard by spinnaker.
the class KubernetesV1DistributedService method ensureRunning.
default void ensureRunning(AccountDeploymentDetails<KubernetesAccount> details, GenerateService.ResolvedConfiguration resolvedConfiguration, List<ConfigSource> configSources, boolean recreate) {
ServiceSettings settings = resolvedConfiguration.getServiceSettings(getService());
SpinnakerRuntimeSettings runtimeSettings = resolvedConfiguration.getRuntimeSettings();
String namespace = getNamespace(settings);
String serviceName = getServiceName();
String replicaSetName = serviceName + "-v000";
int port = settings.getPort();
SpinnakerMonitoringDaemonService monitoringService = getMonitoringDaemonService();
ServiceSettings monitoringSettings = runtimeSettings.getServiceSettings(monitoringService);
KubernetesClient client = KubernetesV1ProviderUtils.getClient(details);
KubernetesV1ProviderUtils.createNamespace(details, namespace);
Map<String, String> serviceSelector = new HashMap<>();
serviceSelector.put("load-balancer-" + serviceName, "true");
Map<String, String> replicaSetSelector = new HashMap<>();
replicaSetSelector.put("replication-controller", replicaSetName);
Map<String, String> podLabels = new HashMap<>();
podLabels.putAll(replicaSetSelector);
podLabels.putAll(serviceSelector);
Map<String, String> serviceLabels = new HashMap<>();
serviceLabels.put("app", "spin");
serviceLabels.put("stack", getCanonicalName());
ServiceBuilder serviceBuilder = new ServiceBuilder();
serviceBuilder = serviceBuilder.withNewMetadata().withName(serviceName).withNamespace(namespace).withLabels(serviceLabels).endMetadata().withNewSpec().withSelector(serviceSelector).withPorts(new ServicePortBuilder().withPort(port).withName("http").build(), new ServicePortBuilder().withPort(monitoringSettings.getPort()).withName("monitoring").build()).endSpec();
boolean create = true;
if (client.services().inNamespace(namespace).withName(serviceName).get() != null) {
if (recreate) {
client.services().inNamespace(namespace).withName(serviceName).delete();
} else {
create = false;
}
}
if (create) {
client.services().inNamespace(namespace).create(serviceBuilder.build());
}
List<Container> containers = new ArrayList<>();
DeploymentEnvironment deploymentEnvironment = details.getDeploymentConfiguration().getDeploymentEnvironment();
containers.add(ResourceBuilder.buildContainer(serviceName, settings, configSources, deploymentEnvironment));
for (SidecarService sidecarService : getSidecars(runtimeSettings)) {
String sidecarName = sidecarService.getService().getServiceName();
ServiceSettings sidecarSettings = resolvedConfiguration.getServiceSettings(sidecarService.getService());
containers.add(ResourceBuilder.buildContainer(sidecarName, sidecarSettings, configSources, deploymentEnvironment));
}
List<Volume> volumes = configSources.stream().map(c -> {
return new VolumeBuilder().withName(c.getId()).withSecret(new SecretVolumeSourceBuilder().withSecretName(c.getId()).build()).build();
}).collect(Collectors.toList());
ReplicaSetBuilder replicaSetBuilder = new ReplicaSetBuilder();
List<LocalObjectReference> imagePullSecrets = getImagePullSecrets(settings);
Map componentSizing = deploymentEnvironment.getCustomSizing().get(serviceName);
replicaSetBuilder = replicaSetBuilder.withNewMetadata().withName(replicaSetName).withNamespace(namespace).endMetadata().withNewSpec().withReplicas(retrieveKubernetesTargetSize(componentSizing)).withNewSelector().withMatchLabels(replicaSetSelector).endSelector().withNewTemplate().withNewMetadata().withAnnotations(settings.getKubernetes().getPodAnnotations()).withLabels(podLabels).endMetadata().withNewSpec().withContainers(containers).withTerminationGracePeriodSeconds(5L).withVolumes(volumes).withImagePullSecrets(imagePullSecrets).endSpec().endTemplate().endSpec();
create = true;
if (client.extensions().replicaSets().inNamespace(namespace).withName(replicaSetName).get() != null) {
if (recreate) {
client.extensions().replicaSets().inNamespace(namespace).withName(replicaSetName).delete();
RunningServiceDetails runningServiceDetails = getRunningServiceDetails(details, runtimeSettings);
while (runningServiceDetails.getLatestEnabledVersion() != null) {
DaemonTaskHandler.safeSleep(TimeUnit.SECONDS.toMillis(5));
runningServiceDetails = getRunningServiceDetails(details, runtimeSettings);
}
} else {
create = false;
}
}
if (create) {
client.extensions().replicaSets().inNamespace(namespace).create(replicaSetBuilder.build());
}
RunningServiceDetails runningServiceDetails = getRunningServiceDetails(details, runtimeSettings);
Integer version = runningServiceDetails.getLatestEnabledVersion();
while (version == null || runningServiceDetails.getInstances().get(version).stream().anyMatch(i -> !(i.isHealthy() && i.isRunning()))) {
DaemonTaskHandler.safeSleep(TimeUnit.SECONDS.toMillis(5));
runningServiceDetails = getRunningServiceDetails(details, runtimeSettings);
version = runningServiceDetails.getLatestEnabledVersion();
}
}
use of com.netflix.spinnaker.halyard.config.model.v1.node.DeploymentEnvironment in project halyard by spinnaker.
the class ResourceBuilder method buildContainer.
static Container buildContainer(String name, ServiceSettings settings, List<ConfigSource> configSources, DeploymentEnvironment deploymentEnvironment) {
int port = settings.getPort();
List<EnvVar> envVars = settings.getEnv().entrySet().stream().map(e -> {
EnvVarBuilder envVarBuilder = new EnvVarBuilder();
return envVarBuilder.withName(e.getKey()).withValue(e.getValue()).build();
}).collect(Collectors.toList());
configSources.forEach(c -> {
c.getEnv().entrySet().forEach(envEntry -> {
EnvVarBuilder envVarBuilder = new EnvVarBuilder();
envVars.add(envVarBuilder.withName(envEntry.getKey()).withValue(envEntry.getValue()).build());
});
});
ProbeBuilder probeBuilder = new ProbeBuilder();
if (settings.getHealthEndpoint() != null) {
probeBuilder = probeBuilder.withNewHttpGet().withNewPort(port).withPath(settings.getHealthEndpoint()).endHttpGet();
} else {
probeBuilder = probeBuilder.withNewTcpSocket().withNewPort().withIntVal(port).endPort().endTcpSocket();
}
List<VolumeMount> volumeMounts = configSources.stream().map(c -> {
return new VolumeMountBuilder().withMountPath(c.getMountPath()).withName(c.getId()).build();
}).collect(Collectors.toList());
ContainerBuilder containerBuilder = new ContainerBuilder();
containerBuilder = containerBuilder.withName(name).withImage(settings.getArtifactId()).withPorts(new ContainerPortBuilder().withContainerPort(port).build()).withVolumeMounts(volumeMounts).withEnv(envVars).withReadinessProbe(probeBuilder.build()).withResources(buildResourceRequirements(name, deploymentEnvironment));
return containerBuilder.build();
}
use of com.netflix.spinnaker.halyard.config.model.v1.node.DeploymentEnvironment in project halyard by spinnaker.
the class ClouddriverProfileFactory method setProfile.
@Override
protected void setProfile(Profile profile, DeploymentConfiguration deploymentConfiguration, SpinnakerRuntimeSettings endpoints) {
super.setProfile(profile, deploymentConfiguration, endpoints);
// We need to make modifications to this deployment configuration, but can't use helpful objects
// like the accountService on a clone. Therefore, we'll make the modifications in place and
// restore to the original state when the modifications are written out.
Providers originalProviders = deploymentConfiguration.getProviders().cloneNode(Providers.class);
Providers modifiedProviders = deploymentConfiguration.getProviders();
DeploymentEnvironment deploymentEnvironment = deploymentConfiguration.getDeploymentEnvironment();
if (deploymentEnvironment.getBootstrapOnly() != null && deploymentEnvironment.getBootstrapOnly()) {
String bootstrapAccountName = deploymentEnvironment.getAccountName();
removeBootstrapOnlyAccount(modifiedProviders, deploymentConfiguration.getName(), bootstrapAccountName);
}
Artifacts artifacts = deploymentConfiguration.getArtifacts();
List<String> files = backupRequiredFiles(modifiedProviders, deploymentConfiguration.getName());
files.addAll(backupRequiredFiles(artifacts, deploymentConfiguration.getName()));
if (deploymentConfiguration.getProviders() != null) {
processProviders(deploymentConfiguration.getProviders());
}
profile.appendContents(yamlToString(modifiedProviders)).appendContents(yamlToString(new ArtifactWrapper(artifacts))).appendContents(profile.getBaseContents()).setRequiredFiles(files);
deploymentConfiguration.setProviders(originalProviders);
}
Aggregations