Skip to content

Commit

Permalink
Disable persistence for mongodb, and add flag
Browse files Browse the repository at this point in the history
This doesn't work on KinD, but works OK on k3s and managed k8s.

Signed-off-by: Alex Ellis (OpenFaaS Ltd) <[email protected]>
  • Loading branch information
alexellis committed Feb 12, 2020
1 parent 812703b commit 248bc6e
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 12 deletions.
2 changes: 1 addition & 1 deletion cmd/apps/crossplane_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ schedule workloads to any Kubernetes cluster`,
}

if applyRes.ExitCode > 0 {
return fmt.Errorf("Error applying templated YAML files, error: %s", applyRes.Stderr)
return fmt.Errorf("error applying templated YAML files, error: %s", applyRes.Stderr)
}
}

Expand Down
4 changes: 2 additions & 2 deletions cmd/apps/inletsoperator_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func MakeInstallInletsOperator() *cobra.Command {
if len(res.Stderr) > 0 && strings.Contains(res.Stderr, "AlreadyExists") {
fmt.Println("[Warning] secret inlets-access-key already exists and will be used.")
} else if len(res.Stderr) > 0 {
return fmt.Errorf("Error from kubectl\n%q", res.Stderr)
return fmt.Errorf("error from kubectl\n%q", res.Stderr)
} else if err != nil {
return err
}
Expand Down Expand Up @@ -172,7 +172,7 @@ func MakeInstallInletsOperator() *cobra.Command {
}

if applyRes.ExitCode > 0 {
return fmt.Errorf("Error applying templated YAML files, error: %s", applyRes.Stderr)
return fmt.Errorf("error applying templated YAML files, error: %s", applyRes.Stderr)
}
}
fmt.Println(inletsOperatorPostInstallMsg)
Expand Down
2 changes: 1 addition & 1 deletion cmd/apps/metricsserver_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func MakeInstallMetricsServer() *cobra.Command {
return applyErr
}
if applyRes.ExitCode > 0 {
return fmt.Errorf("Error applying templated YAML files, error: %s", applyRes.Stderr)
return fmt.Errorf("error applying templated YAML files, error: %s", applyRes.Stderr)
}

}
Expand Down
18 changes: 13 additions & 5 deletions cmd/apps/mongodb_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"log"
"os"
"path"
"strconv"

"github.com/alexellis/k3sup/pkg"
"github.com/alexellis/k3sup/pkg/config"
Expand All @@ -25,6 +26,7 @@ func MakeInstallMongoDB() *cobra.Command {

command.Flags().StringArray("set", []string{},
"Use custom flags or override existing flags \n(example --set=mongodbUsername=admin)")
command.Flags().Bool("persistence", false, "Create and bind a persistent volume, not recommended for development")

command.RunE = func(command *cobra.Command, args []string) error {

Expand Down Expand Up @@ -54,6 +56,8 @@ func MakeInstallMongoDB() *cobra.Command {

helm3 := true

persistence, _ := command.Flags().GetBool("persistence")

_, err = helm.TryDownloadHelm(userPath, clientArch, clientOS, helm3)
if err != nil {
return err
Expand Down Expand Up @@ -83,6 +87,8 @@ func MakeInstallMongoDB() *cobra.Command {

overrides := map[string]string{}

overrides["persistence.enabled"] = strconv.FormatBool(persistence)

outputPath := path.Join(chartPath, "mongodb")

customFlags, err := command.Flags().GetStringArray("set")
Expand Down Expand Up @@ -111,19 +117,21 @@ const mongoDBPostInstallMsg = `=================================================
"\n\n" + pkg.ThanksForUsing

var MongoDBInfoMsg = `
MongoDB can be accessed via port 27017 on the following DNS name from within your cluster:
# MongoDB can be accessed via port 27017 on the following DNS name from within your cluster:
mongodb.{{namespace}}.svc.cluster.local
To get the root password run:
# To get the root password run:
export MONGODB_ROOT_PASSWORD=$(kubectl get secret --namespace {{namespace}} mongodb -o jsonpath="{.data.mongodb-root-password}" | base64 --decode)
To connect to your database run the following command:
# To connect to your database run the following command:
kubectl run --namespace {{namespace}} mongodb-client --rm --tty -i --restart='Never' --image bitnami/mongodb --command -- mongo admin --host mongodb --authenticationDatabase admin -u root -p $MONGODB_ROOT_PASSWORD
To connect to your database from outside the cluster execute the following commands:
# To connect to your database from outside the cluster execute the following commands:
kubectl port-forward --namespace {{namespace}} svc/mongodb 27017:27017 &
mongo --host 127.0.0.1 --authenticationDatabase admin -p $MONGODB_ROOT_PASSWORD`
mongo --host 127.0.0.1 --authenticationDatabase admin -p $MONGODB_ROOT_PASSWORD
# More on GitHub : https://github.com/helm/charts/tree/master/stable/mongodb`
2 changes: 1 addition & 1 deletion cmd/apps/openfaas_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ func MakeInstallOpenFaaS() *cobra.Command {
}

if applyRes.ExitCode > 0 {
return fmt.Errorf("Error applying templated YAML files, error: %s", applyRes.Stderr)
return fmt.Errorf("error applying templated YAML files, error: %s", applyRes.Stderr)
}
}

Expand Down
4 changes: 2 additions & 2 deletions cmd/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ func MakeInstall() *cobra.Command {
res, err := operator.Execute(installK3scommand)

if err != nil {
return fmt.Errorf("Error received processing command: %s", err)
return fmt.Errorf("error received processing command: %s", err)
}

fmt.Printf("Result: %s %s\n", string(res.StdOut), string(res.StdErr))
Expand Down Expand Up @@ -190,7 +190,7 @@ func obtainKubeconfig(operator operator.CommandOperator, getConfigcommand, ip, c
res, err := operator.Execute(getConfigcommand)

if err != nil {
return fmt.Errorf("Error received processing command: %s", err)
return fmt.Errorf("error received processing command: %s", err)
}

fmt.Printf("Result: %s %s\n", string(res.StdOut), string(res.StdErr))
Expand Down

0 comments on commit 248bc6e

Please sign in to comment.