configmap

package
v0.82.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 27, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Cmd = &cobra.Command{
	Use:     "configmap",
	Short:   "Get data from ConfigMap",
	Aliases: []string{"cm"},
	Args:    cobra.NoArgs,
	Run: func(c *cobra.Command, args []string) {
		clientset, defaultNamespace, _ := k8s.KubernetesClient()

		namespace := defaultNamespace
		if CmdFlagNamespace != "" {
			namespace = CmdFlagNamespace
		}

		configmapClient := clientset.CoreV1().ConfigMaps(namespace)

		configmap, err := configmapClient.Get(context.TODO(), CmdFlagName, metav1.GetOptions{})
		if err != nil {
			log.Fatal(err)
		}

		if CmdFlagKey != "" {
			if FlagJson {
				outJson, err := json.Marshal(string(configmap.Data[CmdFlagKey]))
				if err != nil {
					panic(err)
				}
				fmt.Println(string(outJson))
			} else {
				fmt.Println(string(configmap.Data[CmdFlagKey]))
			}
		} else {
			if FlagJson {
				out := make(map[string]string)
				for key, val := range configmap.Data {
					out[key] = string(val)
				}
				outJson, err := json.Marshal(out)
				if err != nil {
					panic(err)
				}
				fmt.Println(string(outJson))
			} else {
				for key, val := range configmap.Data {
					fmt.Printf("KEY:   %s\nVALUE: %s\n---\n", key, val)
				}
			}
		}
	},
}
View Source
var CmdFlagKey string
View Source
var CmdFlagName string
View Source
var CmdFlagNamespace string
View Source
var FlagJson bool

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL