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 868e092
Show file tree
Hide file tree
Showing 15 changed files with 375 additions and 72 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
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
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
3 changes: 1 addition & 2 deletions docs/en/quick-start.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ Services:
Created at: ...
Updated at: ...
Traits:
- ✅ ingress: domain=testsvc.example.com
http=map[/:8000]
- ✅ ingress: Visiting URL: testsvc.example.com, IP: <your IP address>
```
**In [kind cluster setup](./install.md#kind)**, you can visit the service via localhost. In other setups, replace localhost with ingress address accordingly.
Expand Down
10 changes: 10 additions & 0 deletions hack/vela-templates/definitions/ingress.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,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
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
5 changes: 2 additions & 3 deletions pkg/commands/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import (
"strings"
"time"

"github.com/oam-dev/kubevela/pkg/oam/util"

"github.com/fatih/color"
"github.com/pkg/errors"
"github.com/spf13/cobra"
Expand All @@ -19,6 +17,7 @@ import (
"github.com/oam-dev/kubevela/pkg/appfile"
"github.com/oam-dev/kubevela/pkg/appfile/api"
cmdutil "github.com/oam-dev/kubevela/pkg/commands/util"
"github.com/oam-dev/kubevela/pkg/oam/util"
)

// HealthStatus represents health status strings.
Expand Down Expand Up @@ -274,7 +273,7 @@ func TrackDeployStatus(ctx context.Context, c client.Client, compName, appName s

// trackHealthCheckingStatus will check health status from health scope
func trackHealthCheckingStatus(ctx context.Context, c client.Client, compName, appName string, env *types.EnvMeta) (CompStatus, HealthStatus, string, error) {
app, err := loadRemoteApplication(c, appName, env.Namespace)
app, err := loadRemoteApplication(c, env.Namespace, appName)
if err != nil {
return compStatusUnknown, HealthStatusNotDiagnosed, "", err
}
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 868e092

Please sign in to comment.