k8sgpt-ai / k8sgpt-operator

Automatic SRE Superpowers within your Kubernetes cluster
https://k8sgpt.ai
Apache License 2.0
293 stars 80 forks source link

[Bug]: Wrong deployment image processing #346

Closed ultram4rine closed 4 months ago

ultram4rine commented 6 months ago

Checklist

Affected Components

K8sGPT Version

v0.3.8

Kubernetes Version

v1.28.0

Host OS and its Version

No response

Steps to reproduce

Include port in repository in K8sGPT object like <host>:<port>/<path>/<image>.

Expected behaviour

Operator will create a deployment with normal image.

Actual behaviour

Operator will turn image in <host>:<tag>, thus result into ImagePullBackOff.

Additional Information

I've found the lines were this happens: https://github.com/k8sgpt-ai/k8sgpt-operator/blob/db04fbdf23bdeeaa1053af1f578a7f3bcf7e0ca0/controllers/k8sgpt_controller.go#L168-L180

Quick solution is to parse image like this:

image := strings.Split(imageURI, ":")
if len(image) == 2 {
    imageRepository = image[0]
    imageVersion = image[1]
} else {
    imageRepository = fmt.Sprintf("%s:%s", image[0], image[1])
    imageVersion = image[2]
}

or

image := strings.Split(imageURI, ":")

imageRepository := strings.Join(image[0:len(image)-1], ":")
imageVersion := image[len(image)-1]

Possible better solution is to use maybe net/url or some other lib.

Test: https://go.dev/play/p/nIFGk2QroT5

ultram4rine commented 6 months ago

Btw, what is going on here: https://github.com/k8sgpt-ai/k8sgpt-operator/blob/db04fbdf23bdeeaa1053af1f578a7f3bcf7e0ca0/controllers/k8sgpt_controller.go#L175-L179

If image repo is not the same as in K8sGPT CRD, it leaves it as is and updates only version.

Maybe it should update image repo to k8sgptConfig.Spec.Repository?

arbreezy commented 5 months ago

Btw, what is going on here:

https://github.com/k8sgpt-ai/k8sgpt-operator/blob/db04fbdf23bdeeaa1053af1f578a7f3bcf7e0ca0/controllers/k8sgpt_controller.go#L175-L179

If image repo is not the same as in K8sGPT CRD, it leaves it as is and updates only version.

Maybe it should update image repo to k8sgptConfig.Spec.Repository?

yes that looks wrong :+1: