@@ -167,8 +167,11 @@ func EscapeAppsetFieldName(field string) string {
167
167
return appsetFieldRegexp .ReplaceAllString (field , "_" )
168
168
}
169
169
170
- func kubeConfig () * clientcmdapi.Config {
170
+ func kubeConfig (kubeconfig string ) * clientcmdapi.Config {
171
171
configAccess := clientcmd .NewDefaultPathOptions ()
172
+ if kubeconfig != "" {
173
+ configAccess .GlobalFile = kubeconfig
174
+ }
172
175
conf , err := configAccess .GetStartingConfig ()
173
176
Die (err , "failed reading kubeconfig file" )
174
177
return conf
@@ -179,8 +182,8 @@ type kubeContext struct {
179
182
Current bool
180
183
}
181
184
182
- func KubeContexts () []kubeContext {
183
- conf := kubeConfig ()
185
+ func KubeContexts (kubeconfig string ) []kubeContext {
186
+ conf := kubeConfig (kubeconfig )
184
187
contexts := make ([]kubeContext , len (conf .Contexts ))
185
188
i := 0
186
189
for key := range conf .Contexts {
@@ -208,8 +211,8 @@ func KubeContexts() []kubeContext {
208
211
return contexts
209
212
}
210
213
211
- func CheckExistingContext (contextName string ) bool {
212
- for _ , context := range KubeContexts () {
214
+ func CheckExistingContext (contextName , kubeconfig string ) bool {
215
+ for _ , context := range KubeContexts (kubeconfig ) {
213
216
if context .Name == contextName {
214
217
return true
215
218
}
@@ -218,8 +221,8 @@ func CheckExistingContext(contextName string) bool {
218
221
return false
219
222
}
220
223
221
- func KubeCurrentServer () (string , error ) {
222
- return KubeServerByContextName ("" )
224
+ func KubeCurrentServer (kubeconfig string ) (string , error ) {
225
+ return KubeServerByContextName ("" , kubeconfig )
223
226
}
224
227
225
228
func CurrentAccount (user * codefresh.User ) (string , error ) {
@@ -255,8 +258,8 @@ func OpenBrowserForGitLogin(ingressHost string, user string, account string) err
255
258
return nil
256
259
}
257
260
258
- func KubeContextNameByServer (server string ) (string , error ) {
259
- conf := kubeConfig ()
261
+ func KubeContextNameByServer (server , kubeconfig string ) (string , error ) {
262
+ conf := kubeConfig (kubeconfig )
260
263
for contextName , context := range conf .Contexts {
261
264
if cluster , ok := conf .Clusters [context .Cluster ]; ok {
262
265
if cluster .Server == server {
@@ -268,8 +271,8 @@ func KubeContextNameByServer(server string) (string, error) {
268
271
return "" , fmt .Errorf ("Context not found for server \" %s\" " , server )
269
272
}
270
273
271
- func KubeServerByContextName (contextName string ) (string , error ) {
272
- conf := kubeConfig ()
274
+ func KubeServerByContextName (contextName , kubeconfig string ) (string , error ) {
275
+ conf := kubeConfig (kubeconfig )
273
276
if contextName == "" {
274
277
contextName = conf .CurrentContext
275
278
}
0 commit comments