-
Notifications
You must be signed in to change notification settings - Fork 2
/
context.go
53 lines (41 loc) · 1.03 KB
/
context.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
package controllercontext
import (
"context"
"github.com/giantswarm/apiextensions-application/api/v1alpha1"
"github.com/giantswarm/helmclient/v4/pkg/helmclient"
"github.com/giantswarm/k8sclient/v7/pkg/k8sclient"
"github.com/giantswarm/microerror"
)
type contextKey string
const controllerKey contextKey = "controller"
type Context struct {
Catalog v1alpha1.Catalog
Clients Clients
Status Status
}
type Clients struct {
K8s k8sclient.Interface
Helm helmclient.Interface
}
type Status struct {
ChartStatus ChartStatus
ClusterStatus ClusterStatus
}
type ChartStatus struct {
Reason string
Status string
}
type ClusterStatus struct {
IsDeleting bool
IsUnavailable bool
}
func NewContext(ctx context.Context, c Context) context.Context {
return context.WithValue(ctx, controllerKey, &c)
}
func FromContext(ctx context.Context) (*Context, error) {
c, ok := ctx.Value(controllerKey).(*Context)
if !ok {
return nil, microerror.Maskf(notFoundError, "context key %q of type %T", controllerKey, controllerKey)
}
return c, nil
}