From c25b2f45810468976b82dbd8799ca97411a474f0 Mon Sep 17 00:00:00 2001 From: Roman Dodin Date: Fri, 6 Dec 2024 19:34:53 +0100 Subject: [PATCH] Skip binds path check option for destroy operation (#2334) skip binds path check option --- .gitignore | 2 ++ clab/clab.go | 22 +++++++++++++++++----- cmd/destroy.go | 3 +++ 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index b4f2394f8..4485f6f1c 100644 --- a/.gitignore +++ b/.gitignore @@ -41,3 +41,5 @@ tests/out **/*.y*ml.bak .python-version + +.devcontainer/private-* diff --git a/clab/clab.go b/clab/clab.go index daafff2b3..2dadf3cca 100644 --- a/clab/clab.go +++ b/clab/clab.go @@ -56,6 +56,9 @@ type CLab struct { // nodeFilter is a list of node names to be deployed, // names are provided exactly as they are listed in the topology file. nodeFilter []string + // checkBindsPaths toggle enables or disables binds paths checks + // when set to true, bind sources are verified to exist on the host. + checkBindsPaths bool } type ClabOption func(c *CLab) error @@ -79,6 +82,14 @@ func WithLabName(n string) ClabOption { } } +// WithSkippedBindsPathsCheck skips the binds paths checks. +func WithSkippedBindsPathsCheck() ClabOption { + return func(c *CLab) error { + c.checkBindsPaths = false + return nil + } +} + // WithManagementNetworkName sets the name of the // management network that is to be used. func WithManagementNetworkName(n string) ClabOption { @@ -333,11 +344,12 @@ func NewContainerLab(opts ...ClabOption) (*CLab, error) { Mgmt: new(types.MgmtNet), Topology: types.NewTopology(), }, - m: new(sync.RWMutex), - Nodes: make(map[string]nodes.Node), - Links: make(map[int]links.Link), - Runtimes: make(map[string]runtime.ContainerRuntime), - Cert: &cert.Cert{}, + m: new(sync.RWMutex), + Nodes: make(map[string]nodes.Node), + Links: make(map[int]links.Link), + Runtimes: make(map[string]runtime.ContainerRuntime), + Cert: &cert.Cert{}, + checkBindsPaths: true, } // init a new NodeRegistry diff --git a/cmd/destroy.go b/cmd/destroy.go index dfb277f87..0f13f2d58 100644 --- a/cmd/destroy.go +++ b/cmd/destroy.go @@ -102,6 +102,9 @@ func destroyFn(_ *cobra.Command, _ []string) error { }, ), clab.WithDebug(debug), + // during destroy we don't want to check bind paths + // as it is irrelevant for this command. + clab.WithSkippedBindsPathsCheck(), } if keepMgmtNet {