-
Notifications
You must be signed in to change notification settings - Fork 19
/
desired_state.go
48 lines (39 loc) · 1.4 KB
/
desired_state.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
package engine
import (
"fmt"
"github.com/Aptomi/aptomi/pkg/engine/resolve"
"github.com/Aptomi/aptomi/pkg/runtime"
)
// DesiredStateObject is an informational data structure with Kind and Constructor for DesiredState
var DesiredStateObject = &runtime.Info{
Kind: "desired-state",
Storable: true,
Versioned: false,
Constructor: func() runtime.Object { return &DesiredState{} },
}
// DesiredState represents snapshot of the state to be achieved by specific revision
type DesiredState struct {
runtime.TypeKind `yaml:",inline"`
RevisionGen runtime.Generation
Resolution resolve.PolicyResolution
}
// NewDesiredState creates new DesiredState instance from revision and policy resolution
func NewDesiredState(revision *Revision, resolution *resolve.PolicyResolution) *DesiredState {
return &DesiredState{
TypeKind: DesiredStateObject.GetTypeKind(),
RevisionGen: revision.GetGeneration(),
Resolution: *resolution,
}
}
// GetName returns name of the DesiredState
func (ds *DesiredState) GetName() string {
return GetDesiredStateName(ds.RevisionGen)
}
// GetNamespace returns namespace of the DesiredState
func (ds *DesiredState) GetNamespace() string {
return runtime.SystemNS
}
// GetDesiredStateName returns name of the DesiredState for specific Revision generations
func GetDesiredStateName(revisionGen runtime.Generation) string {
return fmt.Sprintf("revision-%s-desired-state", revisionGen)
}