diff --git a/class/keycloak.yml b/class/keycloak.yml index 7d022e50..b5e1f932 100644 --- a/class/keycloak.yml +++ b/class/keycloak.yml @@ -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}" diff --git a/postprocess/api_version.jsonnet b/postprocess/api_version.jsonnet new file mode 100644 index 00000000..70497e05 --- /dev/null +++ b/postprocess/api_version.jsonnet @@ -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 +} diff --git a/tests/builtin/statefulset_postgres_test.go b/tests/builtin/statefulset_postgres_test.go index 06010d1c..a3c5e86c 100644 --- a/tests/builtin/statefulset_postgres_test.go +++ b/tests/builtin/statefulset_postgres_test.go @@ -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) diff --git a/tests/common/boilerplate.go b/tests/common/boilerplate.go index ad06c91f..22260f5d 100644 --- a/tests/common/boilerplate.go +++ b/tests/common/boilerplate.go @@ -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)