@@ -600,6 +600,22 @@ func (s *sPodGuestInstance) getCreateParams() (jsonutils.JSONObject, error) {
600600 return jsonutils .ParseString (createParamsStr )
601601}
602602
603+ func (s * sPodGuestInstance ) getPostStopCleanupConfig () (* computeapi.PodPostStopCleanupConfig , error ) {
604+ data , ok := s .GetDesc ().Metadata [computeapi .POD_METADATA_POST_STOP_CLEANUP_CONFIG ]
605+ if ! ok {
606+ return nil , nil
607+ }
608+ jsonData , err := jsonutils .ParseString (data )
609+ if err != nil {
610+ return nil , errors .Wrapf (err , "parse to json" )
611+ }
612+ input := new (computeapi.PodPostStopCleanupConfig )
613+ if err := jsonData .Unmarshal (input ); err != nil {
614+ return nil , errors .Wrapf (err , "unmarshal to pod post stop cleanup config" )
615+ }
616+ return input , nil
617+ }
618+
603619func (s * sPodGuestInstance ) getPodCreateParams () (* computeapi.PodCreateInput , error ) {
604620 createParams , err := s .getCreateParams ()
605621 if err != nil {
@@ -1130,6 +1146,25 @@ func (s *sPodGuestInstance) stopPod(ctx context.Context, timeout int64) error {
11301146 return err
11311147 }
11321148 ReleaseGuestCpuset (s .manager , s )
1149+ if err := s .postStopCleanup (ctx ); err != nil {
1150+ return errors .Wrapf (err , "post stop cleanup" )
1151+ }
1152+ return nil
1153+ }
1154+
1155+ func (s * sPodGuestInstance ) postStopCleanup (ctx context.Context ) error {
1156+ config , err := s .getPostStopCleanupConfig ()
1157+ if err != nil {
1158+ return errors .Wrapf (err , "get post stop cleanup config" )
1159+ }
1160+ if config == nil {
1161+ return nil
1162+ }
1163+ for _ , dir := range config .Dirs {
1164+ if err := os .RemoveAll (dir ); err != nil {
1165+ return errors .Wrapf (err , "remove dir %s" , dir )
1166+ }
1167+ }
11331168 return nil
11341169}
11351170
0 commit comments