Skip to content

Commit

Permalink
Remove usage of getOpenShiftManifestOrDefault from OpenShiftExtension
Browse files Browse the repository at this point in the history
We had getOpenShiftManifestOrDefault method in OpenShiftExtension which
was used for getting openshift manifests in case of OpenShift. However,
this seemed redundant as we had getManifest method in
KubernetesExtension(overridden in OpenShiftExtension) for same task.

To keep it simple, remove getOpenShiftManifstOrDefault method from
OpenShiftExtension and override getKubernetesManifestOrDefault method
in OpenShiftExtension

Signed-off-by: Rohan Kumar <[email protected]>
  • Loading branch information
rohanKanojia committed Oct 27, 2021
1 parent e1030d3 commit b693e5f
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,27 +32,19 @@ public KubernetesHelmTask(Class<? extends KubernetesExtension> extensionClass) {
@Override
public void run() {
try {
File manifest = resolveManifest();
File manifest = kubernetesExtension.getKubernetesManifestOrDefault();
if (manifest == null || !manifest.isFile()) {
logManifestNotFoundWarning(manifest);
}
HelmConfig helm = initHelmConfig(kubernetesExtension.getDefaultHelmType(), kubernetesExtension.javaProject,
resolveManifest(), resolveTemplate(),
kubernetesExtension.getKubernetesManifestOrDefault(), kubernetesExtension.getKubernetesTemplateOrDefault(),
kubernetesExtension.helm).build();
jKubeServiceHub.getHelmService().generateHelmCharts(helm);
} catch (IOException exception) {
throw new IllegalStateException(exception.getMessage());
}
}

protected File resolveManifest() {
return kubernetesExtension.getKubernetesManifestOrDefault();
}

protected File resolveTemplate() {
return kubernetesExtension.getKubernetesTemplateOrDefault();
}

protected void logManifestNotFoundWarning(File manifest) {
kitLogger.warn("No kubernetes manifest file has been generated yet by the k8sResource task at: " + manifest);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,9 @@ public void run() {
}
}

protected File findResources() {
return kubernetesExtension.getKubernetesManifestOrDefault();
}

protected List<File> findManifestsToUndeploy() {
final List<File> ret = new ArrayList<>();
ret.add(findResources());
ret.add(kubernetesExtension.getKubernetesManifestOrDefault());
return ret;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ public ResourceClassifier getResourceClassifier() {
@Override
public File getManifest(KitLogger kitLogger, KubernetesClient kubernetesClient) {
if (OpenshiftHelper.isOpenShift(kubernetesClient)) {
return getOpenShiftManifestOrDefault();
return getKubernetesManifestOrDefault();
}
return getKubernetesManifestOrDefault();
return super.getKubernetesManifestOrDefault();
}

@Override
Expand Down Expand Up @@ -115,11 +115,13 @@ public HelmConfig.HelmType getDefaultHelmType() {
return HelmConfig.HelmType.OPENSHIFT;
}

public File getOpenShiftTemplateOrDefault() {
@Override
public File getKubernetesTemplateOrDefault() {
return getOrDefaultFile("jkube.kubernetesTemplate", this::getKubernetesTemplate, javaProject.getOutputDirectory().toPath().resolve(DEFAULT_OPENSHIFT_TEMPLATE).toFile());
}

public File getOpenShiftManifestOrDefault() {
@Override
public File getKubernetesManifestOrDefault() {
return getOrDefaultFile("jkube.openshiftManifest", this::getOpenShiftManifest, javaProject.getOutputDirectory().toPath().resolve(DEFAULT_OPENSHIFT_MANIFEST).toFile());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,6 @@ public OpenShiftHelmTask(Class<? extends OpenShiftExtension> extensionClass) {
"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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@ public OpenShiftUndeployTask(Class<? extends OpenShiftExtension> extensionClass)
"Undeploys (deletes) the OpenShift resources generated by the current project.");
}

@Override
protected File findResources() {
return getOpenShiftExtension().getOpenShiftManifestOrDefault();
}

@Override
protected List<File> findManifestsToUndeploy() {
final List<File> ret = super.findManifestsToUndeploy();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public static Collection<Object[]> data() {
new Object[] { "getBuildOutputKindOrDefault", "jkube.build.buildOutput.kind", "DockerImage", "DockerImage",
"ImageStreamTag" },
new Object[] { "getProcessTemplatesLocallyOrDefault", "jkube.deploy.processTemplatesLocally", "true", true, false },
new Object[] { "getOpenShiftManifestOrDefault", "jkube.openshiftManifest",
new Object[] { "getKubernetesManifestOrDefault", "jkube.openshiftManifest",
Paths.get("META-INF", "jkube", "other.yml").toString(),
Paths.get("META-INF", "jkube", "other.yml").toFile(),
new File(BASE, "build").toPath().resolve(Paths.get("META-INF", "jkube", "openshift.yml")).toFile() },
Expand Down

0 comments on commit b693e5f

Please sign in to comment.