Skip to content

Conversation

AlexNPavel
Copy link
Contributor

Description of the change: This commit exposes more test framework functions, reduces the chance of namespace collision for GetNamespace, and adds godocs for all exposed test framework functions and variables.

Motivation for the change: The test framework contains various features (specifically automated cleanup of created resources and autogeneration of new testing namespaces) that may be useful outside of the context of code run via go test. This commit builds upon PR #1195, which removed the TestCtx's dependence on the testing.T field, and exposes functions that are necessary to use this outside of go test (specifically, it exposes Setup and CreateFromYAML, and adds a SetNamespace function).

@openshift-ci-robot openshift-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Mar 13, 2019
@AlexNPavel AlexNPavel force-pushed the test-framework-expose branch from dfe9cf7 to bd12703 Compare March 14, 2019 23:20
Copy link
Member

@shawn-hurley shawn-hurley left a comment

Choose a reason for hiding this comment

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

I am trying to understand why we are doing this, is this in service of exposing scorecard tests for users?

Copy link
Member

@lilic lilic left a comment

Choose a reason for hiding this comment

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

Same question as Shawn had, I thought we were against exposing functions until we actually need to make them public?

@AlexNPavel
Copy link
Contributor Author

@lilic @shawn-hurley

The main use for exposing more functions right now is going to be the new scorecard plugin that I described in the User Defined scorecard tests proposal. I feel that there are more use cases though where the automated setup and cleanup functionality of the test framework are useful. Even if we are not in a go test environment, we may want to be able to automatically clean up all resources when a function exits. This PR would allow for that.


id := prefix + "-" + strconv.FormatInt(time.Now().Unix(), 10)
// add a creation timestamp to the ID
id := prefix + "-" + strconv.FormatInt(time.Now().UnixNano(), 10)
Copy link
Member

Choose a reason for hiding this comment

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

What is the reason for switching to UnixNano?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To prevent collisions. Collisions shouldn't have happened before due to the namespace being based on the name of the test, but now it could be more likely to happen if users run create multiple contexts in parallel since those would use the same name and potentially be created in the same second. Using nanoseconds should prevent collisions.

KubeClient kubernetes.Interface
Scheme *runtime.Scheme
NamespacedManPath *string
NamespacedManPath string
Copy link
Member

Choose a reason for hiding this comment

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

Was this done initially in case we could have a nil and do we not have that case anymore?

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'm not sure why it was a pointer. We don't have any nil checks anywhere, so this doesn't affect anything. Just makes more sense to have it as a normal string IMO

Copy link
Member

Choose a reason for hiding this comment

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

Makes sense, will this be a breaking change for the users, should we explicitly mention it in the changelog.

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 don't think it's something the users should have been accessing directly in the first place. It might make sense to unexport this field (and maybe a few others)

Copy link
Contributor

Choose a reason for hiding this comment

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

Hi @AlexNPavel,

I think that namespace can be null, is not possible the user/dev use it as an lib/imported in their project?

if *singleNamespace {
namespace = os.Getenv(TestNamespaceEnv)
// Setup initializes the Global.Framework variable and its fields.
func Setup(kubeconfigPath, namespacedManPath, namespace string, singleNamespace, localOperator bool) error {
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 not sure if there are problematic implications, but can this function signature be refactored to something like:

type FrameworkOptions struct {
    KubeconfigPath string
    NamespacedManPath string
    Namespace string
    SingleNamespace bool
    LocalOperator bool
}

func NewFramework(opts FrameworkOptions) (*Framework, error)

Then AddToFrameworkScheme() could be a method on the Framework struct and renamed to AddToScheme().

I realize this would be a breaking change, so that's worth some discussion.

I think we should try to avoid having global mutable state as much as possible and favor returning and passing values around instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The biggest difficulty with not having the global Framework variable is how the framework would be passed around in the tests. We don't have a simple way to pass down variables through tests without global variables and having the global variable makes it easier for us to implement the main entry that sets up a single framework that all tests run after the entry can use.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

One way to avoid the global state in pkg/test would be to have a global framework variable in the user's main_test.go file that gets set to the result of NewFramework. But this would be a pretty important breaking change that we would have to make very clear to users.

Copy link
Member

Choose a reason for hiding this comment

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

Ok I think I'm understanding this a little bit better now having taken a look at https://github.com/operator-framework/operator-sdk/blob/master/test/test-framework/test/e2e/memcached_test.go.

If I understand correctly, right now it's basically required for tests to call f.MainEntry(m) to get Global setup properly. My concern is that if we open up more of the test framework and make it possible to run tests without calling f.MainEntry, then users will have to know the right order of calls to make before Global is safe to use.

If getting rid of the exported Global variable will cause too big of a breaking change, would it be possible to make its zero value (or initialized value) usable?

@openshift-ci-robot
Copy link

@AlexNPavel: PR needs rebase.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@openshift-ci-robot openshift-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label May 12, 2019
@openshift-ci-robot
Copy link

@AlexNPavel: The following tests failed, say /retest to rerun them all:

Test name Commit Details Rerun command
ci/prow/e2e-aws-ansible 17f3575 link /test e2e-aws-ansible
ci/prow/images 17f3575 link /test images
ci/prow/e2e-aws-helm 17f3575 link /test e2e-aws-helm
ci/prow/e2e-aws-go 17f3575 link /test e2e-aws-go
ci/prow/e2e-aws-subcommand 17f3575 link /test e2e-aws-subcommand

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

@hasbro17 hasbro17 added kind/documentation Categorizes issue or PR as related to documentation. and removed docs labels Sep 3, 2019
@camilamacedo86
Copy link
Contributor

Hi @AlexNPavel,

Is it a PR which still valid? If yes, could you please rebase with the master and let us know if has anything else that is missing here or just the review?

@joelanford joelanford closed this Oct 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/documentation Categorizes issue or PR as related to documentation. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants