4
4
package diff
5
5
6
6
import (
7
+ "encoding/json"
7
8
"fmt"
8
9
"os"
9
10
@@ -68,13 +69,13 @@ func (r ResourceWithHistory) AllowsRecordingLastApplied() bool {
68
69
return ! found
69
70
}
70
71
71
- func (r ResourceWithHistory ) RecordLastAppliedResource (appliedChange Change ) (ctlres. Resource , bool , error ) {
72
+ func (r ResourceWithHistory ) RecordLastAppliedResource (appliedChange Change ) (string , bool , error ) {
72
73
// Use compact representation to take as little space as possible
73
74
// because annotation value max length is 262144 characters
74
75
// (https://github.com/vmware-tanzu/carvel-kapp/issues/48).
75
76
appliedResBytes , err := appliedChange .AppliedResource ().AsCompactBytes ()
76
77
if err != nil {
77
- return nil , true , err
78
+ return "" , true , err
78
79
}
79
80
80
81
diff := appliedChange .OpsDiff ()
@@ -84,37 +85,30 @@ func (r ResourceWithHistory) RecordLastAppliedResource(appliedChange Change) (ct
84
85
r .resource .Description (), diff .MinimalMD5 (), diff .MinimalString ())
85
86
}
86
87
87
- annsMod := ctlres.StringMapAppendMod {
88
- ResourceMatcher : ctlres.AllMatcher {},
89
- Path : ctlres .NewPathFromStrings ([]string {"metadata" , "annotations" }),
90
- KVs : map [string ]string {
91
- appliedResAnnKey : string (appliedResBytes ),
92
- appliedResDiffMD5AnnKey : diff .MinimalMD5 (),
88
+ annsKVS := map [string ]string {
89
+ appliedResAnnKey : string (appliedResBytes ),
90
+ appliedResDiffMD5AnnKey : diff .MinimalMD5 (),
93
91
94
- // Following fields useful for debugging:
95
- // debugAppliedResDiffAnnKey: diff.MinimalString(),
96
- // debugAppliedResDiffFullAnnKey: diff.FullString(),
97
- },
92
+ // Following fields useful for debugging:
93
+ // debugAppliedResDiffAnnKey: diff.MinimalString(),
94
+ // debugAppliedResDiffFullAnnKey: diff.FullString(),
98
95
}
99
96
100
97
const annValMaxLen = 262144
101
98
102
99
// kapp deploy should work without adding disable annotation when annotation value max length exceed
103
100
// (https://github.com/vmware-tanzu/carvel-kapp/issues/410)
104
- for _ , annVal := range annsMod . KVs {
101
+ for _ , annVal := range annsKVS {
105
102
if len (annVal ) > annValMaxLen {
106
- return nil , false , nil
103
+ return "" , false , nil
107
104
}
108
105
}
109
106
110
- resultRes := r .resource .DeepCopy ()
111
-
112
- err = annsMod .Apply (resultRes )
107
+ result , err := json .Marshal (annsKVS )
113
108
if err != nil {
114
- return nil , true , err
109
+ return "" , false , err
115
110
}
116
-
117
- return resultRes , true , nil
111
+ return string (result ), true , nil
118
112
}
119
113
120
114
func (r ResourceWithHistory ) CalculateChange (appliedRes ctlres.Resource ) (Change , error ) {
0 commit comments