is my operator deployed when using envtest

24 views
Skip to first unread message

Jennifer Wirth

unread,
Jun 27, 2022, 1:35:30 AM6/27/22
to Operator Framework

Hi,

I am trying to set-up an integration test using envtest. So far I have been able to add the required CRDs and deploy my own operator yaml file.

My operator adds various objects to the cluster based on the data in the CRD (deployment, service etc).

However when i run my envtest, the deployment cannot be found when i add my resource. I tried extending the timeout and add a long sleep, but none of this worked (see code sample at the bottom of this post)

Do i need to do something to make my operator “work” during my envtest?

tx.,

func (ts *TotoTestSuite) Test_Smoke() {
    toto :=  &acme.Toto{
        ObjectMeta: metav1.ObjectMeta{
        …
        },
        Spec: …
    }

    err := ts.Client.Create(ts.Ctx, toto)
    ts.Require().NoError(err)
    dep := v1.Deployment{}
    timedCtx, cancel := context.WithTimeout(ts.Ctx, 5*time.Second)
    defer cancel()

    //time.Sleep(4 * time.Minute)

    ts.Require().NoError(ts.Client.Get(timedCtx, types.NamespacedName{Name: name(toto), Namespace: "test"}, &dep))
    ts.Require().Equal(dep.Name, "foobar")
}

Camila Macedo

unread,
Jun 27, 2022, 7:16:56 AM6/27/22
to Jennifer Wirth, Operator Framework
Hi, 

See in the following link how you config the env test and pass your CRDs:


I hope that helps you out. 

Cheers,
 

CAMILA MACEDO

SR. SOFTWARE ENGINEER 

RED HAT Operator framework

Red Hat UK

She / Her / Hers

IM: cmacedo

I respect your work-life balance. Therefore there is no need to answer this email out of your office hours.




--
You received this message because you are subscribed to the Google Groups "Operator Framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to operator-framew...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/operator-framework/cf961c30-11a3-4447-a16b-81e669665839n%40googlegroups.com.

Jennifer Wirth

unread,
Jun 28, 2022, 12:21:16 AM6/28/22
to Operator Framework

Hi,

Thanks for your reply.

I believe I went through all those steps. I am able to deploy my CRD during my test. What i am not able to verify is that a resource (in this case a Deployment) is added to the cluster by my operator. I feel that my operator is not running during the test. 

tx.,

Varsha Prasad Narsing

unread,
Jun 28, 2022, 2:05:07 PM6/28/22
to Jennifer Wirth, Operator Framework
Hi Jennifer

In order to run the operator in your cluster, are you:
1. Building and loading the operator image in the test cluster. This is an example PR in progess but would be helpful to give an idea, or
2. Starting the controller directly, and running the reconciler instead of building the image and loading it.

A few other debugging points to ensure your operator is running in the cluster. You can use environment variables mentioned here to:
- Use an existing cluster to run the test, that would be helpful in verifying manually in parallel if the deployment you want is running or not. If its running, then you can continue by writing tests programmatically.
- Use controller-plane's output to see if the cluster started and events are getting emitted.

Please let us know if any of the above points help in debugging the issue.

Thanks
Varsha




--
Varsha Prasad
Software Engineer
Operator SDK Team
Red Hat Inc. San Francisco
Reply all
Reply to author
Forward
0 new messages