blob: 4364374ef4054c92551fb104457c509a862f49ac [file] [log] [blame]
Matthias Andreas Benkard832a54e2019-01-29 09:27:38 +01001/*
2Copyright 2014 The Kubernetes Authors.
3
4Licensed under the Apache License, Version 2.0 (the "License");
5you may not use this file except in compliance with the License.
6You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10Unless required by applicable law or agreed to in writing, software
11distributed under the License is distributed on an "AS IS" BASIS,
12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13See the License for the specific language governing permissions and
14limitations under the License.
15*/
16
17package generic
18
19import (
20 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
21 "k8s.io/apimachinery/pkg/fields"
22)
23
24// ObjectMetaFieldsSet returns a fields that represent the ObjectMeta.
25func ObjectMetaFieldsSet(objectMeta *metav1.ObjectMeta, hasNamespaceField bool) fields.Set {
26 if !hasNamespaceField {
27 return fields.Set{
28 "metadata.name": objectMeta.Name,
29 }
30 }
31 return fields.Set{
32 "metadata.name": objectMeta.Name,
33 "metadata.namespace": objectMeta.Namespace,
34 }
35}
36
37// AdObjectMetaField add fields that represent the ObjectMeta to source.
38func AddObjectMetaFieldsSet(source fields.Set, objectMeta *metav1.ObjectMeta, hasNamespaceField bool) fields.Set {
39 source["metadata.name"] = objectMeta.Name
40 if hasNamespaceField {
41 source["metadata.namespace"] = objectMeta.Namespace
42 }
43 return source
44}
45
46// MergeFieldsSets merges a fields'set from fragment into the source.
47func MergeFieldsSets(source fields.Set, fragment fields.Set) fields.Set {
48 for k, value := range fragment {
49 source[k] = value
50 }
51 return source
52}