add conditions to karmada cr
Signed-off-by: calvin <wen.chen@daocloud.io>
This commit is contained in:
parent
912ba8eac4
commit
1d37894492
|
@ -16,8 +16,8 @@ spec:
|
|||
scope: Namespaced
|
||||
versions:
|
||||
- additionalPrinterColumns:
|
||||
- jsonPath: .status.controlPlaneReady
|
||||
name: Status
|
||||
- jsonPath: .status.conditions[?(@.type=="Ready")].status
|
||||
name: Ready
|
||||
type: string
|
||||
- jsonPath: .metadata.creationTimestamp
|
||||
name: Age
|
||||
|
|
|
@ -16,8 +16,8 @@ spec:
|
|||
scope: Namespaced
|
||||
versions:
|
||||
- additionalPrinterColumns:
|
||||
- jsonPath: .status.controlPlaneReady
|
||||
name: Status
|
||||
- jsonPath: .status.conditions[?(@.type=="Ready")].status
|
||||
name: Ready
|
||||
type: string
|
||||
- jsonPath: .metadata.creationTimestamp
|
||||
name: Age
|
||||
|
|
|
@ -2,9 +2,48 @@ package v1alpha1
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
apimeta "k8s.io/apimachinery/pkg/api/meta"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
)
|
||||
|
||||
// Name returns the image name.
|
||||
func (image *Image) Name() string {
|
||||
return fmt.Sprintf("%s:%s", image.ImageRepository, image.ImageTag)
|
||||
}
|
||||
|
||||
func KarmadaInProgressing(karmada *Karmada, conditionType ConditionType, message string) {
|
||||
karmada.Status.Conditions = []metav1.Condition{}
|
||||
newCondition := metav1.Condition{
|
||||
Type: string(conditionType),
|
||||
Status: metav1.ConditionFalse,
|
||||
Reason: "Progressing",
|
||||
Message: message,
|
||||
}
|
||||
|
||||
apimeta.SetStatusCondition(&karmada.Status.Conditions, newCondition)
|
||||
}
|
||||
|
||||
func KarmadaCompleted(karmada *Karmada, conditionType ConditionType, message string) {
|
||||
karmada.Status.Conditions = []metav1.Condition{}
|
||||
newCondition := metav1.Condition{
|
||||
Type: string(conditionType),
|
||||
Status: metav1.ConditionTrue,
|
||||
Reason: "Completed",
|
||||
Message: message,
|
||||
}
|
||||
|
||||
apimeta.SetStatusCondition(&karmada.Status.Conditions, newCondition)
|
||||
}
|
||||
|
||||
func KarmadaFailed(karmada *Karmada, conditionType ConditionType, message string) {
|
||||
karmada.Status.Conditions = []metav1.Condition{}
|
||||
newCondition := metav1.Condition{
|
||||
Type: string(conditionType),
|
||||
Status: metav1.ConditionFalse,
|
||||
Reason: "Failed",
|
||||
Message: message,
|
||||
}
|
||||
|
||||
apimeta.SetStatusCondition(&karmada.Status.Conditions, newCondition)
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@ import (
|
|||
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
|
||||
// +kubebuilder:subresource:status
|
||||
// +kubebuilder:path=karmadas,scope=Namespaced,categories={karmada-io}
|
||||
// +kubebuilder:printcolumn:JSONPath=`.status.controlPlaneReady`,name="Status",type=string
|
||||
// +kubebuilder:printcolumn:JSONPath=`.status.conditions[?(@.type=="Ready")].status`,name="Ready",type=string
|
||||
// +kubebuilder:printcolumn:JSONPath=`.metadata.creationTimestamp`,name="Age",type=date
|
||||
|
||||
// Karmada enables declarative installation of karmada.
|
||||
|
@ -557,10 +557,6 @@ type HostCluster struct {
|
|||
type ConditionType string
|
||||
|
||||
const (
|
||||
// Unknown represent a condition type the karmada not be reconciled by operator
|
||||
// or unpredictable condition.
|
||||
Unknown ConditionType = "Unknown"
|
||||
|
||||
// Ready represent a condition type the all installation process to karmada have completed.
|
||||
Ready ConditionType = "Ready"
|
||||
)
|
||||
|
|
|
@ -59,8 +59,8 @@ func (ctrl *Controller) Reconcile(ctx context.Context, req controllerruntime.Req
|
|||
|
||||
// The object is being deleted
|
||||
if !karmada.DeletionTimestamp.IsZero() {
|
||||
value, isExist := karmada.Labels[DisableCascadingDeletionLabel]
|
||||
if !isExist || value == strconv.FormatBool(false) {
|
||||
val, ok := karmada.Labels[DisableCascadingDeletionLabel]
|
||||
if !ok || val == strconv.FormatBool(false) {
|
||||
if err := ctrl.syncKarmada(karmada); err != nil {
|
||||
return controllerruntime.Result{}, err
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package karmada
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"k8s.io/client-go/rest"
|
||||
|
@ -83,10 +84,44 @@ func recognizeActionFor(karmada *operatorv1alpha1.Karmada) Action {
|
|||
func (p *Planner) Execute() error {
|
||||
klog.InfoS("Start execute the workflow", "workflow", p.action, "karmada", klog.KObj(p.karmada))
|
||||
|
||||
if err := p.preRunJob(); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := p.job.Run(); err != nil {
|
||||
return p.runJobErr(err)
|
||||
}
|
||||
if err := p.afterRunJob(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
klog.InfoS("Successfully executed the workflow", "workflow", p.action, "karmada", klog.KObj(p.karmada))
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *Planner) preRunJob() error {
|
||||
if p.action == InitAction {
|
||||
operatorv1alpha1.KarmadaInProgressing(p.karmada, operatorv1alpha1.Ready, "karmada init job is in progressing")
|
||||
}
|
||||
if p.action == DeInitAction {
|
||||
operatorv1alpha1.KarmadaInProgressing(p.karmada, operatorv1alpha1.Ready, "karmada deinit job is in progressing")
|
||||
}
|
||||
|
||||
return p.Client.Status().Update(context.TODO(), p.karmada)
|
||||
}
|
||||
|
||||
func (p *Planner) runJobErr(err error) error {
|
||||
operatorv1alpha1.KarmadaFailed(p.karmada, operatorv1alpha1.Ready, err.Error())
|
||||
return p.Client.Status().Update(context.TODO(), p.karmada)
|
||||
}
|
||||
|
||||
func (p *Planner) afterRunJob() error {
|
||||
if p.action == InitAction {
|
||||
operatorv1alpha1.KarmadaCompleted(p.karmada, operatorv1alpha1.Ready, "karmada init job is completed")
|
||||
return p.Client.Status().Update(context.TODO(), p.karmada)
|
||||
}
|
||||
|
||||
// if it is deInit workflow, the cr will be deleted with karmada is be deleted, so we need not to
|
||||
// update the karmada status.
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue