Skip to content

Commit

Permalink
Add status info to YurtAppSet/YurtAppDaemon (openyurtio#1702)
Browse files Browse the repository at this point in the history
* adjust CRD and add wildcard

* add configuration of deployment webhook

* add register of webhook and controller

* call deployment webhook directly

* remove flatternYaml and add more info

* modify deployment webhook failurePolicy

* do some modifies

* rename missing configrender to overrider

* remove the outer  of *

* fix problems in the comments

* fix error in e2e of yurtappoverrider

* fix error in e2e of yurtappoverrider

* fix error in validating webhook of yurtappoverrider

* add more UT

* gci writting ut

* fix error in ut

* add more UT

* supplement status

* supplement status of yurtappset

* add status info to yurtappset/yurtappdaemon

* feat: manifests

* fix some problems

* feat: refactor import

* fix error of image scan

* fix errors in github checks

* go mod tidy

* feat: manifests

* fix errors in the comments

* fix errors in the comments

* fix errors in the comments

* fix gci problems

* add poolReplicas field to YurtAppSet

* feat: manifests

* feat: manifests

* delete useless files

* fix errors in the comments

* add workloadsummaries to yurtappdaemon

* feat: manifests

* fix problems in the UT file

* fix golangci-lint

* add omitempty

* feat: manifests

---------

Co-authored-by: 飞倚 <zhoupengchuan.zpc@alibaba-inc.com>
  • Loading branch information
vie-serendipity and 飞倚 authored Sep 17, 2023
1 parent 6006a94 commit f782021
Show file tree
Hide file tree
Showing 20 changed files with 308 additions and 43 deletions.
27 changes: 27 additions & 0 deletions charts/yurt-manager/crds/apps.openyurt.io_yurtappdaemons.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ spec:
jsonPath: .metadata.creationTimestamp
name: AGE
type: date
- description: The name of overrider bound to this yurtappdaemon
jsonPath: .status.overriderRef
name: OverriderRef
type: string
name: v1alpha1
schema:
openAPIV3Schema:
Expand Down Expand Up @@ -225,9 +229,32 @@ spec:
which is updated on mutation by the API Server.
format: int64
type: integer
overriderRef:
type: string
templateType:
description: TemplateType indicates the type of PoolTemplate
type: string
workloadSummary:
description: Records the topology detailed information of each workload.
items:
properties:
availableCondition:
type: string
readyReplicas:
format: int32
type: integer
replicas:
format: int32
type: integer
workloadName:
type: string
required:
- availableCondition
- readyReplicas
- replicas
- workloadName
type: object
type: array
required:
- currentRevision
- templateType
Expand Down
27 changes: 27 additions & 0 deletions charts/yurt-manager/crds/apps.openyurt.io_yurtappsets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ spec:
jsonPath: .metadata.creationTimestamp
name: AGE
type: date
- description: The name of overrider bound to this yurtappset
jsonPath: .status.overriderRef
name: OverriderRef
type: string
name: v1alpha1
schema:
openAPIV3Schema:
Expand Down Expand Up @@ -329,6 +333,8 @@ spec:
which is updated on mutation by the API Server.
format: int64
type: integer
overriderRef:
type: string
poolReplicas:
additionalProperties:
format: int32
Expand All @@ -347,6 +353,27 @@ spec:
templateType:
description: TemplateType indicates the type of PoolTemplate
type: string
workloadSummary:
description: Records the topology detailed information of each workload.
items:
properties:
availableCondition:
type: string
readyReplicas:
format: int32
type: integer
replicas:
format: int32
type: integer
workloadName:
type: string
required:
- availableCondition
- readyReplicas
- replicas
- workloadName
type: object
type: array
required:
- currentRevision
- replicas
Expand Down
12 changes: 6 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ require (
go.etcd.io/etcd/api/v3 v3.5.0
go.etcd.io/etcd/client/pkg/v3 v3.5.0
go.etcd.io/etcd/client/v3 v3.5.0
golang.org/x/net v0.14.0
golang.org/x/sys v0.11.0
golang.org/x/net v0.15.0
golang.org/x/sys v0.12.0
google.golang.org/grpc v1.57.0
gopkg.in/cheggaaa/pb.v1 v1.0.28
gopkg.in/square/go-jose.v2 v2.6.0
Expand Down Expand Up @@ -150,11 +150,11 @@ require (
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/multierr v1.6.0 // indirect
go.uber.org/zap v1.24.0 // indirect
golang.org/x/crypto v0.12.0 // indirect
golang.org/x/crypto v0.13.0 // indirect
golang.org/x/oauth2 v0.7.0 // indirect
golang.org/x/sync v0.1.0 // indirect
golang.org/x/term v0.11.0 // indirect
golang.org/x/text v0.12.0 // indirect
golang.org/x/sync v0.3.0 // indirect
golang.org/x/term v0.12.0 // indirect
golang.org/x/text v0.13.0 // indirect
golang.org/x/time v0.3.0 // indirect
gomodules.xyz/jsonpatch/v2 v2.2.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
Expand Down
24 changes: 12 additions & 12 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -773,8 +773,8 @@ golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8U
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20201002170205-7f63de1d35b0/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20210220033148-5ea612d1eb83/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I=
golang.org/x/crypto v0.12.0 h1:tFM/ta59kqch6LlvYnPa0yx5a83cL2nHflFhYKvv9Yk=
golang.org/x/crypto v0.12.0/go.mod h1:NF0Gs7EO5K4qLn+Ylc+fih8BSTeIjAP05siRnAh98yw=
golang.org/x/crypto v0.13.0 h1:mvySKfSWJ+UKUii46M40LOvyWfN0s2U+46/jDd0e6Ck=
golang.org/x/crypto v0.13.0/go.mod h1:y6Z2r+Rw4iayiXXAIxJIDAJ1zMW4yaTpebo8fPOliYc=
golang.org/x/exp v0.0.0-20180321215751-8460e604b9de/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20180807140117-3d87b88a115f/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
Expand Down Expand Up @@ -855,8 +855,8 @@ golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96b
golang.org/x/net v0.0.0-20210428140749-89ef3d95e781/go.mod h1:OJAsFXCWl8Ukc7SiCT/9KSuxbyM7479/AVlXFRxuMCk=
golang.org/x/net v0.0.0-20210520170846-37e1c6afe023/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20211029224645-99673261e6eb/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.14.0 h1:BONx9s002vGdD9umnlX1Po8vOZmrgH34qlHcD1MfK14=
golang.org/x/net v0.14.0/go.mod h1:PpSgVXXLK0OxS0F31C1/tv6XNguvCrnXIDrFMspZIUI=
golang.org/x/net v0.15.0 h1:ugBLEUaxABaB5AJqW9enI0ACdci2RUd4eP51NTBvuJ8=
golang.org/x/net v0.15.0/go.mod h1:idbUs1IY1+zTqbi8yxTbhexhEEk5ur9LInksu6HrEpk=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
Expand All @@ -873,8 +873,8 @@ golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJ
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o=
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.3.0 h1:ftCYgMx6zT/asHUrPw8BLLscYtGznsLAnjq5RH9P66E=
golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y=
golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
Expand Down Expand Up @@ -939,13 +939,13 @@ golang.org/x/sys v0.0.0-20210906170528-6f6e22806c34/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20211025201205-69cdffdb9359/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211116061358-0a5406a5449c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.11.0 h1:eG7RXZHdqOJ1i+0lgLgCpSXAp6M3LYlAo6osgSi0xOM=
golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o=
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.11.0 h1:F9tnn/DA/Im8nCwm+fX+1/eBwi4qFjRT++MhtVC4ZX0=
golang.org/x/term v0.11.0/go.mod h1:zC9APTIj3jG3FdV/Ons+XE1riIZXG4aZ4GTHiPZJPIU=
golang.org/x/term v0.12.0 h1:/ZfYdc3zq+q02Rv9vGqTeSItdzZTSNDmfTi0mBAuidU=
golang.org/x/term v0.12.0/go.mod h1:owVbMEjm3cBLCHdkQu9b1opXd4ETQWc3BhuQGKgXgvU=
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
Expand All @@ -954,8 +954,8 @@ golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.12.0 h1:k+n5B8goJNdU7hSvEtMUz3d1Q6D/XW4COJSJR6fN0mc=
golang.org/x/text v0.12.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k=
golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
Expand Down
7 changes: 7 additions & 0 deletions pkg/apis/apps/v1alpha1/yurtappdaemon_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ type YurtAppDaemonStatus struct {
// +optional
Conditions []YurtAppDaemonCondition `json:"conditions,omitempty"`

OverriderRef string `json:"overriderRef,omitempty"`

// Records the topology detailed information of each workload.
// +optional
WorkloadSummaries []WorkloadSummary `json:"workloadSummary,omitempty"`

// TemplateType indicates the type of PoolTemplate
TemplateType TemplateType `json:"templateType"`

Expand Down Expand Up @@ -105,6 +111,7 @@ type YurtAppDaemonCondition struct {
// +kubebuilder:resource:scope=Namespaced,path=yurtappdaemons,shortName=yad,categories=all
// +kubebuilder:printcolumn:name="WorkloadTemplate",type="string",JSONPath=".status.templateType",description="The WorkloadTemplate Type."
// +kubebuilder:printcolumn:name="AGE",type="date",JSONPath=".metadata.creationTimestamp",description="CreationTimestamp is a timestamp representing the server time when this object was created. It is not guaranteed to be set in happens-before order across separate operations. Clients may not set this value. It is represented in RFC3339 form and is in UTC."
// +kubebuilder:printcolumn:name="OverriderRef",type="string",JSONPath=".status.overriderRef",description="The name of overrider bound to this yurtappdaemon"

// YurtAppDaemon is the Schema for the samples API
type YurtAppDaemon struct {
Expand Down
14 changes: 14 additions & 0 deletions pkg/apis/apps/v1alpha1/yurtappset_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,12 @@ type YurtAppSetStatus struct {
// +optional
Conditions []YurtAppSetCondition `json:"conditions,omitempty"`

// Records the topology detailed information of each workload.
// +optional
WorkloadSummaries []WorkloadSummary `json:"workloadSummary,omitempty"`

OverriderRef string `json:"overriderRef,omitempty"`

// Records the topology detail information of the replicas of each pool.
// +optional
PoolReplicas map[string]int32 `json:"poolReplicas,omitempty"`
Expand All @@ -178,6 +184,13 @@ type YurtAppSetStatus struct {
TemplateType TemplateType `json:"templateType"`
}

type WorkloadSummary struct {
AvailableCondition corev1.ConditionStatus `json:"availableCondition"`
Replicas int32 `json:"replicas"`
ReadyReplicas int32 `json:"readyReplicas"`
WorkloadName string `json:"workloadName"`
}

// YurtAppSetCondition describes current state of a YurtAppSet.
type YurtAppSetCondition struct {
// Type of in place set condition.
Expand All @@ -203,6 +216,7 @@ type YurtAppSetCondition struct {
// +kubebuilder:printcolumn:name="READY",type="integer",JSONPath=".status.readyReplicas",description="The number of pods ready."
// +kubebuilder:printcolumn:name="WorkloadTemplate",type="string",JSONPath=".status.templateType",description="The WorkloadTemplate Type."
// +kubebuilder:printcolumn:name="AGE",type="date",JSONPath=".metadata.creationTimestamp",description="CreationTimestamp is a timestamp representing the server time when this object was created. It is not guaranteed to be set in happens-before order across separate operations. Clients may not set this value. It is represented in RFC3339 form and is in UTC."
// +kubebuilder:printcolumn:name="OverriderRef",type="string",JSONPath=".status.overriderRef",description="The name of overrider bound to this yurtappset"

// YurtAppSet is the Schema for the yurtAppSets API
type YurtAppSet struct {
Expand Down
25 changes: 25 additions & 0 deletions pkg/apis/apps/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions pkg/yurtmanager/controller/yurtappdaemon/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ func GetYurtAppDaemonCondition(status unitv1alpha1.YurtAppDaemonStatus, condType
return nil
}

// RemoveYurtAppDaemonCondition removes the YurtAppDaemon condition with the provided type.
func RemoveYurtAppDaemonCondition(status *unitv1alpha1.YurtAppDaemonStatus, condType unitv1alpha1.YurtAppDaemonConditionType) {
status.Conditions = filterOutCondition(status.Conditions, condType)
}

// SetYurtAppDaemonCondition updates the YurtAppDaemon to include the provided condition. If the condition that
// we are about to add already exists and has the same status, reason and message then we are not going to update.
func SetYurtAppDaemonCondition(status *unitv1alpha1.YurtAppDaemonStatus, condition *unitv1alpha1.YurtAppDaemonCondition) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"errors"

appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
Expand Down Expand Up @@ -185,6 +186,13 @@ func (d *DeploymentControllor) GetAllWorkloads(yad *v1alpha1.YurtAppDaemon) ([]*
for i, o := range objs {
deploy := o.(*appsv1.Deployment)
spec := deploy.Spec
var availableCondition corev1.ConditionStatus
for _, condition := range deploy.Status.Conditions {
if condition.Type == appsv1.DeploymentAvailable {
availableCondition = condition.Status
break
}
}
w := &Workload{
Name: o.GetName(),
Namespace: o.GetNamespace(),
Expand All @@ -194,6 +202,11 @@ func (d *DeploymentControllor) GetAllWorkloads(yad *v1alpha1.YurtAppDaemon) ([]*
NodeSelector: spec.Template.Spec.NodeSelector,
Tolerations: spec.Template.Spec.Tolerations,
},
Status: WorkloadStatus{
Replicas: deploy.Status.Replicas,
ReadyReplicas: deploy.Status.ReadyReplicas,
AvailableCondition: availableCondition,
},
}
workloads = append(workloads, w)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ type WorkloadSpec struct {

// WorkloadStatus stores the observed state of the Workload.
type WorkloadStatus struct {
Replicas int32
ReadyReplicas int32
AvailableCondition corev1.ConditionStatus
}

func (w *Workload) GetRevision() string {
Expand Down
Loading

0 comments on commit f782021

Please sign in to comment.