forked from eclipse-jkube/jkube
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix eclipse-jkube#1053: Add ocHelm task to OpenShift Gradle Plugin
Implement `oc:helm` equivalent functionality `ocHelm` for OpenShift Gradle Plugin. Signed-off-by: Rohan Kumar <[email protected]>
- Loading branch information
1 parent
93d556d
commit e1030d3
Showing
10 changed files
with
189 additions
and
8 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
44 changes: 44 additions & 0 deletions
44
...lugin/openshift/src/main/java/org/eclipse/jkube/gradle/plugin/task/OpenShiftHelmTask.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,44 @@ | ||
/** | ||
* Copyright (c) 2019 Red Hat, Inc. | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at: | ||
* | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Red Hat, Inc. - initial API and implementation | ||
*/ | ||
package org.eclipse.jkube.gradle.plugin.task; | ||
|
||
import org.eclipse.jkube.gradle.plugin.OpenShiftExtension; | ||
|
||
import javax.inject.Inject; | ||
import java.io.File; | ||
|
||
public class OpenShiftHelmTask extends KubernetesHelmTask implements OpenShiftJKubeTask { | ||
|
||
@Inject | ||
public OpenShiftHelmTask(Class<? extends OpenShiftExtension> extensionClass) { | ||
super(extensionClass); | ||
setDescription( | ||
"Generates a Helm chart for the OpenShift resources."); | ||
} | ||
|
||
@Override | ||
protected File resolveManifest() { | ||
return getOpenShiftExtension().getOpenShiftManifestOrDefault(); | ||
} | ||
|
||
@Override | ||
protected File resolveTemplate() { | ||
return getOpenShiftExtension().getOpenShiftTemplateOrDefault(); | ||
} | ||
|
||
@Override | ||
protected void logManifestNotFoundWarning(File manifest) { | ||
kitLogger.warn("No OpenShift manifest file has been generated yet by the ocResource task at: " + manifest); | ||
} | ||
} |
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
79 changes: 79 additions & 0 deletions
79
...n/openshift/src/test/java/org/eclipse/jkube/gradle/plugin/task/OpenShiftHelmTaskTest.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,79 @@ | ||
/** | ||
* Copyright (c) 2019 Red Hat, Inc. | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at: | ||
* | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Red Hat, Inc. - initial API and implementation | ||
*/ | ||
package org.eclipse.jkube.gradle.plugin.task; | ||
|
||
import org.eclipse.jkube.gradle.plugin.OpenShiftExtension; | ||
import org.eclipse.jkube.gradle.plugin.TestOpenShiftExtension; | ||
import org.eclipse.jkube.kit.resource.helm.HelmService; | ||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.mockito.MockedConstruction; | ||
|
||
import java.io.IOException; | ||
|
||
import static org.assertj.core.api.AssertionsForClassTypes.assertThat; | ||
import static org.junit.Assert.assertThrows; | ||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.Mockito.mockConstruction; | ||
import static org.mockito.Mockito.times; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.when; | ||
|
||
public class OpenShiftHelmTaskTest { | ||
@Rule | ||
public TaskEnvironment taskEnvironment = new TaskEnvironment(); | ||
|
||
private TestOpenShiftExtension extension; | ||
private MockedConstruction<HelmService> helmServiceMockedConstruction; | ||
|
||
@Before | ||
public void setUp() { | ||
extension = new TestOpenShiftExtension(); | ||
helmServiceMockedConstruction = mockConstruction(HelmService.class); | ||
when(taskEnvironment.project.getExtensions().getByType(OpenShiftExtension.class)).thenReturn(extension); | ||
} | ||
|
||
@Test | ||
public void runTask_withNoTemplateDir_shouldThrowException() { | ||
// Given | ||
OpenShiftHelmTask kubernetesHelmTask = new OpenShiftHelmTask(OpenShiftExtension.class); | ||
|
||
// When | ||
IllegalStateException illegalStateException = assertThrows(IllegalStateException.class, kubernetesHelmTask::runTask); | ||
|
||
// Then | ||
assertThat(illegalStateException) | ||
.hasMessageContaining("META-INF/jkube/openshift (No such file or directory)"); | ||
} | ||
|
||
@Test | ||
public void runTask_withTemplateDir_shouldCallHelmService() throws IOException { | ||
// Given | ||
taskEnvironment.withOpenShiftTemplate(); | ||
OpenShiftHelmTask kubernetesHelmTask = new OpenShiftHelmTask(OpenShiftExtension.class); | ||
|
||
// When | ||
kubernetesHelmTask.runTask(); | ||
|
||
// Then | ||
verify((helmServiceMockedConstruction.constructed().iterator().next()), times(1)).generateHelmCharts(any()); | ||
} | ||
|
||
@After | ||
public void tearDown() { | ||
helmServiceMockedConstruction.close(); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,3 +41,26 @@ kubernetes { | |
}] | ||
} | ||
} | ||
|
||
openshift { | ||
resources { | ||
labels { | ||
all { | ||
testProject = 'spring-boot-with-yaml-label-for-all' | ||
} | ||
} | ||
} | ||
generator { | ||
config { | ||
'spring-boot' { | ||
color = 'always' | ||
} | ||
} | ||
} | ||
helm { | ||
maintainers = [{ | ||
name = 'John' | ||
email = '[email protected]' | ||
}] | ||
} | ||
} |