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

MTV-1682 | Mutate ESXi secret before testing connection #1289

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

yaacov
Copy link
Member

@yaacov yaacov commented Dec 30, 2024

Issue:
When testing ESXi Host connection, we don't take into account the mutation of the secret via the mutation hook.

Fix:
a. use the ESXi provider user and password when testing connection in the admission hook, like the secret will be once it's mutated by the mutation hook.
b. when checking for nil user field, also check for empty string to allow for tooling that sand "" instead of nil.

Images:
Before:
MTV-1682-before

After:
https://github.com/user-attachments/assets/4aa589af-075e-4ec9-a0db-7b3d2375339a

Ref:
https://issues.redhat.com/browse/MTV-1682

@yaacov yaacov requested a review from mnecas as a code owner December 30, 2024 10:46
@codecov-commenter
Copy link

codecov-commenter commented Dec 30, 2024

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

Attention: Patch coverage is 0% with 1 line in your changes missing coverage. Please review.

Project coverage is 15.44%. Comparing base (bfb0a81) to head (df2e92c).

Files with missing lines Patch % Lines
...bhooks/mutating-webhook/mutators/secret-mutator.go 0.00% 1 Missing ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1289      +/-   ##
==========================================
- Coverage   15.47%   15.44%   -0.04%     
==========================================
  Files         112      112              
  Lines       23399    23399              
==========================================
- Hits         3621     3613       -8     
- Misses      19490    19501      +11     
+ Partials      288      285       -3     
Flag Coverage Δ
unittests 15.44% <0.00%> (-0.04%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@yaacov yaacov force-pushed the esxi-secret-admitter-hook branch from f14b93f to e689a6d Compare December 30, 2024 11:25
@@ -126,7 +126,7 @@ func (admitter *SecretAdmitter) validateProviderSecret() *admissionv1.AdmissionR
func (admitter *SecretAdmitter) validateHostSecret() *admissionv1.AdmissionResponse {
if hostName, ok := admitter.secret.GetLabels()["createdForResource"]; ok {
if _, ok := admitter.secret.Data["user"]; !ok {
err := errors.New("Missing credentials on Host secret")
err := errors.New("missing credentials on Host secret")
Copy link
Member Author

Choose a reason for hiding this comment

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

unrelated nitpick, error should not be capitalized

@yaacov yaacov force-pushed the esxi-secret-admitter-hook branch from e689a6d to df2e92c Compare December 30, 2024 11:49
@@ -171,6 +171,27 @@ func (admitter *SecretAdmitter) buildProviderCollector(providerType *api.Provide
}
}

func (admitter *SecretAdmitter) ensureEsxiCredentials(provider *api.Provider) (*core.Secret, error) {
Copy link
Member Author

Choose a reason for hiding this comment

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

mimic the mutation hook that check for data["user"] and then for api.SDK

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.

2 participants