Skip to content

Commit

Permalink
fix: add clone method for Kubectl2
Browse files Browse the repository at this point in the history
Signed-off-by: Lenin Mehedy <lenin.mehedy@swirldslabs.com>
  • Loading branch information
leninmehedy committed Jan 24, 2024
1 parent af5e7a4 commit 7387dff
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions fullstack-network-manager/src/core/kubectl2.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ import * as tar from 'tar'
import { v4 as uuid4 } from 'uuid'

/**
* A kubectl wrapper class providing custom functionalities required by fsnetman
* A kubernetes API wrapper class providing custom functionalities required by fsnetman
*
* Note: Take care if the same instance is used for parallel execution, as the behaviour may be unpredictable.
* For parallel execution, create separate instances by invoking clone()
*/
export class Kubectl2 {
constructor (configManager, logger) {
Expand All @@ -23,6 +26,17 @@ export class Kubectl2 {
this.init()
}

/**
* Clone a new instance with the same config manager and logger
* Internally it instantiates a new kube API client
*
* @return {Kubectl2}
*/
clone () {
const c = new Kubectl2(this.configManager, this.logger)
return c.init()
}

getKubeConfig () {
return this.kubeConfig
}
Expand All @@ -42,7 +56,8 @@ export class Kubectl2 {
}

this.kubeClient = this.kubeConfig.makeApiClient(k8s.CoreV1Api)
this.kubeCopy = new k8s.Cp(this.kubeConfig)

return this // to enable chaining
}

/**
Expand Down

0 comments on commit 7387dff

Please sign in to comment.