|
| 1 | +package myhandler |
| 2 | + |
| 3 | +import ( |
| 4 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 5 | + "k8s.io/apimachinery/pkg/runtime/schema" |
| 6 | + |
| 7 | + commonv1alpha1 "github.com/triggermesh/scoby/pkg/apis/common/v1alpha1" |
| 8 | + hookv1 "github.com/triggermesh/scoby/pkg/hook/v1" |
| 9 | + corev1 "k8s.io/api/core/v1" |
| 10 | + |
| 11 | + "github.com/triggermesh/scoby-hook-triggermesh/pkg/handlers" |
| 12 | +) |
| 13 | + |
| 14 | +type KuardHandler struct { |
| 15 | + gvr schema.GroupVersionResource |
| 16 | + kind string |
| 17 | +} |
| 18 | + |
| 19 | +var _ handlers.Handler = (*KuardHandler)(nil) |
| 20 | + |
| 21 | +func New() *KuardHandler { |
| 22 | + return &KuardHandler{ |
| 23 | + gvr: schema.GroupVersionResource{ |
| 24 | + Group: "extensions.triggermesh.io", |
| 25 | + Version: "v1", |
| 26 | + Resource: "kuards", |
| 27 | + }, |
| 28 | + kind: "Kuard", |
| 29 | + } |
| 30 | +} |
| 31 | + |
| 32 | +func (h *KuardHandler) GroupVersionResource() *schema.GroupVersionResource { |
| 33 | + return &h.gvr |
| 34 | +} |
| 35 | + |
| 36 | +// Kind for the managed object |
| 37 | +func (h *KuardHandler) Kind() string { |
| 38 | + return h.kind |
| 39 | +} |
| 40 | + |
| 41 | +func (h *KuardHandler) Reconcile(obj metav1.Object) *hookv1.HookResponse { |
| 42 | + return &hookv1.HookResponse{ |
| 43 | + Status: &hookv1.HookStatus{ |
| 44 | + Conditions: commonv1alpha1.Conditions{ |
| 45 | + { |
| 46 | + Type: "HookReportedStatus", |
| 47 | + Status: metav1.ConditionTrue, |
| 48 | + Reason: "HOOKREPORTSOK", |
| 49 | + }, |
| 50 | + }, |
| 51 | + Annotations: map[string]string{ |
| 52 | + "io.triggermesh.hook/my-annotation": "annotation from hook", |
| 53 | + }, |
| 54 | + }, |
| 55 | + EnvVars: []corev1.EnvVar{ |
| 56 | + { |
| 57 | + Name: "FROM_HOOK_NAME", |
| 58 | + Value: obj.GetName(), |
| 59 | + }, |
| 60 | + { |
| 61 | + Name: "FROM_HOOK_NAMESPACE", |
| 62 | + Value: obj.GetNamespace(), |
| 63 | + }, |
| 64 | + }, |
| 65 | + } |
| 66 | +} |
0 commit comments