Skip to content
This repository has been archived by the owner on Jun 8, 2022. It is now read-only.

Commit

Permalink
Use AppConfig's generation to get latest dependency only
Browse files Browse the repository at this point in the history
- pass AC's generation into child objects' labels
- check generation in getting data input

Signed-off-by: Hongchao Deng <[email protected]>
  • Loading branch information
hongchaodeng committed Sep 28, 2020
1 parent 97b69a0 commit 450760e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
17 changes: 15 additions & 2 deletions pkg/controller/v1alpha2/applicationconfiguration/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -494,12 +496,23 @@ 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)
}
paved := fieldpath.Pave(u.UnstructuredContent())

pavedAC := fieldpath.Pave(ac.UnstructuredContent())
var acGeneration int
if err := pavedAC.GetValueInto("metadata.generation", &acGeneration); err != nil {
return nil, false, err.Error(), err
}

// The source object's app generation should match current AC. Otherwise it is from an old AC and we should wait until
// it is updated then reconcile again.
if g1, g2 := u.GetLabels()[oam.LabelAppGeneration], strconv.Itoa(acGeneration); g1 != g2 {
return nil, false, fmt.Sprintf("generation not match: %s, %s", g1, g2), nil
}

paved := fieldpath.Pave(u.UnstructuredContent())
rawval, err := paved.GetValue(obj.FieldPath)
if err != nil {
if fieldpath.IsNotFound(err) {
Expand Down
2 changes: 2 additions & 0 deletions pkg/oam/labels.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down

0 comments on commit 450760e

Please sign in to comment.