Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,12 @@ spec:
{{- end }}
command:
- /manager
{{- if .Values.controllerManager.image.digest }}
image: "{{ .Values.controllerManager.image.repository }}@{{ .Values.controllerManager.image.digest }}"
{{- else }}
image: "{{ .Values.controllerManager.image.repository }}:{{ .Values.controllerManager.image.tag }}"
{{- end }}
imagePullPolicy: "{{ .Values.controllerManager.image.pullPolicy }}"
livenessProbe:
httpGet:
path: /healthz
Expand All @@ -52,13 +57,10 @@ spec:
port: 8081
initialDelaySeconds: 5
periodSeconds: 10
{{- with .Values.controllerManager.resources }}
resources:
limits:
cpu: 500m
memory: 128Mi
requests:
cpu: 10m
memory: 64Mi
{{- toYaml . | nindent 20 }}
{{- end }}
securityContext:
allowPrivilegeEscalation: false
capabilities:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@ spec:
- --health-probe-bind-address=:8081
command:
- /manager
{{- if .Values.controllerManager.image.digest }}
image: "{{ .Values.controllerManager.image.repository }}@{{ .Values.controllerManager.image.digest }}"
{{- else }}
image: "{{ .Values.controllerManager.image.repository }}:{{ .Values.controllerManager.image.tag }}"
{{- end }}
imagePullPolicy: "{{ .Values.controllerManager.image.pullPolicy }}"
livenessProbe:
httpGet:
path: /healthz
Expand All @@ -43,13 +48,10 @@ spec:
port: 8081
initialDelaySeconds: 5
periodSeconds: 10
{{- with .Values.controllerManager.resources }}
resources:
limits:
cpu: 500m
memory: 128Mi
requests:
cpu: 10m
memory: 64Mi
{{- toYaml . | nindent 20 }}
{{- end }}
securityContext:
allowPrivilegeEscalation: false
capabilities:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,12 @@ spec:
{{- end }}
command:
- /manager
{{- if .Values.controllerManager.image.digest }}
image: "{{ .Values.controllerManager.image.repository }}@{{ .Values.controllerManager.image.digest }}"
{{- else }}
image: "{{ .Values.controllerManager.image.repository }}:{{ .Values.controllerManager.image.tag }}"
{{- end }}
imagePullPolicy: "{{ .Values.controllerManager.image.pullPolicy }}"
livenessProbe:
httpGet:
path: /healthz
Expand All @@ -52,13 +57,10 @@ spec:
port: 8081
initialDelaySeconds: 5
periodSeconds: 10
{{- with .Values.controllerManager.resources }}
resources:
limits:
cpu: 500m
memory: 128Mi
requests:
cpu: 10m
memory: 64Mi
{{- toYaml . | nindent 20 }}
{{- end }}
securityContext:
allowPrivilegeEscalation: false
capabilities:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import (
"fmt"
"strings"

"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"

Expand Down Expand Up @@ -91,7 +92,7 @@
}

// ExtractDeploymentConfig extracts configuration values from the deployment for values.yaml
func (c *ChartConverter) ExtractDeploymentConfig() map[string]interface{} {

Check failure on line 95 in pkg/plugins/optional/helm/v2alpha/scaffolds/internal/kustomize/chart_converter.go

View workflow job for this annotation

GitHub Actions / golangci-lint

cyclomatic complexity 37 of func `(*ChartConverter).ExtractDeploymentConfig` is high (> 30) (gocyclo)
if c.resources.Deployment == nil {
return make(map[string]interface{})
}
Expand Down Expand Up @@ -128,12 +129,30 @@
return config
}

// Use the first container (manager container)
firstContainer, ok := containersList[0].(map[string]interface{})
if !ok {
return config
// Find manager container by name, fallback to first container
var targetContainer map[string]interface{}
for _, c := range containersList {
container, ok := c.(map[string]interface{})
if !ok {
continue
}
if name, nameOk := container["name"].(string); nameOk && name == "manager" {
targetContainer = container
break
}
}

// Fallback to first container if manager not found
if targetContainer == nil {
if firstContainer, ok := containersList[0].(map[string]interface{}); ok {
targetContainer = firstContainer
} else {
return config
}
}

firstContainer := targetContainer

// Extract environment variables
if env, envFound, envErr := unstructured.NestedFieldNoCopy(firstContainer, "env"); envFound && envErr == nil {
if envList, envOk := env.([]interface{}); envOk && len(envList) > 0 {
Expand All @@ -157,5 +176,48 @@
}
}

// Extract image configuration
if image, found, err := unstructured.NestedString(firstContainer, "image"); found && err == nil && image != "" {
config["image"] = parseImageString(image)
}

// Extract imagePullPolicy
if pullPolicy, found, err := unstructured.NestedString(firstContainer, "imagePullPolicy"); found && err == nil && pullPolicy != "" {

Check failure on line 185 in pkg/plugins/optional/helm/v2alpha/scaffolds/internal/kustomize/chart_converter.go

View workflow job for this annotation

GitHub Actions / golangci-lint

The line is 133 characters long, which exceeds the maximum of 120 characters. (lll)
config["imagePullPolicy"] = pullPolicy
}

return config
}

// parseImageString parses "<repo>[@<digest>]" or "<repo>[:<tag>]".
// It distinguishes registry ports from tags by requiring the tag colon
// to come AFTER the last '/'.
func parseImageString(image string) map[string]interface{} {
out := make(map[string]interface{})

// Digest form takes precedence
if at := strings.IndexByte(image, '@'); at != -1 {
out["repository"] = image[:at]
if at+1 < len(image) {
out["digest"] = image[at+1:]
}
return out
}

lastSlash := strings.LastIndexByte(image, '/')
lastColon := strings.LastIndexByte(image, ':')

// Tag only if the colon comes after the last slash
if lastColon != -1 && lastColon > lastSlash {
out["repository"] = image[:lastColon]
if lastColon+1 < len(image) {
out["tag"] = image[lastColon+1:]
}
return out
}

// Untagged/undigested; kube will pull :latest, but we surface it explicitly
out["repository"] = image
out["tag"] = "latest"
return out
}
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,12 @@ var _ = Describe("ChartConverter", func() {
Expect(config).NotTo(BeNil())
Expect(config).To(HaveKey("env"))
Expect(config).To(HaveKey("resources"))

// Verify image extraction
Expect(config).To(HaveKey("image"))
imageConfig := config["image"].(map[string]interface{})
Expect(imageConfig["repository"]).To(Equal("controller"))
Expect(imageConfig["tag"]).To(Equal("latest"))
})

It("should handle deployment without containers", func() {
Expand Down
Loading
Loading