Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Wrong deployment image processing #346

Closed
3 of 4 tasks
ultram4rine opened this issue Feb 16, 2024 · 2 comments · Fixed by #348
Closed
3 of 4 tasks

[Bug]: Wrong deployment image processing #346

ultram4rine opened this issue Feb 16, 2024 · 2 comments · Fixed by #348

Comments

@ultram4rine
Copy link
Contributor

ultram4rine commented Feb 16, 2024

Checklist

  • I've searched for similar issues and couldn't find anything matching
  • I've included steps to reproduce the behavior

Affected Components

  • K8sGPT (CLI)
  • K8sGPT Operator

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:

// Check the version of the deployment image matches the version set in the K8sGPT CR
imageURI := deployment.Spec.Template.Spec.Containers[0].Image
image := strings.Split(imageURI, ":")
imageRepository := image[0]
imageVersion := image[1]
// if one of repository or tag is changed, we need to update the deployment
if imageRepository != k8sgptConfig.Spec.Repository || imageVersion != k8sgptConfig.Spec.Version {
// Update the deployment image
deployment.Spec.Template.Spec.Containers[0].Image = fmt.Sprintf("%s:%s",
imageRepository, k8sgptConfig.Spec.Version)
err = r.Update(ctx, &deployment)

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
Copy link
Contributor Author

Btw, what is going on here:

// if one of repository or tag is changed, we need to update the deployment
if imageRepository != k8sgptConfig.Spec.Repository || imageVersion != k8sgptConfig.Spec.Version {
// Update the deployment image
deployment.Spec.Template.Spec.Containers[0].Image = fmt.Sprintf("%s:%s",
imageRepository, k8sgptConfig.Spec.Version)

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
Copy link
Member

Btw, what is going on here:

// if one of repository or tag is changed, we need to update the deployment
if imageRepository != k8sgptConfig.Spec.Repository || imageVersion != k8sgptConfig.Spec.Version {
// Update the deployment image
deployment.Spec.Template.Spec.Containers[0].Image = fmt.Sprintf("%s:%s",
imageRepository, k8sgptConfig.Spec.Version)

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 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants