use corev1.ObjectReference insteadof crossplane-runtime TypedReference (#1974)

* refactor crossplane-runtime TypedReference to ObjectReference and make condtion locally

* fix test
This commit is contained in:
Jianbo Sun
2021-07-28 13:59:13 +08:00
committed by GitHub
parent e7041f913f
commit e71d71c6b7
108 changed files with 3116 additions and 1893 deletions

View File

@@ -21,9 +21,10 @@ import (
"fmt"
"reflect"
"github.com/oam-dev/kubevela/apis/core.oam.dev/condition"
controller "github.com/oam-dev/kubevela/pkg/controller/core.oam.dev"
cpv1alpha1 "github.com/crossplane/crossplane-runtime/apis/core/v1alpha1"
"github.com/crossplane/crossplane-runtime/pkg/event"
"github.com/go-logr/logr"
"github.com/pkg/errors"
@@ -100,7 +101,7 @@ func (r *Reconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) {
log.Error(err, "Failed to render a deployment")
r.record.Event(eventObj, event.Warning(errRenderDeployment, err))
return ctrl.Result{},
util.EndReconcileWithNegativeCondition(ctx, r, &workload, cpv1alpha1.ReconcileError(errors.Wrap(err, errRenderDeployment)))
util.EndReconcileWithNegativeCondition(ctx, r, &workload, condition.ReconcileError(errors.Wrap(err, errRenderDeployment)))
}
// server side apply
applyOpts := []client.PatchOption{client.ForceOwnership, client.FieldOwner(workload.GetUID())}
@@ -108,14 +109,14 @@ func (r *Reconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) {
log.Error(err, "Failed to apply to a deployment")
r.record.Event(eventObj, event.Warning(errApplyDeployment, err))
return ctrl.Result{},
util.EndReconcileWithNegativeCondition(ctx, r, &workload, cpv1alpha1.ReconcileError(errors.Wrap(err, errApplyDeployment)))
util.EndReconcileWithNegativeCondition(ctx, r, &workload, condition.ReconcileError(errors.Wrap(err, errApplyDeployment)))
}
r.record.Event(eventObj, event.Normal("Deployment created",
fmt.Sprintf("Workload `%s` successfully patched a deployment `%s`",
workload.Name, deploy.Name)))
// record the new deployment
workload.Status.Resources = []cpv1alpha1.TypedReference{
workload.Status.Resources = []corev1.ObjectReference{
{
APIVersion: deploy.GetObjectKind().GroupVersionKind().GroupVersion().String(),
Kind: deploy.GetObjectKind().GroupVersionKind().Kind,
@@ -133,21 +134,21 @@ func (r *Reconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) {
log.Error(err, "Failed to render a service")
r.record.Event(eventObj, event.Warning(errRenderService, err))
return ctrl.Result{},
util.EndReconcileWithNegativeCondition(ctx, r, &workload, cpv1alpha1.ReconcileError(errors.Wrap(err, errRenderService)))
util.EndReconcileWithNegativeCondition(ctx, r, &workload, condition.ReconcileError(errors.Wrap(err, errRenderService)))
}
// server side apply the service
if err := r.Patch(ctx, service, client.Apply, applyOpts...); err != nil {
log.Error(err, "Failed to apply a service")
r.record.Event(eventObj, event.Warning(errApplyDeployment, err))
return ctrl.Result{},
util.EndReconcileWithNegativeCondition(ctx, r, &workload, cpv1alpha1.ReconcileError(errors.Wrap(err, errApplyService)))
util.EndReconcileWithNegativeCondition(ctx, r, &workload, condition.ReconcileError(errors.Wrap(err, errApplyService)))
}
r.record.Event(eventObj, event.Normal("Service created",
fmt.Sprintf("Workload `%s` successfully server side patched a service `%s`",
workload.Name, service.Name)))
// record the new service
workload.Status.Resources = append(workload.Status.Resources, cpv1alpha1.TypedReference{
workload.Status.Resources = append(workload.Status.Resources, corev1.ObjectReference{
APIVersion: service.GetObjectKind().GroupVersionKind().GroupVersion().String(),
Kind: service.GetObjectKind().GroupVersionKind().Kind,
Name: service.GetName(),
@@ -155,9 +156,9 @@ func (r *Reconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) {
})
}
workload.SetConditions(cpv1alpha1.ReconcileSuccess())
workload.SetConditions(condition.ReconcileSuccess())
if err := r.UpdateStatus(ctx, &workload); err != nil {
return ctrl.Result{}, util.EndReconcileWithNegativeCondition(ctx, r, &workload, cpv1alpha1.ReconcileError(err))
return ctrl.Result{}, util.EndReconcileWithNegativeCondition(ctx, r, &workload, condition.ReconcileError(err))
}
return ctrl.Result{}, nil
}