use of com.netflix.spinnaker.halyard.deploy.spinnaker.v1.SpinnakerRuntimeSettings in project halyard by spinnaker.
the class LocalGitDeployer method prep.
@Override
public RemoteAction prep(LocalServiceProvider serviceProvider, DeploymentDetails deploymentDetails, SpinnakerRuntimeSettings runtimeSettings, List<SpinnakerService.Type> serviceTypes) {
LocalGitServiceProvider localGitServiceProvider = (LocalGitServiceProvider) serviceProvider;
List<LocalGitService> enabledServices = localGitServiceProvider.getLocalGitServices(serviceTypes);
List<String> prepCommands = enabledServices.stream().filter(i -> !runtimeSettings.getServiceSettings(i.getService()).getSkipLifeCycleManagement()).map(s -> {
s.commitWrapperScripts();
return s.prepArtifactCommand(deploymentDetails);
}).collect(Collectors.toList());
String prepCommand = localGitServiceProvider.getPrepCommand(deploymentDetails, prepCommands);
RemoteAction result = new RemoteAction();
result.setAutoRun(true);
result.setScript(prepCommand);
return result;
}
use of com.netflix.spinnaker.halyard.deploy.spinnaker.v1.SpinnakerRuntimeSettings 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;
}
use of com.netflix.spinnaker.halyard.deploy.spinnaker.v1.SpinnakerRuntimeSettings in project halyard by spinnaker.
the class KubernetesV1DistributedService method buildRollbackPipeline.
@Override
default Map<String, Object> buildRollbackPipeline(AccountDeploymentDetails<KubernetesAccount> details, SpinnakerRuntimeSettings runtimeSettings) {
ServiceSettings settings = runtimeSettings.getServiceSettings(getService());
Map<String, Object> pipeline = DistributedService.super.buildRollbackPipeline(details, runtimeSettings);
List<Map<String, Object>> stages = (List<Map<String, Object>>) pipeline.get("stages");
assert (stages != null && !stages.isEmpty());
for (Map<String, Object> stage : stages) {
stage.put("namespaces", Collections.singletonList(getNamespace(settings)));
stage.put("interestingHealthProviderNames", Collections.singletonList("KubernetesService"));
stage.remove("region");
}
return pipeline;
}
use of com.netflix.spinnaker.halyard.deploy.spinnaker.v1.SpinnakerRuntimeSettings in project halyard by spinnaker.
the class KubernetesV1DistributedService method connectToService.
@Override
default <S> S connectToService(AccountDeploymentDetails<KubernetesAccount> details, SpinnakerRuntimeSettings runtimeSettings, SpinnakerService<S> service) {
ServiceSettings settings = runtimeSettings.getServiceSettings(service);
KubernetesV1ProviderUtils.Proxy proxy = KubernetesV1ProviderUtils.openProxy(getJobExecutor(), details);
String endpoint = KubernetesV1ProviderUtils.proxyServiceEndpoint(proxy, getNamespace(settings), getServiceName(), settings.getPort()).toString();
return getServiceInterfaceFactory().createService(endpoint, service);
}
use of com.netflix.spinnaker.halyard.deploy.spinnaker.v1.SpinnakerRuntimeSettings in project halyard by spinnaker.
the class KubernetesV1DistributedService method getRunningServiceDetails.
@Override
default RunningServiceDetails getRunningServiceDetails(AccountDeploymentDetails<KubernetesAccount> details, SpinnakerRuntimeSettings runtimeSettings) {
ServiceSettings settings = runtimeSettings.getServiceSettings(getService());
RunningServiceDetails res = new RunningServiceDetails();
KubernetesClient client = KubernetesV1ProviderUtils.getClient(details);
String name = getServiceName();
String namespace = getNamespace(settings);
RunningServiceDetails.LoadBalancer lb = new RunningServiceDetails.LoadBalancer();
lb.setExists(client.services().inNamespace(namespace).withName(name).get() != null);
res.setLoadBalancer(lb);
List<Pod> pods = client.pods().inNamespace(namespace).withLabel("load-balancer-" + name, "true").list().getItems();
pods.addAll(client.pods().inNamespace(namespace).withLabel("load-balancer-" + name, "false").list().getItems());
Map<Integer, List<Instance>> instances = res.getInstances();
for (Pod pod : pods) {
String podName = pod.getMetadata().getName();
String serverGroupName = podName.substring(0, podName.lastIndexOf("-"));
Names parsedName = Names.parseName(serverGroupName);
Integer version = parsedName.getSequence();
if (version == null) {
throw new IllegalStateException("Server group for service " + getServiceName() + " has unknown sequence (" + serverGroupName + ")");
}
String location = pod.getMetadata().getNamespace();
String id = pod.getMetadata().getName();
Instance instance = new Instance().setId(id).setLocation(location);
List<ContainerStatus> containerStatuses = pod.getStatus().getContainerStatuses();
if (!containerStatuses.isEmpty() && containerStatuses.stream().allMatch(ContainerStatus::getReady)) {
instance.setHealthy(true);
}
if (!containerStatuses.isEmpty() && containerStatuses.stream().allMatch(s -> s.getState().getRunning() != null && s.getState().getTerminated() == null)) {
instance.setRunning(true);
}
List<Instance> knownInstances = instances.getOrDefault(version, new ArrayList<>());
knownInstances.add(instance);
instances.put(version, knownInstances);
}
List<ReplicaSet> replicaSets = client.extensions().replicaSets().inNamespace(settings.getLocation()).list().getItems();
for (ReplicaSet rs : replicaSets) {
String rsName = rs.getMetadata().getName();
Names parsedRsName = Names.parseName(rsName);
if (!parsedRsName.getCluster().equals(getServiceName())) {
continue;
}
instances.computeIfAbsent(parsedRsName.getSequence(), i -> new ArrayList<>());
}
return res;
}
Aggregations