-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added new task CreateNamespace and fixed some doc issues.
- Loading branch information
dancc
authored and
dancc
committed
Feb 21, 2018
1 parent
cc88942
commit fa67d39
Showing
5 changed files
with
174 additions
and
12 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
106 changes: 106 additions & 0 deletions
106
...m/bmuschko/gradle/kubernetes/plugin/tasks/namespaces/CreateNamespaceFunctionalTest.groovy
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,106 @@ | ||
/* | ||
* 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.namespaces | ||
|
||
import com.bmuschko.gradle.kubernetes.plugin.AbstractFunctionalTest | ||
import org.gradle.testkit.runner.BuildResult | ||
import spock.lang.Requires | ||
|
||
/** | ||
* | ||
* All functional tests for the `CreateNamespace` task. | ||
* | ||
*/ | ||
class CreateNamespaceFunctionalTest extends AbstractFunctionalTest { | ||
|
||
def "Create namespace, execute reactive-streams, and fail with no config"() { | ||
buildFile << """ | ||
import com.bmuschko.gradle.kubernetes.plugin.tasks.namespaces.CreateNamespace | ||
task namespaceWork(type: CreateNamespace) { | ||
onError { exc -> | ||
logger.quiet "\${exc.message}" | ||
} | ||
onNext { output -> | ||
logger.quiet '$SHOULD_NOT_REACH_HERE' | ||
} | ||
onComplete { | ||
logger.quiet '$SHOULD_NOT_REACH_HERE' | ||
} | ||
doLast { | ||
if (response()) { | ||
logger.quiet '$RESPONSE_SET_MESSAGE' | ||
} | ||
} | ||
} | ||
task workflow(dependsOn: namespaceWork) | ||
""" | ||
|
||
when: | ||
BuildResult result = build('workflow') | ||
|
||
then: | ||
result.output.contains('Creating namespace...') | ||
result.output.contains('Required value: name or generateName is required') | ||
!result.output.contains(SHOULD_NOT_REACH_HERE) | ||
} | ||
|
||
def "Create namespace, execute reactive-streams, and with config"() { | ||
|
||
def generatedNamespaceName = randomString() | ||
|
||
buildFile << """ | ||
import com.bmuschko.gradle.kubernetes.plugin.tasks.namespaces.CreateNamespace | ||
task namespaceWork(type: CreateNamespace) { | ||
config { | ||
withName("${generatedNamespaceName}") | ||
} | ||
onError { | ||
logger.quiet '$ON_ERROR_NOT_REACHED' | ||
} | ||
onNext { output -> | ||
if (output) { | ||
logger.quiet "$ON_NEXT_REACHED with name \${output.getMetadata().getName()}" | ||
} | ||
} | ||
onComplete { | ||
logger.quiet '$ON_COMPLETE_REACHED' | ||
} | ||
doLast { | ||
if (response()) { | ||
logger.quiet '$RESPONSE_SET_MESSAGE' | ||
} | ||
} | ||
} | ||
task workflow(dependsOn: namespaceWork) | ||
""" | ||
|
||
when: | ||
BuildResult result = build('workflow') | ||
|
||
then: | ||
result.output.contains('Creating namespace...') | ||
!result.output.contains(ON_ERROR_NOT_REACHED) | ||
!result.output.contains(SHOULD_NOT_REACH_HERE) | ||
result.output.contains(ON_NEXT_REACHED + " with name ${generatedNamespaceName}") | ||
result.output.contains(ON_COMPLETE_REACHED) | ||
result.output.contains(RESPONSE_SET_MESSAGE) | ||
} | ||
} |
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
43 changes: 43 additions & 0 deletions
43
...main/groovy/com/bmuschko/gradle/kubernetes/plugin/tasks/namespaces/CreateNamespace.groovy
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,43 @@ | ||
/* | ||
* 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.namespaces | ||
|
||
import com.bmuschko.gradle.kubernetes.plugin.tasks.AbstractKubernetesTask | ||
|
||
/** | ||
* Create a namespace. | ||
*/ | ||
class CreateNamespace extends AbstractKubernetesTask { | ||
|
||
@Override | ||
def handleClient(kubernetesClient) { | ||
|
||
logger.quiet 'Creating namespace...' | ||
def namespaceMetadata = kubernetesClient.namespaces().createNew().withNewMetadata() | ||
|
||
// configure on meta-data | ||
namespaceMetadata = configureOn(namespaceMetadata) | ||
|
||
// finalize creation of namespace | ||
def localResponse = namespaceMetadata.endMetadata().done() | ||
|
||
// register response for downstream use which in this case | ||
// is just a `Namespace` instance. | ||
responseOn(localResponse) | ||
} | ||
} | ||
|
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