-
Notifications
You must be signed in to change notification settings - Fork 432
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2310 from FabianKramm/main
fix: ignore excluded annotations on create
- Loading branch information
Showing
4 changed files
with
151 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
package translate | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/loft-sh/vcluster/pkg/syncer/synccontext" | ||
"gotest.tools/v3/assert" | ||
storagev1 "k8s.io/api/storage/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/types" | ||
) | ||
|
||
func TestAnnotationsSync(t *testing.T) { | ||
// exclude the default class | ||
vAnnotations, pAnnotations := AnnotationsBidirectionalUpdate(synccontext.NewSyncEventWithOld( | ||
&storagev1.StorageClass{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Annotations: map[string]string{ | ||
"storageclass.kubernetes.io/is-default-class": "my-default", | ||
}, | ||
}, | ||
}, | ||
&storagev1.StorageClass{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Annotations: map[string]string{ | ||
"storageclass.kubernetes.io/is-default-class": "my-other", | ||
}, | ||
}, | ||
}, | ||
&storagev1.StorageClass{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Annotations: map[string]string{ | ||
"storageclass.kubernetes.io/is-default-class": "my-default", | ||
}, | ||
}, | ||
}, | ||
&storagev1.StorageClass{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Annotations: map[string]string{ | ||
"storageclass.kubernetes.io/is-default-class": "my-default", | ||
}, | ||
}, | ||
}, | ||
), "storageclass.kubernetes.io/is-default-class") | ||
assert.DeepEqual(t, vAnnotations, map[string]string{ | ||
"storageclass.kubernetes.io/is-default-class": "my-default", | ||
}) | ||
assert.DeepEqual(t, pAnnotations, map[string]string{ | ||
"storageclass.kubernetes.io/is-default-class": "my-other", | ||
NameAnnotation: "", | ||
UIDAnnotation: "", | ||
KindAnnotation: storagev1.SchemeGroupVersion.WithKind("StorageClass").String(), | ||
HostNameAnnotation: "", | ||
}) | ||
|
||
// not exclude the default class | ||
vAnnotations, pAnnotations = AnnotationsBidirectionalUpdate(synccontext.NewSyncEventWithOld( | ||
&storagev1.StorageClass{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Annotations: map[string]string{ | ||
"storageclass.kubernetes.io/is-default-class": "my-default", | ||
}, | ||
}, | ||
}, | ||
&storagev1.StorageClass{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Annotations: map[string]string{ | ||
"storageclass.kubernetes.io/is-default-class": "my-other", | ||
}, | ||
}, | ||
}, | ||
&storagev1.StorageClass{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Annotations: map[string]string{ | ||
"storageclass.kubernetes.io/is-default-class": "my-default", | ||
}, | ||
}, | ||
}, | ||
&storagev1.StorageClass{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Annotations: map[string]string{ | ||
"storageclass.kubernetes.io/is-default-class": "my-default", | ||
}, | ||
}, | ||
}, | ||
)) | ||
assert.DeepEqual(t, vAnnotations, map[string]string{ | ||
"storageclass.kubernetes.io/is-default-class": "my-other", | ||
}) | ||
assert.DeepEqual(t, pAnnotations, map[string]string{ | ||
"storageclass.kubernetes.io/is-default-class": "my-other", | ||
NameAnnotation: "", | ||
UIDAnnotation: "", | ||
KindAnnotation: storagev1.SchemeGroupVersion.WithKind("StorageClass").String(), | ||
HostNameAnnotation: "", | ||
}) | ||
|
||
// check on creation with exclude host -> virtual | ||
pObj := &storagev1.StorageClass{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Annotations: map[string]string{ | ||
"storageclass.kubernetes.io/is-default-class": "my-default", | ||
"not-excluded": "true", | ||
}, | ||
}, | ||
} | ||
vObj := CopyObjectWithName(pObj, types.NamespacedName{}, true, "storageclass.kubernetes.io/is-default-class") | ||
vAnnotations = VirtualAnnotations(pObj, vObj, "storageclass.kubernetes.io/is-default-class") | ||
assert.DeepEqual(t, vAnnotations, map[string]string{ | ||
"not-excluded": "true", | ||
}) | ||
|
||
// check on creation with exclude virtual -> host | ||
vObj = &storagev1.StorageClass{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Annotations: map[string]string{ | ||
"storageclass.kubernetes.io/is-default-class": "my-default", | ||
"not-excluded": "true", | ||
}, | ||
}, | ||
} | ||
pObj = CopyObjectWithName(vObj, types.NamespacedName{}, true, "storageclass.kubernetes.io/is-default-class") | ||
pAnnotations = HostAnnotations(vObj, pObj, "storageclass.kubernetes.io/is-default-class") | ||
assert.DeepEqual(t, pAnnotations, map[string]string{ | ||
"not-excluded": "true", | ||
ManagedAnnotationsAnnotation: "not-excluded", | ||
NameAnnotation: "", | ||
UIDAnnotation: "", | ||
KindAnnotation: storagev1.SchemeGroupVersion.WithKind("StorageClass").String(), | ||
HostNameAnnotation: "", | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters