Skip to content
This repository has been archived by the owner on Jun 29, 2022. It is now read-only.

Pass kubeconfig content around rather than file path #631

Merged
merged 9 commits into from
Aug 3, 2020
10 changes: 8 additions & 2 deletions cli/cmd/component-delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package cmd

import (
invidian marked this conversation as resolved.
Show resolved Hide resolved
"fmt"
"io/ioutil"
"strings"

log "github.com/sirupsen/logrus"
Expand Down Expand Up @@ -91,12 +92,17 @@ func runDelete(cmd *cobra.Command, args []string) {
contextLogger.Fatalf("Error in finding kubeconfig file: %s", err)
}

if err := deleteComponents(kubeconfig, componentsObjects...); err != nil {
kubeconfigContent, err := ioutil.ReadFile(kubeconfig) // #nosec G304
if err != nil {
contextLogger.Fatalf("Failed to read kubeconfig file: %q: %v", kubeconfig, err)
}

if err := deleteComponents(kubeconfigContent, componentsObjects...); err != nil {
contextLogger.Fatal(err)
}
}

func deleteComponents(kubeconfig string, componentObjects ...components.Component) error {
func deleteComponents(kubeconfig []byte, componentObjects ...components.Component) error {
for _, compObj := range componentObjects {
fmt.Printf("Deleting component '%s'...\n", compObj.Metadata().Name)

Expand Down
18 changes: 4 additions & 14 deletions pkg/components/util/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ func ReleaseExists(actionConfig action.Configuration, name string) (bool, error)
}

// UninstallComponent uninstalls a component and optionally removes it's namespace.
func UninstallComponent(c components.Component, kubeconfig string, deleteNSBool bool) error {
func UninstallComponent(c components.Component, kubeconfig []byte, deleteNSBool bool) error {
name := c.Metadata().Name
if name == "" {
// This should never fail in real user usage, if this does that means the component was not
Expand All @@ -206,12 +206,7 @@ func UninstallComponent(c components.Component, kubeconfig string, deleteNSBool
panic(fmt.Errorf("component %s namespace is empty", name))
}

kubeconfigContent, err := ioutil.ReadFile(kubeconfig) // #nosec G304
if err != nil {
return fmt.Errorf("failed to read kubeconfig file %q: %v", kubeconfig, err)
}

cfg, err := HelmActionConfig(ns, kubeconfigContent)
cfg, err := HelmActionConfig(ns, kubeconfig)
if err != nil {
return fmt.Errorf("failed preparing helm client: %w", err)
}
Expand Down Expand Up @@ -243,13 +238,8 @@ func UninstallComponent(c components.Component, kubeconfig string, deleteNSBool
return nil
}

func deleteNS(ns string, kubeconfig string) error {
kubeconfigContent, err := ioutil.ReadFile(kubeconfig) // #nosec G304
if err != nil {
return fmt.Errorf("failed to read kubeconfig file: %v", err)
}

cs, err := k8sutil.NewClientset(kubeconfigContent)
func deleteNS(ns string, kubeconfig []byte) error {
cs, err := k8sutil.NewClientset(kubeconfig)
if err != nil {
return err
}
Expand Down