kubernetes/kops

`kops env` should show up current configuration and environment settings

Opened this issue · 2 comments

/kind feature

1. Describe IN DETAIL the feature/behavior/change you would like to see.

I would like to have a command such as kops env or kops config that would show up all the configuration environment variables used by kops.

2. Feel free to provide a design supporting your feature request.

I was thinking about leveraging viper to be sure to catch all configurations options.

package main

import (
	"context"
	"fmt"
	"github.com/spf13/cobra"
	"github.com/spf13/viper"
	"io"
	"k8s.io/kops/cmd/kops/util"
	"k8s.io/kops/pkg/commands/commandutils"
	"k8s.io/kubectl/pkg/util/i18n"
)

func NewCmdEnv(f *util.Factory, out io.Writer) *cobra.Command {
	cmd := &cobra.Command{
		Use:   "env",
		Short: i18n.T(`Get all environment variables.`),
		RunE: func(cmd *cobra.Command, args []string) error {
			return RunEnv(cmd.Context(), f, out)
		},
	}

	return cmd
}

func RunEnv(ctx context.Context, f commandutils.Factory, out io.Writer) error {
	viper.AllSettings()
	for k, v := range viper.AllSettings() {
		fmt.Fprintf(out, "%s: %s\n", k, v)
	}
	return nil
}

What do you think of it? Is there a different configuration/settings store that I could use and iterate over?

Related to #1764

In complement to this function I would like to have an env package that would bind all the environment variables used across kops. This binding function should be called as early as possible to ensure that we are able to access the string using viper.GetString.

/kind office-hours