This repository has been archived by the owner on Apr 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
api.go
66 lines (59 loc) · 2.08 KB
/
api.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package api
import (
"github.com/caos/orbos/internal/operator/boom/api/common"
"github.com/caos/orbos/internal/operator/boom/api/latest"
"github.com/caos/orbos/internal/operator/boom/api/migrate"
"github.com/caos/orbos/internal/operator/boom/api/v1beta1"
"github.com/caos/orbos/internal/operator/boom/api/v1beta2"
"github.com/caos/orbos/internal/secret"
"github.com/caos/orbos/internal/tree"
"github.com/pkg/errors"
)
func ParseToolset(desiredTree *tree.Tree) (*latest.Toolset, bool, map[string]*secret.Secret, error) {
desiredKindCommon := common.New()
if err := desiredTree.Original.Decode(desiredKindCommon); err != nil {
return nil, false, nil, errors.Wrap(err, "parsing desired state failed")
}
switch desiredKindCommon.APIVersion {
case "boom.caos.ch/v1beta1":
old, _, err := v1beta1.ParseToolset(desiredTree)
if err != nil {
return nil, false, nil, err
}
v1beta2Toolset, _ := migrate.V1beta1Tov1beta2(old)
v1Toolset, secrets := migrate.V1beta2Tov1(v1beta2Toolset)
return v1Toolset, true, secrets, err
case "boom.caos.ch/v1beta2":
v1beta2Toolset, _, err := v1beta2.ParseToolset(desiredTree)
if err != nil {
return nil, false, nil, err
}
v1Toolset, secrets := migrate.V1beta2Tov1(v1beta2Toolset)
return v1Toolset, true, secrets, nil
case "boom.caos.ch/v1":
desiredKind, secrets, err := latest.ParseToolset(desiredTree)
if err != nil {
return nil, false, nil, err
}
return desiredKind, false, secrets, nil
default:
return nil, false, nil, errors.New("APIVersion unknown")
}
}
/*
func SecretsFunc() secret.Func {
return func(monitor mntr.Monitor, desiredTree *tree.Tree) (secrets map[string]*secret.Secret, err error) {
desiredKindCommon := common.New()
if err := desiredTree.Original.Decode(desiredKindCommon); err != nil {
return nil, errors.Wrap(err, "parsing desired state failed")
}
switch desiredKindCommon.APIVersion {
case "boom.caos.ch/v1beta1":
return v1beta1.SecretsFunc(desiredTree)
case "boom.caos.ch/v1beta2":
return v1beta2.SecretsFunc(desiredTree)
default:
return nil, errors.New("APIVersion unknown")
}
}
}*/