Skip to content

Commit 2a62f11

Browse files
committed
feat: add new WithRestConfig option
Signed-off-by: Ilya Mayorov <[email protected]>
1 parent 649b7f6 commit 2a62f11

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

client/client.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,10 @@ func (c *Client) WithMetricLabels(labels map[string]string) {
129129
c.metricLabels = labels
130130
}
131131

132+
func (c *Client) WithRestConfig(config *rest.Config) {
133+
c.restConfig = config
134+
}
135+
132136
func (c *Client) DefaultNamespace() string {
133137
return c.defaultNamespace
134138
}
@@ -160,7 +164,12 @@ func (c *Client) Init() error {
160164
configType := "out-of-cluster"
161165
var defaultNs string
162166

163-
if c.server == "" {
167+
switch {
168+
case c.restConfig != nil:
169+
config = c.restConfig
170+
defaultNs = "default"
171+
configType = "server"
172+
case c.server == "":
164173
// Try to load from kubeconfig in flags or from ~/.kube/config
165174
var outOfClusterErr error
166175
config, defaultNs, outOfClusterErr = getOutOfClusterConfig(c.contextName, c.configPath)
@@ -191,7 +200,7 @@ func (c *Client) Init() error {
191200
}
192201
configType = "in-cluster"
193202
}
194-
} else {
203+
default:
195204
// use specific server to connect to API
196205
config = &rest.Config{
197206
Host: c.server,

0 commit comments

Comments
 (0)