|
4 | 4 | "context"
|
5 | 5 | "fmt"
|
6 | 6 | "math/rand"
|
| 7 | + "reflect" |
7 | 8 |
|
8 | 9 | "github.com/golang-jwt/jwt/v4"
|
9 | 10 | "github.com/google/go-cmp/cmp"
|
@@ -116,10 +117,6 @@ func (r *StorageDefaulter) Default(ctx context.Context, obj runtime.Object) erro
|
116 | 117 | storage := obj.(*Storage)
|
117 | 118 | storagelog.Info("default", "name", storage.Name)
|
118 | 119 |
|
119 |
| - if !storage.Spec.OperatorSync { |
120 |
| - return nil |
121 |
| - } |
122 |
| - |
123 | 120 | if storage.Spec.OperatorConnection != nil {
|
124 | 121 | if storage.Spec.OperatorConnection.Oauth2TokenExchange != nil {
|
125 | 122 | if storage.Spec.OperatorConnection.Oauth2TokenExchange.SignAlg == "" {
|
@@ -311,9 +308,38 @@ func hasUpdatesBesidesFrozen(oldStorage, newStorage *Storage) (bool, string) {
|
311 | 308 | oldStorageCopy.Spec.OperatorSync = false
|
312 | 309 | newStorageCopy.Spec.OperatorSync = false
|
313 | 310 |
|
314 |
| - ignoreNonSpecFields := cmpopts.IgnoreFields(Storage{}, "Status", "ObjectMeta", "TypeMeta") |
| 311 | + // We will allow configuration diffs if they are limited to |
| 312 | + // formatting, order of keys in the map etc. If two maps are |
| 313 | + // meaningfully different (not deep-equal), we still disallow |
| 314 | + // the diff of course. |
| 315 | + configurationCompareOpt := cmp.FilterPath( |
| 316 | + func(path cmp.Path) bool { |
| 317 | + if sf, ok := path.Last().(cmp.StructField); ok { |
| 318 | + return sf.Name() == "Configuration" |
| 319 | + } |
| 320 | + return false |
| 321 | + }, |
| 322 | + cmp.Comparer(func(a, b string) bool { |
| 323 | + var o1, o2 any |
315 | 324 |
|
316 |
| - diff := cmp.Diff(oldStorageCopy, newStorageCopy, ignoreNonSpecFields) |
| 325 | + if err := yaml.Unmarshal([]byte(a), &o1); err != nil { |
| 326 | + return false |
| 327 | + } |
| 328 | + if err := yaml.Unmarshal([]byte(b), &o2); err != nil { |
| 329 | + return false |
| 330 | + } |
| 331 | + |
| 332 | + return reflect.DeepEqual(o1, o2) |
| 333 | + }), |
| 334 | + ) |
| 335 | + |
| 336 | + ignoreNonSpecFields := cmpopts.IgnoreFields(Storage{}, "Status", "ObjectMeta", "TypeMeta") |
| 337 | + diff := cmp.Diff( |
| 338 | + oldStorageCopy, |
| 339 | + newStorageCopy, |
| 340 | + ignoreNonSpecFields, |
| 341 | + configurationCompareOpt, |
| 342 | + ) |
317 | 343 | return diff != "", diff
|
318 | 344 | }
|
319 | 345 |
|
|
0 commit comments