Skip to content

Commit

Permalink
Fix logic to test for config metadata (#618)
Browse files Browse the repository at this point in the history
Signed-off-by: Sean Sundberg <seansund@us.ibm.com>
  • Loading branch information
seansund authored Jul 4, 2023
1 parent 35b683c commit 07f1521
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/services/gitops-metadata/gitops-metadata.api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ export enum MetadataErrorType {
export class MetadataMissing extends Error {
readonly errorType: MetadataErrorType = MetadataErrorType.missing

constructor() {
super('Metadata not found in gitops repository!');
constructor(path: string) {
super(`Metadata not found in gitops repository: ${path}`);
}
}

Expand Down
13 changes: 7 additions & 6 deletions src/services/gitops-metadata/gitops-metadata.impl.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import {GitApi, PullRequest} from "@cloudnativetoolkit/git-client";
import * as fs from "fs-extra";
import {pathExists} from "fs-extra";
import {join} from 'path';
import {SimpleGit} from "simple-git";
import {Container} from "typescript-ioc";
import * as YAML from 'js-yaml';
Expand All @@ -9,14 +11,13 @@ import {
GitopsMetadataRetrieveInput,
GitopsMetadataRetrieveResult,
GitopsMetadataUpdateInput,
GitopsMetadataUpdateResult, Metadata
GitopsMetadataUpdateResult, Metadata, MetadataMissing
} from "./gitops-metadata.api";
import {ClusterSummaryApi, ClusterSummaryResult} from "../cluster-summary";
import {PackageManifestSummaryApi, PackageManifestSummaryResult} from "../package-manifest-summary";
import {BootstrapConfig, PayloadConfig} from "../../model";
import {gitopsUtil} from "../../util/gitops-util";
import {Logger} from "../../util/logger";
import {pathExists} from "fs-extra";

/*
'{packages: [.items[] | {"catalogSource": .status.catalogSource, "catalogSourceNamespace": .status.catalogSourceNamespace, "packageName": .status.packageName, "defaultChannel": .status.defaultChannel, "provider": .status.provider.name, "channels": [{"name": .status.channels[].name}] }] }'
Expand Down Expand Up @@ -182,11 +183,11 @@ export class GitopsMetadataImpl implements GitopsMetadataApi {

const currentBranch = await getCurrentBranch(input.branch)

const overlayPath = `${config.path}/cluster/${input.serverName}`;
const metadataPath = `${repoDir}/${overlayPath}/metadata.yaml`;
const overlayPath = join(config.path, 'cluster', input.serverName, 'metadata.yaml');
const metadataPath = join(repoDir, overlayPath);

if (!(await pathExists(overlayPath))) {
throw new Error('Metadata not found in gitops repository!')
if (!(await pathExists(metadataPath))) {
throw new MetadataMissing(overlayPath)
}

const content = await fs.readFile(metadataPath);
Expand Down

0 comments on commit 07f1521

Please sign in to comment.