Skip to content

Commit

Permalink
Pass spinnaker endpoints to proflie configuration (#122)
Browse files Browse the repository at this point in the history
This will be needed by deck's config
  • Loading branch information
lwander committed Feb 7, 2017
1 parent 62ed6d7 commit 068a6d6
Show file tree
Hide file tree
Showing 9 changed files with 113 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public class DeploymentFactory {
public Deployment create(DeploymentConfiguration deploymentConfiguration, GenerateResult generateResult) {
DeploymentType type = deploymentConfiguration.getDeploymentEnvironment().getType();
DeploymentDetails deploymentDetails = new DeploymentDetails()
.setEndpoints(generateResult.getEndpoints())
.setGenerateResult(generateResult)
.setDeploymentName(deploymentConfiguration.getName())
.setDeploymentEnvironment(deploymentConfiguration.getDeploymentEnvironment());
Expand All @@ -53,13 +54,13 @@ public Deployment create(DeploymentConfiguration deploymentConfiguration, Genera
case LocalhostDebian:
return new LocalhostDebianDeployment(deploymentDetails);
case Flotilla:
return createClusteredSimpleDeployment(deploymentConfiguration, deploymentDetails);
return createFlotillaDeployment(deploymentConfiguration, deploymentDetails);
default:
throw new IllegalArgumentException("Unrecognized deployment type " + type);
}
}

private Deployment createClusteredSimpleDeployment(DeploymentConfiguration deploymentConfiguration, DeploymentDetails deploymentDetails) {
private Deployment createFlotillaDeployment(DeploymentConfiguration deploymentConfiguration, DeploymentDetails deploymentDetails) {
DeploymentEnvironment deploymentEnvironment = deploymentConfiguration.getDeploymentEnvironment();
String accountName = deploymentEnvironment.getAccountName();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* Copyright 2017 Google, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License")
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.netflix.spinnaker.halyard.deploy.deployment.v1;

import com.netflix.spinnaker.halyard.config.model.v1.node.Account;
import com.netflix.spinnaker.halyard.config.model.v1.node.DeploymentConfiguration;
import com.netflix.spinnaker.halyard.config.model.v1.node.DeploymentEnvironment;
import com.netflix.spinnaker.halyard.config.model.v1.node.Provider;
import com.netflix.spinnaker.halyard.config.model.v1.problem.ConfigProblemBuilder;
import com.netflix.spinnaker.halyard.config.services.v1.AccountService;
import com.netflix.spinnaker.halyard.core.error.v1.HalException;
import com.netflix.spinnaker.halyard.core.problem.v1.Problem;
import com.netflix.spinnaker.halyard.deploy.spinnaker.v1.SpinnakerEndpoints;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class EndpointFactory {
@Autowired
AccountService accountService;

public SpinnakerEndpoints create(DeploymentConfiguration deploymentConfiguration ) {
DeploymentEnvironment.DeploymentType type = deploymentConfiguration.getDeploymentEnvironment().getType();
switch (type) {
case LocalhostDebian:
return new SpinnakerEndpoints();
case Flotilla:
return createFlotillaEndpoints(deploymentConfiguration);
default:
throw new IllegalArgumentException("Unrecognized deployment type " + type);
}
}

private SpinnakerEndpoints createFlotillaEndpoints(DeploymentConfiguration deploymentConfiguration) {
DeploymentEnvironment deploymentEnvironment = deploymentConfiguration.getDeploymentEnvironment();
String accountName = deploymentEnvironment.getAccountName();

if (accountName == null || accountName.isEmpty()) {
throw new HalException(new ConfigProblemBuilder(Problem.Severity.FATAL, "An account name must be "
+ "specified as the desired place to run your simple clustered deployment.").build());
}

Account account = accountService.getAnyProviderAccount(deploymentConfiguration.getName(), accountName);
Provider.ProviderType providerType = ((Provider) account.getParent()).providerType();

switch (providerType) {
case KUBERNETES:
SpinnakerEndpoints endpoints = new SpinnakerEndpoints();
SpinnakerEndpoints.Services services = endpoints.getServices();

services.getClouddriver().setAddress("spin-clouddriver.spinnaker").setHost("0.0.0.0");
services.getDeck().setAddress("spin-deck.spinnaker").setHost("0.0.0.0");
services.getEcho().setAddress("spin-echo.spinnaker").setHost("0.0.0.0");
services.getFiat().setAddress("spin-fiat.spinnaker").setHost("0.0.0.0");
services.getFront50().setAddress("spin-front50.spinnaker").setHost("0.0.0.0");
services.getGate().setAddress("spin-gate.spinnaker").setHost("0.0.0.0");
services.getIgor().setAddress("spin-igor.spinnaker").setHost("0.0.0.0");
services.getOrca().setAddress("spin-orca.spinnaker").setHost("0.0.0.0");
services.getRosco().setAddress("spin-rosco.spinnaker").setHost("0.0.0.0");
services.getRedis().setAddress("spin-redis.spinnaker").setHost("0.0.0.0");
default:
throw new IllegalArgumentException("No Clustered Simple Deployment for " + providerType.getId());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,10 @@

abstract public class FlotillaDeployment<T extends Account> extends Deployment {
public FlotillaDeployment(AccountDeploymentDetails<T> deploymentDetails, ProviderInterface<T> providerInterface) {
deploymentDetails.setEndpoints(specializeEndpoints(deploymentDetails.getEndpoints()));

this.deploymentDetails = deploymentDetails;
this.providerInterface = providerInterface;
}

protected abstract SpinnakerEndpoints specializeEndpoints(SpinnakerEndpoints endpoints);

@Override
public DeploymentType deploymentType() {
return DeploymentType.Flotilla;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,4 @@ public KubernetesFlotillaDeployment(
KubernetesProviderInterface providerInterface) {
super(deploymentDetails, providerInterface);
}

@Override
protected SpinnakerEndpoints specializeEndpoints(SpinnakerEndpoints endpoints) {
Services services = endpoints.getServices();

services.getClouddriver().setAddress("spin-clouddriver.spinnaker").setHost("0.0.0.0");
services.getDeck().setAddress("spin-deck.spinnaker").setHost("0.0.0.0");
services.getEcho().setAddress("spin-echo.spinnaker").setHost("0.0.0.0");
services.getFiat().setAddress("spin-fiat.spinnaker").setHost("0.0.0.0");
services.getFront50().setAddress("spin-front50.spinnaker").setHost("0.0.0.0");
services.getGate().setAddress("spin-gate.spinnaker").setHost("0.0.0.0");
services.getIgor().setAddress("spin-igor.spinnaker").setHost("0.0.0.0");
services.getOrca().setAddress("spin-orca.spinnaker").setHost("0.0.0.0");
services.getRosco().setAddress("spin-rosco.spinnaker").setHost("0.0.0.0");
services.getRedis().setAddress("spin-redis.spinnaker").setHost("0.0.0.0");

return endpoints;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
import com.netflix.spinnaker.halyard.config.services.v1.DeploymentService;
import com.netflix.spinnaker.halyard.deploy.deployment.v1.Deployment;
import com.netflix.spinnaker.halyard.deploy.deployment.v1.DeploymentFactory;
import com.netflix.spinnaker.halyard.deploy.deployment.v1.EndpointFactory;
import com.netflix.spinnaker.halyard.deploy.services.v1.GenerateService.GenerateResult;
import com.netflix.spinnaker.halyard.deploy.spinnaker.v1.SpinnakerEndpoints;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@

import com.fasterxml.jackson.databind.ObjectMapper;
import com.netflix.spinnaker.halyard.config.config.v1.AtomicFileWriter;
import com.netflix.spinnaker.halyard.config.model.v1.node.DeploymentConfiguration;
import com.netflix.spinnaker.halyard.config.model.v1.problem.ConfigProblemBuilder;
import com.netflix.spinnaker.halyard.config.services.v1.DeploymentService;
import com.netflix.spinnaker.halyard.core.error.v1.HalException;
import com.netflix.spinnaker.halyard.core.problem.v1.Problem.Severity;
import com.netflix.spinnaker.halyard.core.tasks.v1.DaemonTaskHandler;
import com.netflix.spinnaker.halyard.deploy.deployment.v1.DeploymentFactory;
import com.netflix.spinnaker.halyard.deploy.deployment.v1.EndpointFactory;
import com.netflix.spinnaker.halyard.deploy.spinnaker.v1.SpinnakerArtifact;
import com.netflix.spinnaker.halyard.deploy.spinnaker.v1.SpinnakerEndpoints;
import com.netflix.spinnaker.halyard.deploy.spinnaker.v1.profile.ProfileConfig;
import com.netflix.spinnaker.halyard.deploy.spinnaker.v1.profile.SpinnakerProfile;
import lombok.Data;
Expand All @@ -43,28 +45,28 @@
@Slf4j
public class GenerateService {
@Autowired
String spinnakerOutputPath;
private String spinnakerOutputPath;

@Autowired
String halconfigDirectory;
private String halconfigDirectory;

@Autowired
DeploymentService deploymentService;
private DeploymentService deploymentService;

@Autowired
DeploymentFactory deploymentFactory;
private EndpointFactory endpointFactory;

@Autowired
String halconfigPath;
private String halconfigPath;

@Autowired
Yaml yamlParser;
private Yaml yamlParser;

@Autowired
ObjectMapper objectMapper;
private ObjectMapper objectMapper;

@Autowired(required = false)
List<SpinnakerProfile> spinnakerProfiles = new ArrayList<>();
private List<SpinnakerProfile> spinnakerProfiles = new ArrayList<>();

void atomicWrite(Path path, String contents) {
AtomicFileWriter writer = null;
Expand Down Expand Up @@ -106,6 +108,9 @@ String yamlToString(Object yaml) {
public GenerateResult generateConfig(String deploymentName) {
log.info("Generating config from \"" + halconfigPath + "\" with deploymentName \"" + deploymentName + "\"");
File spinnakerOutput = new File(spinnakerOutputPath);
DeploymentConfiguration deploymentConfiguration = deploymentService.getDeploymentConfiguration(deploymentName);

SpinnakerEndpoints endpoints = endpointFactory.create(deploymentConfiguration);

// Step 1.
try {
Expand All @@ -127,7 +132,7 @@ public GenerateResult generateConfig(String deploymentName) {
Path path;
for (SpinnakerProfile profile : spinnakerProfiles) {
path = defaultFileSystem.getPath(spinnakerOutputPath, profile.getProfileFileName());
ProfileConfig config = profile.getFullConfig(deploymentName);
ProfileConfig config = profile.getFullConfig(deploymentName, endpoints);
log.info("Writing " + profile.getProfileName() + " profile to " + path + " with " + config.getRequiredFiles().size() + " required files");
DaemonTaskHandler.log("Writing profile " + path.getFileName().toFile().getName());
atomicWrite(path, config.getConfigContents());
Expand Down Expand Up @@ -159,12 +164,14 @@ public GenerateResult generateConfig(String deploymentName) {

return new GenerateResult()
.setArtifactVersion(artifactVersions)
.setProfileRequirements(profileRequirements);
.setProfileRequirements(profileRequirements)
.setEndpoints(endpoints);
}

@Data
public static class GenerateResult {
private Map<String, List<String>> profileRequirements = new HashMap<>();
private Map<SpinnakerArtifact, String> artifactVersion = new HashMap<>();
SpinnakerEndpoints endpoints;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.netflix.spinnaker.halyard.config.model.v1.node.DeploymentConfiguration;
import com.netflix.spinnaker.halyard.config.model.v1.node.Providers;
import com.netflix.spinnaker.halyard.deploy.spinnaker.v1.SpinnakerArtifact;
import com.netflix.spinnaker.halyard.deploy.spinnaker.v1.SpinnakerEndpoints;
import org.springframework.stereotype.Component;

import java.util.List;
Expand All @@ -36,7 +37,7 @@ public SpinnakerArtifact getArtifact() {
}

@Override
public ProfileConfig generateFullConfig(ProfileConfig config, DeploymentConfiguration deploymentConfiguration) {
public ProfileConfig generateFullConfig(ProfileConfig config, DeploymentConfiguration deploymentConfiguration, SpinnakerEndpoints endpoints) {
Providers providers = deploymentConfiguration.getProviders();
List<String> files = dependentFiles(providers);
return config.appendConfig(yamlToString(deploymentConfiguration.getProviders())).setRequiredFiles(files);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.netflix.spinnaker.halyard.core.error.v1.HalException;
import com.netflix.spinnaker.halyard.core.problem.v1.Problem.Severity;
import com.netflix.spinnaker.halyard.deploy.spinnaker.v1.SpinnakerArtifact;
import com.netflix.spinnaker.halyard.deploy.spinnaker.v1.SpinnakerEndpoints;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
Expand All @@ -45,7 +46,7 @@ public SpinnakerArtifact getArtifact() {
}

@Override
public ProfileConfig generateFullConfig(ProfileConfig config, DeploymentConfiguration deploymentConfiguration) {
public ProfileConfig generateFullConfig(ProfileConfig config, DeploymentConfiguration deploymentConfiguration, SpinnakerEndpoints endpoints) {
PersistentStorage storage = deploymentConfiguration.getPersistentStorage();
Account account = accountService.getProviderAccount(deploymentConfiguration.getName(), "google", storage.getAccountName());
Front50Credentials credentials = new Front50Credentials();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.netflix.spinnaker.halyard.core.problem.v1.Problem.Severity;
import com.netflix.spinnaker.halyard.deploy.services.v1.ArtifactService;
import com.netflix.spinnaker.halyard.deploy.spinnaker.v1.SpinnakerArtifact;
import com.netflix.spinnaker.halyard.deploy.spinnaker.v1.SpinnakerEndpoints;
import com.netflix.spinnaker.halyard.deploy.spinnaker.v1.profile.registry.ProfileRegistry;
import org.springframework.beans.factory.annotation.Autowired;
import org.yaml.snakeyaml.Yaml;
Expand Down Expand Up @@ -73,11 +74,11 @@ abstract public class SpinnakerProfile {

public abstract SpinnakerArtifact getArtifact();

public ProfileConfig getFullConfig(String deploymentName) {
public ProfileConfig getFullConfig(String deploymentName, SpinnakerEndpoints endpoints) {
DeploymentConfiguration deploymentConfiguration = deploymentService.getDeploymentConfiguration(deploymentName);
ProfileConfig result = generateFullConfig(
getBaseConfig(deploymentConfiguration),
deploymentConfiguration);
ProfileConfig result = generateFullConfig(getBaseConfig(deploymentConfiguration),
deploymentConfiguration,
endpoints);
result.setConfigContents(EDIT_WARNING + result.getConfigContents());
return result;
}
Expand All @@ -89,9 +90,10 @@ public ProfileConfig getFullConfig(String deploymentName) {
*
* @param config the base halconfig returned from the config storage.
* @param deploymentConfiguration the deployment configuration being translated into Spinnaker config.
* @param endpoints are the endpoints spinnaker will be running at.
* @return the fully written configuration.
*/
protected ProfileConfig generateFullConfig(ProfileConfig config, DeploymentConfiguration deploymentConfiguration) {
protected ProfileConfig generateFullConfig(ProfileConfig config, DeploymentConfiguration deploymentConfiguration, SpinnakerEndpoints endpoints) {
return config;
}

Expand Down

0 comments on commit 068a6d6

Please sign in to comment.