Skip to content

Commit

Permalink
Merge pull request #41 from projectsyn/fix-apiversion
Browse files Browse the repository at this point in the history
Patch apiVersion in postgresql helm chart
  • Loading branch information
ccremer authored Aug 5, 2021
2 parents ac9b31e + 5b9a332 commit d8cc5d7
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 9 deletions.
7 changes: 7 additions & 0 deletions class/keycloak.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,10 @@ parameters:
release_name: ${keycloak:release_name}
namespace: '${keycloak:namespace}'
helm_values: ${keycloak:helm_values}
commodore:
postprocess:
filters:
- type: jsonnet
filter: postprocess/api_version.jsonnet
path: ${_instance}/01_keycloak_helmchart/keycloak/charts/postgresql/templates
enabled: "${keycloak:helm_values:postgresql:enabled}"
42 changes: 42 additions & 0 deletions postprocess/api_version.jsonnet
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
* Adjust StatefuleSet generated by helm template:
* * Fix the apiVersion
*/
local com = import 'lib/commodore.libjsonnet';
local kap = import 'lib/kapitan.libjsonnet';
local inv = kap.inventory();
local params = inv.parameters.keycloak;

local chart_output_dir = std.extVar('output_path');

local list_dir(dir, basename=true) =
std.native('list_dir')(dir, basename);

local chart_files = list_dir(chart_output_dir);

local input_file(elem) = chart_output_dir + '/' + elem;
local stem(elem) =
local elems = std.split(elem, '.');
std.join('.', elems[:std.length(elems) - 1]);


local fix_api_version(sts) =
sts {
apiVersion: 'apps/v1',
};

local fixup_obj(obj) =
if obj.kind == 'StatefulSet' then
fix_api_version(obj)
else
obj;

local fixup(obj_file) =
local objs = std.prune(com.yaml_load_all(obj_file));
// process all objs
[ fixup_obj(obj) for obj in objs ];

{
[stem(elem)]: fixup(input_file(elem))
for elem in chart_files
}
2 changes: 1 addition & 1 deletion tests/builtin/statefulset_postgres_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

func Test_Database_StatefulSet_Secrets(t *testing.T) {
subject := common.DecodeStatefulsetV1Beta2(t, testPath+"/01_keycloak_helmchart/keycloak/charts/postgresql/templates/statefulset.yaml")
subject := common.DecodeStatefulsetV1(t, testPath+"/01_keycloak_helmchart/keycloak/charts/postgresql/templates/statefulset.yaml")
require.NotEmpty(t, subject.Spec.Template.Spec.Containers)
require.NotEmpty(t, subject.Spec.Template.Spec.Containers[0].Env)

Expand Down
8 changes: 0 additions & 8 deletions tests/common/boilerplate.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,12 @@ import (

"github.com/stretchr/testify/require"
appsv1 "k8s.io/api/apps/v1"
appsv1beta2 "k8s.io/api/apps/v1beta2"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/serializer"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
)

func DecodeStatefulsetV1Beta2(t *testing.T, path string) *appsv1beta2.StatefulSet {
subject := &appsv1beta2.StatefulSet{}
scheme := NewSchemeWithDefault(t)
require.NoError(t, appsv1beta2.AddToScheme(scheme))
return DecodeWithSchema(t, path, subject, scheme).(*appsv1beta2.StatefulSet)
}

func DecodeStatefulsetV1(t *testing.T, path string) *appsv1.StatefulSet {
subject := &appsv1.StatefulSet{}
scheme := NewSchemeWithDefault(t)
Expand Down

0 comments on commit d8cc5d7

Please sign in to comment.