@@ -27,7 +27,7 @@ import (
2727const eksConfigDir = "/etc/eks"
2828
2929type (
30- CNIUninstall func () error
30+ CNIUninstall func (* zap. Logger ) error
3131)
3232
3333type Uninstaller struct {
@@ -53,7 +53,7 @@ func (u *Uninstaller) Run(ctx context.Context) error {
5353
5454 u .Logger .Info ("Finished uninstallation tasks..." )
5555
56- return tracker .Clear ()
56+ return tracker .Clear (u . Logger )
5757}
5858
5959func (u * Uninstaller ) uninstallDaemons (ctx context.Context ) error {
@@ -62,9 +62,27 @@ func (u *Uninstaller) uninstallDaemons(ctx context.Context) error {
6262 if err := u .DaemonManager .StopDaemon (kubelet .KubeletDaemonName ); err != nil {
6363 return err
6464 }
65- if err := kubelet .Uninstall (kubelet.UninstallOptions {}); err != nil {
65+
66+ // Log the kubelet directories that will be removed
67+ kubeletPaths := []string {
68+ "/usr/bin/kubelet" ,
69+ "/etc/systemd/system/kubelet.service" ,
70+ "/etc/kubernetes/kubelet/kubeconfig" ,
71+ "/etc/kubernetes" ,
72+ "/etc/kubernetes/kubelet/pki/kubelet-server-current.pem" ,
73+ }
74+
75+ for _ , kubeletPath := range kubeletPaths {
76+ if _ , err := os .Stat (kubeletPath ); err == nil {
77+ u .Logger .Info ("Removing kubelet path" , zap .String ("path" , kubeletPath ))
78+ }
79+ }
80+
81+ if err := kubelet .Uninstall (kubelet.UninstallOptions {Logger : u .Logger }); err != nil {
82+ u .Logger .Error ("Failed to uninstall kubelet" , zap .Error (err ))
6683 return err
6784 }
85+ u .Logger .Info ("Successfully uninstalled kubelet" )
6886 }
6987 if u .Artifacts .Ssm {
7088 u .Logger .Info ("Stopping SSM daemon..." )
@@ -114,7 +132,7 @@ func (u *Uninstaller) uninstallDaemons(ctx context.Context) error {
114132 if err := u .DaemonManager .StopDaemon (containerd .ContainerdDaemonName ); err != nil {
115133 return err
116134 }
117- if err := containerd .Uninstall (ctx , u .PackageManager ); err != nil {
135+ if err := containerd .Uninstall (ctx , u .PackageManager , u . Logger ); err != nil {
118136 return err
119137 }
120138 }
@@ -124,31 +142,39 @@ func (u *Uninstaller) uninstallDaemons(ctx context.Context) error {
124142func (u * Uninstaller ) uninstallBinaries (ctx context.Context ) error {
125143 if u .Artifacts .Kubectl {
126144 u .Logger .Info ("Uninstalling kubectl..." )
127- if err := kubectl .Uninstall (); err != nil {
145+ if err := kubectl .Uninstall (u . Logger ); err != nil {
128146 return err
129147 }
130148 }
131149 if u .Artifacts .CniPlugins {
132150 u .Logger .Info ("Uninstalling cni-plugins..." )
133- if err := u .CNIUninstall (); err != nil {
151+ // Use the existing CNI uninstall function but add our own logging
152+ if _ , err := os .Stat ("/opt/cni" ); os .IsNotExist (err ) {
153+ u .Logger .Info ("CNI directory does not exist, skipping removal" , zap .String ("path" , "/opt/cni" ))
154+ } else if err != nil {
155+ u .Logger .Error ("Error checking CNI directory status" , zap .String ("path" , "/opt/cni" ), zap .Error (err ))
134156 return err
157+ } else {
158+ if err := u .CNIUninstall (u .Logger ); err != nil {
159+ return err
160+ }
135161 }
136162 }
137163 if u .Artifacts .IamAuthenticator {
138164 u .Logger .Info ("Uninstalling IAM authenticator..." )
139- if err := iamauthenticator .Uninstall (); err != nil {
165+ if err := iamauthenticator .Uninstall (u . Logger ); err != nil {
140166 return err
141167 }
142168 }
143169 if u .Artifacts .IamRolesAnywhere {
144170 u .Logger .Info ("Uninstalling AWS signing helper..." )
145- if err := iamrolesanywhere .Uninstall (); err != nil {
171+ if err := iamrolesanywhere .Uninstall (u . Logger ); err != nil {
146172 return err
147173 }
148174 }
149175 if u .Artifacts .ImageCredentialProvider {
150176 u .Logger .Info ("Uninstalling image credential provider..." )
151- if err := imagecredentialprovider .Uninstall (); err != nil {
177+ if err := imagecredentialprovider .Uninstall (u . Logger ); err != nil {
152178 return err
153179 }
154180 }
@@ -167,8 +193,37 @@ func (u *Uninstaller) cleanup() error {
167193 return err
168194 }
169195
170- if err := os .RemoveAll (eksConfigDir ); err != nil {
196+ // Log and remove EKS config directory
197+ if _ , err := os .Stat (eksConfigDir ); os .IsNotExist (err ) {
198+ u .Logger .Info ("EKS config directory does not exist, skipping removal" , zap .String ("path" , eksConfigDir ))
199+ } else if err != nil {
200+ u .Logger .Error ("Error checking EKS config directory status" , zap .String ("path" , eksConfigDir ), zap .Error (err ))
171201 return err
202+ } else {
203+
204+ passwdFile := "/etc/passwd"
205+ if _ , err := os .Stat (passwdFile ); os .IsNotExist (err ) {
206+ u .Logger .Warn ("Before /etc/passwd file does not exist" , zap .String ("path" , passwdFile ))
207+ } else if err != nil {
208+ u .Logger .Error ("Before Error checking /etc/passwd file status" , zap .String ("path" , passwdFile ), zap .Error (err ))
209+ } else {
210+ u .Logger .Info ("Before /etc/passwd file is present" , zap .String ("path" , passwdFile ))
211+ }
212+
213+ u .Logger .Info ("Removing EKS config directory" , zap .String ("path" , eksConfigDir ))
214+ if err := os .RemoveAll (eksConfigDir ); err != nil {
215+ u .Logger .Error ("Failed to remove EKS config directory" , zap .String ("path" , eksConfigDir ), zap .Error (err ))
216+ return err
217+ }
218+ u .Logger .Info ("Successfully removed EKS config directory" , zap .String ("path" , eksConfigDir ))
219+
220+ if _ , err := os .Stat (passwdFile ); os .IsNotExist (err ) {
221+ u .Logger .Warn ("After /etc/passwd file does not exist" , zap .String ("path" , passwdFile ))
222+ } else if err != nil {
223+ u .Logger .Error ("After Error checking /etc/passwd file status" , zap .String ("path" , passwdFile ), zap .Error (err ))
224+ } else {
225+ u .Logger .Info ("After /etc/passwd file is present" , zap .String ("path" , passwdFile ))
226+ }
172227 }
173228
174229 return nil
0 commit comments