use of com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.ServiceSettings in project halyard by spinnaker.
the class KubernetesV1DistributedService method connectCommand.
default String connectCommand(AccountDeploymentDetails<KubernetesAccount> details, SpinnakerRuntimeSettings runtimeSettings, int localPort) {
ServiceSettings settings = runtimeSettings.getServiceSettings(getService());
RunningServiceDetails runningServiceDetails = getRunningServiceDetails(details, runtimeSettings);
Map<Integer, List<Instance>> instances = runningServiceDetails.getInstances();
Integer latest = runningServiceDetails.getLatestEnabledVersion();
String namespace = getNamespace(settings);
List<Instance> latestInstances = instances.get(latest);
if (latestInstances.isEmpty()) {
throw new HalException(Problem.Severity.FATAL, "No instances running in latest server group for service " + getServiceName() + " in namespace " + namespace);
}
return Strings.join(KubernetesV1ProviderUtils.kubectlPortForwardCommand(details, namespace, latestInstances.get(0).getId(), settings.getPort(), localPort), " ");
}
use of com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.ServiceSettings 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.ServiceSettings 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.ServiceSettings in project halyard by spinnaker.
the class KubernetesV1DistributedService method connectToInstance.
@Override
default <S> S connectToInstance(AccountDeploymentDetails<KubernetesAccount> details, SpinnakerRuntimeSettings runtimeSettings, SpinnakerService<S> sidecar, String instanceId) {
ServiceSettings settings = runtimeSettings.getServiceSettings(sidecar);
String namespace = getNamespace(settings);
int localPort = SocketUtils.findAvailableTcpPort();
int targetPort = settings.getPort();
List<String> command = KubernetesV1ProviderUtils.kubectlPortForwardCommand(details, namespace, instanceId, targetPort, localPort);
JobRequest request = new JobRequest().setTokenizedCommand(command);
String jobId = getJobExecutor().startJob(request);
// Wait for the proxy to spin up.
DaemonTaskHandler.safeSleep(TimeUnit.SECONDS.toMillis(5));
JobStatus status = getJobExecutor().updateJob(jobId);
// This should be a long-running job.
if (status.getState() == JobStatus.State.COMPLETED) {
throw new HalException(Problem.Severity.FATAL, "Unable to establish a proxy against " + getServiceName() + ":\n" + status.getStdOut() + "\n" + status.getStdErr());
}
return getServiceInterfaceFactory().createService(settings.getScheme() + "://localhost:" + localPort, sidecar);
}
use of com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.ServiceSettings in project halyard by spinnaker.
the class KubernetesV1DistributedService method getLoadBalancerDescription.
default Map<String, Object> getLoadBalancerDescription(AccountDeploymentDetails<KubernetesAccount> details, SpinnakerRuntimeSettings runtimeSettings) {
ServiceSettings settings = runtimeSettings.getServiceSettings(getService());
int port = settings.getPort();
String accountName = details.getAccount().getName();
KubernetesLoadBalancerDescription description = new KubernetesLoadBalancerDescription();
String namespace = getNamespace(settings);
String name = getServiceName();
Names parsedName = Names.parseName(name);
description.setApp(parsedName.getApp());
description.setStack(parsedName.getStack());
description.setDetail(parsedName.getDetail());
description.setName(name);
description.setNamespace(namespace);
description.setAccount(accountName);
KubernetesNamedServicePort servicePort = new KubernetesNamedServicePort();
servicePort.setPort(port);
servicePort.setTargetPort(port);
servicePort.setName("http");
servicePort.setProtocol("TCP");
KubernetesNamedServicePort monitoringPort = new KubernetesNamedServicePort();
monitoringPort.setPort(8008);
monitoringPort.setTargetPort(8008);
monitoringPort.setName("monitoring");
monitoringPort.setProtocol("TCP");
List<KubernetesNamedServicePort> servicePorts = new ArrayList<>();
servicePorts.add(servicePort);
servicePorts.add(monitoringPort);
description.setPorts(servicePorts);
return getObjectMapper().convertValue(description, new TypeReference<Map<String, Object>>() {
});
}
Aggregations