Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit 6b4b602
Author: Jeromy Cannon <[email protected]>
Date:   Sun Feb 9 19:47:06 2025 +0000

    fixed rebase issue

    Signed-off-by: Jeromy Cannon <[email protected]>

commit 475712c
Author: Jeromy Cannon <[email protected]>
Date:   Sun Feb 9 18:47:05 2025 +0000

    removed some TODOs

    Signed-off-by: Jeromy Cannon <[email protected]>

commit e803801
Author: Jeromy Cannon <[email protected]>
Date:   Sun Feb 9 18:11:10 2025 +0000

    refactor: align to kube hierarchial folder structure

    Signed-off-by: Jeromy Cannon <[email protected]>

commit cb27150
Author: Jeromy Cannon <[email protected]>
Date:   Sun Feb 9 16:53:15 2025 +0000

    Revert "fixed test case"

    This reverts commit bbb4738.

    Signed-off-by: Jeromy Cannon <[email protected]>

commit bdad9ae
Author: Jeromy Cannon <[email protected]>
Date:   Sun Feb 9 15:44:29 2025 +0000

    aligned to code style

    Signed-off-by: Jeromy Cannon <[email protected]>

commit 89a3081
Author: Jeromy Cannon <[email protected]>
Date:   Sun Feb 9 13:56:19 2025 +0000

    moved pod files to resource/pod folder

    Signed-off-by: Jeromy Cannon <[email protected]>

Signed-off-by: Jeromy Cannon <[email protected]>
  • Loading branch information
jeromy-cannon committed Feb 9, 2025
1 parent eadfabd commit da6eb9f
Show file tree
Hide file tree
Showing 74 changed files with 191 additions and 211 deletions.
4 changes: 2 additions & 2 deletions src/commands/mirror_node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import {type Optional, type SoloListrTask} from '../types/index.js';
import * as Base64 from 'js-base64';
import {type NamespaceName} from '../core/kube/resources/namespace/namespace_name.js';
import {PodRef} from '../core/kube/resources/pod/pod_ref.js';
import {ContainerName} from '../core/kube/container_name.js';
import {ContainerRef} from '../core/kube/container_ref.js';
import {ContainerName} from '../core/kube/resources/container/container_name.js';
import {ContainerRef} from '../core/kube/resources/container/container_ref.js';

