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

Commit

Permalink
pkg/components/util: make UninstallComponent take kubeconfig content
Browse files Browse the repository at this point in the history
So we don't necesserily need a file on file system to perfrom this
action, which is needed to resolve #608.

Signed-off-by: Mateusz Gozdek <mateusz@kinvolk.io>
  • Loading branch information
invidian committed Jun 16, 2020
1 parent c3e1e16 commit 795b4c6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 16 deletions.
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 (
"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 @@ -137,7 +137,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 @@ -152,12 +152,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 @@ -189,13 +184,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

0 comments on commit 795b4c6

Please sign in to comment.