Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

display trait status information with customized style #975

Merged
merged 5 commits into from
Feb 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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"`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename to "componentStatus"? I think it might also good to fold this to the "Components"

Copy link
Collaborator

@wonderflow wonderflow Feb 3, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Components is occupied, componentStatus not very good name

}

// 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