Skip to content

Commit

Permalink
kapp deploy without disable original annotation when resource size ex…
Browse files Browse the repository at this point in the history
…ceed (carvel-dev#430)
  • Loading branch information
sethiyash authored Feb 17, 2022
1 parent af35dd5 commit 3486b0b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
7 changes: 6 additions & 1 deletion pkg/kapp/clusterapply/add_or_update_change.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,11 +235,16 @@ func (c AddOrUpdateChange) recordAppliedResource(savedRes ctlres.Resource) error
}

// Record last applied change on the latest version of a resource
latestResWithHistoryUpdated, err := latestResWithHistory.RecordLastAppliedResource(applyChange)
latestResWithHistoryUpdated, madeAnyModifications, err := latestResWithHistory.RecordLastAppliedResource(applyChange)
if err != nil {
return true, fmt.Errorf("Recording last applied resource: %s", err)
}

// when annotation value max length exceed then don't record the resource hence not making any modification
if !madeAnyModifications {
return true, nil
}

_, err = c.identifiedResources.Update(latestResWithHistoryUpdated)
if err != nil {
latestResWithHistory = nil // Get again
Expand Down
16 changes: 8 additions & 8 deletions pkg/kapp/diff/resource_with_history.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,13 @@ func (r ResourceWithHistory) AllowsRecordingLastApplied() bool {
return !found
}

func (r ResourceWithHistory) RecordLastAppliedResource(appliedChange Change) (ctlres.Resource, error) {
func (r ResourceWithHistory) RecordLastAppliedResource(appliedChange Change) (ctlres.Resource, bool, error) {
// Use compact representation to take as little space as possible
// because annotation value max length is 262144 characters
// (https://github.com/vmware-tanzu/carvel-kapp/issues/48).
appliedResBytes, err := appliedChange.AppliedResource().AsCompactBytes()
if err != nil {
return nil, err
return nil, true, err
}

diff := appliedChange.OpsDiff()
Expand All @@ -100,22 +100,22 @@ func (r ResourceWithHistory) RecordLastAppliedResource(appliedChange Change) (ct

const annValMaxLen = 262144

for annKey, annVal := range annsMod.KVs {
// kapp deploy should work without adding disable annotation when annotation value max length exceed
// (https://github.com/vmware-tanzu/carvel-kapp/issues/410)
for _, annVal := range annsMod.KVs {
if len(annVal) > annValMaxLen {
return nil, fmt.Errorf("Expected annotation '%s' value length %d to be <= max length %d "+
"(hint: consider using annotation '%s')",
annKey, len(annVal), annValMaxLen, disableOriginalAnnKey)
return nil, false, nil
}
}

resultRes := r.resource.DeepCopy()

err = annsMod.Apply(resultRes)
if err != nil {
return nil, err
return nil, true, err
}

return resultRes, nil
return resultRes, true, nil
}

func (r ResourceWithHistory) CalculateChange(appliedRes ctlres.Resource) (Change, error) {
Expand Down

0 comments on commit 3486b0b

Please sign in to comment.