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

[PoC] Launch test YAMLs directly #1487

Closed
wants to merge 1 commit into from
Closed

[PoC] Launch test YAMLs directly #1487

wants to merge 1 commit into from

Conversation

josvazg
Copy link
Collaborator

@josvazg josvazg commented Apr 2, 2024

PoC not to merge but to be used for API testing.

All Submissions:

  • Have you signed our CLA?

@josvazg josvazg marked this pull request as draft April 2, 2024 17:19
@josvazg josvazg force-pushed the launch-yamls branch 9 times, most recently from df67e12 to 3f6195f Compare April 3, 2024 15:06
@josvazg josvazg changed the title Launch test YAMLs directly [PoC] Launch test YAMLs directly Apr 3, 2024
Signed-off-by: jose.vazquez <jose.vazquez@mongodb.com>

const (
ExpectedContext = "kind-kind"

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stylistic nit: remove those extra newlines, const blocks are tight.

// Launch will try to launch the operator and apply the given YAML for it to handle
func (l *Launcher) Launch(yml string, waitCfg *WaitConfig) error {
if err := l.ensureK8sCluster(); err != nil {
return err
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wrap all errors below. In this case:

Suggested change
return err
return fmt.Errorf("error ensuring k8s cluster: %w", err)

@s-urbaniak
Copy link
Collaborator

@josvazg I see you are inventing your own testing framework here. What about just using https://kuttl.dev/ ?

@josvazg
Copy link
Collaborator Author

josvazg commented Apr 10, 2024

See https://kuttl.dev/docs/kuttl-test-harness.html#writing-your-first-test and https://kuttl.dev/docs/api-integration.html#test-harness.

This is not a testing framework, it is a simple testing helper. It could be used as a framework maybe, but it is NOT the intent here and for that I agree that KUTTL is a better option.

Think of this as the function I call in Go to get the Atlas infrastructure in the state I need to run a contract test, which is defined in Go code, not in YAML. A test that calls our translation layer that talks to the API using the same code that the reconcile logic uses. If KUTTL could be used in the same unobtrusive way, then maybe we could use it for all, I am not 100% convinced yet.

Sample custom test:

  l := launcher.NewFromEnv(testVersion) // instantiate a launcher
  l.Launch(testYml, launcher.WaitReady("atlasprojects/my-project", 30*time.Second))) // launch the YAML and wait for it
  
  // run custom test code - might not be part of KUTTLE, like a custom go code driven contract test

   l.Cleanup()) // optionally cleanup the infrastructure required for the test (does KUTTL allow for optional cleanup?)

@s-urbaniak
Copy link
Collaborator

@josvazg I am leaving the final assertion to you 👍 I didn't have a deeper look at kuttl, just worried about NIH implementations. Again, final call is yours :-)

@josvazg
Copy link
Collaborator Author

josvazg commented Apr 10, 2024

@josvazg I am leaving the final assertion to you 👍 I didn't have a deeper look at kuttl, just worried about NIH implementations. Again, final call is yours :-)

I think the best way forward now is to actually force myself to use KUTTL for some real Contract tests, for Atlas Search. If I see no blockers, then we can probably use for everything and forget about this PoC for good.


func (cfg *WaitConfig) waitArgs() []string {
args := []string{"wait", fmt.Sprintf("--for=%s", cfg.Condition), cfg.Target}
if cfg.Timeout == 0 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a mistake or do you really want to set timeout only when it's zero?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was a mistake, the logic had to be reversed

@helderjs
Copy link
Collaborator

@josvazg This PoC links well to my comment on the CI Revamp document regarding GitHub Actions.

Why didn't you write a Github action workflow for it? I'd say we probably won't need any code for it.
I see your code doing what Github Action should be doing, and I believe that's why @s-urbaniak also saw it as a framework wrapping the tooling needed to achieve the goal. Code is a liability and I prefer to have no code when we already have a toolchain in place to do the job. In the end, you would still use a workflow to trigger this task.
Think that a CI tool like GH action offers us out-of-box multi-stage pipeline and jobs, some level of security, lifecycle control... keep in mind that once you have signaled you will drop this to a new PoC with KUTTL

Comment on lines +13 to +25
const (
ExpectedContext = "kind-kind"

LauncherTestInstall = "test-ako"

HelmRepoURL = "https://mongodb.github.io/helm-chart"

RepoRef = "mongodb"

OperatorChart = "mongodb-atlas-operator"

AtlasURI = "https://cloud-qa.mongodb.com"
)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const (
ExpectedContext = "kind-kind"
LauncherTestInstall = "test-ako"
HelmRepoURL = "https://mongodb.github.io/helm-chart"
RepoRef = "mongodb"
OperatorChart = "mongodb-atlas-operator"
AtlasURI = "https://cloud-qa.mongodb.com"
)
const (
ExpectedContext = "kind-kind"
LauncherTestInstall = "test-ako"
HelmRepoURL = "https://mongodb.github.io/helm-chart"
RepoRef = "mongodb"
OperatorChart = "mongodb-atlas-operator"
AtlasURI = "https://cloud-qa.mongodb.com"
)

@josvazg
Copy link
Collaborator Author

josvazg commented Apr 10, 2024

@josvazg This PoC links well to my comment on the CI Revamp document regarding GitHub Actions.

Why didn't you write a Github action workflow for it? I'd say we probably won't need any code for it. I see your code doing what Github Action should be doing, and I believe that's why @s-urbaniak also saw it as a framework wrapping the tooling needed to achieve the goal. Code is a liability and I prefer to have no code when we already have a toolchain in place to do the job. In the end, you would still use a workflow to trigger this task. Think that a CI tool like GH action offers us out-of-box multi-stage pipeline and jobs, some level of security, lifecycle control... keep in mind that once you have signaled you will drop this to a new PoC with KUTTL

I want us to be able to do our development without any Github involvement, using the GitHub CI actions or workflow only to automatically re-run tests at the proper time to ensure what we release is correct and did not include any regressions.

The idea is to be able to write contract tests in Go that look like this:

  1. Get a particular set of Atlas resources in a particular state.
  2. Run one or more contract tests against the Atlas API.
  3. Tear down all resources required for the test.

During development, in your laptop and before any code reaches GitHub, you iterate with steps 1-2 until you test all APIs you needed to verify. Then do step 3, when you are done. It is only later on you send a PR and then the CI might also want to run those tests at some point, maybe at merge time only.

This might be doable with KUTTL, because it seems to have a programmatic interface. I will need to test it.
But as a pure GitHub action or workflow it would be completely useless for contract testing.

BTW, even if KUTTL could not do the job fully and this simple launcher would be required, I have the impression it would be able to replace a lot of our current test helper code, which would mean a net removal of code and thus reduced liability instead.

@josvazg
Copy link
Collaborator Author

josvazg commented Apr 10, 2024

Going to close this PoC now:

  • It was never the intention to merge this at this point.
  • It was needed for me as a way to run contract tests, but haven't gotten there yet.
  • Seems KUTTL has a programmatic interface that might allow it to be used within tests as a helper, in which case this code will not be needed.
  • Should KUTTL prove inadequate later, we can always dig up this PR again.
  • The main goal of the PoC is achieved, launching declarative YAML infrastructure for a test OR as a helper to setup before a test is not only doable but also relatively simple.

@roothorp roothorp deleted the launch-yamls branch September 26, 2024 10:02
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 this pull request may close these issues.

3 participants