Skip to content

Commit c532fcf

Browse files
authored
Show error if there's no secret to encode (#1580)
**Description of the change** Kubeseal will throw an error when trying to seal no secrets. This will happen when the file is empty or invalid, and the error suggests the user to check the file encoding as this seems to be a common issue especially in some versions of Windows #1410 #1560 **Benefits** Give feedback to the user to help debugging a common issue **Possible drawbacks** Kubeseal will now throw an error where it previously just silently succeeded with no output **Applicable issues** - fixes #1410 - fixes #1560 --------- Signed-off-by: Alejandro Moreno <[email protected]>
1 parent de1f4dd commit c532fcf

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

integration/kubeseal_test.go

+15
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,21 @@ var _ = Describe("kubeseal", func() {
189189
})
190190
})
191191

192+
var _ = Describe("kubeseal (with invalid input)", func() {
193+
var input io.Reader
194+
var output *bytes.Buffer
195+
var args []string
196+
197+
BeforeEach(func() {
198+
output = &bytes.Buffer{}
199+
})
200+
201+
It("should throw an error", func() {
202+
err := runKubeseal(args, input, output)
203+
Expect(err).To(HaveOccurred())
204+
})
205+
})
206+
192207
var _ = Describe("kubeseal --fetch-cert", func() {
193208
var c corev1.CoreV1Interface
194209
var input io.Reader

pkg/kubeseal/kubeseal.go

+5
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ func readSecrets(r io.Reader) ([]*v1.Secret, error) {
189189
return nil, err
190190
}
191191
}
192+
192193
return secrets, nil
193194
}
194195

@@ -226,6 +227,10 @@ func Seal(clientConfig ClientConfig, outputFormat string, in io.Reader, out io.W
226227
return err
227228
}
228229

230+
if len(secrets) == 0 {
231+
return fmt.Errorf("no secrets found. Ensure the input is valid and UTF-8 encoded")
232+
}
233+
229234
for _, secret := range secrets {
230235
if len(secret.Data) == 0 && len(secret.StringData) == 0 && !allowEmptyData {
231236
return fmt.Errorf("secret.data is empty in input Secret, assuming this is an error and aborting. To work with empty data, --allow-empty-data can be used")

0 commit comments

Comments
 (0)