public ServiceSettings getDefaultServiceSettings(DeploymentConfiguration deploymentConfiguration) { File userSettingsFile = new File( halconfigDirectoryStructure.getUserServiceSettingsPath(deploymentConfiguration.getName()).toString(), getCanonicalName() + ".yml" ); if (userSettingsFile.exists() && userSettingsFile.length() != 0) { try { log.info("Reading user provided service settings from " + userSettingsFile); return objectMapper.convertValue( yamlParser.load(new FileInputStream(userSettingsFile)), ServiceSettings.class ); } catch (FileNotFoundException e) { throw new HalException(Problem.Severity.FATAL, "Unable to read provided user settings: " + e.getMessage(), e); } } else { return new ServiceSettings(); } }
@JsonIgnore public String getAuthBaseUrl() { return buildBaseUri() .get() .setUserInfo(getUsername(), getPassword()) .toString(); }
private Optional<URIBuilder> buildBaseUri() { if (!StringUtils.isBlank(overrideBaseUrl)) { try { return Optional.of(new URIBuilder(overrideBaseUrl)); } catch (URISyntaxException e) { throw new HalException(Problem.Severity.FATAL, "Illegal override baseURL: " + overrideBaseUrl, e); } } if (!StringUtils.isBlank(baseUrl)) { try { return Optional.of(new URIBuilder(baseUrl)); } catch (URISyntaxException e) { throw new HalException(Problem.Severity.FATAL, "Illegal baseURL: " + baseUrl, e); } } if (getScheme() != null && getPort() != null && getAddress() != null) { return Optional.of(new URIBuilder() .setScheme(getScheme()) .setPort(getPort()) .setHost(getAddress())); } return Optional.empty(); }
public ServiceSettings withOnlyBaseUrl() { return new ServiceSettings(getBaseUrl()); }
default List<String> getReadinessExecCommand(ServiceSettings settings) { return Arrays.asList("wget", "--no-check-certificate", "--spider", "-q", settings.getScheme() + "://localhost:" + settings.getPort() + settings.getHealthEndpoint()); }
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(); String scheme = settings.getScheme(); if (StringUtils.isNotEmpty(scheme)) { scheme = scheme.toUpperCase(); if (settings.getHealthEndpoint() != null) { probeBuilder = probeBuilder .withNewHttpGet() .withNewPort(port) .withPath(settings.getHealthEndpoint()) .withScheme(scheme) .endHttpGet(); containerBuilder = containerBuilder .withName(name) .withImage(settings.getArtifactId()) .withPorts(new ContainerPortBuilder().withContainerPort(port).build()) .withVolumeMounts(volumeMounts)
default ServiceSettings buildServiceSettings(DeploymentConfiguration deploymentConfiguration) { KubernetesSharedServiceSettings kubernetesSharedServiceSettings = new KubernetesSharedServiceSettings(deploymentConfiguration); ServiceSettings settings = defaultServiceSettings(deploymentConfiguration); String location = kubernetesSharedServiceSettings.getDeployLocation(); settings.setAddress(buildAddress(location)) .setArtifactId(getArtifactId(deploymentConfiguration.getName())) .setLocation(location) .setEnabled(isEnabled(deploymentConfiguration)); if (runsOnJvm()) { // Use half the available memory allocated to the container for the JVM heap settings.getEnv().put("JAVA_OPTS", "-XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap -XX:MaxRAMFraction=2"); } return settings; }
@JsonIgnore public String getMetricsUrl() { URIBuilder builder = new URIBuilder() .setScheme(getScheme()) .setPort(getPort()) .setHost("localhost") .setPath("spectator/metrics"); if (getBasicAuthEnabled() != null && getBasicAuthEnabled()) { builder.setUserInfo(getUsername(), getPassword()); } try { return builder.build().toString(); } catch (URISyntaxException e) { throw new HalException(Problem.Severity.FATAL, "Could not build metrics endpoint. This is probably a bug.", e); } }
SpinnakerService service = distributedService.getService(); ServiceSettings settings = runtimeSettings.getServiceSettings(service); boolean safeToUpdate = settings.getSafeToUpdate(); if (!settings.getEnabled() || distributedService.isRequiredToBootstrap() || !safeToUpdate || settings.getSkipLifeCycleManagement()) { continue; SpinnakerService service = distributedService.getService(); ServiceSettings settings = runtimeSettings.getServiceSettings(service); if (!settings.getEnabled() || settings.getSkipLifeCycleManagement()) { continue; boolean safeToUpdate = settings.getSafeToUpdate(); if (distributedService.isRequiredToBootstrap() || !safeToUpdate) {
public SlimServiceSettings slim() { return new SlimServiceSettings(getHost(), getPort(), getBaseUrl(), getEnabled()); }
if (settings.getEnabled() == null || settings.getEnabled()) { return; if (settings.getSkipLifeCycleManagement() != null && settings.getSkipLifeCycleManagement()) { return;
default List<SidecarService> getSidecars(SpinnakerRuntimeSettings runtimeSettings) { SpinnakerMonitoringDaemonService monitoringService = getMonitoringDaemonService(); ServiceSettings monitoringSettings = runtimeSettings.getServiceSettings(monitoringService); ServiceSettings thisSettings = runtimeSettings.getServiceSettings(getService()); List<SidecarService> result = new ArrayList<>(); if (monitoringSettings.getEnabled() && thisSettings.getMonitored()) { result.add(monitoringService); } return result; }
}).collect(Collectors.toList()); volumeMounts.addAll(settings.getKubernetes().getVolumes().stream() .map(c -> { TemplatedResource volume = new JinjaJarResource("/kubernetes/manifests/volumeMount.yml"); if (StringUtils.isNotEmpty(settings.getHealthEndpoint())) { probe = new JinjaJarResource("/kubernetes/manifests/execReadinessProbe.yml"); probe.addBinding("command", getReadinessExecCommand(settings)); } else { probe = new JinjaJarResource("/kubernetes/manifests/tcpSocketReadinessProbe.yml"); probe.addBinding("port", settings.getPort()); container.addBinding("imageId", settings.getArtifactId()); TemplatedResource port = new JinjaJarResource("/kubernetes/manifests/port.yml"); port.addBinding("port", settings.getPort()); container.addBinding("port", port.toString()); container.addBinding("volumeMounts", volumeMounts);
SecurityConfig(ServiceSettings settings) { if (settings.getBasicAuthEnabled() == null || settings.getBasicAuthEnabled()) { String username = settings.getUsername(); String password = settings.getPassword(); assert(username != null && password != null); basic.setEnabled(true); user.setName(username); user.setPassword(password); } }
@Override protected void setProfile(Profile profile, DeploymentConfiguration deploymentConfiguration, SpinnakerRuntimeSettings endpoints) { super.setProfile(profile, deploymentConfiguration, endpoints); ServiceSettings deckSettings = endpoints.getServiceSettings(Type.DECK); ServiceSettings gateSettings = endpoints.getServiceSettings(Type.GATE); ApacheSsl apacheSsl= deploymentConfiguration.getSecurity().getUiSecurity().getSsl(); Map<String, String> env = profile.getEnv(); if (apacheSsl.isEnabled()) { env.put("DECK_HOST", deckSettings.getHost()); env.put("DECK_PORT", deckSettings.getPort() + ""); env.put("API_HOST", gateSettings.getBaseUrl()); env.put("DECK_CERT", apacheSsl.getSslCertificateFile()); env.put("DECK_KEY", apacheSsl.getSslCertificateKeyFile()); env.put("PASSPHRASE", apacheSsl.getSslCertificatePassphrase()); } env.put("AUTH_ENABLED", Boolean.toString(deploymentConfiguration.getSecurity().getAuthn().isEnabled())); env.put("FIAT_ENABLED", Boolean.toString(deploymentConfiguration.getSecurity().getAuthz().isEnabled())); } }
description.setPodAnnotations(settings.getKubernetes().getPodAnnotations()); if (monitoringSettings.getEnabled() && serviceSettings.getMonitored()) { serviceSettings = runtimeSettings.getServiceSettings(monitoringService); container = buildContainer(monitoringService.getServiceName(), serviceSettings, configSources, deploymentEnvironment, description);
Compute compute = GoogleProviderUtils.getCompute(details); String project = account.getProject(); String zone = settings.getLocation(); GoogleProviderUtils.waitOnGlobalOperation(compute, project, operation); } catch (IOException e) { throw new HalException(FATAL, "Failed to create instance template for " + settings.getArtifactId() + ": " + e.getMessage(), e); manager.setInstanceTemplate(instanceTemplateUrl); manager.setBaseInstanceName(migName); manager.setTargetSize(settings.getTargetSize()); manager.setName(migName); operation = compute.instanceGroupManagers().insert(project, settings.getLocation(), manager).execute(); GoogleProviderUtils.waitOnZoneOperation(compute, project, settings.getLocation(), operation); } catch (IOException e) { throw new HalException(FATAL, "Failed to create instance group to run artifact " + settings.getArtifactId() + ": " + e.getMessage(), e);
@Override protected void appendReadonlyClouddriverForDeck(Profile profile, DeploymentConfiguration deploymentConfiguration, SpinnakerRuntimeSettings endpoints) { if (hasServiceOverrides(deploymentConfiguration)) { Map<String, Map<String, Map<String, Map<String, Map<String, String>>>>> services = Collections.singletonMap( "services", Collections.singletonMap( "clouddriver", Collections.singletonMap( "config", Collections.singletonMap( "dynamicEndpoints", Collections.singletonMap( "deck", endpoints.getServiceSettings(Type.CLOUDDRIVER_RO_DECK).getBaseUrl()))))); profile.appendContents(getYamlParser().dump(services)); } } }
public boolean serviceIsEnabled(Type type) { return services.containsKey(type) && services.get(type).getEnabled(); } }