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 9da61d4
Showing
20 changed files
with
1,128 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
39 changes: 39 additions & 0 deletions
39
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,39 @@ | ||
/** | ||
* 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.DeploymentGeneratorImpl; | ||
import io.fabric8.kubernetes.client.utils.GeneratorRunConfig; | ||
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 GeneratorRunConfig.Builder()); | ||
} | ||
|
||
@Override | ||
public DeploymentGeneratorImpl deployments() { | ||
return new DeploymentGeneratorImpl(httpClient, getConfiguration(), null, new GeneratorRunConfig.Builder()); | ||
} | ||
} |
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
36 changes: 36 additions & 0 deletions
36
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,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.dsl; | ||
|
||
import io.fabric8.kubernetes.client.Client; | ||
import io.fabric8.kubernetes.client.utils.DeploymentGeneratorImpl; | ||
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(); | ||
|
||
/** | ||
* Run a Deployment (apps/v1) | ||
* | ||
* @return returns {@link DeploymentGeneratorImpl} that allows you to run a Deployment based on few parameters(e.g. name, image etc) | ||
*/ | ||
DeploymentGeneratorImpl deployments(); | ||
} |
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
94 changes: 94 additions & 0 deletions
94
...etes-client/src/main/java/io/fabric8/kubernetes/client/utils/DeploymentGeneratorImpl.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,94 @@ | ||
/** | ||
* 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.apps.Deployment; | ||
import io.fabric8.kubernetes.api.model.apps.DeploymentBuilder; | ||
import io.fabric8.kubernetes.client.Config; | ||
import io.fabric8.kubernetes.client.dsl.internal.apps.v1.DeploymentOperationsImpl; | ||
import okhttp3.OkHttpClient; | ||
|
||
public class DeploymentGeneratorImpl { | ||
private final OkHttpClient client; | ||
private final Config config; | ||
private final String namespace; | ||
private final GeneratorRunConfig.Builder generatorRunConfigBuilder; | ||
|
||
public DeploymentGeneratorImpl(OkHttpClient client, Config config, String namespace, GeneratorRunConfig.Builder runConfig) { | ||
this.client = client; | ||
this.config = config; | ||
this.namespace = namespace; | ||
this.generatorRunConfigBuilder = runConfig; | ||
} | ||
|
||
/** | ||
* Specify namespace for the operation | ||
* | ||
* @param namespace namespace in which resource needs to be created | ||
* @return {@link DeploymentGeneratorImpl} with injected namespace | ||
*/ | ||
public DeploymentGeneratorImpl inNamespace(String namespace) { | ||
return new DeploymentGeneratorImpl(this.client, this.config, namespace, this.generatorRunConfigBuilder); | ||
} | ||
|
||
/** | ||
* Specify image for the Deployment | ||
* | ||
* @param image image as a string | ||
* @return {@link DeploymentGeneratorImpl} with image injected into {@link GeneratorRunConfig} | ||
*/ | ||
public DeploymentGeneratorImpl withImage(String image) { | ||
return new DeploymentGeneratorImpl(this.client, this.config, namespace, this.generatorRunConfigBuilder.withImage(image)); | ||
} | ||
|
||
/** | ||
* Specify name for the Deployment | ||
* | ||
* @param name name of the pod to be created | ||
* @return {@link DeploymentGeneratorImpl} with name injected into {@link GeneratorRunConfig} | ||
*/ | ||
public DeploymentGeneratorImpl withName(String name) { | ||
return new DeploymentGeneratorImpl(this.client, this.config, namespace, this.generatorRunConfigBuilder.withName(name)); | ||
} | ||
|
||
/** | ||
* Specify complex configuration for Deployment creating using {@link GeneratorRunConfig} | ||
* | ||
* @param generatorRunConfig {@link GeneratorRunConfig} which allows to provide configuring environment variables, labels, resources, ports etc | ||
* @return {@link DeploymentGeneratorImpl} with specified configuration | ||
*/ | ||
public DeploymentGeneratorImpl withRunConfig(GeneratorRunConfig generatorRunConfig) { | ||
return new DeploymentGeneratorImpl(this.client, this.config, namespace, new GeneratorRunConfig.Builder(generatorRunConfig)); | ||
} | ||
|
||
/** | ||
* Apply the {@link GeneratorRunConfig} onto the cluster and create Deployment | ||
* | ||
* @return Deployment which got created from the operation | ||
*/ | ||
public Deployment done() { | ||
DeploymentOperationsImpl podOperations = new DeploymentOperationsImpl(client, config, namespace); | ||
return podOperations.create(convertRunConfigIntoDeployment()); | ||
} | ||
|
||
protected Deployment convertRunConfigIntoDeployment() { | ||
GeneratorRunConfig finalGeneratorConfig = generatorRunConfigBuilder.build(); | ||
return new DeploymentBuilder() | ||
.withMetadata(GeneratorRunConfigUtil.getObjectMetadataFromRunConfig(finalGeneratorConfig)) | ||
.withSpec(GeneratorRunConfigUtil.getDeploymentSpecFromRunConfig(finalGeneratorConfig)) | ||
.build(); | ||
} | ||
} |
Oops, something went wrong.