Remove BPA from Makefile
[icn.git] / cmd / bpa-operator / vendor / sigs.k8s.io / controller-runtime / pkg / runtime / scheme / scheme.go
1 /*
2 Copyright 2018 The Kubernetes Authors.
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8     http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15 */
16
17 package scheme
18
19 import (
20         metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
21         "k8s.io/apimachinery/pkg/runtime"
22         "k8s.io/apimachinery/pkg/runtime/schema"
23 )
24
25 // Builder builds a new Scheme for mapping go types to Kubernetes GroupVersionKinds.
26 type Builder struct {
27         GroupVersion schema.GroupVersion
28         runtime.SchemeBuilder
29 }
30
31 // Register adds one or objects to the SchemeBuilder so they can be added to a Scheme.  Register mutates bld.
32 func (bld *Builder) Register(object ...runtime.Object) *Builder {
33         bld.SchemeBuilder.Register(func(scheme *runtime.Scheme) error {
34                 scheme.AddKnownTypes(bld.GroupVersion, object...)
35                 metav1.AddToGroupVersion(scheme, bld.GroupVersion)
36                 return nil
37         })
38         return bld
39 }
40
41 // RegisterAll registers all types from the Builder argument.  RegisterAll mutates bld.
42 func (bld *Builder) RegisterAll(b *Builder) *Builder {
43         bld.SchemeBuilder = append(bld.SchemeBuilder, b.SchemeBuilder...)
44         return bld
45 }
46
47 // AddToScheme adds all registered types to s.
48 func (bld *Builder) AddToScheme(s *runtime.Scheme) error {
49         return bld.SchemeBuilder.AddToScheme(s)
50 }
51
52 // Build returns a new Scheme containing the registered types.
53 func (bld *Builder) Build() (*runtime.Scheme, error) {
54         s := runtime.NewScheme()
55         return s, bld.AddToScheme(s)
56 }