This repository has been archived by the owner on May 23, 2023. It is now read-only.
generated from vshn/go-bootstrap
/
result.go
60 lines (52 loc) · 1.82 KB
/
result.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
package runtime
import (
"context"
"github.com/crossplane/crossplane/apis/apiextensions/fn/io/v1alpha1"
controllerruntime "sigs.k8s.io/controller-runtime"
)
type Result interface {
Resolve() v1alpha1.Result
}
type result v1alpha1.Result
// NewWarning returns a warning Result from a message string. The entire
// Composition will run to completion but warning events and debug logs
// associated with the composite resource will be emitted.
func NewWarning(ctx context.Context, msg string) Result {
controllerruntime.LoggerFrom(ctx).Info(msg)
return result{
Severity: v1alpha1.SeverityWarning,
Message: msg,
}
}
// NewFatalErr returns a fatal Result from a message string and an error. The result is fatal,
// subsequent Composition Functions may run, but the Composition Function pipeline run
// will be considered a failure and the first error will be returned.
func NewFatalErr(ctx context.Context, msg string, err error) Result {
controllerruntime.LoggerFrom(ctx).Error(err, msg)
return result{
Severity: v1alpha1.SeverityFatal,
Message: msg,
}
}
// NewFatal returns a fatal Result from a message string. The result is fatal,
// subsequent Composition Functions may run, but the Composition Function
// pipeline run will be considered a failure and the first error will be returned.
func NewFatal(ctx context.Context, msg string) Result {
controllerruntime.LoggerFrom(ctx).Info(msg)
return result{
Severity: v1alpha1.SeverityFatal,
Message: msg,
}
}
// NewNormal results are emitted as normal events and debug logs associated
// with the composite resource.
func NewNormal() Result {
return result{
Severity: v1alpha1.SeverityNormal,
Message: "function ran successfully",
}
}
// Resolve returns the wrapped object v1alpha1.Result from crossplane
func (r result) Resolve() v1alpha1.Result {
return v1alpha1.Result(r)
}