diff --git a/e2e/resources/attachedcluster.go b/e2e/resources/attachedcluster.go index 6b64cdb1..ae5dd238 100644 --- a/e2e/resources/attachedcluster.go +++ b/e2e/resources/attachedcluster.go @@ -53,8 +53,16 @@ func CreateOrUpdateAttachedCluster(client kurator.Interface, attachedCluster *cl if getErr != nil { return getErr } - attachedCluster.ResourceVersion = originalAttachedCluster.ResourceVersion - attachedClusterPatchData, createPatchErr := CreatePatchData(originalAttachedCluster, attachedCluster) + modifiedObjectMeta := ModifiedObjectMeta(originalAttachedCluster.ObjectMeta, attachedCluster.ObjectMeta) + oldAttachedCluster := clusterv1a1.AttachedCluster{ + ObjectMeta: originalAttachedCluster.ObjectMeta, + Spec: originalAttachedCluster.Spec, + } + modAttachedCluster := clusterv1a1.AttachedCluster{ + ObjectMeta: modifiedObjectMeta, + Spec: attachedCluster.Spec, + } + attachedClusterPatchData, createPatchErr := CreatePatchData(oldAttachedCluster, modAttachedCluster) if createPatchErr != nil { return createPatchErr } diff --git a/e2e/resources/fleet.go b/e2e/resources/fleet.go index 60fc367b..2aae959d 100644 --- a/e2e/resources/fleet.go +++ b/e2e/resources/fleet.go @@ -55,8 +55,16 @@ func CreateOrUpdateFleet(client kurator.Interface, fleet *fleetv1a1.Fleet) error if getErr != nil { return getErr } - fleet.ResourceVersion = originalFleet.ResourceVersion - fleetPatchData, createPatchErr := CreatePatchData(originalFleet, fleet) + modifiedObjectMeta := ModifiedObjectMeta(originalFleet.ObjectMeta, fleet.ObjectMeta) + oldFleet := fleetv1a1.Fleet{ + ObjectMeta: originalFleet.ObjectMeta, + Spec: originalFleet.Spec, + } + modFleet := fleetv1a1.Fleet{ + ObjectMeta: modifiedObjectMeta, + Spec: fleet.Spec, + } + fleetPatchData, createPatchErr := CreatePatchData(oldFleet, modFleet) if createPatchErr != nil { return createPatchErr } diff --git a/e2e/resources/secret.go b/e2e/resources/secret.go index 221427b5..50d723a9 100644 --- a/e2e/resources/secret.go +++ b/e2e/resources/secret.go @@ -50,8 +50,16 @@ func CreateOrUpdateSecret(client kubernetes.Interface, secret *corev1.Secret) er if getErr != nil { return getErr } - secret.ResourceVersion = originalSecret.ResourceVersion - secretPatchData, createPatchErr := CreatePatchData(originalSecret, secret) + modifiedObjectMeta := ModifiedObjectMeta(originalSecret.ObjectMeta, secret.ObjectMeta) + oldSecret := corev1.Secret{ + ObjectMeta: originalSecret.ObjectMeta, + Data: originalSecret.Data, + } + modSecret := corev1.Secret{ + ObjectMeta: modifiedObjectMeta, + Data: secret.Data, + } + secretPatchData, createPatchErr := CreatePatchData(oldSecret, modSecret) if createPatchErr != nil { return createPatchErr } diff --git a/e2e/resources/util.go b/e2e/resources/util.go index cf1a322b..3e6c2166 100644 --- a/e2e/resources/util.go +++ b/e2e/resources/util.go @@ -20,14 +20,15 @@ import ( "encoding/json" jsonpatch "github.com/evanphx/json-patch" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) -func CreatePatchData(originalAttachedCluster, modifiedAttachedCluster interface{}) ([]byte, error) { - originalData, originalErr := json.Marshal(originalAttachedCluster) +func CreatePatchData(original, modified interface{}) ([]byte, error) { + originalData, originalErr := json.Marshal(original) if originalErr != nil { return nil, originalErr } - modifiedData, modifiedErr := json.Marshal(modifiedAttachedCluster) + modifiedData, modifiedErr := json.Marshal(modified) if modifiedErr != nil { return nil, modifiedErr } @@ -37,3 +38,40 @@ func CreatePatchData(originalAttachedCluster, modifiedAttachedCluster interface{ } return patchData, nil } + +func ModifiedObjectMeta(original, modified metav1.ObjectMeta) metav1.ObjectMeta { + var labelsMap = make(map[string]string) + var annotationMap = make(map[string]string) + + if original.Labels != nil { + for key, value := range original.Labels { + labelsMap[key] = value + } + } + if modified.Labels != nil { + for key, value := range modified.Labels { + labelsMap[key] = value + } + } + + if original.Annotations != nil { + for key, value := range original.Annotations { + annotationMap[key] = value + } + } + if modified.Annotations != nil { + for key, value := range modified.Annotations { + annotationMap[key] = value + } + } + + modified.Labels = labelsMap + modified.Annotations = annotationMap + if modified.Finalizers == nil { + modified.Finalizers = original.Finalizers + } + if modified.ResourceVersion == "" { + modified.ResourceVersion = original.ResourceVersion + } + return modified +}