diff --git a/apis/core.oam.dev/common/types.go b/apis/core.oam.dev/common/types.go index a18949b7c..429257911 100644 --- a/apis/core.oam.dev/common/types.go +++ b/apis/core.oam.dev/common/types.go @@ -162,10 +162,11 @@ const ( type ApplicationComponentStatus struct { Name string `json:"name"` // WorkloadDefinition is the definition of a WorkloadDefinition, such as deployments/apps.v1 - WorkloadDefinition WorkloadGVK `json:"workloadDefinition,omitempty"` - Healthy bool `json:"healthy"` - Message string `json:"message,omitempty"` - Traits []ApplicationTraitStatus `json:"traits,omitempty"` + WorkloadDefinition WorkloadGVK `json:"workloadDefinition,omitempty"` + Healthy bool `json:"healthy"` + Message string `json:"message,omitempty"` + Traits []ApplicationTraitStatus `json:"traits,omitempty"` + Scopes []v1alpha12.TypedReference `json:"scopes,omitempty"` } // ApplicationTraitStatus records the trait health status diff --git a/apis/core.oam.dev/common/zz_generated.deepcopy.go b/apis/core.oam.dev/common/zz_generated.deepcopy.go index 3153bd12e..510f8f177 100644 --- a/apis/core.oam.dev/common/zz_generated.deepcopy.go +++ b/apis/core.oam.dev/common/zz_generated.deepcopy.go @@ -71,6 +71,11 @@ func (in *ApplicationComponentStatus) DeepCopyInto(out *ApplicationComponentStat *out = make([]ApplicationTraitStatus, len(*in)) copy(*out, *in) } + if in.Scopes != nil { + in, out := &in.Scopes, &out.Scopes + *out = make([]v1alpha1.TypedReference, len(*in)) + copy(*out, *in) + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ApplicationComponentStatus. diff --git a/charts/vela-core/crds/core.oam.dev_applicationrevisions.yaml b/charts/vela-core/crds/core.oam.dev_applicationrevisions.yaml index 0617c3dbe..e0e68680f 100644 --- a/charts/vela-core/crds/core.oam.dev_applicationrevisions.yaml +++ b/charts/vela-core/crds/core.oam.dev_applicationrevisions.yaml @@ -431,6 +431,28 @@ spec: type: string name: type: string + scopes: + items: + description: A TypedReference refers to an object by Name, Kind, and APIVersion. It is commonly used to reference cluster-scoped objects or objects where the namespace is already known. + properties: + apiVersion: + description: APIVersion of the referenced object. + type: string + kind: + description: Kind of the referenced object. + type: string + name: + description: Name of the referenced object. + type: string + uid: + description: UID of the referenced object. + type: string + required: + - apiVersion + - kind + - name + type: object + type: array traits: items: description: ApplicationTraitStatus records the trait health status @@ -1497,6 +1519,28 @@ spec: type: string name: type: string + scopes: + items: + description: A TypedReference refers to an object by Name, Kind, and APIVersion. It is commonly used to reference cluster-scoped objects or objects where the namespace is already known. + properties: + apiVersion: + description: APIVersion of the referenced object. + type: string + kind: + description: Kind of the referenced object. + type: string + name: + description: Name of the referenced object. + type: string + uid: + description: UID of the referenced object. + type: string + required: + - apiVersion + - kind + - name + type: object + type: array traits: items: description: ApplicationTraitStatus records the trait health status diff --git a/charts/vela-core/crds/core.oam.dev_applications.yaml b/charts/vela-core/crds/core.oam.dev_applications.yaml index bf03b684d..c35687043 100644 --- a/charts/vela-core/crds/core.oam.dev_applications.yaml +++ b/charts/vela-core/crds/core.oam.dev_applications.yaml @@ -443,6 +443,28 @@ spec: type: string name: type: string + scopes: + items: + description: A TypedReference refers to an object by Name, Kind, and APIVersion. It is commonly used to reference cluster-scoped objects or objects where the namespace is already known. + properties: + apiVersion: + description: APIVersion of the referenced object. + type: string + kind: + description: Kind of the referenced object. + type: string + name: + description: Name of the referenced object. + type: string + uid: + description: UID of the referenced object. + type: string + required: + - apiVersion + - kind + - name + type: object + type: array traits: items: description: ApplicationTraitStatus records the trait health status @@ -912,6 +934,28 @@ spec: type: string name: type: string + scopes: + items: + description: A TypedReference refers to an object by Name, Kind, and APIVersion. It is commonly used to reference cluster-scoped objects or objects where the namespace is already known. + properties: + apiVersion: + description: APIVersion of the referenced object. + type: string + kind: + description: Kind of the referenced object. + type: string + name: + description: Name of the referenced object. + type: string + uid: + description: UID of the referenced object. + type: string + required: + - apiVersion + - kind + - name + type: object + type: array traits: items: description: ApplicationTraitStatus records the trait health status diff --git a/docs/en/end-user/health.md b/docs/en/end-user/health.md new file mode 100644 index 000000000..70542e381 --- /dev/null +++ b/docs/en/end-user/health.md @@ -0,0 +1,95 @@ +--- +title: Define Application Health Probe +--- + +In this documentation, we will show how to define health probe for application + +## Set Health Check Rule + +Basically you can set application `spec.status.healthPolicy` field to specifying health check rule for application. [reference](../cue/status) + +## Advanced Health Probe + +By using HealthyScope you can check all pods of workload weather are healthy. + +1.Create health scope by apply this yaml +```yaml +apiVersion: core.oam.dev/v1alpha2 +kind: HealthScope +metadata: + name: health-check + namespace: default +spec: + probe-interval: 60 + workloadRefs: + - apiVersion: apps/v1 + kind: Deployment + name: express-server +``` +2. Create an application with the health scope +```yaml +apiVersion: core.oam.dev/v1beta1 +kind: Application +metadata: + name: vela-app +spec: + components: + - name: express-server + type: webservice + properties: + image: crccheck/hello-world + port: 8080 # change port + cpu: 0.5 # add requests cpu units + scopes: + healthscopes.core.oam.dev: health-check +``` +3. Check app status, will see health scope in `status.service.scopes` +```shell +$ kubectl get app vela-app -o yaml +``` +```yaml +apiVersion: core.oam.dev/v1beta1 +kind: Application +metadata: + name: vela-app +... +status: +... + services: + - healthy: true + name: express-server + scopes: + - apiVersion: core.oam.dev/v1alpha2 + kind: HealthScope + name: health-check +``` +4.Check health scope status +```shell +$ kubectl get healthscope health-check -o yaml +``` +```yaml +apiVersion: core.oam.dev/v1alpha2 +kind: HealthScope +metadata: + name: health-check +... +spec: + probe-interval: 60 + workloadRefs: + - apiVersion: apps/v1 + kind: Deployment + name: express-server +status: + healthConditions: + - componentName: express-server + diagnosis: 'Ready:1/1 ' + healthStatus: HEALTHY + targetWorkload: + apiVersion: apps/v1 + kind: Deployment + name: express-server + scopeHealthCondition: + healthStatus: HEALTHY + healthyWorkloads: 1 + total: 1 +``` diff --git a/docs/sidebars.js b/docs/sidebars.js index 4c90a12cc..a220235e6 100644 --- a/docs/sidebars.js +++ b/docs/sidebars.js @@ -38,6 +38,7 @@ module.exports = { 'end-user/cloud-resources', 'end-user/volumes', 'end-user/monitoring', + 'end-user/health', ] }, ] diff --git a/legacy/charts/vela-core-legacy/crds/core.oam.dev_applicationrevisions.yaml b/legacy/charts/vela-core-legacy/crds/core.oam.dev_applicationrevisions.yaml index 90c985f6f..8eff3a375 100644 --- a/legacy/charts/vela-core-legacy/crds/core.oam.dev_applicationrevisions.yaml +++ b/legacy/charts/vela-core-legacy/crds/core.oam.dev_applicationrevisions.yaml @@ -425,6 +425,28 @@ spec: type: string name: type: string + scopes: + items: + description: A TypedReference refers to an object by Name, Kind, and APIVersion. It is commonly used to reference cluster-scoped objects or objects where the namespace is already known. + properties: + apiVersion: + description: APIVersion of the referenced object. + type: string + kind: + description: Kind of the referenced object. + type: string + name: + description: Name of the referenced object. + type: string + uid: + description: UID of the referenced object. + type: string + required: + - apiVersion + - kind + - name + type: object + type: array traits: items: description: ApplicationTraitStatus records the trait health status diff --git a/legacy/charts/vela-core-legacy/crds/core.oam.dev_applications.yaml b/legacy/charts/vela-core-legacy/crds/core.oam.dev_applications.yaml index ed84f6c97..1b955725f 100644 --- a/legacy/charts/vela-core-legacy/crds/core.oam.dev_applications.yaml +++ b/legacy/charts/vela-core-legacy/crds/core.oam.dev_applications.yaml @@ -411,6 +411,28 @@ spec: type: string name: type: string + scopes: + items: + description: A TypedReference refers to an object by Name, Kind, and APIVersion. It is commonly used to reference cluster-scoped objects or objects where the namespace is already known. + properties: + apiVersion: + description: APIVersion of the referenced object. + type: string + kind: + description: Kind of the referenced object. + type: string + name: + description: Name of the referenced object. + type: string + uid: + description: UID of the referenced object. + type: string + required: + - apiVersion + - kind + - name + type: object + type: array traits: items: description: ApplicationTraitStatus records the trait health status diff --git a/pkg/controller/core.oam.dev/v1alpha2/application/application_controller_test.go b/pkg/controller/core.oam.dev/v1alpha2/application/application_controller_test.go index cea0d081a..b39b35b13 100644 --- a/pkg/controller/core.oam.dev/v1alpha2/application/application_controller_test.go +++ b/pkg/controller/core.oam.dev/v1alpha2/application/application_controller_test.go @@ -710,6 +710,13 @@ spec: Expect(k8sClient.Get(ctx, appKey, curApp)).Should(BeNil()) Expect(curApp.Status.Phase).Should(Equal(common.ApplicationRunning)) + By("Check App scope status") + scopes := curApp.Status.Services[0].Scopes + Expect(len(scopes)).Should(BeEquivalentTo(1)) + Expect(scopes[0].APIVersion).Should(BeEquivalentTo("core.oam.dev/v1alpha2")) + Expect(scopes[0].Kind).Should(BeEquivalentTo("HealthScope")) + Expect(scopes[0].Name).Should(BeEquivalentTo("appWithTraitAndScope-default-health")) + By("Check AppConfig and trait created as expected") appContext := &v1alpha2.ApplicationContext{} Expect(k8sClient.Get(ctx, client.ObjectKey{ diff --git a/pkg/controller/core.oam.dev/v1alpha2/application/apply.go b/pkg/controller/core.oam.dev/v1alpha2/application/apply.go index 0c61d6569..8913c308b 100644 --- a/pkg/controller/core.oam.dev/v1alpha2/application/apply.go +++ b/pkg/controller/core.oam.dev/v1alpha2/application/apply.go @@ -266,6 +266,7 @@ func (h *appHandler) statusAggregate(appFile *appfile.Appfile) ([]common.Applica traitStatusList = append(traitStatusList, traitStatus) } status.Traits = traitStatusList + status.Scopes = generateScopeReference(wl.Scopes) appStatus = append(appStatus, status) } return appStatus, healthy, nil @@ -708,3 +709,15 @@ outLoop: } return nil } + +func generateScopeReference(scopes []appfile.Scope) []runtimev1alpha1.TypedReference { + var references []runtimev1alpha1.TypedReference + for _, scope := range scopes { + references = append(references, runtimev1alpha1.TypedReference{ + APIVersion: scope.GVK.GroupVersion().String(), + Kind: scope.GVK.Kind, + Name: scope.Name, + }) + } + return references +}