Skip to content

Commit

Permalink
First try: fully qualified Flux API names
Browse files Browse the repository at this point in the history
Signed-off-by: Kingdon Barrett <[email protected]>
  • Loading branch information
Kingdon Barrett committed Sep 5, 2023
1 parent aa60ca9 commit f8763dc
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/cli/kubernetes/kubectlGet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { HelmRelease } from 'types/flux/helmRelease';
import { HelmRepository } from 'types/flux/helmRepository';
import { Kustomization } from 'types/flux/kustomization';
import { OCIRepository } from 'types/flux/ociRepository';
import { Deployment, Kind, KubernetesObject, Pod } from 'types/kubernetes/kubernetesTypes';
import { Deployment, FullyQualifiedKinds, Kind, KubernetesObject, Pod } from 'types/kubernetes/kubernetesTypes';
import { TelemetryError } from 'types/telemetryEventNames';
import { parseJson, parseJsonItems } from 'utils/jsonUtils';
import { invokeKubectlCommand } from './kubernetesToolsKubectl';
Expand Down Expand Up @@ -49,9 +49,12 @@ export async function getResourcesAllNamespaces<T extends KubernetesObject>(kind
return list as T[];
}

let fqKind = FullyQualifiedKinds[kind];

const shellResult = await invokeKubectlCommand(`get ${kind} -A -o json`);

const shellResult = await invokeKubectlCommand(`get ${fqKind} -A -o json`);
// if (kind == Kind.HelmRelease) {
// console.warn("HelmRelease is not fully qualified, put your debugger instance here");
// }
if (shellResult?.code !== 0) {
console.warn(`Failed to \`kubectl get ${kind} -A\`: ${shellResult?.stderr}`);
if (shellResult?.stderr && !notAnErrorServerDoesntHaveResourceTypeRegExp.test(shellResult.stderr)) {
Expand Down Expand Up @@ -181,4 +184,3 @@ export async function getPodsOfADeployment(name = '', namespace = ''): Promise<P

return parseJsonItems(podResult?.stdout);
}

35 changes: 35 additions & 0 deletions src/types/kubernetes/kubernetesTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,41 @@ export const enum Kind {
GitOpsTemplate = 'GitOpsTemplate',
}

export const enum FullyKind {
Bucket = 'Buckets.source.toolkit.fluxcd.io',
GitRepository = 'GitRepositories.source.toolkit.fluxcd.io',
OCIRepository = 'OCIRepositories.source.toolkit.fluxcd.io',
HelmRepository = 'HelmRepositories.source.toolkit.fluxcd.io',
HelmRelease = 'HelmReleases.helm.toolkit.fluxcd.io',
Kustomization = 'Kustomizations.kustomize.toolkit.fluxcd.io',
GitOpsTemplate = 'GitOpsTemplates.templates.weave.works',
List = '',
Deployment = '',
Node = '',
Pod = '',
Namespace = '',
ConfigMap = '',
}

type KindMapType = {
[id in Kind]: FullyKind;
};

export const FullyQualifiedKinds: KindMapType = {
Bucket: FullyKind.Bucket,
GitRepository: FullyKind.GitRepository,
OCIRepository: FullyKind.OCIRepository,
HelmRepository: FullyKind.HelmRepository,
HelmReleases: FullyKind.HelmRelease,

Check failure on line 78 in src/types/kubernetes/kubernetesTypes.ts

View workflow job for this annotation

GitHub Actions / e2e-testing

Type '{ Bucket: FullyKind.Bucket; GitRepository: FullyKind.GitRepository; OCIRepository: FullyKind.OCIRepository; HelmRepository: FullyKind.HelmRepository; HelmReleases: FullyKind; ... 7 more ...; ConfigMap: FullyKind.List; }' is not assignable to type 'KindMapType'.
Kustomization: FullyKind.Kustomization,
GitOpsTemplate: FullyKind.GitOpsTemplate,
List: FullyKind.List,
Deployment: FullyKind.Deployment,
Node: FullyKind.Node,
Pod: FullyKind.Pod,
Namespace: FullyKind.Namespace,
ConfigMap: FullyKind.ConfigMap,
};

export const enum SourceKind {
Bucket = 'Bucket',
Expand Down

0 comments on commit f8763dc

Please sign in to comment.