mirror of https://github.com/k3s-io/k3s
pkg/api: move HasObjectMetaSystemFieldValues into apimachinery
parent
96cfe7b938
commit
d6adb51e6c
|
@ -1,27 +0,0 @@
|
|||
/*
|
||||
Copyright 2014 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package api
|
||||
|
||||
import (
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
)
|
||||
|
||||
// HasObjectMetaSystemFieldValues returns true if fields that are managed by the system on ObjectMeta have values.
|
||||
func HasObjectMetaSystemFieldValues(meta *metav1.ObjectMeta) bool {
|
||||
return !meta.CreationTimestamp.Time.IsZero() ||
|
||||
len(meta.UID) != 0
|
||||
}
|
|
@ -49,11 +49,11 @@ func TestFillObjectMetaSystemFields(t *testing.T) {
|
|||
func TestHasObjectMetaSystemFieldValues(t *testing.T) {
|
||||
ctx := genericapirequest.NewDefaultContext()
|
||||
resource := metav1.ObjectMeta{}
|
||||
if api.HasObjectMetaSystemFieldValues(&resource) {
|
||||
if metav1.HasObjectMetaSystemFieldValues(&resource) {
|
||||
t.Errorf("the resource does not have all fields yet populated, but incorrectly reports it does")
|
||||
}
|
||||
FillObjectMetaSystemFields(ctx, &resource)
|
||||
if !api.HasObjectMetaSystemFieldValues(&resource) {
|
||||
if !metav1.HasObjectMetaSystemFieldValues(&resource) {
|
||||
t.Errorf("the resource does have all fields populated, but incorrectly reports it does not")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -328,7 +328,7 @@ func (t *Tester) testCreateHasMetadata(valid runtime.Object) {
|
|||
t.Fatalf("Unexpected object from result: %#v", obj)
|
||||
}
|
||||
defer t.delete(t.TestContext(), obj)
|
||||
if !api.HasObjectMetaSystemFieldValues(objectMeta) {
|
||||
if !metav1.HasObjectMetaSystemFieldValues(objectMeta) {
|
||||
t.Errorf("storage did not populate object meta field values")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -98,7 +98,7 @@ func TestServiceRegistryCreate(t *testing.T) {
|
|||
t.Fatalf("Unexpected error: %v", err)
|
||||
}
|
||||
created_service := created_svc.(*api.Service)
|
||||
if !api.HasObjectMetaSystemFieldValues(&created_service.ObjectMeta) {
|
||||
if !metav1.HasObjectMetaSystemFieldValues(&created_service.ObjectMeta) {
|
||||
t.Errorf("storage did not populate object meta field values")
|
||||
}
|
||||
if created_service.Name != "foo" {
|
||||
|
@ -218,7 +218,7 @@ func TestServiceRegistryCreateMultiNodePortsService(t *testing.T) {
|
|||
t.Fatalf("Unexpected error: %v", err)
|
||||
}
|
||||
created_service := created_svc.(*api.Service)
|
||||
if !api.HasObjectMetaSystemFieldValues(&created_service.ObjectMeta) {
|
||||
if !metav1.HasObjectMetaSystemFieldValues(&created_service.ObjectMeta) {
|
||||
t.Errorf("storage did not populate object meta field values")
|
||||
}
|
||||
if created_service.Name != test.name {
|
||||
|
|
|
@ -226,3 +226,9 @@ func NewUIDPreconditions(uid string) *Preconditions {
|
|||
u := types.UID(uid)
|
||||
return &Preconditions{UID: &u}
|
||||
}
|
||||
|
||||
// HasObjectMetaSystemFieldValues returns true if fields that are managed by the system on ObjectMeta have values.
|
||||
func HasObjectMetaSystemFieldValues(meta *ObjectMeta) bool {
|
||||
return !meta.CreationTimestamp.Time.IsZero() ||
|
||||
len(meta.UID) != 0
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue