forked from fabric8io/kubernetes-client
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix fabric8io#2284: Support running/creating a particular image in a …
…Pod operation Add support for client.run() with which we should be able to create Pod/Deployments just based on few parameters. For example, creating a simple pod should be like: client.run().pods().withName("nginx").withImage("nginx:1.39").done()
- Loading branch information
1 parent
d31483b
commit f0d29e2
Showing
18 changed files
with
761 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
kubernetes-client/src/main/java/io/fabric8/kubernetes/client/GeneratorRunClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/** | ||
* Copyright (C) 2015 Red Hat, 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 io.fabric8.kubernetes.client; | ||
|
||
import io.fabric8.kubernetes.client.dsl.GeneratorRunDSL; | ||
import io.fabric8.kubernetes.client.utils.GeneratorRunConfigBuilder; | ||
import io.fabric8.kubernetes.client.utils.PodGeneratorImpl; | ||
import okhttp3.OkHttpClient; | ||
|
||
public class GeneratorRunClient extends BaseClient implements GeneratorRunDSL { | ||
|
||
public GeneratorRunClient(OkHttpClient httpClient, final Config config) { | ||
super(httpClient, config); | ||
} | ||
|
||
@Override | ||
public PodGeneratorImpl pods() { | ||
return new PodGeneratorImpl(httpClient, getConfiguration(), null, new GeneratorRunConfigBuilder()); | ||
} | ||
|
||
} |
36 changes: 36 additions & 0 deletions
36
...netes-client/src/main/java/io/fabric8/kubernetes/client/GeneratorRunExtensionAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/** | ||
* Copyright (C) 2015 Red Hat, 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 io.fabric8.kubernetes.client; | ||
|
||
import okhttp3.OkHttpClient; | ||
|
||
public class GeneratorRunExtensionAdapter extends APIGroupExtensionAdapter<GeneratorRunClient> { | ||
|
||
@Override | ||
protected String getAPIGroupName() { | ||
return "run"; | ||
} | ||
|
||
@Override | ||
public Class<GeneratorRunClient> getExtensionType() { | ||
return GeneratorRunClient.class; | ||
} | ||
|
||
@Override | ||
protected GeneratorRunClient newInstance(Client client) { | ||
return new GeneratorRunClient(client.adapt(OkHttpClient.class), client.getConfiguration()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/GeneratorRunDSL.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/** | ||
* Copyright (C) 2015 Red Hat, 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 io.fabric8.kubernetes.client.dsl; | ||
|
||
import io.fabric8.kubernetes.client.Client; | ||
import io.fabric8.kubernetes.client.utils.PodGeneratorImpl; | ||
|
||
public interface GeneratorRunDSL 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) | ||
*/ | ||
PodGeneratorImpl pods(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
171 changes: 171 additions & 0 deletions
171
kubernetes-client/src/main/java/io/fabric8/kubernetes/client/utils/GeneratorRunConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,171 @@ | ||
/** | ||
* Copyright (C) 2015 Red Hat, 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 io.fabric8.kubernetes.client.utils; | ||
|
||
import io.fabric8.kubernetes.api.model.Quantity; | ||
import io.sundr.builder.annotations.Buildable; | ||
|
||
import java.util.Map; | ||
|
||
/** | ||
* Configuration for client run | ||
*/ | ||
public class GeneratorRunConfig { | ||
/** | ||
* Name of resource | ||
*/ | ||
private String name; | ||
/** | ||
* Image to use | ||
*/ | ||
private String image; | ||
/** | ||
* ImagePullPolicy to be used | ||
*/ | ||
private String imagePullPolicy; | ||
/** | ||
* Pod restart policy | ||
*/ | ||
private String restartPolicy; | ||
/** | ||
* Service Account name to be used | ||
*/ | ||
private String serviceAccount; | ||
/** | ||
* labels to add | ||
*/ | ||
private Map<String, String> labels; | ||
/** | ||
* Environment variables to be add | ||
*/ | ||
private Map<String, String> env; | ||
/** | ||
* Resource limits | ||
*/ | ||
private Map<String, Quantity> limits; | ||
/** | ||
* Resource requests | ||
*/ | ||
private Map<String, Quantity> requests; | ||
/** | ||
* replicas | ||
*/ | ||
private int replicas; | ||
/** | ||
* Port to use | ||
*/ | ||
private int port; | ||
|
||
@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) { | ||
this.name = name; | ||
this.image = image; | ||
this.imagePullPolicy = imagePullPolicy; | ||
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 getImage() { | ||
return image; | ||
} | ||
|
||
public String getImagePullPolicy() { | ||
return imagePullPolicy; | ||
} | ||
|
||
public Map<String, String> getLabels() { | ||
return labels; | ||
} | ||
|
||
public Map<String, String> getEnv() { | ||
return env; | ||
} | ||
|
||
public Map<String, Quantity> getLimits() { | ||
return limits; | ||
} | ||
|
||
public Map<String, Quantity> getRequests() { | ||
return requests; | ||
} | ||
|
||
public int getReplicas() { | ||
return replicas; | ||
} | ||
|
||
public int getPort() { | ||
return port; | ||
} | ||
|
||
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 void setServiceAccount(String serviceAccount) { | ||
this.serviceAccount = serviceAccount; | ||
} | ||
public void setPort(int port) { | ||
this.port = port; | ||
} | ||
|
||
public void setReplicas(int replicas) { | ||
this.replicas = replicas; | ||
} | ||
|
||
public void setRequests(Map<String, Quantity> requests) { | ||
this.requests = requests; | ||
} | ||
|
||
public void setLimits(Map<String, Quantity> limits) { | ||
this.limits = limits; | ||
} | ||
|
||
public void setEnv(Map<String, String> env) { | ||
this.env = env; | ||
} | ||
|
||
public void setLabels(Map<String, String> labels) { | ||
this.labels = labels; | ||
} | ||
|
||
public void setImagePullPolicy(String imagePullPolicy) { | ||
this.imagePullPolicy = imagePullPolicy; | ||
} | ||
|
||
public void setImage(String image) { | ||
this.image = image; | ||
} | ||
} |
Oops, something went wrong.