Skip to content

Commit

Permalink
move health check and status out of extention
Browse files Browse the repository at this point in the history
  • Loading branch information
wonderflow committed Feb 4, 2021
1 parent 87e52bb commit c42daf4
Show file tree
Hide file tree
Showing 10 changed files with 322 additions and 67 deletions.
18 changes: 18 additions & 0 deletions apis/core.oam.dev/v1alpha2/core_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,26 @@ type WorkloadDefinitionSpec struct {
// +optional
PodSpecPath string `json:"podSpecPath,omitempty"`

// Status defines the custom health policy and status message for workload
// +optional
Status *Status `json:"status,omitempty"`

// Extension is used for extension needs by OAM platform builders
// +optional
// +kubebuilder:pruning:PreserveUnknownFields
Extension *runtime.RawExtension `json:"extension,omitempty"`
}

// Status defines the loop back status of the abstraction by using CUE template
type Status struct {
// CustomStatus defines the custom status message that could display to user
// +optional
CustomStatus string `json:"customStatus,omitempty"`
// HealthPolicy defines the health check policy for the abstraction
// +optional
HealthPolicy string `json:"healthPolicy,omitempty"`
}

// +kubebuilder:object:root=true

// A WorkloadDefinition registers a kind of Kubernetes custom resource as a
Expand Down Expand Up @@ -126,6 +140,10 @@ type TraitDefinitionSpec struct {
// +optional
ConflictsWith []string `json:"conflictsWith,omitempty"`

// Status defines the custom health policy and status message for trait
// +optional
Status *Status `json:"status,omitempty"`

// Extension is used for extension needs by OAM platform builders
// +optional
// +kubebuilder:pruning:PreserveUnknownFields
Expand Down
25 changes: 25 additions & 0 deletions apis/core.oam.dev/v1alpha2/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions charts/vela-core/crds/core.oam.dev_traitdefinitions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,16 @@ spec:
revisionEnabled:
description: Revision indicates whether a trait is aware of component revision
type: boolean
status:
description: Status defines the custom health policy and status message for trait
properties:
customStatus:
description: CustomStatus defines the custom status message that could display to user
type: string
healthPolicy:
description: HealthPolicy defines the health check policy for the abstraction
type: string
type: object
workloadRefPath:
description: WorkloadRefPath indicates where/if a trait accepts a workloadRef object
type: string
Expand Down
10 changes: 10 additions & 0 deletions charts/vela-core/crds/core.oam.dev_workloaddefinitions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,16 @@ spec:
revisionLabel:
description: RevisionLabel indicates which label for underlying resources(e.g. pods) of this workload can be used by trait to create resource selectors(e.g. label selector for pods).
type: string
status:
description: Status defines the custom health policy and status message for workload
properties:
customStatus:
description: CustomStatus defines the custom status message that could display to user
type: string
healthPolicy:
description: HealthPolicy defines the health check policy for the abstraction
type: string
type: object
required:
- definitionRef
type: object
Expand Down
7 changes: 4 additions & 3 deletions config/samples/app-with-status/template.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# Code generated by KubeVela templates. DO NOT EDIT.
apiVersion: core.oam.dev/v1alpha2
kind: WorkloadDefinition
metadata:
Expand All @@ -8,11 +7,12 @@ metadata:
spec:
definitionRef:
name: deployments.apps
extension:
status:
healthPolicy: |
isHealth: (context.output.status.readyReplicas > 0) && (context.output.status.readyReplicas == context.output.status.replicas)
customStatus: |-
message: "type: " + context.output.spec.template.spec.containers[0].image + ",\t enemies:" + context.outputs.gameconfig.data.enemies
extension:
template: |
output: {
apiVersion: "apps/v1"
Expand Down Expand Up @@ -73,11 +73,12 @@ kind: TraitDefinition
metadata:
name: ingress
spec:
extension:
status:
customStatus: |-
message: "type: "+ context.outputs.service.spec.type +",\t clusterIP:"+ context.outputs.service.spec.clusterIP+",\t ports:"+ "\(context.outputs.service.spec.ports[0].port)"+",\t domain"+context.outputs.ingress.spec.rules[0].host
healthPolicy: |
isHealth: len(context.outputs.service.spec.clusterIP) > 0
extension:
template: |
parameter: {
domain: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,16 @@ spec:
revisionEnabled:
description: Revision indicates whether a trait is aware of component revision
type: boolean
status:
description: Status defines the custom health policy and status message for trait
properties:
customStatus:
description: CustomStatus defines the custom status message that could display to user
type: string
healthPolicy:
description: HealthPolicy defines the health check policy for the abstraction
type: string
type: object
workloadRefPath:
description: WorkloadRefPath indicates where/if a trait accepts a workloadRef object
type: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,16 @@ spec:
revisionLabel:
description: RevisionLabel indicates which label for underlying resources(e.g. pods) of this workload can be used by trait to create resource selectors(e.g. label selector for pods).
type: string
status:
description: Status defines the custom health policy and status message for workload
properties:
customStatus:
description: CustomStatus defines the custom status message that could display to user
type: string
healthPolicy:
description: HealthPolicy defines the health check policy for the abstraction
type: string
type: object
required:
- definitionRef
type: object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func (r *Reconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) {
}

app.Status.SetConditions(readyCondition("Built"))
applog.Info("apply applicationconfig & component to the cluster")
applog.Info("apply appConfig & component to the cluster")
// apply appConfig & component to the cluster
if err := handler.apply(ctx, ac, comps); err != nil {
handler.l.Error(err, "[Handle apply]")
Expand Down

0 comments on commit c42daf4

Please sign in to comment.