diff --git a/pkg/controller/v1alpha2/applicationconfiguration/render.go b/pkg/controller/v1alpha2/applicationconfiguration/render.go index 9de78df9..ec5489c4 100644 --- a/pkg/controller/v1alpha2/applicationconfiguration/render.go +++ b/pkg/controller/v1alpha2/applicationconfiguration/render.go @@ -21,6 +21,7 @@ import ( "encoding/json" "fmt" "reflect" + "strconv" runtimev1alpha1 "github.com/crossplane/crossplane-runtime/apis/core/v1alpha1" "github.com/crossplane/crossplane-runtime/pkg/fieldpath" @@ -136,6 +137,7 @@ func (r *components) renderComponent(ctx context.Context, acc v1alpha2.Applicati oam.LabelAppComponent: acc.ComponentName, oam.LabelAppComponentRevision: componentRevisionName, oam.LabelOAMResourceType: oam.ResourceTypeWorkload, + oam.LabelAppGeneration: strconv.FormatInt(ac.Generation, 10), } util.AddLabels(w, compInfoLabels) @@ -494,9 +496,14 @@ func (r *components) getDataInput(ctx context.Context, s *dagSource, ac *unstruc u.SetGroupVersionKind(obj.GroupVersionKind()) err := r.client.Get(ctx, key, u) if err != nil { - reason := fmt.Sprintf("failed to get object (%s)", key.String()) + reason := fmt.Sprintf("failed to get object (%s): %v", key.String(), err) return nil, false, reason, errors.Wrap(resource.IgnoreNotFound(err), reason) } + // + if u.GetLabels()[oam.LabelAppGeneration] != strconv.FormatInt(ac.GetGeneration(), 10) { + return nil, false, "generation not match", nil + } + paved := fieldpath.Pave(u.UnstructuredContent()) pavedAC := fieldpath.Pave(ac.UnstructuredContent()) diff --git a/pkg/oam/labels.go b/pkg/oam/labels.go index 97b72447..3377553b 100644 --- a/pkg/oam/labels.go +++ b/pkg/oam/labels.go @@ -25,6 +25,8 @@ const ( LabelAppComponent = "app.oam.dev/component" // LabelAppComponentRevision records the revision name of Component LabelAppComponentRevision = "app.oam.dev/revision" + // LabelAppGeneration records the generation of AppConfig + LabelAppGeneration = "app.oam.dev/generation" // LabelOAMResourceType whether a CR is workload or trait LabelOAMResourceType = "app.oam.dev/resourceType" )