Skip to content

Commit

Permalink
Merge pull request #468 from weaveworks/attempt-fqNames
Browse files Browse the repository at this point in the history
(Prerelease) Fix fully qualified Flux API names
  • Loading branch information
Kingdon Barrett authored Sep 5, 2023
2 parents aa60ca9 + 19d9bc4 commit e86c19a
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 6 deletions.
7 changes: 3 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,9 @@ 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 (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 +181,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,
HelmRelease: FullyKind.HelmRelease,
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
21 changes: 19 additions & 2 deletions src/ui/treeviews/nodes/treeNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Command, MarkdownString, ThemeColor, ThemeIcon, TreeItem, TreeItemColla

import { CommandId } from 'types/extensionIds';
import { FileTypes } from 'types/fileTypes';
import { KubernetesObject } from 'types/kubernetes/kubernetesTypes';
import { Kind, FullyQualifiedKinds, KubernetesObject } from 'types/kubernetes/kubernetesTypes';
import { asAbsolutePath } from 'utils/asAbsolutePath';
import { getResourceUri } from 'utils/getResourceUri';
import { KnownTreeNodeResources, createMarkdownTable } from 'utils/markdownUtils';
Expand Down Expand Up @@ -141,6 +141,22 @@ export class TreeNode extends TreeItem {
.join('');
}

fullyQualifyKind(): string {
let stringKind = '';
if(this.resource) {
stringKind = this.resource.kind as string;
}
if (stringKind) {
let typedKind: Kind = stringKind as Kind;
let fqKind = FullyQualifiedKinds[typedKind];

if(fqKind !== '') {
stringKind = fqKind as string;
}
}
return stringKind;
}

// @ts-ignore
get tooltip(): string | MarkdownString {
if (this.resource) {
Expand All @@ -152,9 +168,10 @@ export class TreeNode extends TreeItem {
get command(): Command | undefined {
// Set click event handler to load kubernetes resource as yaml file in editor.
if (this.resource) {
let stringKind = this.fullyQualifyKind();
const resourceUri = getResourceUri(
this.resource.metadata?.namespace,
`${this.resource.kind}/${this.resource.metadata?.name}`,
`${stringKind}/${this.resource.metadata?.name}`,
FileTypes.Yaml,
);

Expand Down

0 comments on commit e86c19a

Please sign in to comment.