|
87 | 87 | ports: |
88 | 88 | - containerPort: 80 |
89 | 89 | ` |
| 90 | + |
| 91 | + strDeploymentWithPort = ` |
| 92 | +apiVersion: apps/v1 |
| 93 | +kind: Deployment |
| 94 | +metadata: |
| 95 | + name: nginx-deployment |
| 96 | + labels: |
| 97 | + app: nginx |
| 98 | +spec: |
| 99 | + replicas: 3 |
| 100 | + selector: |
| 101 | + matchLabels: |
| 102 | + app: nginx |
| 103 | + template: |
| 104 | + metadata: |
| 105 | + labels: |
| 106 | + app: nginx |
| 107 | + spec: |
| 108 | + containers: |
| 109 | + - name: nginx |
| 110 | + image: localhost:6001/my_project:latest |
| 111 | + ports: |
| 112 | + - containerPort: 80 |
| 113 | +` |
90 | 114 | ) |
91 | 115 |
|
92 | 116 | func Test_pod_Process(t *testing.T) { |
@@ -212,4 +236,43 @@ func Test_pod_Process(t *testing.T) { |
212 | 236 | }, tmpl) |
213 | 237 | }) |
214 | 238 |
|
| 239 | + t.Run("deployment with image tag and port", func(t *testing.T) { |
| 240 | + var deploy appsv1.Deployment |
| 241 | + obj := internal.GenerateObj(strDeploymentWithPort) |
| 242 | + err := runtime.DefaultUnstructuredConverter.FromUnstructured(obj.Object, &deploy) |
| 243 | + specMap, tmpl, err := ProcessSpec("nginx", &metadata.Service{}, deploy.Spec.Template.Spec) |
| 244 | + assert.NoError(t, err) |
| 245 | + |
| 246 | + assert.Equal(t, map[string]interface{}{ |
| 247 | + "containers": []interface{}{ |
| 248 | + map[string]interface{}{ |
| 249 | + "env": []interface{}{ |
| 250 | + map[string]interface{}{ |
| 251 | + "name": "KUBERNETES_CLUSTER_DOMAIN", |
| 252 | + "value": "{{ quote .Values.kubernetesClusterDomain }}", |
| 253 | + }, |
| 254 | + }, |
| 255 | + "image": "{{ .Values.nginx.nginx.image.repository }}:{{ .Values.nginx.nginx.image.tag | default .Chart.AppVersion }}", |
| 256 | + "name": "nginx", "ports": []interface{}{ |
| 257 | + map[string]interface{}{ |
| 258 | + "containerPort": int64(80), |
| 259 | + }, |
| 260 | + }, |
| 261 | + "resources": map[string]interface{}{}, |
| 262 | + }, |
| 263 | + }, |
| 264 | + }, specMap) |
| 265 | + |
| 266 | + assert.Equal(t, helmify.Values{ |
| 267 | + "nginx": map[string]interface{}{ |
| 268 | + "nginx": map[string]interface{}{ |
| 269 | + "image": map[string]interface{}{ |
| 270 | + "repository": "localhost:6001/my_project", |
| 271 | + "tag": "latest", |
| 272 | + }, |
| 273 | + }, |
| 274 | + }, |
| 275 | + }, tmpl) |
| 276 | + }) |
| 277 | + |
215 | 278 | } |
0 commit comments