Skip to content

Commit

Permalink
Merge pull request #975 from leejanee/app-status
Browse files Browse the repository at this point in the history
display trait status information with customized style
  • Loading branch information
wonderflow committed Feb 4, 2021
2 parents f2bd881 + 868e092 commit b6f10bb
Show file tree
Hide file tree
Showing 32 changed files with 1,572 additions and 733 deletions.
20 changes: 20 additions & 0 deletions apis/core.oam.dev/v1alpha2/application_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ const (
ApplicationRendering ApplicationPhase = "rendering"
// ApplicationRunning means the app finished rendering and applied result to the cluster
ApplicationRunning ApplicationPhase = "running"
// ApplicationHealthChecking means the app finished rendering and applied result to the cluster, but still unhealthy
ApplicationHealthChecking ApplicationPhase = "healthChecking"
)

// AppStatus defines the observed state of Application
Expand All @@ -49,6 +51,24 @@ type AppStatus struct {

// Components record the related Components created by Application Controller
Components []runtimev1alpha1.TypedReference `json:"components,omitempty"`

// Services record the status of the application services
Services []ApplicationComponentStatus `json:"services,omitempty"`
}

// ApplicationComponentStatus record the health status of App component
type ApplicationComponentStatus struct {
Name string `json:"name"`
Healthy bool `json:"healthy"`
Message string `json:"message,omitempty"`
Traits []ApplicationTraitStatus `json:"traits,omitempty"`
}

// ApplicationTraitStatus records the trait health status
type ApplicationTraitStatus struct {
Type string `json:"type"`
Healthy bool `json:"healthy"`
Message string `json:"message,omitempty"`
}

// ApplicationTrait defines the trait of application
Expand Down
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
67 changes: 67 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.

31 changes: 31 additions & 0 deletions charts/vela-core/crds/core.oam.dev_applications.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,37 @@ spec:
- type
type: object
type: array
services:
description: Services record the status of the application services
items:
description: ApplicationComponentStatus record the health status of App component
properties:
healthy:
type: boolean
message:
type: string
name:
type: string
traits:
items:
description: ApplicationTraitStatus records the trait health status
properties:
healthy:
type: boolean
message:
type: string
type:
type: string
required:
- healthy
- type
type: object
type: array
required:
- healthy
- name
type: object
type: array
status:
description: ApplicationPhase is a label for the condition of a application at the current time
type: string
Expand Down
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
10 changes: 10 additions & 0 deletions charts/vela-core/templates/defwithtemplate/ingress.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@ metadata:
Please use route trait in cap center for advanced usage."
name: ingress
spec:
status:
customStatus: |-
if len(context.outputs.ingress.status.loadBalancer.ingress) > 0 {
message: "Visiting URL: " + context.outputs.ingress.spec.rules[0].host + ", IP: " + context.outputs.ingress.status.loadBalancer.ingress[0].ip
}
if len(context.outputs.ingress.status.loadBalancer.ingress) == 0 {
message: "No loadBalancer found, visiting by using 'vela port-forward " + context.appName + " --route'\n"
}
healthPolicy: |
isHealth: len(context.outputs.service.spec.clusterIP) > 0
appliesToWorkloads:
- webservice
- worker
Expand Down
21 changes: 21 additions & 0 deletions config/samples/app-with-status/app.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
apiVersion: core.oam.dev/v1alpha2
kind: Application
metadata:
name: application-sample
spec:
components:
- name: myweb
type: worker
settings:
image: "busybox"
cmd:
- sleep
- "1000"
lives: "3"
enemies: "alien"
traits:
- name: ingress
properties:
domain: "www.example.com"
http:
"/": 80

0 comments on commit b6f10bb

Please sign in to comment.