Skip to content

Commit

Permalink
Merge pull request #177 from utkarsh-pro/utkarsh-pro/fix/istio-instal…
Browse files Browse the repository at this point in the history
…l-process

Fix istio install and uninstall process
  • Loading branch information
leecalcote authored Dec 24, 2020
2 parents 123e1d0 + 6088299 commit 3d335a1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 22 deletions.
10 changes: 5 additions & 5 deletions istio/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ var (
// when an invalid mesh config is found
ErrMeshConfigCode = "istio_test_code"

// ErrFetchManifestCode represents the errors which are generated
// ErrRunIstioCtlCmdCode represents the errors which are generated
// during fetch manifest process
ErrFetchManifestCode = "istio_test_code"
ErrRunIstioCtlCmdCode = "istio_test_code"

// ErrDownloadBinaryCode represents the errors which are generated
// during binary download process
Expand Down Expand Up @@ -99,9 +99,9 @@ func ErrMeshConfig(err error) error {
return errors.NewDefault(ErrMeshConfigCode, fmt.Sprintf("Error configuration mesh: %s", err.Error()))
}

// ErrFetchManifest is the error for mesh port forward
func ErrFetchManifest(err error, des string) error {
return errors.NewDefault(ErrFetchManifestCode, fmt.Sprintf("Error fetching mesh manifest: %s", des))
// ErrRunIstioCtlCmd is the error for mesh port forward
func ErrRunIstioCtlCmd(err error, des string) error {
return errors.NewDefault(ErrRunIstioCtlCmdCode, fmt.Sprintf("Error running istioctl command: %s", des))
}

// ErrDownloadBinary is the error while downloading istio binary
Expand Down
22 changes: 5 additions & 17 deletions istio/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,6 @@ func (istio *Istio) installIstio(del bool, version, namespace string) (string, e
istio.Log.Debug(fmt.Sprintf("Requested action is delete: %v", del))
istio.Log.Debug(fmt.Sprintf("Requested action is in namespace: %s", namespace))

// Overiding the namespace to be empty
// This is intentional as deploying istio on custom namespace
// is a bit tricky
namespace = ""
istio.Log.Debug(fmt.Sprintf("Overidden namespace: %s", namespace))

st := status.Installing

if del {
Expand All @@ -43,13 +37,7 @@ func (istio *Istio) installIstio(del bool, version, namespace string) (string, e
return st, ErrMeshConfig(err)
}

manifest, err := istio.fetchManifest(version, del)
if err != nil {
istio.Log.Error(ErrInstallIstio(err))
return st, ErrInstallIstio(err)
}

err = istio.applyManifest([]byte(manifest), del, namespace)
err = istio.runIstioCtlCmd(version, del)
if err != nil {
istio.Log.Error(ErrInstallIstio(err))
return st, ErrInstallIstio(err)
Expand All @@ -61,15 +49,15 @@ func (istio *Istio) installIstio(del bool, version, namespace string) (string, e
return status.Installed, nil
}

func (istio *Istio) fetchManifest(version string, isDel bool) (string, error) {
func (istio *Istio) runIstioCtlCmd(version string, isDel bool) error {
var (
out bytes.Buffer
er bytes.Buffer
)

Executable, err := istio.getExecutable(version)
if err != nil {
return "", ErrFetchManifest(err, err.Error())
return ErrRunIstioCtlCmd(err, err.Error())
}
execCmd := []string{"install", "--set", "profile=demo", "-y"}
if isDel {
Expand All @@ -83,10 +71,10 @@ func (istio *Istio) fetchManifest(version string, isDel bool) (string, error) {
command.Stderr = &er
err = command.Run()
if err != nil {
return "", ErrFetchManifest(err, er.String())
return ErrRunIstioCtlCmd(err, er.String())
}

return out.String(), nil
return nil
}

func (istio *Istio) applyManifest(contents []byte, isDel bool, namespace string) error {
Expand Down

0 comments on commit 3d335a1

Please sign in to comment.