interface MirrorNodeDeployConfigClass {
chartDirectory: string;
Expand Down
2 changes: 1 addition & 1 deletion src/commands/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import {v4 as uuidv4} from 'uuid';
import * as Base64 from 'js-base64';
import {type SoloListrTask} from '../types/index.js';
import {type NamespaceName} from '../core/kube/resources/namespace/namespace_name.js';
import {SecretType} from '../core/kube/secret_type.js';
import {SecretType} from '../core/kube/resources/secret/secret_type.js';

export interface NetworkDeployConfigClass {
applicationEnv: string;
Expand Down
2 changes: 1 addition & 1 deletion src/commands/node/tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ import {GenesisNetworkDataConstructor} from '../../core/genesis_network_models/g
import {NodeOverridesModel} from '../../core/node_overrides_model.js';
import {type NamespaceName} from '../../core/kube/resources/namespace/namespace_name.js';
import {PodRef} from '../../core/kube/resources/pod/pod_ref.js';
import {ContainerRef} from '../../core/kube/container_ref.js';
import {ContainerRef} from '../../core/kube/resources/container/container_ref.js';
import {NetworkNodes} from '../../core/network_nodes.js';
import {container} from 'tsyringe-neo';
import * as helpers from '../../core/helpers.js';
Expand Down
2 changes: 1 addition & 1 deletion src/core/account_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import {inject, injectable} from 'tsyringe-neo';
import {patchInject} from './container_helper.js';
import {type NamespaceName} from './kube/resources/namespace/namespace_name.js';
import {PodRef} from './kube/resources/pod/pod_ref.js';
import {SecretType} from './kube/secret_type.js';
import {SecretType} from './kube/resources/secret/secret_type.js';
import {type V1Pod} from '@kubernetes/client-node';

const REASON_FAILED_TO_GET_KEYS = 'failed to get keys for accountId';
Expand Down
2 changes: 1 addition & 1 deletion src/core/certificate_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {type NodeAlias} from '../types/aliases.js';
import {inject, injectable} from 'tsyringe-neo';
import {patchInject} from './container_helper.js';
import {type NamespaceName} from './kube/resources/namespace/namespace_name.js';
import {SecretType} from './kube/secret_type.js';
import {SecretType} from './kube/resources/secret/secret_type.js';

/**
* Used to handle interactions with certificates data and inject it into the K8s cluster secrets
Expand Down
2 changes: 1 addition & 1 deletion src/core/cluster_checks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {SoloLogger} from './logging.js';
import {inject, injectable} from 'tsyringe-neo';
import {type K8} from './kube/k8.js';
import {type Pod} from './kube/resources/pod/pod.js';
import {type IngressClass} from './kube/ingress_class.js';
import {type IngressClass} from './kube/resources/ingress_class/ingress_class.js';
import {type V1Pod, type V1ConfigMap} from '@kubernetes/client-node';

/**
Expand Down
2 changes: 1 addition & 1 deletion src/core/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {color, type ListrLogger, PRESET_TIMER} from 'listr2';
import path, {dirname, normalize} from 'path';
import {fileURLToPath} from 'url';
import {NamespaceName} from './kube/resources/namespace/namespace_name.js';
import {ContainerName} from './kube/container_name.js';
import {ContainerName} from './kube/resources/container/container_name.js';

export const ROOT_DIR = path.join(dirname(fileURLToPath(import.meta.url)), '..', '..');

Expand Down
2 changes: 1 addition & 1 deletion src/core/kube/errors/invalid_resource_name_error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* SPDX-License-Identifier: Apache-2.0
*/
import {SoloError} from '../../errors.js';
import {type ResourceType} from '../resource_type.js';
import {type ResourceType} from '../resources/resource_type.js';

const RFC_1123_POSTFIX = (prefix: string) => `${prefix} is invalid, must be a valid RFC-1123 DNS label. \` +
"A DNS 1123 label must consist of lower case alphanumeric characters, '-' " +
Expand Down
4 changes: 2 additions & 2 deletions src/core/kube/errors/resource_operation_errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
* SPDX-License-Identifier: Apache-2.0
*/
import {SoloError} from '../../errors.js';
import {ResourceOperation} from '../resource_operation.js';
import {type ResourceType} from '../resource_type.js';
import {ResourceOperation} from '../resources/resource_operation.js';
import {type ResourceType} from '../resources/resource_type.js';
import {type NamespaceName} from '../resources/namespace/namespace_name.js';

export class ResourceOperationError extends SoloError {
Expand Down
18 changes: 8 additions & 10 deletions src/core/kube/k8.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
/**
* SPDX-License-Identifier: Apache-2.0
*/
import type * as k8s from '@kubernetes/client-node';
import {type V1Lease} from '@kubernetes/client-node';
import {type TarCreateFilter} from '../../types/aliases.js';
import {type TDirectoryData} from './t_directory_data.js';
import {type Namespaces} from './resources/namespace/namespaces.js';
import {type NamespaceName} from './resources/namespace/namespace_name.js';
import {type Containers} from './containers.js';
import {type Clusters} from './clusters.js';
import {type ConfigMaps} from './config_maps.js';
import {type ContainerRef} from './container_ref.js';
import {type Contexts} from './contexts.js';
import {type Containers} from './resources/container/containers.js';
import {type Clusters} from './resources/cluster/clusters.js';
import {type ConfigMaps} from './resources/config_map/config_maps.js';
import {type ContainerRef} from './resources/container/container_ref.js';
import {type Contexts} from './resources/context/contexts.js';
import {type Pvcs} from './resources/pvc/pvcs.js';
import {type Services} from './services.js';
import {type Services} from './resources/service/services.js';
import {type Pods} from './resources/pod/pods.js';
import {type Leases} from './resources/lease/leases.js';
import {type IngressClasses} from './ingress_classes.js';
import {type Secrets} from './secrets.js';
import {type IngressClasses} from './resources/ingress_class/ingress_classes.js';
import {type Secrets} from './resources/secret/secrets.js';

export interface K8 {
/**
Expand Down
39 changes: 17 additions & 22 deletions src/core/kube/k8_client/k8_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,28 @@ import {patchInject} from '../../container_helper.js';
import {type K8} from '../k8.js';
import {type Namespaces} from '../resources/namespace/namespaces.js';
import {type NamespaceName} from '../resources/namespace/namespace_name.js';
import {K8ClientClusters} from '../k8_client/k8_client_clusters.js';
import {type Clusters} from '../clusters.js';
import {type ConfigMaps} from '../config_maps.js';
import {K8ClientConfigMaps} from '../k8_client/k8_client_config_maps.js';
import {type ContainerRef} from '../container_ref.js';
import {K8ClientContainers} from '../k8_client/k8_client_containers.js';
import {type Containers} from '../containers.js';
import {type Contexts} from '../contexts.js';
import {K8ClientContexts} from '../k8_client/k8_client_contexts.js';
import {K8ClientClusters} from '../k8_client/resources/cluster/k8_client_clusters.js';
import {type Clusters} from '../resources/cluster/clusters.js';
import {type ConfigMaps} from '../resources/config_map/config_maps.js';
import {K8ClientConfigMaps} from '../k8_client/resources/config_map/k8_client_config_maps.js';
import {type ContainerRef} from '../resources/container/container_ref.js';
import {K8ClientContainers} from '../k8_client/resources/container/k8_client_containers.js';
import {type Containers} from '../resources/container/containers.js';
import {type Contexts} from '../resources/context/contexts.js';
import {K8ClientContexts} from '../k8_client/resources/context/k8_client_contexts.js';
import {K8ClientPods} from '../k8_client/resources/pod/k8_client_pods.js';
import {type Pods} from '../resources/pod/pods.js';
import {K8ClientBase} from '../k8_client/k8_client_base.js';
import {type Services} from '../services.js';
import {K8ClientServices} from '../k8_client/k8_client_services.js';
import {type Services} from '../resources/service/services.js';
import {K8ClientServices} from '../k8_client/resources/service/k8_client_services.js';
import {type Pvcs} from '../resources/pvc/pvcs.js';
import {K8ClientPvcs} from '../k8_client/resources/pvc/k8_client_pvcs.js';
import {type Leases} from '../resources/lease/leases.js';
import {K8ClientLeases} from '../k8_client/resources/lease/k8_client_leases.js';
import {K8ClientNamespaces} from '../k8_client/resources/namespace/k8_client_namespaces.js';
import {K8ClientIngressClasses} from '../k8_client/k8_client_ingress_classes.js';
import {type IngressClasses} from '../ingress_classes.js';
import {type Secrets} from '../secrets.js';
import {K8ClientSecrets} from '../k8_client/k8_client_secrets.js';
import {K8ClientIngressClasses} from '../k8_client/resources/ingress_class/k8_client_ingress_classes.js';
import {type IngressClasses} from '../resources/ingress_class/ingress_classes.js';
import {type Secrets} from '../resources/secret/secrets.js';
import {K8ClientSecrets} from '../k8_client/resources/secret/k8_client_secrets.js';
import {PvcRef} from '../resources/pvc/pvc_ref.js';
import {PvcName} from '../resources/pvc/pvc_name.js';

Expand All @@ -44,11 +43,8 @@ import {PvcName} from '../resources/pvc/pvc_name.js';
* 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()
*/
// TODO move to kube folder
@injectable()
export class K8Client extends K8ClientBase implements K8 {
// TODO - remove extends K8ClientFilter after services refactor, it is using filterItem()

export class K8Client implements K8 {
private kubeConfig!: k8s.KubeConfig;
kubeClient!: k8s.CoreV1Api;
private coordinationApiClient: k8s.CoordinationV1Api;
Expand All @@ -70,7 +66,6 @@ export class K8Client extends K8ClientBase implements K8 {
@inject(ConfigManager) private readonly configManager?: ConfigManager,
@inject(SoloLogger) private readonly logger?: SoloLogger,
) {
super();
this.configManager = patchInject(configManager, ConfigManager, this.constructor.name);
this.logger = patchInject(logger, SoloLogger, this.constructor.name);

Expand All @@ -96,7 +91,7 @@ export class K8Client extends K8ClientBase implements K8 {

this.k8Clusters = new K8ClientClusters(this.kubeConfig);
this.k8ConfigMaps = new K8ClientConfigMaps(this.kubeClient);
this.k8Containers = new K8ClientContainers(this.kubeConfig);
this.k8Containers = new K8ClientContainers(this.kubeConfig, this.k8Pods);
this.k8Contexts = new K8ClientContexts(this.kubeConfig);
this.k8Services = new K8ClientServices(this.kubeClient);
this.k8Pods = new K8ClientPods(this.kubeClient, this.kubeConfig);
Expand Down
4 changes: 2 additions & 2 deletions src/core/kube/k8_client/k8_client_base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
*/
import {IllegalArgumentError, MissingArgumentError, SoloError} from '../../errors.js';
import {type V1ObjectMeta} from '@kubernetes/client-node';
import {type ObjectMeta} from '../object_meta.js';
import {K8ClientObjectMeta} from './k8_client_object_meta.js';
import {type ObjectMeta} from '../resources/object_meta.js';
import {K8ClientObjectMeta} from './resources/k8_client_object_meta.js';
import {NamespaceName} from '../resources/namespace/namespace_name.js';

/**
Expand Down
16 changes: 0 additions & 16 deletions src/core/kube/k8_client/k8_client_containers.ts

This file was deleted.

15 changes: 0 additions & 15 deletions src/core/kube/k8_client/k8_client_service.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/**
* SPDX-License-Identifier: Apache-2.0
*/
import {type Clusters} from '../clusters.js';
import {type Clusters} from '../../../resources/cluster/clusters.js';
import {type KubeConfig} from '@kubernetes/client-node';
import {IllegalArgumentError} from '../../errors.js';
import {IllegalArgumentError} from '../../../../errors.js';

export class K8ClientClusters implements Clusters {
public constructor(private readonly kubeConfig: KubeConfig) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@
* SPDX-License-Identifier: Apache-2.0
*/
import {type CoreV1Api, V1ConfigMap, V1ObjectMeta} from '@kubernetes/client-node';
import {type ConfigMaps} from '../config_maps.js';
import {type NamespaceName} from '../resources/namespace/namespace_name.js';
import {type ConfigMaps} from '../../../resources/config_map/config_maps.js';
import {type NamespaceName} from '../../../resources/namespace/namespace_name.js';
import {
ResourceCreateError,
ResourceDeleteError,
ResourceNotFoundError,
ResourceReplaceError,
} from '../errors/resource_operation_errors.js';
import {ResourceType} from '../resource_type.js';
import {ResourceOperation} from '../resource_operation.js';
import {KubeApiResponse} from '../kube_api_response.js';
import {SoloError} from '../../errors.js';
} from '../../../errors/resource_operation_errors.js';
import {ResourceType} from '../../../resources/resource_type.js';
import {ResourceOperation} from '../../../resources/resource_operation.js';
import {KubeApiResponse} from '../../../kube_api_response.js';
import {SoloError} from '../../../../errors.js';

export class K8ClientConfigMaps implements ConfigMaps {
public constructor(private readonly kubeClient: CoreV1Api) {}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,34 +1,33 @@
/**
* SPDX-License-Identifier: Apache-2.0
*/
import {type Container} from '../container.js';
import {type TarCreateFilter} from '../../../types/aliases.js';
import {type TDirectoryData} from '../t_directory_data.js';
import {type ContainerRef} from '../container_ref.js';
import {IllegalArgumentError, MissingArgumentError, SoloError} from '../../errors.js';
import {container} from 'tsyringe-neo';
import type * as WebSocket from 'ws';
import * as tar from 'tar';
import {type Container} from '../../../resources/container/container.js';
import {type TarCreateFilter} from '../../../../../types/aliases.js';
import {type TDirectoryData} from '../../../t_directory_data.js';
import {type ContainerRef} from '../../../resources/container/container_ref.js';
import {IllegalArgumentError, MissingArgumentError, SoloError} from '../../../../errors.js';
import path from 'path';
import fs from 'fs';
import {type LocalContextObject} from '../../../types/index.js';
import stream from 'node:stream';
import {type LocalContextObject} from '../../../../../types/index.js';
import * as stream from 'node:stream';
import {v4 as uuid4} from 'uuid';
import {SoloLogger} from '../../logging.js';
import {type K8} from '../k8.js';
import {SoloLogger} from '../../../../logging.js';
import os from 'os';
import {Exec, type KubeConfig} from '@kubernetes/client-node';
import {container} from 'tsyringe-neo';
import type * as WebSocket from 'ws';
import * as tar from 'tar';
import {type Pods} from '../../../resources/pod/pods.js';

export class K8ClientContainer implements Container {
private readonly logger: SoloLogger;
private readonly k8: K8; // TODO switches to Pods after that implementation is ready

public constructor(
private readonly kubeConfig: KubeConfig,
private readonly containerRef: ContainerRef,
private readonly pods: Pods,
) {
this.logger = container.resolve(SoloLogger);
this.k8 = container.resolve('K8') as K8;
}

public async copyFrom(srcPath: string, destDir: string): Promise<unknown> {
Expand All @@ -37,7 +36,7 @@ export class K8ClientContainer implements Container {
const guid = uuid4();
const messagePrefix = `copyFrom[${this.containerRef.parentRef.name},${guid}]: `;

if (!(await self.k8.pods().read(this.containerRef.parentRef)))
if (!(await self.pods.read(this.containerRef.parentRef)))
throw new IllegalArgumentError(`Invalid pod ${this.containerRef.parentRef.name}`);

self.logger.info(`${messagePrefix}[srcPath=${srcPath}, destDir=${destDir}]`);
Expand Down Expand Up @@ -171,7 +170,7 @@ export class K8ClientContainer implements Container {
const guid = uuid4();
const messagePrefix = `copyTo[${this.containerRef.parentRef.name},${guid}]: `;

if (!(await self.k8.pods().read(this.containerRef.parentRef)))
if (!(await self.pods.read(this.containerRef.parentRef)))
throw new IllegalArgumentError(`Invalid pod ${this.containerRef.parentRef.name}`);

self.logger.info(`${messagePrefix}[srcPath=${srcPath}, destDir=${destDir}]`);
Expand Down Expand Up @@ -256,7 +255,7 @@ export class K8ClientContainer implements Container {
const guid = uuid4();
const messagePrefix = `execContainer[${this.containerRef.parentRef.name},${guid}]:`;

if (!(await self.k8.pods().read(this.containerRef.parentRef)))
if (!(await self.pods.read(this.containerRef.parentRef)))
throw new IllegalArgumentError(`Invalid pod ${this.containerRef.parentRef.name}`);

if (!command) throw new MissingArgumentError('command cannot be empty');
Expand Down Expand Up @@ -386,25 +385,6 @@ export class K8ClientContainer implements Container {
}

public async listDir(destPath: string): Promise<any[] | TDirectoryData[]> {
// TODO future, return the following
// return this.pods.byName(podName).listDir(containerName, destPath);
// byName(podName) can use an underlying cache to avoid multiple calls to the API
// caching can be added later, it doesn't have to be done right away
// byLabel(label) can also cache/lazy initialize if desired
// pods are qualified by namespace, so we should really also be passing namespace
// string is also an object with a large prototype, same weight as a class instance
// PodName can be turned into a class that we can use for the parameters for more control.
// PodName.of(namespace, podName)
// TODO - make namespace first on all of the methods
// TODO - create ContainerName for the containerName, validate the containerName. ContainerName.of(containerName)
// - to avoid having to do (new ContainerName(containerName))
// - NamespaceName.of(namespace): store as class instead of string after we have validated and put it in ConfigManager
// - PodRef.of(namespace, podName)
// - ContainerRef.of(podRef, containerName)
// - ContainerRef.of(PodRef.of(namespace, podName), containerName)
// - namespace is coming from user and should definitely be validate and kick back if it is invalid
// below implementation moves to K8Pod class, current usage would still compile.

try {
const output = (await this.execContainer(['ls', '-la', destPath])) as string;
if (!output) return [];
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* SPDX-License-Identifier: Apache-2.0
*/
import {type Containers} from '../../../resources/container/containers.js';
import {type ContainerRef} from '../../../resources/container/container_ref.js';
import {type Container} from '../../../resources/container/container.js';
import {K8ClientContainer} from './k8_client_container.js';
import {type KubeConfig} from '@kubernetes/client-node';
import {type Pods} from '../../../resources/pod/pods.js';

export class K8ClientContainers implements Containers {
public constructor(
private readonly kubeConfig: KubeConfig,
private readonly pods: Pods,
) {}

public readByRef(containerRef: ContainerRef): Container {
return new K8ClientContainer(this.kubeConfig, containerRef, this.pods);
}
}
Loading

0 comments on commit da6eb9f

Please sign in to comment.