Skip to content

Commit

Permalink
fix: use proper reference to Kind
Browse files Browse the repository at this point in the history
  • Loading branch information
etrikp committed Feb 16, 2024
1 parent 55fe94a commit f1f443d
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 20 deletions.
5 changes: 3 additions & 2 deletions pkg/processor/daemonset/daemonset.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package daemonset

import (
"fmt"
"github.com/arttor/helmify/pkg/processor/pod"
"io"
"strings"
"text/template"

"github.com/arttor/helmify/pkg/processor/pod"

"github.com/arttor/helmify/pkg/helmify"
"github.com/arttor/helmify/pkg/processor"
yamlformat "github.com/arttor/helmify/pkg/yaml"
Expand Down Expand Up @@ -98,7 +99,7 @@ func (d daemonset) Process(appMeta helmify.AppMetadata, obj *unstructured.Unstru
}

nameCamel := strcase.ToLowerCamel(name)
specMap, podValues, err := pod.ProcessSpec(nameCamel, appMeta, dae.Spec.Template.Spec)
specMap, podValues, err := pod.ProcessSpec(nameCamel, appMeta, dae.Spec.Template.Spec, dae.TypeMeta.Kind)
if err != nil {
return true, nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/processor/deployment/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func (d deployment) Process(appMeta helmify.AppMetadata, obj *unstructured.Unstr
}

nameCamel := strcase.ToLowerCamel(name)
specMap, podValues, err := pod.ProcessSpec(nameCamel, appMeta, depl.Spec.Template.Spec)
specMap, podValues, err := pod.ProcessSpec(nameCamel, appMeta, depl.Spec.Template.Spec, depl.TypeMeta.Kind)
if err != nil {
return true, nil, err
}
Expand Down
9 changes: 5 additions & 4 deletions pkg/processor/job/cron.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@ package job

import (
"fmt"
"io"
"strings"
"text/template"

"github.com/arttor/helmify/pkg/helmify"
"github.com/arttor/helmify/pkg/processor"
"github.com/arttor/helmify/pkg/processor/pod"
yamlformat "github.com/arttor/helmify/pkg/yaml"
"github.com/iancoleman/strcase"
"io"
batchv1 "k8s.io/api/batch/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"strings"
"text/template"
)

var cronTempl, _ = template.New("cron").Parse(
Expand Down Expand Up @@ -105,7 +106,7 @@ func (p cron) Process(appMeta helmify.AppMetadata, obj *unstructured.Unstructure
}

// process job pod template:
podSpecMap, podValues, err := pod.ProcessSpec(nameCamelCase, appMeta, jobObj.Spec.JobTemplate.Spec.Template.Spec)
podSpecMap, podValues, err := pod.ProcessSpec(nameCamelCase, appMeta, jobObj.Spec.JobTemplate.Spec.Template.Spec, jobObj.TypeMeta.Kind)
if err != nil {
return true, nil, err
}
Expand Down
9 changes: 5 additions & 4 deletions pkg/processor/job/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@ package job

import (
"fmt"
"io"
"strings"
"text/template"

"github.com/arttor/helmify/pkg/helmify"
"github.com/arttor/helmify/pkg/processor"
"github.com/arttor/helmify/pkg/processor/pod"
yamlformat "github.com/arttor/helmify/pkg/yaml"
"github.com/iancoleman/strcase"
"io"
batchv1 "k8s.io/api/batch/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"strings"
"text/template"
)

var jobTempl, _ = template.New("job").Parse(
Expand Down Expand Up @@ -104,7 +105,7 @@ func (p job) Process(appMeta helmify.AppMetadata, obj *unstructured.Unstructured
}
}
// process job pod template:
podSpecMap, podValues, err := pod.ProcessSpec(nameCamelCase, appMeta, jobObj.Spec.Template.Spec)
podSpecMap, podValues, err := pod.ProcessSpec(nameCamelCase, appMeta, jobObj.Spec.Template.Spec, jobObj.TypeMeta.Kind)
if err != nil {
return true, nil, err
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/processor/pod/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ const envValue = "{{ quote .Values.%[1]s.%[2]s.%[3]s.%[4]s }}"

func CalculateBaseIndent(resourceType string) int {
switch resourceType {
case "cronJob", "job":
case "CronJob", "Job":
return 4 // Adjusting for the deeper nesting within a JobTemplate
default:
return 0 // Regular Template
}
}

func ProcessSpec(objName string, appMeta helmify.AppMetadata, spec corev1.PodSpec) (map[string]interface{}, helmify.Values, error) {
baseIndent := CalculateBaseIndent(objName)
func ProcessSpec(objName string, appMeta helmify.AppMetadata, spec corev1.PodSpec, kind string) (map[string]interface{}, helmify.Values, error) {
baseIndent := CalculateBaseIndent(kind)

values, err := processPodSpec(objName, appMeta, &spec)
if err != nil {
Expand Down
8 changes: 4 additions & 4 deletions pkg/processor/pod/pod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func Test_pod_Process(t *testing.T) {
var deploy appsv1.Deployment
obj := internal.GenerateObj(strDeployment)
err := runtime.DefaultUnstructuredConverter.FromUnstructured(obj.Object, &deploy)
specMap, tmpl, err := ProcessSpec("nginx", &metadata.Service{}, deploy.Spec.Template.Spec)
specMap, tmpl, err := ProcessSpec("nginx", &metadata.Service{}, deploy.Spec.Template.Spec, deploy.TypeMeta.Kind)
assert.NoError(t, err)

assert.Equal(t, map[string]interface{}{
Expand Down Expand Up @@ -162,7 +162,7 @@ func Test_pod_Process(t *testing.T) {
var deploy appsv1.Deployment
obj := internal.GenerateObj(strDeploymentWithNoArgs)
err := runtime.DefaultUnstructuredConverter.FromUnstructured(obj.Object, &deploy)
specMap, tmpl, err := ProcessSpec("nginx", &metadata.Service{}, deploy.Spec.Template.Spec)
specMap, tmpl, err := ProcessSpec("nginx", &metadata.Service{}, deploy.Spec.Template.Spec, deploy.TypeMeta.Kind)
assert.NoError(t, err)

assert.Equal(t, map[string]interface{}{
Expand Down Expand Up @@ -201,7 +201,7 @@ func Test_pod_Process(t *testing.T) {
var deploy appsv1.Deployment
obj := internal.GenerateObj(strDeploymentWithTagAndDigest)
err := runtime.DefaultUnstructuredConverter.FromUnstructured(obj.Object, &deploy)
specMap, tmpl, err := ProcessSpec("nginx", &metadata.Service{}, deploy.Spec.Template.Spec)
specMap, tmpl, err := ProcessSpec("nginx", &metadata.Service{}, deploy.Spec.Template.Spec, deploy.TypeMeta.Kind)
assert.NoError(t, err)

assert.Equal(t, map[string]interface{}{
Expand Down Expand Up @@ -240,7 +240,7 @@ func Test_pod_Process(t *testing.T) {
var deploy appsv1.Deployment
obj := internal.GenerateObj(strDeploymentWithPort)
err := runtime.DefaultUnstructuredConverter.FromUnstructured(obj.Object, &deploy)
specMap, tmpl, err := ProcessSpec("nginx", &metadata.Service{}, deploy.Spec.Template.Spec)
specMap, tmpl, err := ProcessSpec("nginx", &metadata.Service{}, deploy.Spec.Template.Spec, deploy.TypeMeta.Kind)
assert.NoError(t, err)

assert.Equal(t, map[string]interface{}{
Expand Down
5 changes: 3 additions & 2 deletions pkg/processor/statefulset/statefulset.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package statefulset

import (
"fmt"
"github.com/arttor/helmify/pkg/processor/pod"
"io"
"strings"
"text/template"

"github.com/arttor/helmify/pkg/processor/pod"

"github.com/arttor/helmify/pkg/helmify"
"github.com/arttor/helmify/pkg/processor"
yamlformat "github.com/arttor/helmify/pkg/yaml"
Expand Down Expand Up @@ -108,7 +109,7 @@ func (d statefulset) Process(appMeta helmify.AppMetadata, obj *unstructured.Unst
}

// process pod spec:
podSpecMap, podValues, err := pod.ProcessSpec(nameCamel, appMeta, ssSpec.Template.Spec)
podSpecMap, podValues, err := pod.ProcessSpec(nameCamel, appMeta, ssSpec.Template.Spec, ss.TypeMeta.Kind)
if err != nil {
return true, nil, err
}
Expand Down

0 comments on commit f1f443d

Please sign in to comment.