@@ -20,7 +20,6 @@ import (
20
20
"encoding/json"
21
21
"errors"
22
22
"fmt"
23
- "reflect"
24
23
"strings"
25
24
26
25
jsonpatch "gomodules.xyz/jsonpatch/v3"
@@ -138,41 +137,28 @@ func notFoundErr(err error) bool {
138
137
return err != nil && strings .Contains (err .Error (), "not found" )
139
138
}
140
139
141
- // This is caused by the different logic of loading from local and loading from secret
142
- // For example, the Raw field, which has the tag `json:"-"`, causes the Unmarshal to be lost when it into Release
143
- // We need to make them follow the JSON tag
144
- // see: https://github.com/helm/helm/blob/cf0c6fed519d48101cd69ce01a355125215ee46f/pkg/storage/driver/util.go#L81
145
- func equalJSONStruct (a , b interface {}) (bool , error ) {
146
- if reflect .ValueOf (a ).IsNil () || reflect .ValueOf (b ).IsNil () {
147
- return apiequality .Semantic .DeepEqual (a , b ), nil
148
- }
149
-
150
- aBuf , bBuf := & bytes.Buffer {}, & bytes.Buffer {}
151
- err := json .NewEncoder (aBuf ).Encode (a )
152
- if err != nil {
153
- return false , err
154
- }
155
- err = json .NewEncoder (bBuf ).Encode (b )
156
- return aBuf .String () == bBuf .String (), err
140
+ func (m manager ) getCandidateRelease (namespace , name string , chart * cpb.Chart ,
141
+ values map [string ]interface {}) (* rpb.Release , error ) {
142
+ upgrade := action .NewUpgrade (m .actionConfig )
143
+ upgrade .Namespace = namespace
144
+ upgrade .DryRun = true
145
+ return upgrade .Run (name , chart , values )
157
146
}
158
147
159
148
func (m manager ) isUpgrade (deployedRelease * rpb.Release ) (bool , error ) {
160
149
if deployedRelease == nil {
161
150
return false , nil
162
151
}
163
152
164
- // Judging whether to skip updates
165
- skip := m .namespace == deployedRelease .Namespace
166
- skip = skip && m .releaseName == deployedRelease .Name
167
-
168
- ok , err := equalJSONStruct (m .chart , deployedRelease .Chart )
153
+ candidateRelease , err := m .getCandidateRelease (m .namespace , m .releaseName , m .chart , m .values )
169
154
if err != nil {
170
155
return false , err
171
156
}
172
- skip = skip && ok
173
157
174
- ok , err = equalJSONStruct (m .values , deployedRelease .Config )
175
- return ! (skip && ok ), err
158
+ skip := apiequality .Semantic .DeepEqual (candidateRelease .Chart , deployedRelease .Chart )
159
+ skip = skip && apiequality .Semantic .DeepEqual (candidateRelease .Config , deployedRelease .Config )
160
+
161
+ return ! skip , nil
176
162
}
177
163
178
164
func (m manager ) getDeployedRelease () (* rpb.Release , error ) {
0 commit comments