Skip to content

Commit

Permalink
Deploy a chart via flux (#3640)
Browse files Browse the repository at this point in the history
* Deploy via flux.

Signed-off-by: Michael Nelson <minelson@vmware.com>

* Lint

Signed-off-by: Michael Nelson <minelson@vmware.com>
  • Loading branch information
absoludity authored Oct 24, 2021
1 parent 8bd8c2f commit c1d6743
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 50 deletions.
10 changes: 6 additions & 4 deletions dashboard/src/components/DeploymentForm/DeploymentForm.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ const defaultProps = {
pkgName: "foo",
cluster: "default",
namespace: "default",
packageCluster: "default",
packageNamespace: "kubeapps",
releaseName: "my-release",
version: "0.0.1",
plugin: { name: "my.plugin", version: "0.0.1" } as Plugin,
Expand All @@ -37,9 +39,9 @@ const defaultSelectedPkg = {
values: "bar: foo",
};

const routePathParam = `/c/${defaultProps.cluster}/ns/${defaultProps.namespace}/apps/new/${defaultProps.plugin.name}/${defaultProps.plugin.version}/${defaultProps.pkgName}/versions/${defaultProps.version}`;
const routePathParam = `/c/${defaultProps.cluster}/ns/${defaultProps.namespace}/apps/new/${defaultProps.plugin.name}/${defaultProps.plugin.version}/${defaultProps.packageCluster}/${defaultProps.packageNamespace}/${defaultProps.pkgName}/versions/${defaultProps.version}`;
const routePath =
"/c/:cluster/ns/:namespace/apps/new/:pluginName/:pluginVersion/:packageId/versions/:packageVersion";
"/c/:cluster/ns/:namespace/apps/new/:pluginName/:pluginVersion/:packageCluster/:packageNamespace/:packageId/versions/:packageVersion";
const history = createMemoryHistory({ initialEntries: [routePathParam] });

let spyOnUseDispatch: jest.SpyInstance;
Expand Down Expand Up @@ -74,7 +76,7 @@ it("fetches the available versions", () => {

expect(fetchAvailablePackageVersions).toHaveBeenCalledWith(
{
context: { cluster: defaultProps.cluster, namespace: defaultProps.namespace },
context: { cluster: defaultProps.packageCluster, namespace: defaultProps.packageNamespace },
identifier: defaultProps.pkgName,
plugin: defaultProps.plugin,
} as AvailablePackageReference,
Expand Down Expand Up @@ -244,7 +246,7 @@ describe("renders an error", () => {
);

expect(history.location.pathname).toBe(
"/c/default/ns/default/apps/new/my.plugin/0.0.1/foo/versions/0.0.1",
`/c/${defaultProps.cluster}/ns/${defaultProps.namespace}/apps/new/my.plugin/0.0.1/${defaultProps.packageCluster}/${defaultProps.packageNamespace}/foo/versions/0.0.1`,
);
});
});
23 changes: 7 additions & 16 deletions dashboard/src/components/DeploymentForm/DeploymentForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ import LoadingWrapper from "../LoadingWrapper/LoadingWrapper";
interface IRouteParams {
cluster: string;
namespace: string;
global: string;
pluginName: string;
pluginVersion: string;
packageCluster: string;
packageNamespace: string;
packageId: string;
packageVersion?: string;
}
Expand All @@ -33,14 +34,14 @@ export default function DeploymentForm() {
const {
cluster: targetCluster,
namespace: targetNamespace,
global,
packageId,
pluginName,
pluginVersion,
packageCluster,
packageNamespace,
packageVersion,
} = ReactRouter.useParams() as IRouteParams;
const {
config,
packages: { isFetching: packagesIsFetching, selected: selectedPackage },
apps,
} = useSelector((state: IStoreState) => state);
Expand All @@ -54,13 +55,10 @@ export default function DeploymentForm() {

const [pluginObj] = useState({ name: pluginName, version: pluginVersion } as Plugin);

// Use the cluster/namespace from the URL unless it comes from a "global" repository.
// In that case, use the cluster/namespace from where kubeapps has been installed on
const isGlobal = global === "global";
const [packageReference] = useState({
context: {
cluster: isGlobal ? config.kubeappsCluster : targetCluster,
namespace: isGlobal ? config.kubeappsNamespace : targetNamespace,
cluster: packageCluster,
namespace: packageNamespace,
},
plugin: pluginObj,
identifier: packageId,
Expand Down Expand Up @@ -130,14 +128,7 @@ export default function DeploymentForm() {
const selectVersion = (e: React.ChangeEvent<HTMLSelectElement>) => {
dispatch(
push(
url.app.apps.new(
targetCluster,
targetNamespace,
pluginObj,
packageId,
e.currentTarget.value,
isGlobal,
),
url.app.apps.new(targetCluster, targetNamespace, packageReference, e.currentTarget.value),
),
);
};
Expand Down
31 changes: 12 additions & 19 deletions dashboard/src/components/PackageHeader/PackageView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,29 +45,26 @@ export default function PackageView() {
packageVersion,
} = ReactRouter.useParams() as IRouteParams;
const {
config,
packages: { isFetching, selected: selectedPackage },
} = useSelector((state: IStoreState) => state);

const [pluginObj] = useState({ name: pluginName, version: pluginVersion } as Plugin);

const isGlobal =
packageCluster === config.kubeappsCluster && packageNamespace === config.kubeappsNamespace;
const [packageReference] = useState({
context: {
cluster: packageCluster,
namespace: packageNamespace,
},
plugin: pluginObj,
identifier: packageId,
} as AvailablePackageReference);

// Fetch the selected/latest version on the initial load
useEffect(() => {
dispatch(
actions.packages.fetchAndSelectAvailablePackageDetail(
{
context: { cluster: packageCluster, namespace: packageNamespace },
plugin: pluginObj,
identifier: packageId,
} as AvailablePackageReference,
packageVersion,
),
actions.packages.fetchAndSelectAvailablePackageDetail(packageReference, packageVersion),
);
return () => {};
}, [dispatch, packageId, packageNamespace, packageCluster, packageVersion, pluginObj]);
}, [dispatch, packageReference, packageVersion]);

// Fetch all versions
useEffect(() => {
Expand Down Expand Up @@ -114,10 +111,8 @@ export default function PackageView() {
to={app.apps.new(
targetCluster,
targetNamespace,
pluginObj,
packageId,
packageReference,
selectedPackage.pkgVersion,
isGlobal,
)}
>
<CdsButton status="primary">
Expand All @@ -141,10 +136,8 @@ export default function PackageView() {
to={app.apps.new(
targetCluster,
targetNamespace,
pluginObj,
packageId,
packageReference,
selectedPackage.pkgVersion,
isGlobal,
)}
>
<CdsButton status="primary">
Expand Down
4 changes: 1 addition & 3 deletions dashboard/src/containers/RoutesContainer/Routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ const privateRoutes = {
"/c/:cluster/ns/:namespace/apps/:pluginName/:pluginVersion/:releaseName/upgrade": AppUpgrade,
"/c/:cluster/ns/:namespace/apps/:pluginName/:pluginVersion/:releaseName/upgrade/:version":
AppUpgrade,
"/c/:cluster/ns/:namespace/apps/new/:pluginName/:pluginVersion/:packageId/versions/:packageVersion":
DeploymentForm,
"/c/:cluster/ns/:namespace/apps/new-from-:global(global)/:pluginName/:pluginVersion/:packageId/versions/:packageVersion":
"/c/:cluster/ns/:namespace/apps/new/:pluginName/:pluginVersion/:packageCluster/:packageNamespace/:packageId/versions/:packageVersion":
DeploymentForm,
"/c/:cluster/ns/:namespace/catalog": Catalog,
"/c/:cluster/ns/:namespace/packages/:pluginName/:pluginVersion/:packageCluster/:packageNamespace/:packageId":
Expand Down
20 changes: 12 additions & 8 deletions dashboard/src/shared/url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,26 @@ import {
AvailablePackageReference,
InstalledPackageReference,
} from "gen/kubeappsapis/core/packages/v1alpha1/packages";
import { Plugin } from "gen/kubeappsapis/core/plugins/v1alpha1/plugins";

export const app = {
apps: {
new: (
cluster: string,
namespace: string,
plugin: Plugin,
packageId: string,
availablePackageReference: AvailablePackageReference,
version: string,
isGlobal: boolean,
) => {
const globalSegment = isGlobal ? "new-from-global" : "new";
return `/c/${cluster}/ns/${namespace}/apps/${globalSegment}/${plugin?.name}/${
plugin?.version
}/${encodeURIComponent(packageId)}/versions/${version}`;
const pkgPluginName = availablePackageReference?.plugin?.name;
const pkgPluginVersion = availablePackageReference?.plugin?.version;
const pkgId = availablePackageReference?.identifier || "";
// Some plugins may not be cluster-aware nor support multi-cluster, so
// if the returned available package ref doesn't set cluster, use the current
// one.
const pkgCluster = availablePackageReference?.context?.cluster || cluster;
const pkgNamespace = availablePackageReference?.context?.namespace;
return `/c/${cluster}/ns/${namespace}/apps/new/${pkgPluginName}/${pkgPluginVersion}/${pkgCluster}/${pkgNamespace}/${encodeURIComponent(
pkgId,
)}/versions/${version}`;
},
list: (cluster?: string, namespace?: string) => `/c/${cluster}/ns/${namespace}/apps`,
get: (installedPackageReference: InstalledPackageReference) => {
Expand Down

0 comments on commit c1d6743

Please sign in to comment.