-
Notifications
You must be signed in to change notification settings - Fork 30
/
spec.go
48 lines (40 loc) · 1.32 KB
/
spec.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 v2
import (
"context"
)
type SpecResolver interface {
Spec(ctx context.Context, object Object) (*Spec, error)
}
type RenderMode string
const (
RenderModeRaw RenderMode = "raw"
)
type Spec struct {
ManifestName string
Path string
OCIRef string
Mode RenderMode
}
func DefaultSpec(path, ociref string, mode RenderMode) *CustomSpecFns {
return &CustomSpecFns{
ManifestNameFn: func(_ context.Context, obj Object) string { return obj.GetName() },
PathFn: func(_ context.Context, _ Object) string { return path },
OCIRefFn: func(_ context.Context, _ Object) string { return ociref },
ModeFn: func(_ context.Context, _ Object) RenderMode { return mode },
}
}
// CustomSpecFns is a simple static resolver that always uses the same chart and values.
type CustomSpecFns struct {
ManifestNameFn func(ctx context.Context, obj Object) string
PathFn func(ctx context.Context, obj Object) string
OCIRefFn func(ctx context.Context, obj Object) string
ModeFn func(ctx context.Context, obj Object) RenderMode
}
func (s *CustomSpecFns) Spec(ctx context.Context, obj Object) (*Spec, error) {
return &Spec{
ManifestName: s.ManifestNameFn(ctx, obj),
Path: s.PathFn(ctx, obj),
OCIRef: s.OCIRefFn(ctx, obj),
Mode: s.ModeFn(ctx, obj),
}, nil
}