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