Skip to content
This repository was archived by the owner on Feb 2, 2021. It is now read-only.

Commit a80f7e3

Browse files
committed
Fix issue with reading minio secret
The quotes in the jsonpath expression were not being parsed correctly by kubectl. Signed-off-by: Alex Ellis (OpenFaaS Ltd) <alexellis2@gmail.com>
1 parent 421fd14 commit a80f7e3

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

cmd/apply.go

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func runApplyCommandE(command *cobra.Command, _ []string) error {
6161
if os.Getuid() == 0 {
6262
return fmt.Errorf("do not run this tool as root, or on your server. Run it from your own client remotely")
6363
}
64-
64+
6565
files, err := command.Flags().GetStringArray("file")
6666
if err != nil {
6767
return err
@@ -97,7 +97,7 @@ func runApplyCommandE(command *cobra.Command, _ []string) error {
9797
}
9898

9999
plan := types.Plan{}
100-
if err := yaml.Unmarshal(yamlBytes, &plan);err != nil {
100+
if err := yaml.Unmarshal(yamlBytes, &plan); err != nil {
101101
return fmt.Errorf("unmarshal of --file %s gave error: %s", yamlFile, err.Error())
102102
}
103103

@@ -304,6 +304,9 @@ func process(plan types.Plan, prefs InstallPreferences) error {
304304
return errors.Wrap(err, "getS3Credentials")
305305
}
306306

307+
if len(accessKey) == 0 || len(secretKey) == 0 {
308+
return fmt.Errorf("S3 secrets returned from getS3Credentials were empty, but should have been generated")
309+
}
307310
if err := installMinio(accessKey, secretKey); err != nil {
308311
return errors.Wrap(err, "installMinio")
309312
}
@@ -575,19 +578,27 @@ func installOpenfaas(scaleToZero, ingressOperator bool) error {
575578
}
576579

577580
func getS3Credentials() (string, string, error) {
578-
args := []string{"get", "secret", "-n", "openfaas-fn", "s3-access-key", "-o jsonpath='{.data.s3-access-key}'"}
581+
args := []string{"get", "secret", "-n", "openfaas-fn", "s3-access-key", "-o", "jsonpath={.data.s3-access-key}"}
579582
res, err := k8s.KubectlTask(args...)
580583
if err != nil {
581584
return "", "", err
582585
}
586+
if res.ExitCode != 0 {
587+
return "", "", fmt.Errorf("error getting s3 secret %s / %s", res.Stderr, res.Stdout)
588+
}
589+
583590
decoded, _ := b64.StdEncoding.DecodeString(res.Stdout)
584591
accessKey := decoded
585592

586-
args = []string{"get", "secret", "-n", "openfaas-fn", "s3-secret-key", "-o jsonpath='{.data.s3-secret-key}'"}
593+
args = []string{"get", "secret", "-n", "openfaas-fn", "s3-secret-key", "-o", "jsonpath={.data.s3-secret-key}"}
587594
res, err = k8s.KubectlTask(args...)
588595
if err != nil {
589596
return "", "", err
590597
}
598+
if res.ExitCode != 0 {
599+
return "", "", fmt.Errorf("error getting s3 secret %s / %s", res.Stderr, res.Stdout)
600+
}
601+
591602
decoded, _ = b64.StdEncoding.DecodeString(res.Stdout)
592603
secretKey := decoded
593604

@@ -606,8 +617,8 @@ func installMinio(accessKey, secretKey string) error {
606617
"--set service.port=9000",
607618
"--set service.type=ClusterIP",
608619
"--set resources.requests.memory=512Mi",
609-
"--secret-key=" + secretKey,
610620
"--access-key=" + accessKey,
621+
"--secret-key=" + secretKey,
611622
"--wait",
612623
}
613624

0 commit comments

Comments
 (0)