//TestUIDContext validates that a UID can be get/set on a context object
func TestUIDContext(t *testing.T) {
	ctx := genericapirequest.NewContext()
	_, ok := genericapirequest.UIDFrom(ctx)
	if ok {
		t.Fatalf("Should not be ok because there is no UID on the context")
	}
	ctx = genericapirequest.WithUID(
		ctx,
		types.UID("testUID"),
	)
	_, ok = genericapirequest.UIDFrom(ctx)
	if !ok {
		t.Fatalf("Error getting UID")
	}
}
Exemple #2
0
// FillObjectMetaSystemFields populates fields that are managed by the system on ObjectMeta.
func FillObjectMetaSystemFields(ctx genericapirequest.Context, meta *metav1.ObjectMeta) {
	meta.CreationTimestamp = metav1.Now()
	// allows admission controllers to assign a UID earlier in the request processing
	// to support tracking resources pending creation.
	uid, found := genericapirequest.UIDFrom(ctx)
	if !found {
		uid = uuid.NewUUID()
	}
	meta.UID = uid
	meta.SelfLink = ""
}