Skip to content

Commit

Permalink
Refactor naming of components (#89)
Browse files Browse the repository at this point in the history
This clears up the abstraction quite a bit. The model now looks like
this:

There are a number of Artifacts (like a docker image or debian), which
each expose an Endpoint (like the Clouddriver REST interface), and can
be extended via a Profile (like gate-googleOAuth.yml). Previously these
were all named "component", making things needlessly confusing.
  • Loading branch information
lwander authored Feb 1, 2017
1 parent b05bb5d commit 66eaba7
Show file tree
Hide file tree
Showing 42 changed files with 472 additions and 390 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import com.beust.jcommander.Parameters;
import com.netflix.spinnaker.halyard.cli.services.v1.Daemon;
import com.netflix.spinnaker.halyard.cli.ui.v1.AnsiUi;
import com.netflix.spinnaker.halyard.config.spinnaker.v1.Versions;
import com.netflix.spinnaker.halyard.deploy.spinnaker.v1.Versions;
import lombok.AccessLevel;
import lombok.Getter;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import com.netflix.spinnaker.halyard.config.model.v1.node.Features;
import com.netflix.spinnaker.halyard.config.model.v1.node.Provider;
import com.netflix.spinnaker.halyard.config.model.v1.node.Providers;
import com.netflix.spinnaker.halyard.config.spinnaker.v1.Versions;
import com.netflix.spinnaker.halyard.deploy.spinnaker.v1.Versions;
import retrofit.RestAdapter;
import retrofit.client.OkClient;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import com.netflix.spinnaker.halyard.config.model.v1.node.Halconfig;
import java.util.List;

import com.netflix.spinnaker.halyard.config.spinnaker.v1.Versions;
import com.netflix.spinnaker.halyard.deploy.spinnaker.v1.Versions;
import retrofit.http.Body;
import retrofit.http.DELETE;
import retrofit.http.GET;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@

import com.netflix.spinnaker.halyard.config.model.v1.node.Account;
import com.netflix.spinnaker.halyard.config.model.v1.node.DeploymentEnvironment.DeploymentType;
import com.netflix.spinnaker.halyard.config.spinnaker.v1.SpinnakerEndpoints;
import com.netflix.spinnaker.halyard.deploy.component.v1.ComponentType;
import com.netflix.spinnaker.halyard.deploy.spinnaker.v1.SpinnakerEndpoints;
import com.netflix.spinnaker.halyard.deploy.spinnaker.v1.endpoint.EndpointType;
import com.netflix.spinnaker.halyard.deploy.provider.v1.ProviderInterface;

abstract public class ClusteredSimpleDeployment<T extends Account> extends Deployment {
Expand All @@ -38,7 +38,7 @@ public DeploymentType deploymentType() {
}

@Override
public Object getService(ComponentType type) {
public Object getService(EndpointType type) {
return providerInterface.connectTo(deploymentDetails, type);
}

Expand All @@ -53,6 +53,6 @@ public SpinnakerEndpoints getEndpoints() {
@Override
public void deploy() {
providerInterface.bootstrapClouddriver(deploymentDetails);
providerInterface.connectTo(deploymentDetails, ComponentType.CLOUDDRIVER);
providerInterface.connectTo(deploymentDetails, EndpointType.CLOUDDRIVER);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
package com.netflix.spinnaker.halyard.deploy.deployment.v1;

import com.netflix.spinnaker.halyard.config.model.v1.node.DeploymentEnvironment.DeploymentType;
import com.netflix.spinnaker.halyard.config.spinnaker.v1.SpinnakerEndpoints;
import com.netflix.spinnaker.halyard.deploy.component.v1.ComponentType;
import com.netflix.spinnaker.halyard.deploy.component.v1.ServiceFactory;
import com.netflix.spinnaker.halyard.deploy.spinnaker.v1.SpinnakerEndpoints;
import com.netflix.spinnaker.halyard.deploy.spinnaker.v1.endpoint.EndpointType;
import com.netflix.spinnaker.halyard.deploy.spinnaker.v1.endpoint.ServiceFactory;
import org.springframework.beans.factory.annotation.Autowired;

/**
Expand All @@ -36,7 +36,7 @@ abstract public class Deployment {
* @param type is the type of service.
* @return is a retrofitted interface for the service.
*/
abstract public Object getService(ComponentType type);
abstract public Object getService(EndpointType type);

/**
* The endpoint format is specific to a provider/deployment pair.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import com.netflix.spinnaker.halyard.config.model.v1.node.Account;
import com.netflix.spinnaker.halyard.config.model.v1.node.DeploymentEnvironment;
import com.netflix.spinnaker.halyard.config.spinnaker.v1.SpinnakerEndpoints;
import com.netflix.spinnaker.halyard.deploy.spinnaker.v1.SpinnakerEndpoints;
import lombok.Data;

@Data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import com.netflix.spinnaker.halyard.config.model.v1.problem.Problem.Severity;
import com.netflix.spinnaker.halyard.config.model.v1.problem.ProblemBuilder;
import com.netflix.spinnaker.halyard.config.services.v1.AccountService;
import com.netflix.spinnaker.halyard.config.spinnaker.v1.SpinnakerEndpoints;
import com.netflix.spinnaker.halyard.deploy.spinnaker.v1.SpinnakerEndpoints;
import com.netflix.spinnaker.halyard.deploy.deployment.v1.kubernetes.KubernetesClusteredSimpleDeployment;
import com.netflix.spinnaker.halyard.deploy.provider.v1.KubernetesProviderInterface;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
package com.netflix.spinnaker.halyard.deploy.deployment.v1;

import com.netflix.spinnaker.halyard.config.model.v1.node.DeploymentEnvironment.DeploymentType;
import com.netflix.spinnaker.halyard.config.spinnaker.v1.SpinnakerEndpoints;
import com.netflix.spinnaker.halyard.config.spinnaker.v1.SpinnakerEndpoints.Service;
import com.netflix.spinnaker.halyard.deploy.component.v1.ComponentType;
import com.netflix.spinnaker.halyard.deploy.spinnaker.v1.SpinnakerEndpoints;
import com.netflix.spinnaker.halyard.deploy.spinnaker.v1.SpinnakerEndpoints.Service;
import com.netflix.spinnaker.halyard.deploy.spinnaker.v1.endpoint.EndpointType;

public class LocalhostDebianDeployment extends Deployment {
@Override
Expand All @@ -28,7 +28,7 @@ public DeploymentType deploymentType() {
}

@Override
public Object getService(ComponentType type) {
public Object getService(EndpointType type) {
String endpoint;
switch (type) {
case CLOUDDRIVER:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,11 @@
package com.netflix.spinnaker.halyard.deploy.deployment.v1.kubernetes;

import com.netflix.spinnaker.halyard.config.model.v1.providers.kubernetes.KubernetesAccount;
import com.netflix.spinnaker.halyard.config.spinnaker.v1.SpinnakerEndpoints;
import com.netflix.spinnaker.halyard.config.spinnaker.v1.SpinnakerEndpoints.Services;
import com.netflix.spinnaker.halyard.deploy.spinnaker.v1.SpinnakerEndpoints;
import com.netflix.spinnaker.halyard.deploy.spinnaker.v1.SpinnakerEndpoints.Services;
import com.netflix.spinnaker.halyard.deploy.deployment.v1.ClusteredSimpleDeployment;
import com.netflix.spinnaker.halyard.deploy.deployment.v1.DeploymentDetails;
import com.netflix.spinnaker.halyard.deploy.provider.v1.KubernetesProviderInterface;
import com.netflix.spinnaker.halyard.deploy.provider.v1.ProviderInterface;

public class KubernetesClusteredSimpleDeployment extends ClusteredSimpleDeployment<KubernetesAccount> {
public KubernetesClusteredSimpleDeployment(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,17 @@
import com.netflix.spinnaker.halyard.config.model.v1.problem.Problem.Severity;
import com.netflix.spinnaker.halyard.config.model.v1.problem.ProblemBuilder;
import com.netflix.spinnaker.halyard.config.model.v1.providers.kubernetes.KubernetesAccount;
import com.netflix.spinnaker.halyard.config.resource.v1.TemplatedResource;
import com.netflix.spinnaker.halyard.config.services.v1.LookupService;
import com.netflix.spinnaker.halyard.config.spinnaker.v1.SpinnakerEndpoints.Service;
import com.netflix.spinnaker.halyard.config.spinnaker.v1.component.SpinnakerComponent;
import com.netflix.spinnaker.halyard.deploy.component.v1.ComponentType;
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.Service;
import com.netflix.spinnaker.halyard.deploy.spinnaker.v1.profile.SpinnakerProfile;
import com.netflix.spinnaker.halyard.deploy.spinnaker.v1.endpoint.EndpointType;
import com.netflix.spinnaker.halyard.deploy.deployment.v1.DeploymentDetails;
import com.netflix.spinnaker.halyard.deploy.job.v1.JobRequest;
import com.netflix.spinnaker.halyard.deploy.job.v1.JobStatus;
import com.netflix.spinnaker.halyard.deploy.job.v1.JobStatus.Result;
import com.netflix.spinnaker.halyard.deploy.job.v1.JobStatus.State;
import com.netflix.spinnaker.halyard.deploy.resource.v1.JarResource;
import io.fabric8.kubernetes.api.model.*;
import io.fabric8.kubernetes.api.model.extensions.ReplicaSetBuilder;
import io.fabric8.kubernetes.client.Config;
Expand All @@ -49,9 +49,7 @@
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.InputStream;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;
Expand All @@ -76,7 +74,7 @@ public class KubernetesProviderInterface extends ProviderInterface<KubernetesAcc

@Autowired
LookupService lookupService;

private static final String CLOUDRIVER_CONFIG_PATH = "/kubernetes/raw/hal-clouddriver.yml";

// Map from deployment name -> the port & job managing the connection.
Expand All @@ -89,17 +87,16 @@ private static class Proxy {
}

@Override
protected String componentArtifact(DeploymentDetails<KubernetesAccount> details, SpinnakerComponent component) {
protected String componentArtifact(DeploymentDetails<KubernetesAccount> details, SpinnakerArtifact artifact) {
NodeFilter filter = new NodeFilter().withAnyHalconfigFile().setDeployment(details.getDeploymentName());
DeploymentConfiguration deploymentConfiguration = deploymentService.getDeploymentConfiguration(filter);
String version = component.getVersion(deploymentConfiguration);
String version = artifactService.getArtifactVersion(filter, artifact);

KubernetesImageDescription image = new KubernetesImageDescription(component.getComponentName(), version, REGISTRY);
KubernetesImageDescription image = new KubernetesImageDescription(artifact.name(), version, REGISTRY);
return KubernetesUtil.getImageId(image);
}

@Override
public Object connectTo(DeploymentDetails<KubernetesAccount> details, ComponentType componentType) {
public Object connectTo(DeploymentDetails<KubernetesAccount> details, EndpointType endpointType) {
Proxy proxy = proxyMap.getOrDefault(details.getDeploymentName(), new Proxy());

if (proxy.jobId == null || proxy.jobId.isEmpty()) {
Expand Down Expand Up @@ -137,25 +134,25 @@ public Object connectTo(DeploymentDetails<KubernetesAccount> details, ComponentT
}
}

Service service = componentType.getService(details.getEndpoints());
Service service = endpointType.getService(details.getEndpoints());

String endpoint = "http://localhost:" + proxy.getPort() + "/api/v1/proxy/namespaces/"
+ getNamespaceFromAddress(service.getAddress()) + "/services/"
+ getServiceFromAddress(service.getAddress()) + ":" + service.getPort() + "/";

return serviceFactory.createService(endpoint, componentType);
return serviceFactory.createService(endpoint, endpointType);
}

@Override
public void bootstrapClouddriver(DeploymentDetails<KubernetesAccount> details) {
KubernetesAccount account = details.getAccount();

Service clouddriver = ComponentType.CLOUDDRIVER.getService(details.getEndpoints());
Service clouddriver = EndpointType.CLOUDDRIVER.getService(details.getEndpoints());
String namespace = getNamespaceFromAddress(clouddriver.getAddress());
String serviceName = getServiceFromAddress(clouddriver.getAddress());
String replicaSetName = "spin-clouddriver-v000";
String credsSecret = "hal-creds-config";
String clouddriverSecret = componentSecret(ComponentType.CLOUDDRIVER.getName());
String clouddriverSecret = componentSecret(EndpointType.CLOUDDRIVER.getName());
int clouddriverPort = clouddriver.getPort();

KubernetesClient client = getClient(account);
Expand Down Expand Up @@ -193,8 +190,8 @@ public void bootstrapClouddriver(DeploymentDetails<KubernetesAccount> details) {
ContainerBuilder containerBuilder = new ContainerBuilder();

containerBuilder = containerBuilder
.withName("clouddriver")
.withImage(componentArtifact(details, getComponentByName("clouddriver")))
.withName(SpinnakerArtifact.CLOUDDRIVER.name())
.withImage(componentArtifact(details, SpinnakerArtifact.CLOUDDRIVER))
.withPorts(new ContainerPortBuilder().withContainerPort(clouddriverPort).build());

ReplicaSetBuilder replicaSetBuilder = new ReplicaSetBuilder();
Expand Down Expand Up @@ -310,9 +307,9 @@ private void stageCredentials(DeploymentDetails<KubernetesAccount> details, Stri
private void stageConfig(DeploymentDetails<KubernetesAccount> details, String namespace) {
File outputPath = new File(spinnakerOutputPath);
File[] profiles = outputPath.listFiles();
spinnakerComponents.forEach(s -> {
String name = componentSecret(s.getComponentName());
createSecret(details, s.profilePaths(profiles), name, namespace);
spinnakerProfiles.forEach(s -> {
String name = componentSecret(s.getProfileName());
createSecret(details, s.getArtifact().profilePaths(profiles), name, namespace);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@

import com.netflix.spinnaker.halyard.config.model.v1.node.Account;
import com.netflix.spinnaker.halyard.config.services.v1.DeploymentService;
import com.netflix.spinnaker.halyard.config.spinnaker.v1.component.ComponentConfig;
import com.netflix.spinnaker.halyard.config.spinnaker.v1.component.SpinnakerComponent;
import com.netflix.spinnaker.halyard.deploy.component.v1.ComponentType;
import com.netflix.spinnaker.halyard.deploy.component.v1.ServiceFactory;
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.profile.SpinnakerProfile;
import com.netflix.spinnaker.halyard.deploy.spinnaker.v1.endpoint.EndpointType;
import com.netflix.spinnaker.halyard.deploy.spinnaker.v1.endpoint.ServiceFactory;
import com.netflix.spinnaker.halyard.deploy.deployment.v1.DeploymentDetails;
import com.netflix.spinnaker.halyard.deploy.job.v1.JobExecutor;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -50,26 +51,20 @@ public abstract class ProviderInterface<T extends Account> {
@Autowired
DeploymentService deploymentService;

@Autowired(required = false)
List<SpinnakerComponent> spinnakerComponents = new ArrayList<>();

Map<String, SpinnakerComponent> componentMap = null;
@Autowired
ArtifactService artifactService;

protected SpinnakerComponent getComponentByName(String name) {
if (componentMap == null) {
componentMap = new HashMap<>();
spinnakerComponents.forEach(c -> componentMap.put(c.getComponentName(), c));
}
@Autowired(required = false)
List<SpinnakerProfile> spinnakerProfiles = new ArrayList<>();

return componentMap.get(name);
}
Map<String, SpinnakerProfile> componentMap = null;

/**
* @return the docker image/debian package/etc... for a certain component.
* @return the docker image/debian package/etc... for a certain profile.
*/
abstract protected String componentArtifact(DeploymentDetails<T> details, SpinnakerComponent component);
abstract protected String componentArtifact(DeploymentDetails<T> details, SpinnakerArtifact artifact);

abstract public Object connectTo(DeploymentDetails<T> details, ComponentType componentType);
abstract public Object connectTo(DeploymentDetails<T> details, EndpointType endpointType);

abstract public void bootstrapClouddriver(DeploymentDetails<T> details);
}
Loading

0 comments on commit 66eaba7

Please sign in to comment.