mirror of
https://github.com/kubevela/kubevela.git
synced 2026-08-19 04:26:39 +00:00
Set scpoe reference in application status.Service (#1540)
* WIP add new type * add code and test * WIP finish docs * add sidbar for docs
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
```
|
||||
@@ -38,6 +38,7 @@ module.exports = {
|
||||
'end-user/cloud-resources',
|
||||
'end-user/volumes',
|
||||
'end-user/monitoring',
|
||||
'end-user/health',
|
||||
]
|
||||
},
|
||||
]
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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{
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user