From db6941e68e4f25d5cd83ab69c4dfbb822fbe8a32 Mon Sep 17 00:00:00 2001 From: RainbowMango Date: Wed, 17 Nov 2021 10:46:51 +0800 Subject: [PATCH] Setup webhook example structure Signed-off-by: RainbowMango --- examples/README.md | 4 ++ .../apis/workload/v1alpha1/workload_types.go | 43 +++++++++++++++++++ .../customresourceexplorer/webhook/main.go | 7 +++ 3 files changed, 54 insertions(+) create mode 100644 examples/README.md create mode 100644 examples/customresourceexplorer/apis/workload/v1alpha1/workload_types.go create mode 100644 examples/customresourceexplorer/webhook/main.go diff --git a/examples/README.md b/examples/README.md new file mode 100644 index 000000000..8c6a8cae6 --- /dev/null +++ b/examples/README.md @@ -0,0 +1,4 @@ +# Examples + +### Custom Resource Explorer +This example implements a new CustomResourceDefinition(CRD), `Workload`, and creates a custom resource explorer webhook. \ No newline at end of file diff --git a/examples/customresourceexplorer/apis/workload/v1alpha1/workload_types.go b/examples/customresourceexplorer/apis/workload/v1alpha1/workload_types.go new file mode 100644 index 000000000..5e3306082 --- /dev/null +++ b/examples/customresourceexplorer/apis/workload/v1alpha1/workload_types.go @@ -0,0 +1,43 @@ +package v1alpha1 + +import ( + corev1 "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +// Workload is a simple Deployment. +type Workload struct { + metav1.TypeMeta `json:",inline"` + metav1.ObjectMeta `json:"metadata,omitempty"` + + // Spec represents the specification of the desired behavior. + // +required + Spec WorkloadSpec `json:"spec"` + + // Status represents most recently observed status of the Workload. + // +optional + Status WorkloadStatus `json:"status,omitempty"` +} + +// WorkloadSpec is the specification of the desired behavior of the Workload. +type WorkloadSpec struct { + // Number of desired pods. This is a pointer to distinguish between explicit + // zero and not specified. Defaults to 1. + // +optional + Replicas *int32 `json:"replicas,omitempty"` + + // Template describes the pods that will be created. + Template corev1.PodTemplateSpec `json:"template" protobuf:"bytes,3,opt,name=template"` + + // Paused indicates that the deployment is paused. + // Note: both user and controllers might set this field. + // +optional + Paused bool `json:"paused,omitempty"` +} + +// WorkloadStatus represents most recently observed status of the Workload. +type WorkloadStatus struct { + // ReadyReplicas represents the total number of ready pods targeted by this Workload. + // +optional + ReadyReplicas int32 `json:"readyReplicas,omitempty"` +} diff --git a/examples/customresourceexplorer/webhook/main.go b/examples/customresourceexplorer/webhook/main.go new file mode 100644 index 000000000..3f234ca0f --- /dev/null +++ b/examples/customresourceexplorer/webhook/main.go @@ -0,0 +1,7 @@ +package main + +import "fmt" + +func main() { + fmt.Printf("Place holder of the webhook.") +}