Skip to content
Open
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
6 changes: 5 additions & 1 deletion src/main/groovy/com/cloudogu/gitops/Feature.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,13 @@ abstract class Feature {
Config config
) {
String repoURL = helmConfig.repoURL
boolean ociChart = false
if (repoURL && repoURL.startsWithIgnoreCase("oci")){
ociChart = true
}
String chartOrPath = helmConfig.chart
String version = helmConfig.version
RepoType repoType = RepoType.HELM
RepoType repoType = ociChart ? RepoType.OCI : RepoType.HELM

this.addHelmValuesData("config", config)
this.addHelmValuesData("statics", new DefaultObjectWrapperBuilder(Configuration.VERSION_2_3_32).build().getStaticModels())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ class ArgoCdApplicationStrategy implements DeploymentStrategy {

String chooseKeyChartOrPath(RepoType repoType) {
switch (repoType) {
case RepoType.OCI:
case RepoType.HELM: 'chart'
break
case RepoType.GIT: 'path'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ interface DeploymentStrategy {
deployFeature(repoURL, repoName, chart, version, namespace, releaseName, helmValuesPath, RepoType.HELM)
}

enum RepoType { HELM, GIT }
enum RepoType { HELM, GIT, OCI }
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,30 @@ class HelmStrategy implements DeploymentStrategy {
"Repo URL: ${repoURL}")
}

log.debug("Imperatively deploying helm release ${releaseName} basing on chart ${chartOrPath} from ${repoURL}, " +
"version ${version}, into namespace ${namespace}. Using values:\n${helmValuesPath.toFile().text}")

helmClient.addRepo(repoName, repoURL)
helmClient.upgrade(releaseName, "$repoName/$chartOrPath",
[namespace: namespace,
version : version,
values : helmValuesPath.toString()])
{

log.debug("Imperatively deploying helm release ${releaseName} basing on chart ${chartOrPath} from ${repoURL}, " +
"version ${version}, into namespace ${namespace}. Using values:\n${helmValuesPath.toFile().text}")

if (RepoType.HELM == repoType ) {
log.debug("adding helm repo {}.", repoURL)
helmClient.addRepo(repoName, repoURL)
helmClient.upgrade(releaseName, "$repoName/$chartOrPath",
[namespace: namespace,
version : version,
values : helmValuesPath.toString()])
} else if (RepoType.OCI == repoType){
def registry = extractOciRegistry(repoURL)
helmClient.upgrade(chartOrPath,"$repoURL",
[namespace: namespace,
version : version,
values : helmValuesPath.toString()])
}
}

}
private static String extractOciRegistry(String repoURL) {
// oci://ghcr.io/myorg/charts -> ghcr.io
return repoURL.replace('oci://', '').split('/')[0]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1214,4 +1214,75 @@ class ContentLoaderTest {
String valuesPath
Config config
}

@Test
void 'deployHelmReleasesFromContent passes oci flag for OCI helm charts'() {
def cfg = Config.fromMap(
content: [
helmReleases: [
[
name : 'my-oci-chart',
repoURL : 'oci://ghcr.io/myorg/charts',
chart : 'mychart',
version : '1.2.3',
namespace: 'my-namespace',

]
]
]
)

def contentLoader = createContent(cfg)
contentLoader.install()

assertThat(contentLoader.deployCalls).hasSize(1)
def call = contentLoader.deployCalls[0]

assertThat(call.helmConfig.repoURL).isEqualTo('oci://ghcr.io/myorg/charts')
assertThat(call.helmConfig.chart).isEqualTo('mychart')
assertThat(call.helmConfig.version).isEqualTo('1.2.3')

}



@Test
void 'deployHelmReleasesFromContent merges inline values for OCI helm charts'(@TempDir Path tempDir) {
Path valuesFile = tempDir.resolve("values.yaml")
Files.writeString(valuesFile, """
replicas: 1
service:
type: ClusterIP
""".stripIndent())

def cfg = Config.fromMap(
content: [
helmReleases: [
[
name : 'my-oci-chart',
repoURL : 'oci://ghcr.io/myorg/charts',
chart : 'mychart',
version : '1.2.3',
namespace : 'my-namespace',
valuesPath: valuesFile.toString(),
values : [
replicas: 3,
service : [type: 'NodePort']
]
]
]
]
)

def contentLoader = createContent(cfg)
contentLoader.install()

assertThat(contentLoader.deployCalls).hasSize(1)
def call = contentLoader.deployCalls[0]


def mergedYaml = new YamlSlurper().parse(Path.of(call.valuesPath).toFile()) as Map
assertThat(mergedYaml['replicas']).isEqualTo(3)
assertThat(((Map) mergedYaml['service'])['type']).isEqualTo('NodePort')
}
}