diff --git a/README.md b/README.md index 4893f7b..9622ed3 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ # kubernetes-toolkit An application used to help facilitate operations within a Kubernetes clusters. + +go run . --namespace kubefirst --name kubefirst-initial-secretssss --use-kubeconfig-in-cluster="false" \ No newline at end of file diff --git a/cmd/createSecret.go b/cmd/createSecret.go index 6435e81..dbada27 100644 --- a/cmd/createSecret.go +++ b/cmd/createSecret.go @@ -25,7 +25,7 @@ var createK8sSecret = &cobra.Command{ func init() { rootCmd.AddCommand(createK8sSecret) - createK8sSecret.PersistentFlags().BoolVar(&CreateK8sSecretCmdOptions.KubeInClusterConfig, "use-kubeconfig-in-cluster", true, "Kube config type - in-cluster (default), set to false to use local") + createK8sSecret.PersistentFlags().StringVar(&CreateK8sSecretCmdOptions.KubeInClusterConfig, "use-kubeconfig-in-cluster", "true", "Kube config type - in-cluster (default), set to false to use local") createK8sSecret.Flags().StringVar(&CreateK8sSecretCmdOptions.Namespace, "namespace", CreateK8sSecretCmdOptions.Namespace, "Kubernetes Namespace to create secret in (required)") err := createK8sSecret.MarkFlagRequired("namespace") diff --git a/cmd/syncEcrToken.go b/cmd/syncEcrToken.go index e81eafd..57e810b 100644 --- a/cmd/syncEcrToken.go +++ b/cmd/syncEcrToken.go @@ -25,7 +25,7 @@ var syncEcrTokenCmd = &cobra.Command{ func init() { rootCmd.AddCommand(syncEcrTokenCmd) - syncEcrTokenCmd.PersistentFlags().BoolVar(&syncEcrCmdOptions.KubeInClusterConfig, "use-kubeconfig-in-cluster", true, "Kube config type - in-cluster (default), set to false to use local") + syncEcrTokenCmd.PersistentFlags().StringVar(&syncEcrCmdOptions.KubeInClusterConfig, "use-kubeconfig-in-cluster", "true", "Kube config type - in-cluster (default), set to false to use local") syncEcrTokenCmd.Flags().StringVar(&syncEcrCmdOptions.Namespace, "namespace", syncEcrCmdOptions.Namespace, "Kubernetes Namespace to create/sync in (required)") err := syncEcrTokenCmd.MarkFlagRequired("namespace") diff --git a/cmd/waitFor.go b/cmd/waitFor.go index 080c7a6..ce69669 100644 --- a/cmd/waitFor.go +++ b/cmd/waitFor.go @@ -22,7 +22,7 @@ type WaitForCmdOptions struct { Name string Label string Timeout int64 - KubeInClusterConfig bool + KubeInClusterConfig string } var waitForCmdOptions *WaitForCmdOptions = &WaitForCmdOptions{} @@ -174,7 +174,7 @@ var waitForVaultUnsealCmd = &cobra.Command{ Run: func(cmd *cobra.Command, args []string) { for { - vaultRootTokenLookup, err := kubernetes.ReadSecretV2(true, "vault", "vault-unseal-secret") + vaultRootTokenLookup, err := kubernetes.ReadSecretV2("true", "vault", "vault-unseal-secret") if err != nil { fmt.Println(err) time.Sleep(5 * time.Second) @@ -234,7 +234,7 @@ var waitForCertificateCmd = &cobra.Command{ func init() { rootCmd.AddCommand(waitForCmd) - waitForCmd.PersistentFlags().BoolVar(&waitForCmdOptions.KubeInClusterConfig, "use-kubeconfig-in-cluster", true, "Kube config type - in-cluster (default), set to false to use local") + waitForCmd.PersistentFlags().StringVar(&waitForCmdOptions.KubeInClusterConfig, "use-kubeconfig-in-cluster", "true", "Kube config type - in-cluster (default), set to false to use local") // waitForDeploymentCmd waitForCmd.AddCommand(waitForDeploymentCmd) diff --git a/internal/kubernetes/config.go b/internal/kubernetes/config.go index a3e4071..e071240 100644 --- a/internal/kubernetes/config.go +++ b/internal/kubernetes/config.go @@ -16,11 +16,11 @@ import ( var fs afero.Fs = afero.NewOsFs() // CreateKubeConfig -func CreateKubeConfig(inCluster bool) (*rest.Config, kubernetes.Clientset, string) { +func CreateKubeConfig(inCluster string) (*rest.Config, kubernetes.Clientset, string) { // inCluster is either true or false // If it's true, we pull Kubernetes API authentication from Pod SA // If it's false, we use local machine settings - if inCluster { + if inCluster == "true" { config, err := rest.InClusterConfig() if err != nil { panic(err.Error()) diff --git a/internal/kubernetes/resources.go b/internal/kubernetes/resources.go index b5ab89d..7d725bb 100644 --- a/internal/kubernetes/resources.go +++ b/internal/kubernetes/resources.go @@ -10,7 +10,7 @@ import ( ) // CreateSecretV2 -func CreateSecretV2(inCluster bool, secret *v1.Secret) error { +func CreateSecretV2(inCluster string, secret *v1.Secret) error { _, clientset, _ := CreateKubeConfig(inCluster) _, err := clientset.CoreV1().Secrets(secret.Namespace).Create( @@ -26,7 +26,7 @@ func CreateSecretV2(inCluster bool, secret *v1.Secret) error { } // ReadConfigMapV2 -func ReadConfigMapV2(inCluster bool, namespace string, configMapName string) (map[string]string, error) { +func ReadConfigMapV2(inCluster string, namespace string, configMapName string) (map[string]string, error) { _, clientset, _ := CreateKubeConfig(inCluster) configMap, err := clientset.CoreV1().ConfigMaps(namespace).Get(context.Background(), configMapName, metav1.GetOptions{}) @@ -43,7 +43,7 @@ func ReadConfigMapV2(inCluster bool, namespace string, configMapName string) (ma } // ReadSecretV2 -func ReadSecretV2(inCluster bool, namespace string, secretName string) (map[string]string, error) { +func ReadSecretV2(inCluster string, namespace string, secretName string) (map[string]string, error) { _, clientset, _ := CreateKubeConfig(inCluster) secret, err := clientset.CoreV1().Secrets(namespace).Get(context.Background(), secretName, metav1.GetOptions{}) @@ -60,7 +60,7 @@ func ReadSecretV2(inCluster bool, namespace string, secretName string) (map[stri } // UpdateConfigMapV2 -func UpdateConfigMapV2(inCluster bool, namespace, configMapName string, key string, value string) error { +func UpdateConfigMapV2(inCluster string, namespace, configMapName string, key string, value string) error { _, clientset, _ := CreateKubeConfig(inCluster) configMap, err := clientset.CoreV1().ConfigMaps(namespace).Get(context.Background(), configMapName, metav1.GetOptions{}) diff --git a/internal/kubernetes/types.go b/internal/kubernetes/types.go index 75f06cb..5ad6309 100644 --- a/internal/kubernetes/types.go +++ b/internal/kubernetes/types.go @@ -15,11 +15,11 @@ type SyncEcrCmdOptions struct { Namespace string Region string RegistryURL string - KubeInClusterConfig bool + KubeInClusterConfig string } type CreateK8sSecretCmdOptions struct { Namespace string Name string - KubeInClusterConfig bool + KubeInClusterConfig string }