Skip to content

Commit

Permalink
fix: deploymentMode is now overrided by conf
Browse files Browse the repository at this point in the history
Related to issue #272
  • Loading branch information
aureamunoz authored and iocanel committed Jul 16, 2019
1 parent 69949dd commit a7be271
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import io.dekorate.component.annotation.Link;
import io.dekorate.component.annotation.ComponentApplication;
import io.dekorate.kubernetes.annotation.Env;
import io.dekorate.component.model.DeploymentMode;

@ComponentApplication(name = "hello-world", exposeService = true, envs = @Env(name = "key1", value = "val1"))
public class Main {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@
import io.dekorate.component.annotation.Link;
import io.dekorate.component.annotation.ComponentApplication;
import io.dekorate.kubernetes.annotation.Env;
import io.dekorate.component.model.DeploymentMode;

@ComponentApplication(name = "hello-world", exposeService = true, envs = @Env(name = "key1", value = "val1"))
@ComponentApplication(name = "hello-world", deploymentMode = DeploymentMode.build, exposeService = true, envs = @Env(name = "key1", value = "val1"))
@Link(name = "hello-world", componentName = "target", envs = @Env(name = "key1", value = "val1"))
public class Main {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import io.dekorate.deps.kubernetes.api.model.KubernetesList;
import io.dekorate.deps.kubernetes.api.model.HasMetadata;
import io.dekorate.component.model.Component;
import io.dekorate.component.model.DeploymentMode;
import io.dekorate.component.model.Link;
import io.dekorate.utils.Serialization;
import java.util.List;
Expand All @@ -37,6 +38,8 @@ public void shouldContainLink() {
assertEquals(2, items.size());
Component component = (Component) items.get(0);
assertEquals("Component", component.getKind());
assertEquals(DeploymentMode.build, component.getSpec().getDeploymentMode());
assertEquals(true, component.getSpec().isExposeService());
Link link = (Link) items.get(1);
assertEquals("Link", link.getKind());
assertEquals(1, link.getSpec().getEnvs().length);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* Copyright 2018 The original authors.
*
* 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 io.dekorate.component.decorator;

import io.dekorate.component.model.ComponentSpecBuilder;
import io.dekorate.component.model.DeploymentMode;
import io.dekorate.kubernetes.decorator.Decorator;

public class DeploymentModeDecorator extends Decorator<ComponentSpecBuilder> {

private final DeploymentMode deploymentMode;

public DeploymentModeDecorator(DeploymentMode deploymentMode) {
this.deploymentMode = deploymentMode;
}

public void visit(ComponentSpecBuilder spec) {
spec.withDeploymentMode(deploymentMode);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,34 +19,26 @@
import io.dekorate.HandlerFactory;
import io.dekorate.Resources;
import io.dekorate.WithProject;
import io.dekorate.project.Project;
import io.dekorate.project.ApplyProjectInfo;
import io.dekorate.config.ConfigurationSupplier;
import io.dekorate.component.config.ComponentConfig;
import io.dekorate.component.config.EditableComponentConfig;
import io.dekorate.component.config.ComponentConfigBuilder;
import io.dekorate.component.decorator.AddBuildConfigToComponentDecorator;
import io.dekorate.component.decorator.AddEnvToComponentDecorator;
import io.dekorate.component.decorator.AddRuntimeTypeToComponentDecorator;
import io.dekorate.component.decorator.AddRuntimeVersionToComponentDecorator;
import io.dekorate.component.decorator.ExposeServiceDecorator;
import io.dekorate.component.config.EditableComponentConfig;
import io.dekorate.component.decorator.*;
import io.dekorate.component.model.Component;
import io.dekorate.component.model.ComponentBuilder;
import io.dekorate.config.ConfigurationSupplier;
import io.dekorate.kubernetes.config.ConfigKey;
import io.dekorate.kubernetes.config.Configuration;
import io.dekorate.kubernetes.config.Env;
import io.dekorate.kubernetes.configurator.ApplyAutoBuild;
import io.dekorate.project.ApplyProjectInfo;
import io.dekorate.project.Project;
import io.dekorate.utils.Strings;

import java.io.File;
import java.io.IOException;
import java.nio.file.Path;

public class ComponentHandler implements HandlerFactory, Handler<ComponentConfig>, WithProject {
public static final ConfigKey<String> RUNTIME_TYPE = new ConfigKey<>("RUNTIME_TYPE", String.class);
public static final ConfigKey<String> RUNTIME_VERSION = new ConfigKey<>("RUNTIME_VERSION", String.class);
// public static final String GITHUB_SSH = "[email protected]:";
// public static final String GITHUB_HTTPS = "https://github.com/";


private final Resources resources;
Expand Down Expand Up @@ -112,6 +104,7 @@ private void addVisitors(ComponentConfig config) {
if (version != null) {
resources.decorateCustom(ResourceGroup.NAME,new AddRuntimeVersionToComponentDecorator(version));
}
resources.decorateCustom(ResourceGroup.NAME,new DeploymentModeDecorator(config.getDeploymentMode()));
for (Env env : config.getEnvs()) {
resources.decorateCustom(ResourceGroup.NAME, new AddEnvToComponentDecorator(env));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ dekorate.component.name=annotationless component
dekorate.component.envs[0].name=key_from_properties
dekorate.component.envs[0].value=value_from_properties
dekorate.component.buildType=docker
dekorate.component.deploymentMode=build
dekorate.link.name=hello-world
dekorate.link.componentName=target
dekorate.link.envs[0].name=link_key1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import io.dekorate.component.model.Component;
import io.dekorate.component.model.Link;
import io.dekorate.component.model.DeploymentMode;
import io.dekorate.deps.kubernetes.api.model.HasMetadata;
import io.dekorate.deps.kubernetes.api.model.KubernetesList;
import io.dekorate.utils.Serialization;
Expand All @@ -42,6 +43,7 @@ public void shouldContainComponentAndLink() {
assertEquals("https://github.com/dekorateio/dekorate.git", component.getSpec().getBuildConfig().getUri());
assertEquals("docker", component.getSpec().getBuildConfig().getType());
assertEquals("component-example-annotationless-properties", component.getSpec().getBuildConfig().getModuleDirName());
assertEquals(DeploymentMode.build, component.getSpec().getDeploymentMode());
assertNotNull("", component.getSpec().getBuildConfig().getRef());
Link link = (Link) items.get(1);
Assertions.assertEquals("Link", link.getKind());
Expand Down

0 comments on commit a7be271

Please sign in to comment.