Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix cluster's apiUrl #846

Merged
merged 3 commits into from
Sep 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/common/cluster-store_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ describe("empty config", () => {
it("adds new cluster to store", async () => {
const cluster = new Cluster({
id: "foo",
contextName: "minikube",
preferences: {
terminalCWD: "/tmp",
icon: "data:;base64,iVBORw0KGgoAAAANSUhEUgAAA1wAAAKoCAYAAABjkf5",
Expand All @@ -54,6 +55,7 @@ describe("empty config", () => {
it("check if store can contain multiple clusters", () => {
const prodCluster = new Cluster({
id: "prod",
contextName: "prod",
preferences: {
clusterName: "prod"
},
Expand All @@ -62,6 +64,7 @@ describe("empty config", () => {
});
const devCluster = new Cluster({
id: "dev",
contextName: "dev",
preferences: {
clusterName: "dev"
},
Expand Down Expand Up @@ -142,11 +145,13 @@ describe("config with existing clusters", () => {
{
id: 'cluster1',
kubeConfig: 'foo',
contextName: 'foo',
preferences: { terminalCWD: '/foo' }
},
{
id: 'cluster2',
kubeConfig: 'foo2',
contextName: 'foo2',
preferences: { terminalCWD: '/foo2' }
}
]
Expand Down Expand Up @@ -339,6 +344,7 @@ describe("pre 3.6.0-beta.1 config with an existing cluster", () => {
{
id: 'cluster1',
kubeConfig: 'kubeconfig content',
contextName: 'cluster',
preferences: {
icon: "store://icon_path",
}
Expand Down
6 changes: 4 additions & 2 deletions src/main/cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,15 @@ export class Cluster implements ClusterModel {

constructor(model: ClusterModel) {
this.updateModel(model);
const kubeconfig = this.getKubeconfig()
if (kubeconfig.getContextObject(this.contextName)) {
this.apiUrl = kubeconfig.getCluster(kubeconfig.getContextObject(this.contextName).cluster).server
}
}

@action
updateModel(model: ClusterModel) {
Object.assign(this, model);
this.apiUrl = this.getKubeconfig().getCurrentCluster()?.server;
this.contextName = this.contextName || this.preferences.clusterName;
}

@action
Expand Down