Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deployment get #23

Merged
merged 3 commits into from
Apr 10, 2018
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ The below table(s) document each of our tasks and their respective `features` in
| Name | `config{}` | `onNext{}` | `response()` |
| --- | --- | --- | --- |
| [ListDeployments](https://github.com/bmuschko/gradle-kubernetes-plugin/blob/master/src/main/groovy/com/bmuschko/gradle/kubernetes/plugin/tasks/deployments/ListDeployments.groovy) | [MixedOperation](http://static.javadoc.io/io.fabric8/kubernetes-client/3.1.8/io/fabric8/kubernetes/client/dsl/MixedOperation.html) | [Deployment](http://static.javadoc.io/io.fabric8/kubernetes-model/2.0.8/io/fabric8/kubernetes/api/model/extensions/Deployment.html) | [DeploymentList](http://static.javadoc.io/io.fabric8/kubernetes-model/2.0.8/io/fabric8/kubernetes/api/model/extensions/DeploymentList.html) |
[GetDeployment](https://github.com/bmuschko/gradle-kubernetes-plugin/blob/master/src/main/groovy/com/bmuschko/gradle/kubernetes/plugin/tasks/deployments/GetDeployment.groovy) | [MixedOperation](http://static.javadoc.io/io.fabric8/kubernetes-client/3.1.8/io/fabric8/kubernetes/client/dsl/MixedOperation.html) | [Deployment](http://static.javadoc.io/io.fabric8/kubernetes-model/2.0.8/io/fabric8/kubernetes/api/model/extensions/Deployment.html) | [Deployment](http://static.javadoc.io/io.fabric8/kubernetes-model/2.0.8/io/fabric8/kubernetes/api/model/extensions/Deployment.html)
[DeleteDeployment](https://github.com/bmuschko/gradle-kubernetes-plugin/blob/master/src/main/groovy/com/bmuschko/gradle/kubernetes/plugin/tasks/deployments/DeleteDeployment.groovy) | [N/A]() | [Boolean](https://docs.oracle.com/javase/7/docs/api/java/lang/Boolean.html) | [Boolean](https://docs.oracle.com/javase/7/docs/api/java/lang/Boolean.html) |

### Namespace operations
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* Copyright 2014 the original author or 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 com.bmuschko.gradle.kubernetes.plugin.tasks.deployments

import com.bmuschko.gradle.kubernetes.plugin.AbstractFunctionalTest
import org.gradle.testkit.runner.BuildResult

/**
*
* All functional tests for the `GetDeployment` task.
*
*/
class GetDeploymentFunctionalTest extends AbstractFunctionalTest {

def "Get non-existent deployment"() {

buildFile << """
import com.bmuschko.gradle.kubernetes.plugin.tasks.deployments.GetDeployment

task getDeployment(type: GetDeployment) {
deployment = "${randomString()}"
onError { exc ->
logger.quiet "$SHOULD_REACH_HERE value=\${exc}"
}
}

task workflow(dependsOn: getDeployment)
"""

when:
BuildResult result = build('workflow')

then:
result.output.contains('Getting deployment...')
result.output.contains(SHOULD_REACH_HERE)
result.output.contains('could not be found.')
}

def "Get non-existent deployment with config"() {

buildFile << """
import com.bmuschko.gradle.kubernetes.plugin.tasks.deployments.GetDeployment

task getDeployment(type: GetDeployment) {
config {
withName("${randomString()}")
}

onError { exc ->
logger.quiet "$SHOULD_REACH_HERE value=\${exc}"
}
}

task workflow(dependsOn: getDeployment)
"""

when:
BuildResult result = build('workflow')

then:
result.output.contains('Getting deployment...')
result.output.contains(SHOULD_REACH_HERE)
result.output.contains('could not be found.')
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Copyright 2014 the original author or 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 com.bmuschko.gradle.kubernetes.plugin.tasks.deployments

import com.bmuschko.gradle.kubernetes.plugin.tasks.AbstractKubernetesTask
import org.gradle.api.GradleException
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.Optional

/**
* Get a deployment.
*/
class GetDeployment extends AbstractKubernetesTask {

@Input
@Optional
String namespace // which namespace the deployment exists within.

@Input
@Optional
String deployment // name of the deployment to retrieve.

@Override
def handleClient(kubernetesClient) {

logger.quiet 'Getting deployment...'
def objToConfigure = kubernetesClient.services()

// no real options to supply so should amount to a no-op
def objReconfigured = configureOn(objToConfigure)

// apply user-defined inputs
def objWithUserInputs = applyInputs(objReconfigured)

// get the service
def localResponse = objWithUserInputs.fromServer().get()
if (!localResponse) {
throw new GradleException('Deployment could not be found.')
}

// register response for downstream use which in this case
// is just a `Service` instance.
responseOn(localResponse)
}

@Override
def applyInputs(obj) {
def objRef = wrapAtomic(obj)
invokeMethod(objRef, 'inNamespace', namespace)
invokeMethod(objRef, 'withName', deployment).get()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class GetNamespace extends AbstractKubernetesTask {
// get the namespace
def localResponse = objWithUserInputs.fromServer().get()
if (!localResponse) {
throw new GradleException("Namespace could not be found.")
throw new GradleException('Namespace could not be found.')
}

// register response for downstream use which in this case
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class GetPod extends AbstractKubernetesTask {
// get the service
def localResponse = objWithUserInputs.fromServer().get()
if (!localResponse) {
throw new GradleException("Pod could not be found.")
throw new GradleException('Pod could not be found.')
}

// register response for downstream use which in this case
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class GetService extends AbstractKubernetesTask {
// get the service
def localResponse = objWithUserInputs.fromServer().get()
if (!localResponse) {
throw new GradleException("Service could not be found.")
throw new GradleException('Service could not be found.')
}

// register response for downstream use which in this case
Expand Down