Skip to content

Commit

Permalink
adopting string values for bool for use in yaml (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jared Edwards authored Feb 15, 2024
1 parent 3c094ae commit dd5720f
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 13 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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"
2 changes: 1 addition & 1 deletion cmd/createSecret.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion cmd/syncEcrToken.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
6 changes: 3 additions & 3 deletions cmd/waitFor.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type WaitForCmdOptions struct {
Name string
Label string
Timeout int64
KubeInClusterConfig bool
KubeInClusterConfig string
}

var waitForCmdOptions *WaitForCmdOptions = &WaitForCmdOptions{}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions internal/kubernetes/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
8 changes: 4 additions & 4 deletions internal/kubernetes/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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{})
Expand All @@ -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{})
Expand All @@ -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{})
Expand Down
4 changes: 2 additions & 2 deletions internal/kubernetes/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit dd5720f

Please sign in to comment.