Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kops env should show up current configuration and environment settings #16465

Open
remyleone opened this issue Apr 17, 2024 · 2 comments
Open
Labels
kind/feature Categorizes issue or PR as related to a new feature. kind/office-hours

Comments

@remyleone
Copy link
Contributor

/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

@k8s-ci-robot k8s-ci-robot added the kind/feature Categorizes issue or PR as related to a new feature. label Apr 17, 2024
@remyleone remyleone changed the title Show up current configuration kops env should show up current configuration and environment settings Apr 17, 2024
@remyleone
Copy link
Contributor Author

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.

@hakman
Copy link
Member

hakman commented May 10, 2024

/kind office-hours

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/feature Categorizes issue or PR as related to a new feature. kind/office-hours
Projects
None yet
Development

No branches or pull requests

3 participants