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

Goal Seeking Keyvaults #3357

Merged
merged 28 commits into from
Oct 12, 2023
Merged

Conversation

theunrepentantgeek
Copy link
Member

@theunrepentantgeek theunrepentantgeek commented Oct 2, 2023

What this PR does / why we need it:

Implements goal seeking for KeyVaults as described in our ADR.

We add two additional options to createMode:

  • createOrRecover - creates a new KeyVault, unless there's a soft-deleted one to recover
  • purgeThenCreate - any existing soft-deleted KeyVault is purged, then a new one created.

Closes #1415

Special notes for your reviewer:

The option purgeThenCreate is dangerous because it results in ASO turning a soft-delete into a hard delete without warning and without the possibility of recovery. Our documentation will call this out.

Prerequisites

How does this PR make you feel:
gif

If applicable:

  • this PR contains tests

v2/api/keyvault/customizations/vault_extensions.go Outdated Show resolved Hide resolved
v2/api/keyvault/customizations/vault_extensions.go Outdated Show resolved Hide resolved
v2/api/keyvault/customizations/vault_extensions.go Outdated Show resolved Hide resolved
var _ extensions.ARMResourceModifier = &VaultExtension{}

const (
CreateMode_Default = "default"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we use the code-gen enums instead?

Copy link
Member Author

Choose a reason for hiding this comment

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

No, we can't.

The enums only exist in the API variants, not the storage variants, and I don't want to couple this extension to a particular API version.

tc.T.Log(line)
tc.T.Log(section)
tc.T.Log(msg)
tc.T.Log(line)
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd suggest something like below here to re-use the code:

// LogSection creates a distinctive header in the log to aid scanning
func (tc *KubePerTestContext) LogSectionf(section string, args ...any) {
	tc.logf(subsection, "=", args)
}

// LogSection creates a distinctive header in the log to aid scanning
func (tc *KubePerTestContext) LogSubsectionf(subsection string, args ...any) {
	tc.logf(subsection, "-", args)
}

func (tc *KubePerTestContext) logf(s string, r string, args ...any) {
	msg := fmt.Sprintf(s, args...)
	line := strings.Repeat(r, len(msg))
	tc.T.Log(line)
	tc.T.Log(msg)
	tc.T.Log(line)
}

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

"context"
"strings"

keyvault "github.com/Azure/azure-service-operator/v2/api/keyvault/v1api20210401previewstorage"
Copy link
Member

Choose a reason for hiding this comment

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

minor: I think these two should go down below in the "local imports" section so that there are a total of 3 sections.

Copy link
Member Author

Choose a reason for hiding this comment

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

I've been deliberately separating out the named imports from the vanilla ones; still respecting the stdlib/library/local order though, so I'll move these down.

Copy link
Member Author

Choose a reason for hiding this comment

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

Moved.

v2/api/keyvault/customizations/vault_extensions.go Outdated Show resolved Hide resolved
v2/api/keyvault/customizations/vault_extensions.go Outdated Show resolved Hide resolved
v2/api/keyvault/customizations/vault_extensions.go Outdated Show resolved Hide resolved
v2/api/keyvault/customizations/vault_extensions.go Outdated Show resolved Hide resolved
@@ -264,6 +264,38 @@ func (client *GenericClient) getByIDHandleResponse(resp *http.Response, resource
return nil
}

func (client *GenericClient) CreatePostRequest(
Copy link
Member

Choose a reason for hiding this comment

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

Fine with these being added but may not be needed if you follow the suggestion by @super-harsh to use the SDK for Go instead.

Copy link
Member Author

Choose a reason for hiding this comment

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

Removed, since we don't need them.

v2/internal/reflecthelpers/reflect_helpers.go Outdated Show resolved Hide resolved
@@ -264,6 +264,38 @@ func (client *GenericClient) getByIDHandleResponse(resp *http.Response, resource
return nil
}

func (client *GenericClient) CreatePostRequest(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we still use this method?

Copy link
Member Author

Choose a reason for hiding this comment

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

No, not anymore.

@theunrepentantgeek theunrepentantgeek mentioned this pull request Oct 11, 2023
3 tasks
) error {
// Find out whether a soft-deleted KeyVault with the same name exists
exists, err := ex.checkForExistenceOfDeletedKeyVault(ctx, kv, resolver, vc, log)
if err != nil {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since KV names should be globally unique - Not sure what happens in the case where the soft-deleted KV is in another subscription and it's just the name that is not available.

Just double-checking if the user would get the name not available event/log anyway ?

Copy link
Member Author

Choose a reason for hiding this comment

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

If the existing KeyVault is in a different subscription, we can't recover nor purge it - and the user gets an appropriate error in the condition of the resource; this is unchanged.

theunrepentantgeek and others added 2 commits October 12, 2023 21:31
Co-authored-by: Harshdeep Singh (harshdsingh) <38904804+super-harsh@users.noreply.github.com>
@codecov-commenter
Copy link

Codecov Report

Merging #3357 (6a96978) into main (00f2427) will decrease coverage by 0.05%.
The diff coverage is 64.23%.

@@            Coverage Diff             @@
##             main    #3357      +/-   ##
==========================================
- Coverage   54.37%   54.33%   -0.05%     
==========================================
  Files        1544     1545       +1     
  Lines      649180   649311     +131     
==========================================
- Hits       353016   352820     -196     
- Misses     238722   239035     +313     
- Partials    57442    57456      +14     
Files Coverage Δ
...t/v1api20210401preview/vault_spec_arm_types_gen.go 33.33% <ø> (ø)
.../v1beta20210401preview/vault_spec_arm_types_gen.go 33.33% <ø> (ø)
v2/internal/testcommon/kube_per_test_context.go 79.13% <100.00%> (+0.76%) ⬆️
...ools/generator/internal/config/type_transformer.go 74.70% <100.00%> (+0.40%) ⬆️
v2/api/keyvault/customizations/vault_extensions.go 57.01% <57.01%> (ø)

... and 36 files with indirect coverage changes

@theunrepentantgeek theunrepentantgeek merged commit f16cd83 into main Oct 12, 2023
8 checks passed
@theunrepentantgeek theunrepentantgeek deleted the feature/goal-seeking-keyvaults branch October 12, 2023 20:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

Successfully merging this pull request may close these issues.

Feature: Goal-seeking creation of Azure Key Vaults
4 participants