This repository has been archived by the owner on Oct 9, 2023. It is now read-only.
Fix secret volume does not get mounted by webhook #332
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
TL;DR
#306 introduced an issue with secret file injection where nil pointer error happens if a pod contains a secret-less volume. A nil check on the secret fixes this error. Relevant logs below:
2021/10/08 06:15:58 http: panic serving 10.42.0.1:46429: runtime error: invalid memory address or nil pointer dereference goroutine 328 [running]: net/http.(*conn).serve.func1(0xc0009903c0) /usr/local/go/src/net/http/server.go:1824 +0x153 panic(0x214cbc0, 0x3826290) /usr/local/go/src/runtime/panic.go:971 +0x499 github.com/flyteorg/flytepropeller/pkg/webhook.AppendVolume(0x28727c8, 0xc00075e880, 0xc000766300, 0x1, 0x1, 0xc000ba92a0, 0x10, 0x0, 0x0, 0x0, ...) /go/src/github.com/flyteorg/flytepropeller/pkg/webhook/utils.go:112 +0xcc github.com/flyteorg/flytepropeller/pkg/webhook.K8sSecretInjector.Inject(0x28727c8, 0xc00075e880, 0xc00070b1a0, 0xc0002ffc00, 0x38, 0xc00076acc0, 0x2, 0x2) /go/src/github.com/flyteorg/flytepropeller/pkg/webhook/k8s_secrets.go:54 +0x1b8 github.com/flyteorg/flytepropeller/pkg/webhook.(*SecretsMutator).Mutate(0xc000fd3ac0, 0x28727c8, 0xc00075e880, 0xc0002ffc00, 0x2826200, 0xc0011f37a0, 0xc000acfb00, 0x3) /go/src/github.com/flyteorg/flytepropeller/pkg/webhook/secrets.go:53 +0x2f5 github.com/flyteorg/flytepropeller/pkg/webhook.PodMutator.Mutate(0xc00075e040, 0x38361c0, 0xc00017d140, 0x1, 0x1, 0x28727c8, 0xc00075e880, 0xc0002ffc00, 0x3, 0x0, ...) /go/src/github.com/flyteorg/flytepropeller/pkg/webhook/pod.go:117 +0xd0 github.com/flyteorg/flytepropeller/pkg/webhook.(*PodMutator).Handle(0xc000988ba0, 0x28727c8, 0xc00075e880, 0xc0011eaff0, 0x24, 0x0, 0x0, 0xc00074d2e8, 0x2, 0xc00074d2ea, ...) /go/src/github.com/flyteorg/flytepropeller/pkg/webhook/pod.go:94 +0x276 sigs.k8s.io/controller-runtime/pkg/webhook/admission.(*Webhook).Handle(0xc000197c80, 0x28727c8, 0xc00075e880, 0xc0011eaff0, 0x24, 0x0, 0x0, 0xc00074d2e8, 0x2, 0xc00074d2ea, ...)
Before:

After:

Task under test:
@task(secret_requests=[Secret(group=SECRET_GROUP, key=SECRET_NAME, mount_requirement=Secret.MountType.FILE)]) def secret_file_task() -> (str, str): # SM here is a handle to the secrets manager sm = flytekit.current_context().secrets f = sm.get_secrets_file(SECRET_GROUP, SECRET_NAME) secret_val = sm.get(SECRET_GROUP, SECRET_NAME) # returning the filename and the secret_val return f, secret_val
Type
Are all requirements met?
Complete description
Tracking Issue
flyteorg/flyte#1451
Follow-up issue
NA