Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ require (
k8s.io/cri-api v0.33.2
k8s.io/kubectl v0.33.2
k8s.io/kubelet v0.33.2
k8s.io/mount-utils v0.33.2
sigs.k8s.io/controller-runtime v0.21.0
sigs.k8s.io/hydrophone v0.7.0
)
Expand All @@ -65,6 +66,7 @@ require (
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mitchellh/go-wordwrap v1.0.1 // indirect
github.com/moby/spdystream v0.5.0 // indirect
github.com/moby/sys/mountinfo v0.7.2 // indirect
github.com/moby/term v0.5.2 // indirect
github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00 // indirect
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f // indirect
Expand Down
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@ github.com/mitchellh/go-wordwrap v1.0.1 h1:TLuKupo69TCn6TQSyGxwI1EblZZEsQ0vMlAFQ
github.com/mitchellh/go-wordwrap v1.0.1/go.mod h1:R62XHJLzvMFRBbcrT7m7WgmE1eOyTSsCt+hzestvNj0=
github.com/moby/spdystream v0.5.0 h1:7r0J1Si3QO/kjRitvSLVVFUjxMEb/YLj6S9FF62JBCU=
github.com/moby/spdystream v0.5.0/go.mod h1:xBAYlnt/ay+11ShkdFKNAG7LsyK/tmNBVvVOwrfMgdI=
github.com/moby/sys/mountinfo v0.7.2 h1:1shs6aH5s4o5H2zQLn796ADW1wMrIwHsyJ2v9KouLrg=
github.com/moby/sys/mountinfo v0.7.2/go.mod h1:1YOa8w8Ih7uW0wALDUgT1dTTSBrZ+HiBLGws92L2RU4=
github.com/moby/term v0.5.2 h1:6qk3FJAFDs6i/q3W/pQ97SX192qKfZgGjCQqfCJkgzQ=
github.com/moby/term v0.5.2/go.mod h1:d3djjFCrjnB+fl8NJux+EJzu0msscUP+f8it8hPkFLc=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
Expand Down Expand Up @@ -266,6 +268,8 @@ golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8U
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.40.0 h1:r4x+VvoG5Fm+eJcxMaY8CQM7Lb0l1lsmjGBQ6s8BfKM=
golang.org/x/crypto v0.40.0/go.mod h1:Qr1vMER5WyS2dfPHAlsOj01wgLbsyWtFn/aY+5+ZdxY=
golang.org/x/exp v0.0.0-20241217172543-b2144cdd0a67 h1:1UoZQm6f0P/ZO0w1Ri+f+ifG/gXhegadRdwBIXEFWDo=
golang.org/x/exp v0.0.0-20241217172543-b2144cdd0a67/go.mod h1:qj5a5QZpwLU2NLQudwIN5koi3beDhSAlJwa67PuM98c=
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.26.0 h1:EGMPT//Ezu+ylkCijjPc+f4Aih7sZvaAr+O3EHBxvZg=
Expand Down Expand Up @@ -351,6 +355,8 @@ k8s.io/kubelet v0.33.2 h1:wxEau5/563oJb3j3KfrCKlNWWx35YlSgDLOYUBCQ0pg=
k8s.io/kubelet v0.33.2/go.mod h1:way8VCDTUMiX1HTOvJv7M3xS/xNysJI6qh7TOqMe5KM=
k8s.io/metrics v0.33.2 h1:gNCBmtnUMDMCRg9Ly5ehxP3OdKISMsOnh1vzk01iCgE=
k8s.io/metrics v0.33.2/go.mod h1:yxoAosKGRsZisv3BGekC5W6T1J8XSV+PoUEevACRv7c=
k8s.io/mount-utils v0.33.2 h1:mZAFhoGs/MwJziVlUpA072vqMhXRc0LGl/W3wybLP20=
k8s.io/mount-utils v0.33.2/go.mod h1:1JR4rKymg8B8bCPo618hpSAdrpO6XLh0Acqok/xVwPE=
k8s.io/utils v0.0.0-20250321185631-1f6e0b77f77e h1:KqK5c/ghOm8xkHYhlodbp6i6+r+ChV2vuAuVRdFbLro=
k8s.io/utils v0.0.0-20250321185631-1f6e0b77f77e/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
sigs.k8s.io/controller-runtime v0.21.0 h1:CYfjpEuicjUecRk+KAeyYh+ouUBn4llGyDYytIGcJS8=
Expand Down
4 changes: 3 additions & 1 deletion internal/artifact/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (
"strings"

"github.com/pkg/errors"

"github.com/aws/eks-hybrid/internal/system"
)

// DefaultDirPerms are the permissions assigned to a directory when an Install* func is called
Expand All @@ -21,7 +23,7 @@ const DefaultDirPerms = fs.ModeDir | 0o755
// InstallFile installs src to dst with perms permissions. It ensures any base paths exist
// before installing.
func InstallFile(dst string, src io.Reader, perms fs.FileMode) error {
if err := os.RemoveAll(dst); err != nil {
if err := system.SafeRemoveAll(dst, false, false); err != nil {
return err
}
if err := os.MkdirAll(path.Dir(dst), DefaultDirPerms); err != nil {
Expand Down
5 changes: 3 additions & 2 deletions internal/cleanup/cleanup.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package cleanup

import (
"fmt"
"os"
"path/filepath"
"strings"

"go.uber.org/zap"

"github.com/aws/eks-hybrid/internal/system"
)

// Directories to clean up when force flag is enabled
Expand Down Expand Up @@ -57,5 +58,5 @@ func (c *Force) Cleanup() error {

func (c *Force) removeDir(dir string) error {
c.logger.Info("Removing directory", zap.String("path", dir))
return os.RemoveAll(dir)
return system.SafeRemoveAll(dir, false, false)
}
4 changes: 2 additions & 2 deletions internal/cni/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ package cni

import (
"context"
"os"
"path/filepath"

"github.com/pkg/errors"
"go.uber.org/zap"

"github.com/aws/eks-hybrid/internal/artifact"
"github.com/aws/eks-hybrid/internal/system"
"github.com/aws/eks-hybrid/internal/tracker"
)

Expand Down Expand Up @@ -93,7 +93,7 @@ func downloadFileTo(ctx context.Context, opts InstallOptions) error {
}

func Uninstall() error {
return os.RemoveAll(rootDir)
return system.SafeRemoveAll(rootDir, false, false)
}

// Upgrade re-installs the cni-plugins available from the source
Expand Down
3 changes: 1 addition & 2 deletions internal/containerd/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package containerd
import (
"context"
"fmt"
"os"
"os/exec"
"time"

Expand Down Expand Up @@ -59,7 +58,7 @@ func Uninstall(ctx context.Context, source Source) error {
return errors.Wrap(err, "uninstalling containerd")
}

if err := os.RemoveAll(containerdConfigDir); err != nil {
if err := system.SafeRemoveAll(containerdConfigDir, false, false); err != nil {
return errors.Wrap(err, "removing containerd config files")
}
}
Expand Down
4 changes: 2 additions & 2 deletions internal/flows/uninstall.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package flows
import (
"context"
"fmt"
"os"
"time"

"github.com/aws/aws-sdk-go-v2/aws/retry"
Expand All @@ -21,6 +20,7 @@ import (
"github.com/aws/eks-hybrid/internal/kubelet"
"github.com/aws/eks-hybrid/internal/packagemanager"
"github.com/aws/eks-hybrid/internal/ssm"
"github.com/aws/eks-hybrid/internal/system"
"github.com/aws/eks-hybrid/internal/tracker"
)

Expand Down Expand Up @@ -167,7 +167,7 @@ func (u *Uninstaller) cleanup() error {
return err
}

if err := os.RemoveAll(eksConfigDir); err != nil {
if err := system.SafeRemoveAll(eksConfigDir, false, false); err != nil {
return err
}

Expand Down
4 changes: 2 additions & 2 deletions internal/iamauthenticator/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ package iamauthenticator

import (
"context"
"os"
"path/filepath"

"github.com/pkg/errors"
"go.uber.org/zap"

"github.com/aws/eks-hybrid/internal/artifact"
"github.com/aws/eks-hybrid/internal/system"
"github.com/aws/eks-hybrid/internal/tracker"
)

Expand Down Expand Up @@ -86,7 +86,7 @@ func downloadFileTo(ctx context.Context, opts InstallOptions) error {
}

func Uninstall() error {
return os.RemoveAll(IAMAuthenticatorBinPath)
return system.SafeRemoveAll(IAMAuthenticatorBinPath, false, false)
}

func Upgrade(ctx context.Context, src IAMAuthenticatorSource, log *zap.Logger) error {
Expand Down
8 changes: 4 additions & 4 deletions internal/iamrolesanywhere/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ package iamrolesanywhere

import (
"context"
"os"
"path"
"path/filepath"

"github.com/pkg/errors"
"go.uber.org/zap"

"github.com/aws/eks-hybrid/internal/artifact"
"github.com/aws/eks-hybrid/internal/system"
"github.com/aws/eks-hybrid/internal/tracker"
)

Expand Down Expand Up @@ -85,13 +85,13 @@ func downloadFileTo(ctx context.Context, opts InstallOptions) error {
}

func Uninstall() error {
if err := os.RemoveAll(SigningHelperServiceFilePath); err != nil {
if err := system.SafeRemoveAll(SigningHelperServiceFilePath, false, false); err != nil {
return err
}
if err := os.RemoveAll(path.Dir(EksHybridAwsCredentialsPath)); err != nil {
if err := system.SafeRemoveAll(path.Dir(EksHybridAwsCredentialsPath), false, false); err != nil {
return err
}
return os.RemoveAll(SigningHelperBinPath)
return system.SafeRemoveAll(SigningHelperBinPath, false, false)
}

func Upgrade(ctx context.Context, signingHelperSrc SigningHelperSource, log *zap.Logger) error {
Expand Down
4 changes: 2 additions & 2 deletions internal/imagecredentialprovider/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ package imagecredentialprovider

import (
"context"
"os"
"path"
"path/filepath"

"github.com/pkg/errors"
"go.uber.org/zap"

"github.com/aws/eks-hybrid/internal/artifact"
"github.com/aws/eks-hybrid/internal/system"
"github.com/aws/eks-hybrid/internal/tracker"
)

Expand Down Expand Up @@ -87,7 +87,7 @@ func downloadFileTo(ctx context.Context, opts InstallOptions) error {
}

func Uninstall() error {
return os.RemoveAll(path.Dir(BinPath))
return system.SafeRemoveAll(path.Dir(BinPath), false, false)
}

func Upgrade(ctx context.Context, src Source, log *zap.Logger) error {
Expand Down
4 changes: 2 additions & 2 deletions internal/kubectl/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ package kubectl

import (
"context"
"os"
"path/filepath"

"github.com/pkg/errors"
"go.uber.org/zap"

"github.com/aws/eks-hybrid/internal/artifact"
"github.com/aws/eks-hybrid/internal/system"
"github.com/aws/eks-hybrid/internal/tracker"
)

Expand Down Expand Up @@ -86,7 +86,7 @@ func downloadFileTo(ctx context.Context, opts InstallOptions) error {
}

func Uninstall() error {
return os.RemoveAll(BinPath)
return system.SafeRemoveAll(BinPath, false, false)
}

func Upgrade(ctx context.Context, src Source, log *zap.Logger) error {
Expand Down
3 changes: 2 additions & 1 deletion internal/kubelet/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"go.uber.org/zap"

"github.com/aws/eks-hybrid/internal/artifact"
"github.com/aws/eks-hybrid/internal/system"
"github.com/aws/eks-hybrid/internal/tracker"
)

Expand Down Expand Up @@ -128,7 +129,7 @@ func Uninstall(opts UninstallOptions) error {
}

for _, path := range pathsToRemove {
if err := os.RemoveAll(path); err != nil {
if err := system.SafeRemoveAll(path, false, false); err != nil {
allErrors = append(allErrors, err)
}
}
Expand Down
2 changes: 1 addition & 1 deletion internal/ssm/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func (s *ssm) PostLaunch() error {
return fmt.Errorf("creating path: %v", err)
}

err = os.RemoveAll(symlinkedAWSConfigPath)
err = system.SafeRemoveAll(symlinkedAWSConfigPath, false, false)
if err != nil && !os.IsNotExist(err) {
return fmt.Errorf("removing directory %s: %v", symlinkedAWSConfigPath, err)
}
Expand Down
5 changes: 3 additions & 2 deletions internal/ssm/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"go.uber.org/zap"

"github.com/aws/eks-hybrid/internal/artifact"
"github.com/aws/eks-hybrid/internal/system"
"github.com/aws/eks-hybrid/internal/tracker"
"github.com/aws/eks-hybrid/internal/util"
"github.com/aws/eks-hybrid/internal/util/cmd"
Expand Down Expand Up @@ -203,7 +204,7 @@ func Uninstall(ctx context.Context, opts UninstallOptions) error {
}

func removeFileOrDir(path, errorMessage string) error {
if err := os.RemoveAll(path); err != nil {
if err := system.SafeRemoveAll(path, false, false); err != nil {
return errors.Wrap(err, errorMessage)
}
return nil
Expand All @@ -224,7 +225,7 @@ func uninstallPreRegisterComponents(ctx context.Context, pkgSource PkgSource) er
if err := cmd.Retry(ctx, ssmPkg.UninstallCmd, 5*time.Second); err != nil {
return errors.Wrapf(err, "uninstalling ssm")
}
return os.RemoveAll(defaultInstallerPath)
return system.SafeRemoveAll(defaultInstallerPath, false, false)
}

func runInstallWithRetries(ctx context.Context, installerPath, region string) error {
Expand Down
Loading