kubernetes-sigs / e2e-framework

A Go framework for end-to-end testing of components running in Kubernetes clusters.
Apache License 2.0
511 stars 99 forks source link

Expose `ko` features as a third-party Envfunc #343

Open vladimirvivien opened 10 months ago

vladimirvivien commented 10 months ago

What do you want to see?

ko is a tool that automates the build and publication of Go code as container images. I think it would be useful to be able to create and deploy (locally or even remotely) container images during testing. This is especially true if building/testing Kubernetes controller/operators.

For instance, the following provides an idea of how that could work :

import(
    "sigs.k8s.io/e2e-framework/third_party/ko"
...
)

var testEnv env.Environment

func TestMain(m *testing.M) {
    testEnv.Setup(
        func(ctx context.Context, cfg *envconf.Config) (context.Context, error) {
            kotool = ko.Install("@latest")
            kotool.SetConfig("some-conf-file")
            kootool.RepoLogin("TOKEN_ENV")
            kotool.BuildLocal(ctx, "package-path") // builds/publishes in local docker, saves image name in ctx
            kotool.BuildRemote(ctx, "repo-path", "package-path")
            return ctx, nil
        }
    )

    testEnv.Finish(
        func(ctx context.Context, cfg *envconf.Config) (context.Context, error) {
            ko.RemoveLocalmage(ctx) // removes all built images from names saved in ctx
        }
}

Extra Labels

No response

heylongdacoder commented 10 months ago

Hello, if no one is working on this yet, may I give it a try? 😄

k8s-triage-robot commented 7 months ago

The Kubernetes project currently lacks enough contributors to adequately respond to all issues.

This bot triages un-triaged issues according to the following rules:

You can:

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

vladimirvivien commented 7 months ago

@heylongdacoder Still interested in working on this ?

/remove-lifecycle stale

heylongdacoder commented 6 months ago

Hey @vladimirvivien, I have finished part of it with test cases. I will probably commit the code for review this weekend. But if I am blocking the progress, please feel free to take this! Many thanks!

vladimirvivien commented 5 months ago

Hi @heylongdacoder were you able to start PR?

heylongdacoder commented 4 months ago

@vladimirvivien sorry for the delay, I am working on it now.

vladimirvivien commented 4 months ago

@heylongdacoder no worries at all.

heylongdacoder commented 2 months ago

hey @vladimirvivien I would like to continue on this and confirm a few things.

  1. Are BuildDockerLocal and BuildDockerRemote still relevant?
  2. If point 1 is still relevant, for RemoveLocalImage, we would need the docker binary since ko does not have the functionality to remove images from Docker. Do you think that is ok?
  3. RemoveLocalImage, if we want to remove the images that were uploaded to KinD, currently I got no idea on how to implement this, since KinD does not provide the functionality to remove the images. Let me know if you have idea about this.

Thanks!

vladimirvivien commented 1 month ago

Hi @heylongdacoder when I wrote the issue, I was giving an example of what could work. You are free to implement whatever works best for the feature.

Thanks agai.