-
Notifications
You must be signed in to change notification settings - Fork 453
/
builder.go
121 lines (104 loc) · 3.79 KB
/
builder.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
// Copyright (c) 2020 SAP SE or an SAP affiliate company. All rights reserved. This file is licensed under the Apache Software License, v. 2 except as noted otherwise in the LICENSE file
//
// 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 fake
import (
kubernetesclientset "k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
"sigs.k8s.io/controller-runtime/pkg/cache"
"sigs.k8s.io/controller-runtime/pkg/client"
"github.com/gardener/gardener/pkg/chartrenderer"
"github.com/gardener/gardener/pkg/client/kubernetes"
)
// ClientSetBuilder is a builder for fake ClientSets
type ClientSetBuilder struct {
applier kubernetes.Applier
chartRenderer chartrenderer.Interface
chartApplier kubernetes.ChartApplier
restConfig *rest.Config
client client.Client
apiReader client.Reader
cache cache.Cache
kubernetes kubernetesclientset.Interface
restClient rest.Interface
version string
}
// NewClientSetBuilder return a new builder for building fake ClientSets
func NewClientSetBuilder() *ClientSetBuilder {
return &ClientSetBuilder{}
}
// WithApplier sets the applier attribute of the builder.
func (b *ClientSetBuilder) WithApplier(applier kubernetes.Applier) *ClientSetBuilder {
b.applier = applier
return b
}
// WithChartRenderer sets the chartRenderer attribute of the builder.
func (b *ClientSetBuilder) WithChartRenderer(chartRenderer chartrenderer.Interface) *ClientSetBuilder {
b.chartRenderer = chartRenderer
return b
}
// WithChartApplier sets the chartApplier attribute of the builder.
func (b *ClientSetBuilder) WithChartApplier(chartApplier kubernetes.ChartApplier) *ClientSetBuilder {
b.chartApplier = chartApplier
return b
}
// WithRESTConfig sets the restConfig attribute of the builder.
func (b *ClientSetBuilder) WithRESTConfig(config *rest.Config) *ClientSetBuilder {
b.restConfig = config
return b
}
// WithClient sets the client attribute of the builder.
func (b *ClientSetBuilder) WithClient(client client.Client) *ClientSetBuilder {
b.client = client
return b
}
// WithAPIReader sets the apiReader attribute of the builder.
func (b *ClientSetBuilder) WithAPIReader(apiReader client.Reader) *ClientSetBuilder {
b.apiReader = apiReader
return b
}
// WithCache sets the cache attribute of the builder.
func (b *ClientSetBuilder) WithCache(cache cache.Cache) *ClientSetBuilder {
b.cache = cache
return b
}
// WithKubernetes sets the kubernetes attribute of the builder.
func (b *ClientSetBuilder) WithKubernetes(kubernetes kubernetesclientset.Interface) *ClientSetBuilder {
b.kubernetes = kubernetes
return b
}
// WithRESTClient sets the restClient attribute of the builder.
func (b *ClientSetBuilder) WithRESTClient(restClient rest.Interface) *ClientSetBuilder {
b.restClient = restClient
return b
}
// WithVersion sets the version attribute of the builder.
func (b *ClientSetBuilder) WithVersion(version string) *ClientSetBuilder {
b.version = version
return b
}
// Build builds the ClientSet.
func (b *ClientSetBuilder) Build() *ClientSet {
return &ClientSet{
applier: b.applier,
chartRenderer: b.chartRenderer,
chartApplier: b.chartApplier,
restConfig: b.restConfig,
client: b.client,
apiReader: b.apiReader,
cache: b.cache,
kubernetes: b.kubernetes,
restClient: b.restClient,
version: b.version,
}
}