diff --git a/pkg/processor/pod/pod.go b/pkg/processor/pod/pod.go index 313d410..09979ab 100644 --- a/pkg/processor/pod/pod.go +++ b/pkg/processor/pod/pod.go @@ -166,7 +166,11 @@ func processPodSpec(name string, appMeta helmify.AppMetadata, pod *corev1.PodSpe } func processPodContainer(name string, appMeta helmify.AppMetadata, c corev1.Container, values *helmify.Values) (corev1.Container, error) { - index := strings.Index(c.Image, ":") + index := strings.LastIndex(c.Image, ":") + if strings.Contains(c.Image, "@") && strings.Count(c.Image, ":") >= 2 { + last := strings.LastIndex(c.Image, ":") + index = strings.LastIndex(c.Image[:last], ":") + } if index < 0 { return c, fmt.Errorf("wrong image format: %q", c.Image) } diff --git a/pkg/processor/pod/pod_test.go b/pkg/processor/pod/pod_test.go index fdf54c3..c55b4fc 100644 --- a/pkg/processor/pod/pod_test.go +++ b/pkg/processor/pod/pod_test.go @@ -87,6 +87,30 @@ spec: ports: - containerPort: 80 ` + + strDeploymentWithPort = ` +apiVersion: apps/v1 +kind: Deployment +metadata: + name: nginx-deployment + labels: + app: nginx +spec: + replicas: 3 + selector: + matchLabels: + app: nginx + template: + metadata: + labels: + app: nginx + spec: + containers: + - name: nginx + image: localhost:6001/my_project:latest + ports: + - containerPort: 80 +` ) func Test_pod_Process(t *testing.T) { @@ -212,4 +236,43 @@ func Test_pod_Process(t *testing.T) { }, tmpl) }) + t.Run("deployment with image tag and port", func(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) + assert.NoError(t, err) + + assert.Equal(t, map[string]interface{}{ + "containers": []interface{}{ + map[string]interface{}{ + "env": []interface{}{ + map[string]interface{}{ + "name": "KUBERNETES_CLUSTER_DOMAIN", + "value": "{{ quote .Values.kubernetesClusterDomain }}", + }, + }, + "image": "{{ .Values.nginx.nginx.image.repository }}:{{ .Values.nginx.nginx.image.tag | default .Chart.AppVersion }}", + "name": "nginx", "ports": []interface{}{ + map[string]interface{}{ + "containerPort": int64(80), + }, + }, + "resources": map[string]interface{}{}, + }, + }, + }, specMap) + + assert.Equal(t, helmify.Values{ + "nginx": map[string]interface{}{ + "nginx": map[string]interface{}{ + "image": map[string]interface{}{ + "repository": "localhost:6001/my_project", + "tag": "latest", + }, + }, + }, + }, tmpl) + }) + }