generated from quarkiverse/quarkiverse-template
-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: generate simple generic helm chart (#665)
Co-authored-by: Chris Laprun <[email protected]>
- Loading branch information
Showing
27 changed files
with
908 additions
and
113 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
28 changes: 28 additions & 0 deletions
28
common-deployment/src/main/java/io/quarkiverse/operatorsdk/common/FileUtils.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,28 @@ | ||
package io.quarkiverse.operatorsdk.common; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.io.File; | ||
import java.util.List; | ||
|
||
import io.fabric8.kubernetes.api.model.HasMetadata; | ||
import io.fabric8.kubernetes.client.utils.KubernetesSerialization; | ||
|
||
public class FileUtils { | ||
private final static KubernetesSerialization serializer = new KubernetesSerialization(); | ||
|
||
public static void ensureDirectoryExists(File dir) { | ||
if (!dir.exists()) { | ||
if (!dir.mkdirs()) { | ||
throw new IllegalArgumentException("Couldn't create " + dir.getAbsolutePath()); | ||
} | ||
} | ||
} | ||
|
||
public static List<HasMetadata> unmarshalFrom(byte[] yamlOrJson) { | ||
return serializer.unmarshal(new ByteArrayInputStream(yamlOrJson)); | ||
} | ||
|
||
public static String asYaml(Object toSerialize) { | ||
return serializer.asYaml(toSerialize); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
...n-deployment/src/main/java/io/quarkiverse/operatorsdk/common/GeneratedResourcesUtils.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,34 @@ | ||
package io.quarkiverse.operatorsdk.common; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
import org.jboss.logging.Logger; | ||
|
||
import io.fabric8.kubernetes.api.model.HasMetadata; | ||
import io.quarkus.kubernetes.spi.GeneratedKubernetesResourceBuildItem; | ||
|
||
public class GeneratedResourcesUtils { | ||
public static final String KUBERNETES_YAML = "kubernetes.yml"; | ||
private static final Logger log = Logger.getLogger(GeneratedResourcesUtils.class.getName()); | ||
|
||
public static List<HasMetadata> loadFrom(List<GeneratedKubernetesResourceBuildItem> generatedResources, | ||
String resourceName) { | ||
if (generatedResources.isEmpty()) { | ||
log.debugv("Couldn't load resource {0} because no resources were generated", resourceName); | ||
return Collections.emptyList(); | ||
} | ||
var buildItem = generatedResources.stream() | ||
.filter(r -> resourceName.equals(r.getName())) | ||
.findAny(); | ||
return buildItem.map(bi -> FileUtils.unmarshalFrom(bi.getContent())) | ||
.orElseThrow(() -> new IllegalArgumentException("Couldn't find resource " + resourceName + | ||
" in generated resources: " + generatedResources.stream() | ||
.map(GeneratedKubernetesResourceBuildItem::getName).collect(Collectors.toSet()))); | ||
} | ||
|
||
public static List<HasMetadata> loadFrom(List<GeneratedKubernetesResourceBuildItem> generatedResources) { | ||
return loadFrom(generatedResources, KUBERNETES_YAML); | ||
} | ||
} |
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
25 changes: 25 additions & 0 deletions
25
.../src/main/java/io/quarkiverse/operatorsdk/deployment/helm/DisableDefaultHelmListener.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,25 @@ | ||
package io.quarkiverse.operatorsdk.deployment.helm; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import io.dekorate.WithSession; | ||
import io.dekorate.kubernetes.config.BaseConfigFluent; | ||
import io.dekorate.kubernetes.config.Configurator; | ||
|
||
/** | ||
* Used to disable default Dekorate Helm chart generator, which would get automatically triggered by depending on the Dekorate | ||
* Helm annotations and the Quarkus Kubernetes extension. | ||
*/ | ||
public class DisableDefaultHelmListener extends Configurator<BaseConfigFluent<?>> implements WithSession { | ||
@Override | ||
public void visit(BaseConfigFluent<?> baseConfigFluent) { | ||
Map<String, Object> helmConfig = new HashMap<>(); | ||
helmConfig.put("enabled", "false"); | ||
|
||
Map<String, Object> config = new HashMap<>(); | ||
config.put("helm", helmConfig); | ||
|
||
WithSession.super.getSession().addPropertyConfiguration(config); | ||
} | ||
} |
Oops, something went wrong.