-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add clusters fluent interface implementation (#1291)
Signed-off-by: Nathan Klick <[email protected]>
- Loading branch information
1 parent
33dc849
commit 95c71f0
Showing
4 changed files
with
59 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/** | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
import {type Clusters} from '../clusters.js'; | ||
import {type KubeConfig} from '@kubernetes/client-node'; | ||
import {IllegalArgumentError} from '../../errors.js'; | ||
|
||
export default class K8ClientClusters implements Clusters { | ||
public constructor(private readonly kubeConfig: KubeConfig) { | ||
if (!kubeConfig) { | ||
throw new IllegalArgumentError('kubeConfig must not be null or undefined'); | ||
} | ||
} | ||
|
||
list(): string[] { | ||
const clusters: string[] = []; | ||
for (const cluster of this.kubeConfig.getClusters()) { | ||
clusters.push(cluster.name); | ||
} | ||
|
||
return clusters; | ||
} | ||
|
||
readCurrent(): string { | ||
const currentCluster = this.kubeConfig.getCurrentCluster(); | ||
return !currentCluster ? '' : currentCluster.name; | ||
} | ||
} |