mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Add the ability to sync kube config files (#2567)
* Add the ability to sync kube config files - Will update when the files changes - add KUBECONFIG_SYNC label - fix rebase and change to addObservableSource - move UI to user settings - support shallow folder watching - add some unit tests for the diff-er Signed-off-by: Sebastian Malton <sebastian@malton.name> * responding to review comments Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix tests and add try/catch Signed-off-by: Sebastian Malton <sebastian@malton.name> * always sync c&p folder, remove bad rebase Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix preferences Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix settings saving and catalog view Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix unit tests Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix synced clusters not connectable Signed-off-by: Sebastian Malton <sebastian@malton.name> * change to non-complete shallow watching Signed-off-by: Sebastian Malton <sebastian@malton.name> * fix sizing Signed-off-by: Sebastian Malton <sebastian@malton.name> * Catch readStream errors Signed-off-by: Sebastian Malton <sebastian@malton.name> * don't clear UserStore on non-existant preference field, fix unlinking not removing items from source Signed-off-by: Sebastian Malton <sebastian@malton.name> * change label to file Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
1 parent
f06d330835
commit
998f7aa934
32 files changed
+1215
-236
No files matched your search
+41
-37
@@ -18,7 +18,7 @@ export class ClusterManager extends Singleton {
|
||||
constructor(public readonly port: number) {
|
||||
super();
|
||||
|
||||
catalogEntityRegistry.addSource("lens:kubernetes-clusters", this.catalogSource);
|
||||
catalogEntityRegistry.addObservableSource("lens:kubernetes-clusters", this.catalogSource);
|
||||
// auto-init clusters
|
||||
reaction(() => ClusterStore.getInstance().enabledClustersList, (clusters) => {
|
||||
clusters.forEach((cluster) => {
|
||||
@@ -59,17 +59,17 @@ export class ClusterManager extends Singleton {
|
||||
}
|
||||
|
||||
@action protected updateCatalogSource(clusters: Cluster[]) {
|
||||
this.catalogSource.forEach((entity, index) => {
|
||||
const clusterIndex = clusters.findIndex((cluster) => entity.metadata.uid === cluster.id);
|
||||
this.catalogSource.replace(this.catalogSource.filter(entity => (
|
||||
clusters.find((cluster) => entity.metadata.uid === cluster.id)
|
||||
)));
|
||||
|
||||
if (clusterIndex === -1) {
|
||||
this.catalogSource.splice(index, 1);
|
||||
for (const cluster of clusters) {
|
||||
if (cluster.ownerRef) {
|
||||
continue;
|
||||
}
|
||||
});
|
||||
|
||||
clusters.filter((c) => !c.ownerRef).forEach((cluster) => {
|
||||
const entityIndex = this.catalogSource.findIndex((entity) => entity.metadata.uid === cluster.id);
|
||||
const newEntity = this.catalogEntityFromCluster(cluster);
|
||||
const newEntity = catalogEntityFromCluster(cluster);
|
||||
|
||||
if (entityIndex === -1) {
|
||||
this.catalogSource.push(newEntity);
|
||||
@@ -84,11 +84,15 @@ export class ClusterManager extends Singleton {
|
||||
};
|
||||
this.catalogSource.splice(entityIndex, 1, newEntity);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@action syncClustersFromCatalog(entities: KubernetesCluster[]) {
|
||||
entities.filter((entity) => entity.metadata.source !== "local").forEach((entity: KubernetesCluster) => {
|
||||
for (const entity of entities) {
|
||||
if (entity.metadata.source !== "local") {
|
||||
continue;
|
||||
}
|
||||
|
||||
const cluster = ClusterStore.getInstance().getById(entity.metadata.uid);
|
||||
|
||||
if (!cluster) {
|
||||
@@ -104,7 +108,7 @@ export class ClusterManager extends Singleton {
|
||||
});
|
||||
} else {
|
||||
cluster.enabled = true;
|
||||
if (!cluster.ownerRef) cluster.ownerRef = clusterOwnerRef;
|
||||
cluster.ownerRef ||= clusterOwnerRef;
|
||||
cluster.preferences.clusterName = entity.metadata.name;
|
||||
cluster.kubeConfigPath = entity.spec.kubeconfigPath;
|
||||
cluster.contextName = entity.spec.kubeconfigContext;
|
||||
@@ -114,32 +118,7 @@ export class ClusterManager extends Singleton {
|
||||
active: !cluster.disconnected
|
||||
};
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
protected catalogEntityFromCluster(cluster: Cluster) {
|
||||
return new KubernetesCluster(toJS({
|
||||
apiVersion: "entity.k8slens.dev/v1alpha1",
|
||||
kind: "KubernetesCluster",
|
||||
metadata: {
|
||||
uid: cluster.id,
|
||||
name: cluster.name,
|
||||
source: "local",
|
||||
labels: {
|
||||
"distro": (cluster.metadata["distribution"] || "unknown").toString()
|
||||
}
|
||||
},
|
||||
spec: {
|
||||
kubeconfigPath: cluster.kubeConfigPath,
|
||||
kubeconfigContext: cluster.contextName
|
||||
},
|
||||
status: {
|
||||
phase: cluster.disconnected ? "disconnected" : "connected",
|
||||
reason: "",
|
||||
message: "",
|
||||
active: !cluster.disconnected
|
||||
}
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
protected onNetworkOffline() {
|
||||
@@ -192,3 +171,28 @@ export class ClusterManager extends Singleton {
|
||||
return cluster;
|
||||
}
|
||||
}
|
||||
|
||||
export function catalogEntityFromCluster(cluster: Cluster) {
|
||||
return new KubernetesCluster(toJS({
|
||||
apiVersion: "entity.k8slens.dev/v1alpha1",
|
||||
kind: "KubernetesCluster",
|
||||
metadata: {
|
||||
uid: cluster.id,
|
||||
name: cluster.name,
|
||||
source: "local",
|
||||
labels: {
|
||||
distro: cluster.distribution,
|
||||
}
|
||||
},
|
||||
spec: {
|
||||
kubeconfigPath: cluster.kubeConfigPath,
|
||||
kubeconfigContext: cluster.contextName
|
||||
},
|
||||
status: {
|
||||
phase: cluster.disconnected ? "disconnected" : "connected",
|
||||
reason: "",
|
||||
message: "",
|
||||
active: !cluster.disconnected
|
||||
}
|
||||
}));
|
||||
}
|
||||
Reference in new issue
Block a user