Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@
import java.util.Optional;

import org.apache.camel.RuntimeCamelException;
import org.apache.camel.dsl.jbang.core.commands.kubernetes.traits.model.Mount;
import org.apache.camel.dsl.jbang.core.commands.kubernetes.traits.model.MountBuilder;
import org.apache.camel.dsl.jbang.core.commands.kubernetes.traits.model.Openapi;
import org.apache.camel.dsl.jbang.core.commands.kubernetes.traits.model.Traits;
import org.apache.camel.dsl.jbang.core.commands.kubernetes.traits.model.TraitsBuilder;
import org.apache.camel.util.ObjectHelper;

public class OpenApiTrait extends BaseTrait {
Expand Down Expand Up @@ -53,13 +54,9 @@ public void apply(Traits traitConfig, TraitContext context) {

if (ObjectHelper.isNotEmpty(openApiTrait.getConfigmaps())) {
MountTrait delegate = new MountTrait();
// ugly code
// TODO : builder or fluent
Traits traits = new Traits();
Mount mount = new Mount();
mount.setResources(openApiTrait.getConfigmaps());
traits.setMount(mount);
delegate.apply(traits, context);
delegate.apply(
TraitsBuilder.traits().withMount(MountBuilder.mount().withResources(openApiTrait.getConfigmaps())).build(),
context);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
import org.apache.camel.dsl.jbang.core.commands.kubernetes.KubernetesHelper;
import org.apache.camel.dsl.jbang.core.commands.kubernetes.MetadataHelper;
import org.apache.camel.dsl.jbang.core.commands.kubernetes.support.SourceMetadata;
import org.apache.camel.dsl.jbang.core.commands.kubernetes.traits.model.Addons;
import org.apache.camel.dsl.jbang.core.commands.kubernetes.traits.model.AddonsBuilder;
import org.apache.camel.dsl.jbang.core.commands.kubernetes.traits.model.Camel;
import org.apache.camel.dsl.jbang.core.commands.kubernetes.traits.model.Container;
import org.apache.camel.dsl.jbang.core.commands.kubernetes.traits.model.Environment;
Expand Down Expand Up @@ -140,7 +140,7 @@ public static Traits parseTraits(String[] traits) {
for (Map.Entry<String, Map<String, Object>> traitConfig : traitConfigMap.entrySet()) {
if (!knownTraits.contains(traitConfig.getKey())) {
traitModel.getAddons().put(traitConfig.getKey(),
new Addons(traitConfig.getValue()));
new AddonsBuilder().withAdditionalProperties(traitConfig.getValue()).build());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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 org.apache.camel.dsl.jbang.core.commands.kubernetes.traits.model;

import java.util.Map;

public final class AddonsBuilder {
private Map<String, Object> additionalProperties;

public AddonsBuilder() {
}

public AddonsBuilder(Addons other) {
this.additionalProperties = other.getAdditionalProperties();
}

public static AddonsBuilder addons() {
return new AddonsBuilder();
}

public AddonsBuilder withAdditionalProperties(Map<String, Object> additionalProperties) {
this.additionalProperties = additionalProperties;
return this;
}

public Addons build() {
Addons addons = new Addons();
addons.setAdditionalProperties(additionalProperties);
return addons;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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 org.apache.camel.dsl.jbang.core.commands.kubernetes.traits.model;

import java.util.List;

public final class CamelBuilder {
private Boolean enabled;
private List<String> properties;

private CamelBuilder() {
}

public static CamelBuilder camel() {
return new CamelBuilder();
}

public CamelBuilder withEnabled(Boolean enabled) {
this.enabled = enabled;
return this;
}

public CamelBuilder withProperties(List<String> properties) {
this.properties = properties;
return this;
}

public Camel build() {
Camel camel = new Camel();
camel.setEnabled(enabled);
camel.setProperties(properties);
return camel;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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 org.apache.camel.dsl.jbang.core.commands.kubernetes.traits.model;

import java.util.List;

public final class ContainerBuilder {
private Boolean allowPrivilegeEscalation;
private Boolean auto;
private List<String> capabilitiesAdd;
private List<String> capabilitiesDrop;
private Boolean enabled;
private Boolean expose;
private String image;
private Container.ImagePullPolicy imagePullPolicy;
private List<String> imagePullSecrets;
private boolean imagePush;
private String limitCPU;
private String limitMemory;
private String name;
private Long port;
private String portName;
private String requestCPU;
private String requestMemory;
private Boolean runAsNonRoot;
private Long runAsUser;
private Container.SeccompProfileType seccompProfileType;
private Long servicePort;
private String servicePortName;

private ContainerBuilder() {
}

public static ContainerBuilder container() {
return new ContainerBuilder();
}

public ContainerBuilder withAllowPrivilegeEscalation(Boolean allowPrivilegeEscalation) {
this.allowPrivilegeEscalation = allowPrivilegeEscalation;
return this;
}

public ContainerBuilder withAuto(Boolean auto) {
this.auto = auto;
return this;
}

public ContainerBuilder withCapabilitiesAdd(List<String> capabilitiesAdd) {
this.capabilitiesAdd = capabilitiesAdd;
return this;
}

public ContainerBuilder withCapabilitiesDrop(List<String> capabilitiesDrop) {
this.capabilitiesDrop = capabilitiesDrop;
return this;
}

public ContainerBuilder withEnabled(Boolean enabled) {
this.enabled = enabled;
return this;
}

public ContainerBuilder withExpose(Boolean expose) {
this.expose = expose;
return this;
}

public ContainerBuilder withImage(String image) {
this.image = image;
return this;
}

public ContainerBuilder withImagePullPolicy(Container.ImagePullPolicy imagePullPolicy) {
this.imagePullPolicy = imagePullPolicy;
return this;
}

public ContainerBuilder withImagePullSecrets(List<String> imagePullSecrets) {
this.imagePullSecrets = imagePullSecrets;
return this;
}

public ContainerBuilder withImagePush(boolean imagePush) {
this.imagePush = imagePush;
return this;
}

public ContainerBuilder withLimitCPU(String limitCPU) {
this.limitCPU = limitCPU;
return this;
}

public ContainerBuilder withLimitMemory(String limitMemory) {
this.limitMemory = limitMemory;
return this;
}

public ContainerBuilder withName(String name) {
this.name = name;
return this;
}

public ContainerBuilder withPort(Long port) {
this.port = port;
return this;
}

public ContainerBuilder withPortName(String portName) {
this.portName = portName;
return this;
}

public ContainerBuilder withRequestCPU(String requestCPU) {
this.requestCPU = requestCPU;
return this;
}

public ContainerBuilder withRequestMemory(String requestMemory) {
this.requestMemory = requestMemory;
return this;
}

public ContainerBuilder withRunAsNonRoot(Boolean runAsNonRoot) {
this.runAsNonRoot = runAsNonRoot;
return this;
}

public ContainerBuilder withRunAsUser(Long runAsUser) {
this.runAsUser = runAsUser;
return this;
}

public ContainerBuilder withSeccompProfileType(Container.SeccompProfileType seccompProfileType) {
this.seccompProfileType = seccompProfileType;
return this;
}

public ContainerBuilder withServicePort(Long servicePort) {
this.servicePort = servicePort;
return this;
}

public ContainerBuilder withServicePortName(String servicePortName) {
this.servicePortName = servicePortName;
return this;
}

public Container build() {
Container container = new Container();
container.setAllowPrivilegeEscalation(allowPrivilegeEscalation);
container.setAuto(auto);
container.setCapabilitiesAdd(capabilitiesAdd);
container.setCapabilitiesDrop(capabilitiesDrop);
container.setEnabled(enabled);
container.setExpose(expose);
container.setImage(image);
container.setImagePullPolicy(imagePullPolicy);
container.setImagePullSecrets(imagePullSecrets);
container.setImagePush(imagePush);
container.setLimitCPU(limitCPU);
container.setLimitMemory(limitMemory);
container.setName(name);
container.setPort(port);
container.setPortName(portName);
container.setRequestCPU(requestCPU);
container.setRequestMemory(requestMemory);
container.setRunAsNonRoot(runAsNonRoot);
container.setRunAsUser(runAsUser);
container.setSeccompProfileType(seccompProfileType);
container.setServicePort(servicePort);
container.setServicePortName(servicePortName);
return container;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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 org.apache.camel.dsl.jbang.core.commands.kubernetes.traits.model;

import java.util.List;

public final class EnvironmentBuilder {
private Boolean enabled;
private List<String> vars;

private EnvironmentBuilder() {
}

public static EnvironmentBuilder environment() {
return new EnvironmentBuilder();
}

public EnvironmentBuilder withEnabled(Boolean enabled) {
this.enabled = enabled;
return this;
}

public EnvironmentBuilder withVars(List<String> vars) {
this.vars = vars;
return this;
}

public Environment build() {
Environment environment = new Environment();
environment.setEnabled(enabled);
environment.setVars(vars);
return environment;
}
}
Loading