talos

Форк
0
55 строк · 1.3 Кб
1
// This Source Code Form is subject to the terms of the Mozilla Public
2
// License, v. 2.0. If a copy of the MPL was not distributed with this
3
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
4

5
package vm
6

7
import (
8
	"context"
9
	"fmt"
10
	"os"
11
	"path/filepath"
12

13
	yaml "gopkg.in/yaml.v3"
14

15
	"github.com/siderolabs/talos/pkg/provision"
16
)
17

18
// Reflect decode state file.
19
func (p *Provisioner) Reflect(ctx context.Context, clusterName, stateDirectory string) (provision.Cluster, error) {
20
	statePath := filepath.Join(stateDirectory, clusterName)
21

22
	st, err := os.Stat(statePath)
23
	if err != nil {
24
		if os.IsNotExist(err) {
25
			return nil, fmt.Errorf("cluster %q not found: %w", clusterName, err)
26
		}
27

28
		return nil, err
29
	}
30

31
	if !st.IsDir() {
32
		return nil, fmt.Errorf("state path %q is not a directory: %s", statePath, st.Mode())
33
	}
34

35
	stateFile, err := os.Open(filepath.Join(statePath, stateFileName))
36
	if err != nil {
37
		return nil, err
38
	}
39

40
	defer stateFile.Close() //nolint:errcheck
41

42
	state := &State{}
43

44
	if err = yaml.NewDecoder(stateFile).Decode(state); err != nil {
45
		return nil, fmt.Errorf("error unmarshalling state file: %w", err)
46
	}
47

48
	if state.ProvisionerName != p.Name {
49
		return nil, fmt.Errorf("cluster %q was created with different provisioner %q", clusterName, state.ProvisionerName)
50
	}
51

52
	state.statePath = statePath
53

54
	return state, nil
55
}
56

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.