mirror of
https://github.com/rancher-sandbox/rancher-desktop.git
synced 2021-10-13 00:04:06 +03:00
Add an ImageProcessorName type
- Used to validate the name passed to `createImageProcessor` - Also add some misc. missing types and comments Signed-off-by: Eric Promislow <epromislow@suse.com>
This commit is contained in:
@@ -8,6 +8,7 @@ import _ from 'lodash';
|
||||
|
||||
import mainEvents from '@/main/mainEvents';
|
||||
import { ImageProcessor } from '@/k8s-engine/images/imageProcessor';
|
||||
import { ImageProcessorName } from '@/k8s-engine/images/imageFactory';
|
||||
import { setupImageProcessor } from '@/main/imageEvents';
|
||||
import * as settings from '@/config/settings';
|
||||
import * as window from '@/window';
|
||||
@@ -28,7 +29,7 @@ Electron.app.setName('Rancher Desktop');
|
||||
const console = Logging.background;
|
||||
// If/when we support more than one image processor this will be a pref with a watcher
|
||||
// for changes, but it's fine as a constant now.
|
||||
const ImageProviderName = 'nerdctl';
|
||||
const ImageProviderName: ImageProcessorName = 'nerdctl';
|
||||
|
||||
const k8smanager = newK8sManager();
|
||||
let imageProcessor: ImageProcessor;
|
||||
@@ -283,7 +284,7 @@ function writeSettings(arg: RecursivePartial<settings.Settings>) {
|
||||
Electron.ipcMain.emit('k8s-restart-required');
|
||||
if (imageProcessor && imageProcessor.namespace !== cfg.images.namespace) {
|
||||
imageProcessor.namespace = cfg.images.namespace;
|
||||
imageProcessor.refreshImages().catch((err) => {
|
||||
imageProcessor.refreshImages().catch((err: Error) => {
|
||||
console.log(`Error refreshing images:`, err);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -2,6 +2,11 @@ import { ImageProcessor } from '@/k8s-engine/images/imageProcessor';
|
||||
import NerdctlImageProcessor from '@/k8s-engine/images/nerdctlImageProcessor';
|
||||
import * as K8s from '@/k8s-engine/k8s';
|
||||
|
||||
/**
|
||||
* An or-barred enum of valid string values for the names of supported image processors
|
||||
*/
|
||||
export type ImageProcessorName = 'nerdctl'; // | 'kim' has been dropped
|
||||
|
||||
/**
|
||||
* Currently there's only one image processor.
|
||||
* But at one point, when we transitioned from kim to nerdctl, there were two.
|
||||
@@ -11,7 +16,7 @@ import * as K8s from '@/k8s-engine/k8s';
|
||||
* @param k8sManager
|
||||
*/
|
||||
|
||||
export default function createImageProcessor(processorName: string, k8sManager: K8s.KubernetesBackend): ImageProcessor {
|
||||
export function createImageProcessor(processorName: ImageProcessorName, k8sManager: K8s.KubernetesBackend): ImageProcessor {
|
||||
switch (processorName) {
|
||||
case 'nerdctl':
|
||||
return new NerdctlImageProcessor(k8sManager);
|
||||
|
||||
@@ -238,10 +238,6 @@ export abstract class ImageProcessor extends EventEmitter {
|
||||
});
|
||||
}
|
||||
|
||||
getNamespaces(): Promise<Array<string>> {
|
||||
throw new Error(`getNamespaces: not implemented for class ${ this.processorName }`);
|
||||
}
|
||||
|
||||
get namespace() {
|
||||
return this.currentNamespace;
|
||||
}
|
||||
@@ -250,7 +246,9 @@ export abstract class ImageProcessor extends EventEmitter {
|
||||
this.currentNamespace = value;
|
||||
}
|
||||
|
||||
/* Subclass-specific method stubs here: */
|
||||
/* Subclass-specific method definitions here: */
|
||||
|
||||
abstract getNamespaces(): Promise<Array<string>>;
|
||||
|
||||
abstract buildImage(dirPart: string, filePart: string, taggedImageName: string): Promise<imageProcessor.childResultType>;
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ import path from 'path';
|
||||
import Electron from 'electron';
|
||||
|
||||
import { ImageProcessor } from '@/k8s-engine/images/imageProcessor';
|
||||
import createImageProcessor from '@/k8s-engine/images/imageFactory';
|
||||
import { createImageProcessor, ImageProcessorName } from '@/k8s-engine/images/imageFactory';
|
||||
import Logging from '@/utils/logging';
|
||||
import * as window from '@/window';
|
||||
import * as K8s from '@/k8s-engine/k8s';
|
||||
@@ -18,7 +18,13 @@ let imageManager: ImageProcessor;
|
||||
let lastBuildDirectory = '';
|
||||
let mountCount = 0;
|
||||
|
||||
export function setupImageProcessor(imageProcessorName: string, k8sManager: K8s.KubernetesBackend): ImageProcessor {
|
||||
/**
|
||||
* Map image-related events to the associated image processor's methods
|
||||
* @param imageProcessorName
|
||||
* @param k8sManager
|
||||
*/
|
||||
|
||||
export function setupImageProcessor(imageProcessorName: ImageProcessorName, k8sManager: K8s.KubernetesBackend): ImageProcessor {
|
||||
imageManager = imageManager ?? createImageProcessor(imageProcessorName, k8sManager);
|
||||
|
||||
interface ImageContents {
|
||||
|
||||
Reference in New Issue
Block a user