-
Notifications
You must be signed in to change notification settings - Fork 7
/
resource.go
33 lines (26 loc) · 903 Bytes
/
resource.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
// Package types provides reusable structs and interfaces used across libflexkube, which
// can also be used by external projects.
package types
import (
"fmt"
"sigs.k8s.io/yaml"
"github.com/flexkube/libflexkube/pkg/container"
)
// Resource interface defines flexkube resource like kubelet pool or static controlplane.
type Resource interface {
StateToYaml() ([]byte, error)
CheckCurrentState() error
Deploy() error
Containers() container.ContainersInterface
}
// ResourceConfig interface defines flexkube resource configuration functionality.
type ResourceConfig interface {
New() (Resource, error)
}
// ResourceFromYaml allows to create any resource instance from YAML configuration.
func ResourceFromYaml(c []byte, r ResourceConfig) (Resource, error) {
if err := yaml.Unmarshal(c, &r); err != nil {
return nil, fmt.Errorf("failed to parse input YAML: %w", err)
}
return r.New()
}