Andrey Smirnov 9da687d2a3 test: firecracker provisioner fixes, implement cluster destroy
This implements `osctl cluster destroy` for Firecracker, adds
new utility command `osctl cluser show`.

Firecracker mode now has control process for firecracker VMs, allowing
clean reboots and background operations.

Lots of small fixes to Firecracker mode, clean CNI shutdown, cleaning up
netns, etc.

Signed-off-by: Andrey Smirnov <smirnov.andrey@gmail.com>
2020-01-21 17:11:06 -08:00

55 lines
1.3 KiB
Go

// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
package firecracker
import (
"context"
"fmt"
"os"
"path/filepath"
"gopkg.in/yaml.v2"
"github.com/talos-systems/talos/internal/pkg/provision"
)
func (p *provisioner) Reflect(ctx context.Context, clusterName, stateDirectory string) (provision.Cluster, error) {
statePath := filepath.Join(stateDirectory, clusterName)
st, err := os.Stat(statePath)
if err != nil {
if os.IsNotExist(err) {
return nil, fmt.Errorf("cluster %q not found: %w", clusterName, err)
}
return nil, err
}
if !st.IsDir() {
return nil, fmt.Errorf("state path %q is not a directory: %s", statePath, st.Mode())
}
stateFile, err := os.Open(filepath.Join(statePath, stateFileName))
if err != nil {
return nil, err
}
defer stateFile.Close() //nolint: errcheck
state := &state{}
if err = yaml.NewDecoder(stateFile).Decode(state); err != nil {
return nil, fmt.Errorf("error unmarshalling state file: %w", err)
}
if state.ProvisionerName != "firecracker" {
return nil, fmt.Errorf("cluster %q was created with different provisioner %q", clusterName, state.ProvisionerName)
}
state.statePath = statePath
return state, nil
}