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

testsys: Refactor code base #2560

Merged
merged 1 commit into from
Nov 18, 2022
Merged

Conversation

ecpullen
Copy link
Contributor

@ecpullen ecpullen commented Nov 8, 2022

Changes the way TestSys crd's are created while keeping the same interface.

Issue number:

Closes #2533

Description of changes:

  • The basis of the changes revolve around CrdCreator. The CrdCreator is responsible for creating all CRDs for a given variant family (aws-k8s, aws-ecs). The CrdCreator has a few functions that need to be implemented that enables support for the standard testing types. To add a new testing family, only a CrdCreator needs to be created.
  • CRD creation is done based on structs instead of function parameters (OrchestratorInput, BottlerocketInput, etc).
  • Additional labels are added, and support for conflicting resources has been streamlined using CrdInput::existing_resources().
  • EC2 CRD creation has been de-duped for aws-k8s and aws-ecs

Testing done:

Created ECS and EKS testing with:

cargo make -e BUILDSYS_VARIANT="aws-ecs-1" test
cargo make -e TESTSYS_TEST="migration" test
cargo make test

After testing was complete the following status was left:

 NAME                                TYPE           STATE           PASSED       SKIPPED      FAILED
 x86-64-aws-ecs-1-test               Test           passed          1            0            0
 x86-64-aws-k8s-123                  Resource       completed
 x86-64-aws-k8s-123-1-initial        Test           passed          1            7051         0
 x86-64-aws-k8s-123-2-migrate        Test           passed          2            0            0
 x86-64-aws-k8s-123-3-migrated       Test           passed          1            7051         0
 x86-64-aws-k8s-123-4-migrate        Test           passed          2            0            0
 x86-64-aws-k8s-123-5-final          Test           passed          1            7051         0
 x86-64-aws-k8s-123-test             Test           passed          1            7051         0

Note: The instance providers are not in the status because DestructionPolicy::OnTestSuccess was used.

Terms of contribution:

By submitting this pull request, I agree that this contribution is dual-licensed under the terms of both the Apache License, version 2.0, and the MIT license.

@ecpullen
Copy link
Contributor Author

ecpullen commented Nov 9, 2022

^ Convert error from anyhow to Snafu.

@ecpullen ecpullen force-pushed the refactor branch 2 times, most recently from 9b684ca to 497aecb Compare November 9, 2022 22:32
@ecpullen
Copy link
Contributor Author

ecpullen commented Nov 9, 2022

^ Add documentation

Copy link
Contributor

@etungsten etungsten left a comment

Choose a reason for hiding this comment

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

Refactor looks good to me. The testing looks good as well.

Copy link
Member

@webern webern left a comment

Choose a reason for hiding this comment

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

Some recommendations. The biggest one is that I think we should stick with cluster over orchestrator, though I don't remember the reasoning behind the choice.

/// Create a Sonobuoy CRD for K8s conformance and quick testing.
pub(crate) fn sonobuoy_crd(test_input: TestInput) -> Result<Test> {
let cluster_resource_name = test_input
.orchestrator_crd_name
Copy link
Member

Choose a reason for hiding this comment

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

I'm leaning toward using the word cluster instead of orchestrator since the word cluster is being used everywhere else already and introducing a new word is cognitively dissonant.

#[snafu(display("{} was missing from {}", item, what))]
Missing { item: String, what: String },

#[snafu(context(false), display("{}", source))]
Copy link
Member

Choose a reason for hiding this comment

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

Is context(false) because the Error type is not std::error::Error? I haven't used that feature before.

    #[snafu(context(false), display("{}", source))]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

context(false) makes it so you don't need to add the .context() for error conversion.

#[serde(untagged)]
pub(crate) enum TestType {
Known(KnownTestType),
Unknown(String),
Copy link
Member

Choose a reason for hiding this comment

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

It's not clear looking at this definition what the String represents. As a doc comment for Unknown.

use std::fs::File;

/// Get the AMI for the given `region` from the `ami_input` file.
pub(crate) fn ami(ami_input: &str, region: &str) -> Result<String> {
Copy link
Member

Choose a reason for hiding this comment

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

It feels like we should have a common struct for serializing/deserializing this

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is but it is private in Pubsys

let config = aws_config::from_env()
.region(Region::new(region.into()))
.load()
.await;
let ec2_client = aws_sdk_ec2::Client::new(&config);
// Find all images named `name` on `arch` in the `region`.
Copy link
Member

Choose a reason for hiding this comment

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

The owners 'self' default assumes that this is being used against developer-built images, right? we can pass in the AMI-ID for other use cases?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Correct.

}
}

#[derive(Clone, Debug, Deserialize)]
pub(crate) struct AmiImage {
Copy link
Member

Choose a reason for hiding this comment

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

What was the purpose of this type? Validation?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Easy deserialization. That was not added in the refactor.

get_ami_id(
format!(
"bottlerocket-{}-{}-{}-{}",
crd_input.variant, crd_input.arch, crd_input.starting_version.as_ref().context(error::InvalidSnafu{what: "The starting version must be provided for migration testing"})?, self.migrate_starting_commit.as_ref().context(error::InvalidSnafu{what: "The commit for the starting version must be provided if the starting image id is not"})?
Copy link
Member

Choose a reason for hiding this comment

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

Can you wrap this? Sadly rustfmt can't seem to handle things inside of macro calls.

get_ami_id(
format!(
"bottlerocket-{}-{}-{}-{}",
crd_input.variant, crd_input.arch, crd_input.starting_version.as_ref().context(error::InvalidSnafu{what: "The starting version must be provided for migration testing"})?, self.migrate_starting_commit.as_ref().context(error::InvalidSnafu{what: "The commit for the starting version must be provided if the starting image id is not"})?
Copy link
Member

Choose a reason for hiding this comment

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

I'm seeing repeated code here. Maybe put this in an ami_name function.

.crd_input
.existing_crds(
&labels,
&["testsys/cluster", "testsys/type", "testsys/region"],
Copy link
Member

Choose a reason for hiding this comment

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

Maybe we should think about constants for these. Technically even the array could be a constant but maybe that's not necessary.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think in this case, it's not necessary.

&self.repo_config.metadata_base_url,
&self.repo_config.targets_url,
) {
debug!(
Copy link
Member

Choose a reason for hiding this comment

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

Can we enable debug log level through cargo make currently? Aside: it might be nice to have a globally respected log level for Bottlerocket build and test processes that is respected throughout Makefile.toml.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

-e RUST_LOG=debug can be used to see those logs.

@ecpullen
Copy link
Contributor Author

^

  • Changed orchestrator -> cluster
  • Added doc comment for TestType::Unknown
  • Manual text wrapping for large format! block
  • Created ami_name function

Changes the way TestSys crd's are created while keeping the same
interface.
@ecpullen ecpullen merged commit 56fab98 into bottlerocket-os:develop Nov 18, 2022
@ecpullen ecpullen deleted the refactor branch November 18, 2022 17:49
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.

testsys: Refactor code base
3 participants