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

Validate Dapr install in Dapr links #4856

Merged
merged 1 commit into from
Dec 13, 2022
Merged

Conversation

rynowak
Copy link
Contributor

@rynowak rynowak commented Dec 13, 2022

Part of: #2952

This change validates the installation status of Dapr inside links RP for Dapr resources. This is step one in removing Dapr from Radius' default installation. After we have a good experience with Dapr missing, we can remove it.

This validation is only applied on PUT calls to be more friendly to API consumers. We still allow clients to get and list dapr link resources without Dapr installed.

The pattern I followed is similar to the validation we perform for the AKV CSI driver.

Part of: #2952

This change validates the installation status of Dapr inside links RP
for Dapr resources. This is step one in removing Dapr from Radius'
default installation. After we have a good experience with Dapr missing,
we can remove it.

This validation is only applied on PUT calls to be more friendly to API
consumers. We still allow clients to get and list dapr link resources
without Dapr installed.

The pattern I followed is similar to the validation we perform for the
AKV CSI driver.
@rynowak rynowak requested a review from a team as a code owner December 13, 2022 09:33
@@ -56,7 +56,7 @@ func TestValidateRequest(t *testing.T) {
})

// Create default Kubernetes fake client.
defaultFakeClient := rptesting.NewFakeKubeClient(nil)
defaultFakeClient := rptesting.NewFakeKubeClient(crdScheme)
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 bug in volume validation had a matching bug in the tests. Since the scheme was not registered, it was failing due to not understanding what a CRD is.

// Licensed under the MIT License.
// ------------------------------------------------------------

package datamodel
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 needed a good place to share code among 4 controllers. Open to suggestions on where to place this very small amount of code if datamodel is not right.

} else if !isSupported {
return rest.NewBadRequestResponse(datamodel.DaprMissingError), nil
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It seemed right to make this the first thing that happens in the controller (before validating data, before looking in the database, etc).

defer mctrl.Finish()

mStorageClient := store.NewMockStorageClient(mctrl)
mDeploymentProcessor := deployment.NewMockDeploymentProcessor(mctrl)
Copy link
Contributor Author

@rynowak rynowak Dec 13, 2022

Choose a reason for hiding this comment

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

I've seen this bug appear in a lot of our tests that use both mocks and subtests. We should always initialize the mock controller inside t.Run() in that case.

The problem with this approach is that the mock controller only does validation when all subtests have run, so if one of the subtests was wrong, you can't find out which one. You're sharing the state of the mock across subtests.

If you initialize the controller inside t.Run() then the validations will be performed as part of each subtest.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also since go version 1.X (kinda old version I think) defer mctrl.Finish() is called for you.

@@ -53,13 +51,15 @@ func TestCreateOrUpdateDaprInvokeHttpRoute_20220315PrivatePreview(t *testing.T)
headerKey string
headerValue string
resourceETag string
daprMissing bool
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changes to tests were all boilerplate copy-paste.

Copy link
Contributor

@ytimocin ytimocin left a comment

Choose a reason for hiding this comment

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

In future we can have a BaseDaprController and move the shared logic to that Controller.

@rynowak rynowak merged commit f3adef4 into main Dec 13, 2022
@rynowak rynowak deleted the rynowak/remove-dapr-dependency branch December 13, 2022 20:57
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