Skip to content

Commit

Permalink
feat: provider: read environment variables
Browse files Browse the repository at this point in the history
  • Loading branch information
boz committed Jun 26, 2020
1 parent 50d68fe commit 720ca6d
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions provider/cmd/run.go
Expand Up @@ -2,6 +2,8 @@ package cmd

import (
"context"
"errors"
"fmt"
"os"

ccontext "github.com/cosmos/cosmos-sdk/client/context"
Expand Down Expand Up @@ -34,6 +36,10 @@ const (
flagGatewayListenAddress = "gateway-listen-address"
)

var (
errInvalidConfig = errors.New("Invalid configuration")
)

func runCmd(cdc *codec.Codec) *cobra.Command {
cmd := &cobra.Command{
Use: "run",
Expand All @@ -46,7 +52,11 @@ func runCmd(cdc *codec.Codec) *cobra.Command {
}

cmd.Flags().Bool(flagClusterK8s, false, "Use Kubernetes cluster")
viper.BindPFlag(flagClusterK8s, cmd.Flags().Lookup(flagClusterK8s))

cmd.Flags().String(flagK8sManifestNS, "lease", "Cluster manifest namespace")
viper.BindPFlag(flagK8sManifestNS, cmd.Flags().Lookup(flagK8sManifestNS))

cmd.Flags().String(flagGatewayListenAddress, "0.0.0.0:8080", "Gateway listen address")
viper.BindPFlag(flagGatewayListenAddress, cmd.Flags().Lookup(flagGatewayListenAddress))

Expand Down Expand Up @@ -141,14 +151,14 @@ func openLogger() log.Logger {
})
}

func createClusterClient(log log.Logger, cmd *cobra.Command, host string) (cluster.Client, error) {
if val, _ := cmd.Flags().GetBool(flagClusterK8s); !val {
func createClusterClient(log log.Logger, _ *cobra.Command, host string) (cluster.Client, error) {
if !viper.GetBool(flagClusterK8s) {
// Condition that there is no Kubernetes API to work with.
return cluster.NullClient(), nil
}
ns, err := cmd.Flags().GetString(flagK8sManifestNS)
if err != nil {
return nil, err
ns := viper.GetString(flagK8sManifestNS)
if ns == "" {
return nil, fmt.Errorf("%w: --%s required", errInvalidConfig, flagK8sManifestNS)
}
return kube.NewClient(log, host, ns)
}

0 comments on commit 720ca6d

Please sign in to comment.