Skip to content

Commit

Permalink
fix: Moved KubernetesClient implementation of kubectl run to separa…
Browse files Browse the repository at this point in the history
…te package
  • Loading branch information
manusa committed Aug 26, 2020
1 parent 09a5c6b commit 3dda5a7
Show file tree
Hide file tree
Showing 17 changed files with 299 additions and 206 deletions.
2 changes: 1 addition & 1 deletion doc/CHEATSHEET.md
Expand Up @@ -2310,7 +2310,7 @@ try (KubernetesClient client = new DefaultKubernetesClient()) {
```
try (KubernetesClient client = new DefaultKubernetesClient()) {
client.run().inNamespace("default")
.withRunConfig(new GeneratorRunConfigBuilder()
.withRunConfig(new RunConfigBuilder()
.withName("nginx")
.withImage("nginx:latest")
.withLabels(Collections.singletonMap("foo", "bar"))
Expand Down
4 changes: 4 additions & 0 deletions kubernetes-client/pom.xml
Expand Up @@ -238,6 +238,10 @@
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
</dependency>
</dependencies>

<build>
Expand Down
Expand Up @@ -64,7 +64,7 @@
import io.fabric8.kubernetes.api.model.ServiceAccount;
import io.fabric8.kubernetes.api.model.ServiceAccountList;
import io.fabric8.kubernetes.api.model.ServiceList;
import io.fabric8.kubernetes.client.utils.PodGeneratorImpl;
import io.fabric8.kubernetes.client.extended.run.RunOperations;
import okhttp3.OkHttpClient;

import java.io.InputStream;
Expand Down Expand Up @@ -263,7 +263,7 @@ public MixedOperation<LimitRange, LimitRangeList, DoneableLimitRange, Resource<L
}

@Override
public PodGeneratorImpl run() {
public RunOperations run() {
return delegate.run();
}

Expand Down
Expand Up @@ -112,8 +112,8 @@
import io.fabric8.kubernetes.client.dsl.internal.core.v1.ServiceAccountOperationsImpl;
import io.fabric8.kubernetes.client.dsl.internal.core.v1.EventOperationsImpl;
import io.fabric8.kubernetes.client.extended.leaderelection.LeaderElectorBuilder;
import io.fabric8.kubernetes.client.utils.GeneratorRunConfigBuilder;
import io.fabric8.kubernetes.client.utils.PodGeneratorImpl;
import io.fabric8.kubernetes.client.extended.run.RunConfigBuilder;
import io.fabric8.kubernetes.client.extended.run.RunOperations;
import io.fabric8.kubernetes.client.utils.Serialization;
import io.fabric8.kubernetes.client.informers.SharedInformerFactory;
import io.fabric8.kubernetes.client.utils.Utils;
Expand Down Expand Up @@ -443,7 +443,7 @@ public MixedOperation<Lease, LeaseList, DoneableLease, Resource<Lease, DoneableL
}

@Override
public PodGeneratorImpl run() {
return new PodGeneratorImpl(httpClient, getConfiguration(), getNamespace(), new GeneratorRunConfigBuilder());
public RunOperations run() {
return new RunOperations(httpClient, getConfiguration(), getNamespace(), new RunConfigBuilder());
}
}
Expand Up @@ -84,8 +84,8 @@
import io.fabric8.kubernetes.client.dsl.base.CustomResourceDefinitionContext;
import io.fabric8.kubernetes.client.dsl.internal.RawCustomResourceOperationsImpl;
import io.fabric8.kubernetes.client.extended.leaderelection.LeaderElectorBuilder;
import io.fabric8.kubernetes.client.extended.run.RunOperations;
import io.fabric8.kubernetes.client.informers.SharedInformerFactory;
import io.fabric8.kubernetes.client.utils.PodGeneratorImpl;

import java.io.InputStream;
import java.util.Collection;
Expand Down Expand Up @@ -519,7 +519,7 @@ public interface KubernetesClient extends Client {
/**
* Run a Pod (core/v1)
*
* @return returns {@link PodGeneratorImpl} that allows you to run a pod based on few parameters(e.g. name, image etc)
* @return returns {@link RunOperations} that allows you to run a pod based on few parameters(e.g. name, image etc)
*/
PodGeneratorImpl run();
RunOperations run();
}
Expand Up @@ -13,17 +13,18 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.fabric8.kubernetes.client.utils;
package io.fabric8.kubernetes.client.extended.run;

import io.fabric8.kubernetes.api.model.Quantity;
import io.sundr.builder.annotations.Buildable;

import java.util.List;
import java.util.Map;

/**
* Configuration for client run
*/
public class GeneratorRunConfig {
public class RunConfig {
/**
* Name of resource
*/
Expand All @@ -36,6 +37,17 @@ public class GeneratorRunConfig {
* ImagePullPolicy to be used
*/
private String imagePullPolicy;
/**
* Command to use instead of the default
*/
private String command;
/**
* Arguments for the default or provided command.
*
* <p> If <code>command</code> is present, these will be used as extra arguments for the command. If not,
* these will be set in the args container configuration.
*/
private List<String> args;
/**
* Pod restart policy
*/
Expand All @@ -60,112 +72,121 @@ public class GeneratorRunConfig {
* Resource requests
*/
private Map<String, Quantity> requests;
/**
* replicas
*/
private int replicas;
/**
* Port to use
*/
private int port;

@SuppressWarnings("java:S107")
@Buildable(builderPackage = "io.fabric8.kubernetes.api.builder")
public GeneratorRunConfig(String name, String image, String imagePullPolicy, String restartPolicy, String serviceAccount, Map<String, String> labels, Map<String, String> env, Map<String, Quantity> limits, Map<String, Quantity> requests, int replicas, int port) {
public RunConfig(String name, String image, String imagePullPolicy, String command, List<String> args, String restartPolicy, String serviceAccount, Map<String, String> labels, Map<String, String> env, Map<String, Quantity> limits, Map<String, Quantity> requests, int port) {
this.name = name;
this.image = image;
this.imagePullPolicy = imagePullPolicy;
this.command = command;
this.args = args;
this.restartPolicy = restartPolicy;
this.serviceAccount = serviceAccount;
this.labels = labels;
this.env = env;
this.limits = limits;
this.requests = requests;
this.replicas = replicas;
this.port = port;
}

public String getName() { return name; }
public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getImage() {
return image;
}

public String getImagePullPolicy() {
return imagePullPolicy;
public void setImage(String image) {
this.image = image;
}

public Map<String, String> getLabels() {
return labels;
public String getImagePullPolicy() {
return imagePullPolicy;
}

public Map<String, String> getEnv() {
return env;
public void setImagePullPolicy(String imagePullPolicy) {
this.imagePullPolicy = imagePullPolicy;
}

public Map<String, Quantity> getLimits() {
return limits;
public String getCommand() {
return command;
}

public Map<String, Quantity> getRequests() {
return requests;
public void setCommand(String command) {
this.command = command;
}

public int getReplicas() {
return replicas;
public List<String> getArgs() {
return args;
}

public int getPort() {
return port;
public void setArgs(List<String> args) {
this.args = args;
}

public String getRestartPolicy() {
return restartPolicy;
}

public String getServiceAccount() {
return serviceAccount;
}

public void setRestartPolicy(String restartPolicy) {
this.restartPolicy = restartPolicy;
}

public void setName(String name) {
this.name = name;
public String getServiceAccount() {
return serviceAccount;
}

public void setServiceAccount(String serviceAccount) {
this.serviceAccount = serviceAccount;
}
public void setPort(int port) {
this.port = port;

public Map<String, String> getLabels() {
return labels;
}

public void setReplicas(int replicas) {
this.replicas = replicas;
public void setLabels(Map<String, String> labels) {
this.labels = labels;
}

public void setRequests(Map<String, Quantity> requests) {
this.requests = requests;
public Map<String, String> getEnv() {
return env;
}

public void setEnv(Map<String, String> env) {
this.env = env;
}

public Map<String, Quantity> getLimits() {
return limits;
}

public void setLimits(Map<String, Quantity> limits) {
this.limits = limits;
}

public void setEnv(Map<String, String> env) {
this.env = env;
public Map<String, Quantity> getRequests() {
return requests;
}

public void setLabels(Map<String, String> labels) {
this.labels = labels;
public void setRequests(Map<String, Quantity> requests) {
this.requests = requests;
}

public void setImagePullPolicy(String imagePullPolicy) {
this.imagePullPolicy = imagePullPolicy;
public int getPort() {
return port;
}

public void setImage(String image) {
this.image = image;
public void setPort(int port) {
this.port = port;
}
}

0 comments on commit 3dda5a7

Please sign in to comment.