Skip to content

Commit c5bfa5f

Browse files
authored
Merge pull request #1738 from afbjorklund/delete-conf
Delete the conf file when instance is stopped
2 parents e788c08 + f628825 commit c5bfa5f

File tree

6 files changed

+20
-2
lines changed

6 files changed

+20
-2
lines changed

examples/default.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,8 +379,10 @@ networks:
379379
# copyToHost:
380380
# - guest: "/etc/myconfig.cfg"
381381
# host: "{{.Dir}}/copied-from-guest/myconfig"
382+
# # deleteOnStop: false
382383
# # "guest" can include these template variables: {{.Home}}, {{.UID}}, and {{.User}}.
383384
# # "host" can include {{.Home}}, {{.Dir}}, {{.Name}}, {{.UID}}, and {{.User}}.
385+
# # "deleteOnStop" will delete the file from the host when the instance is stopped.
384386

385387
# Message. Information to be shown to the user, given as a Go template for the instance.
386388
# The same template variables as for listing instances can be used, for example {{.Dir}}.

examples/experimental/rke2.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ probes:
6767
copyToHost:
6868
- guest: "/etc/rancher/rke2/rke2.yaml"
6969
host: "{{.Dir}}/copied-from-guest/kubeconfig.yaml"
70+
deleteOnStop: true
7071
message: |
7172
To run `kubectl` on the host (assumes kubectl is installed), run the following commands:
7273
------

examples/k3s.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ probes:
5757
copyToHost:
5858
- guest: "/etc/rancher/k3s/k3s.yaml"
5959
host: "{{.Dir}}/copied-from-guest/kubeconfig.yaml"
60+
deleteOnStop: true
6061
message: |
6162
To run `kubectl` on the host (assumes kubectl is installed), run the following commands:
6263
------

examples/k8s.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ probes:
156156
copyToHost:
157157
- guest: "/etc/kubernetes/admin.conf"
158158
host: "{{.Dir}}/copied-from-guest/kubeconfig.yaml"
159+
deleteOnStop: true
159160
message: |
160161
To run `kubectl` on the host (assumes kubectl is installed), run the following commands:
161162
------

pkg/hostagent/hostagent.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,18 @@ sudo chown -R "${USER}" /run/host-services`
461461
mErr = errors.Join(mErr, err)
462462
}
463463
}
464+
a.onClose = append(a.onClose, func() error {
465+
var mErr error
466+
for _, rule := range a.y.CopyToHost {
467+
if rule.DeleteOnStop {
468+
logrus.Infof("Deleting %s", rule.HostFile)
469+
if err := os.RemoveAll(rule.HostFile); err != nil {
470+
mErr = errors.Join(mErr, err)
471+
}
472+
}
473+
}
474+
return mErr
475+
})
464476
return mErr
465477
}
466478

pkg/limayaml/limayaml.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,9 @@ type PortForward struct {
210210
}
211211

212212
type CopyToHost struct {
213-
GuestFile string `yaml:"guest,omitempty" json:"guest,omitempty"`
214-
HostFile string `yaml:"host,omitempty" json:"host,omitempty"`
213+
GuestFile string `yaml:"guest,omitempty" json:"guest,omitempty"`
214+
HostFile string `yaml:"host,omitempty" json:"host,omitempty"`
215+
DeleteOnStop bool `yaml:"deleteOnStop,omitempty" json:"deleteOnStop,omitempty"`
215216
}
216217

217218
type Network struct {

0 commit comments

Comments
 (0)