use of com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.SpinnakerService in project halyard by spinnaker.
the class DeployService method deploy.
public RemoteAction deploy(String deploymentName, List<DeployOption> deployOptions, List<String> serviceNames) {
DeploymentConfiguration deploymentConfiguration = deploymentService.getDeploymentConfiguration(deploymentName);
SpinnakerServiceProvider<DeploymentDetails> serviceProvider = serviceProviderFactory.create(deploymentConfiguration);
List<SpinnakerService.Type> serviceTypes = serviceNames.stream().map(SpinnakerService.Type::fromCanonicalName).collect(Collectors.toList());
if (serviceTypes.isEmpty()) {
serviceTypes = serviceProvider.getServices().stream().map(SpinnakerService::getType).collect(Collectors.toList());
}
ResolvedConfiguration resolvedConfiguration;
if (deployOptions.contains(DeployOption.OMIT_CONFIG)) {
resolvedConfiguration = generateService.generateConfig(deploymentName, Collections.emptyList());
} else {
resolvedConfiguration = generateService.generateConfig(deploymentName, serviceTypes);
}
Path serviceSettingsPath = halconfigDirectoryStructure.getServiceSettingsPath(deploymentName);
configParser.atomicWrite(serviceSettingsPath, resolvedConfiguration.getRuntimeSettings());
Path serviceProfilesPath = halconfigDirectoryStructure.getServiceProfilesPath(deploymentName);
configParser.atomicWrite(serviceProfilesPath, resolvedConfiguration.getServiceProfiles());
Deployer deployer = getDeployer(deploymentConfiguration);
DeploymentDetails deploymentDetails = getDeploymentDetails(deploymentConfiguration);
RemoteAction action = deployer.deploy(serviceProvider, deploymentDetails, resolvedConfiguration, serviceTypes);
halconfigParser.backupConfig();
if (deployOptions.contains(DeployOption.FLUSH_INFRASTRUCTURE_CACHES)) {
deployer.flushInfrastructureCaches(serviceProvider, deploymentDetails, resolvedConfiguration.getRuntimeSettings());
}
if (!action.getScript().isEmpty()) {
action.commitScript(halconfigDirectoryStructure.getInstallScriptPath(deploymentName));
}
return action;
}
use of com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.SpinnakerService in project halyard by spinnaker.
the class DeployService method prep.
public RemoteAction prep(String deploymentName, List<String> serviceNames) {
DeploymentConfiguration deploymentConfiguration = deploymentService.getDeploymentConfiguration(deploymentName);
DeploymentDetails deploymentDetails = getDeploymentDetails(deploymentConfiguration);
Deployer deployer = getDeployer(deploymentConfiguration);
SpinnakerServiceProvider<DeploymentDetails> serviceProvider = serviceProviderFactory.create(deploymentConfiguration);
SpinnakerRuntimeSettings runtimeSettings = serviceProvider.buildRuntimeSettings(deploymentConfiguration);
List<SpinnakerService.Type> serviceTypes = serviceNames.stream().map(SpinnakerService.Type::fromCanonicalName).collect(Collectors.toList());
if (serviceTypes.isEmpty()) {
serviceTypes = serviceProvider.getServices().stream().map(SpinnakerService::getType).collect(Collectors.toList());
}
RemoteAction action = deployer.prep(serviceProvider, deploymentDetails, runtimeSettings, serviceTypes);
if (!action.getScript().isEmpty()) {
action.commitScript(halconfigDirectoryStructure.getPrepScriptPath(deploymentName));
}
return action;
}
use of com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.SpinnakerService in project halyard by spinnaker.
the class DeployService method rollback.
public void rollback(String deploymentName, List<String> serviceNames) {
DeploymentConfiguration deploymentConfiguration = deploymentService.getDeploymentConfiguration(deploymentName);
SpinnakerServiceProvider<DeploymentDetails> serviceProvider = serviceProviderFactory.create(deploymentConfiguration);
List<SpinnakerService.Type> serviceTypes = serviceNames.stream().map(SpinnakerService.Type::fromCanonicalName).collect(Collectors.toList());
if (serviceTypes.isEmpty()) {
serviceTypes = serviceProvider.getServices().stream().map(SpinnakerService::getType).collect(Collectors.toList());
}
SpinnakerRuntimeSettings runtimeSettings = serviceProvider.buildRuntimeSettings(deploymentConfiguration);
Deployer deployer = getDeployer(deploymentConfiguration);
DeploymentDetails deploymentDetails = getDeploymentDetails(deploymentConfiguration);
deployer.rollback(serviceProvider, deploymentDetails, runtimeSettings, serviceTypes);
}
use of com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.SpinnakerService in project halyard by spinnaker.
the class KubectlDeployer method deploy.
@Override
public RemoteAction deploy(KubectlServiceProvider serviceProvider, AccountDeploymentDetails<KubernetesAccount> deploymentDetails, GenerateService.ResolvedConfiguration resolvedConfiguration, List<SpinnakerService.Type> serviceTypes) {
List<KubernetesV2Service> services = serviceProvider.getServicesByPriority(serviceTypes);
services.stream().forEach((service) -> {
ServiceSettings settings = resolvedConfiguration.getServiceSettings((SpinnakerService) service);
if (settings.getEnabled() != null && !settings.getEnabled()) {
return;
}
if (settings.getSkipLifeCycleManagement() != null && settings.getSkipLifeCycleManagement()) {
return;
}
DaemonTaskHandler.newStage("Deploying " + service.getServiceName() + " with kubectl");
KubernetesAccount account = deploymentDetails.getAccount();
String namespaceDefinition = service.getNamespaceYaml(resolvedConfiguration);
String serviceDefinition = service.getServiceYaml(resolvedConfiguration);
if (!KubernetesV2Utils.exists(account, namespaceDefinition)) {
KubernetesV2Utils.apply(account, namespaceDefinition);
}
if (!KubernetesV2Utils.exists(account, serviceDefinition)) {
KubernetesV2Utils.apply(account, serviceDefinition);
}
String resourceDefinition = service.getResourceYaml(deploymentDetails, resolvedConfiguration);
DaemonTaskHandler.message("Running kubectl apply on the resource definition...");
KubernetesV2Utils.apply(account, resourceDefinition);
});
return new RemoteAction();
}
use of com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.SpinnakerService in project halyard by spinnaker.
the class KubernetesV1DistributedService method stageProfiles.
default List<ConfigSource> stageProfiles(AccountDeploymentDetails<KubernetesAccount> details, GenerateService.ResolvedConfiguration resolvedConfiguration) {
SpinnakerService thisService = getService();
ServiceSettings thisServiceSettings = resolvedConfiguration.getServiceSettings(thisService);
SpinnakerRuntimeSettings runtimeSettings = resolvedConfiguration.getRuntimeSettings();
Integer version = getRunningServiceDetails(details, runtimeSettings).getLatestEnabledVersion();
if (version == null) {
version = 0;
} else {
version++;
}
String namespace = getNamespace(thisServiceSettings);
KubernetesV1ProviderUtils.createNamespace(details, namespace);
String name = getServiceName();
Map<String, String> env = new HashMap<>();
List<ConfigSource> configSources = new ArrayList<>();
Map<String, Profile> serviceProfiles = resolvedConfiguration.getProfilesForService(thisService.getType());
Set<String> requiredFiles = new HashSet<>();
for (SidecarService sidecarService : getSidecars(runtimeSettings)) {
for (Profile profile : sidecarService.getSidecarProfiles(resolvedConfiguration, thisService)) {
if (profile == null) {
throw new HalException(Problem.Severity.FATAL, "Service " + sidecarService.getService().getCanonicalName() + " is required but was not supplied for deployment.");
}
serviceProfiles.put(profile.getName(), profile);
requiredFiles.addAll(profile.getRequiredFiles());
}
}
Map<String, Set<Profile>> collapseByDirectory = new HashMap<>();
for (Map.Entry<String, Profile> entry : serviceProfiles.entrySet()) {
Profile profile = entry.getValue();
String mountPoint = Paths.get(profile.getOutputFile()).getParent().toString();
Set<Profile> profiles = collapseByDirectory.getOrDefault(mountPoint, new HashSet<>());
profiles.add(profile);
requiredFiles.addAll(profile.getRequiredFiles());
collapseByDirectory.put(mountPoint, profiles);
}
String stagingPath = getSpinnakerStagingPath(details.getDeploymentName());
if (!requiredFiles.isEmpty()) {
String secretName = KubernetesV1ProviderUtils.componentDependencies(name, version);
String mountPoint = null;
for (String file : requiredFiles) {
String nextMountPoint = Paths.get(file).getParent().toString();
if (mountPoint == null) {
mountPoint = nextMountPoint;
}
assert (mountPoint.equals(nextMountPoint));
}
Set<Pair<File, String>> pairs = requiredFiles.stream().map(f -> {
return new ImmutablePair<>(new File(f), new File(f).getName());
}).collect(Collectors.toSet());
KubernetesV1ProviderUtils.upsertSecret(details, pairs, secretName, namespace);
configSources.add(new ConfigSource().setId(secretName).setMountPath(mountPoint));
}
int ind = 0;
for (Map.Entry<String, Set<Profile>> entry : collapseByDirectory.entrySet()) {
env.clear();
String mountPoint = entry.getKey();
Set<Profile> profiles = entry.getValue();
env.putAll(profiles.stream().reduce(new HashMap<>(), (acc, profile) -> {
acc.putAll(profile.getEnv());
return acc;
}, (a, b) -> {
a.putAll(b);
return a;
}));
String secretName = KubernetesV1ProviderUtils.componentSecret(name + ind, version);
ind += 1;
Set<Pair<File, String>> pairs = profiles.stream().map(p -> {
return new ImmutablePair<>(new File(stagingPath, p.getName()), new File(p.getOutputFile()).getName());
}).collect(Collectors.toSet());
KubernetesV1ProviderUtils.upsertSecret(details, pairs, secretName, namespace);
configSources.add(new ConfigSource().setId(secretName).setMountPath(mountPoint).setEnv(env));
}
return configSources;
}
Aggregations