Skip to content

Commit 503ef5a

Browse files
committed
fix: fetch cluster from repoName for values
1 parent 6b43b73 commit 503ef5a

File tree

5 files changed

+43
-33
lines changed

5 files changed

+43
-33
lines changed

pkg/suse-ai-rancher-ext/pages/AppInstances.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ export default defineComponent({
502502
if (repoFromQuery) {
503503
try {
504504
console.log(`[SUSE-AI] Loading app info from specified repository: ${repoFromQuery}`);
505-
const repoApps = await fetchAppsFromRepository(store, repoFromQuery, currentClusterId);
505+
const repoApps = await fetchAppsFromRepository(store, repoFromQuery);
506506
const repoApp = repoApps.find(a => a.slug_name === props.slug);
507507
if (repoApp) {
508508
appInfo.value = repoApp;

pkg/suse-ai-rancher-ext/pages/Apps.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@ export default defineComponent({
545545
repoLoading.value = true;
546546
error.value = null;
547547
console.log('[SUSE-AI] Loading all repository apps...');
548-
allRepositoryApps.value = await fetchAllRepositoryApps(store, currentClusterId);
548+
allRepositoryApps.value = await fetchAllRepositoryApps(store);
549549
repositoriesLoaded.value = true;
550550
console.log('[SUSE-AI] Loaded apps from repositories:', Object.keys(allRepositoryApps.value));
551551
@@ -563,7 +563,7 @@ export default defineComponent({
563563
repoLoading.value = true;
564564
error.value = null;
565565
console.log('[SUSE-AI] Loading apps from repository:', newRepo);
566-
const repoApps = await fetchAppsFromRepository(store, newRepo, currentClusterId);
566+
const repoApps = await fetchAppsFromRepository(store, newRepo);
567567
allRepositoryApps.value[newRepo] = repoApps;
568568
console.log('[SUSE-AI] Loaded apps from repository:', { repo: newRepo, count: repoApps.length });
569569
}

pkg/suse-ai-rancher-ext/services/app-collection.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { getClusterContext } from 'utils/cluster-operations';
12
import { log as logger } from '../utils/logger';
23

34
export type PackagingFormat = 'HELM_CHART' | 'CONTAINER';
@@ -311,14 +312,21 @@ function getRepoType(repo: any): string {
311312
}
312313

313314
/** Fetch apps from a specific cluster repository */
314-
export async function fetchAppsFromRepository($store: any, repoName: string, clusterId: string): Promise<AppCollectionItem[]> {
315+
export async function fetchAppsFromRepository($store: any, repoName: string): Promise<AppCollectionItem[]> {
315316
logger.debug('Starting repository apps fetch', {
316317
component: 'AppCollection',
317318
data: { repoName }
318319
});
320+
321+
const found = await getClusterContext($store, { repoName: repoName});
322+
if (!found) {
323+
logger.warn(`ClusterRepo "${repoName}" not found in any cluster`);
324+
return [];
325+
}
326+
const { baseApi } = found
319327

320328
try {
321-
const indexUrl = `/k8s/clusters/${encodeURIComponent(clusterId)}/v1/catalog.cattle.io.clusterrepos/${encodeURIComponent(repoName)}?link=index`;
329+
const indexUrl = `${baseApi}/catalog.cattle.io.clusterrepos/${encodeURIComponent(repoName)}?link=index`;
322330
logger.debug('Requesting repository index', {
323331
component: 'AppCollection',
324332
data: { repoName, indexUrl }
@@ -379,7 +387,7 @@ export async function fetchAppsFromRepository($store: any, repoName: string, clu
379387
}
380388

381389
/** Fetch apps from all cluster repositories */
382-
export async function fetchAllRepositoryApps($store: any, clusterId: string): Promise<{ [repoName: string]: AppCollectionItem[] }> {
390+
export async function fetchAllRepositoryApps($store: any): Promise<{ [repoName: string]: AppCollectionItem[] }> {
383391
logger.debug('Starting fetch all repository apps', {
384392
component: 'AppCollection'
385393
});
@@ -400,7 +408,7 @@ export async function fetchAllRepositoryApps($store: any, clusterId: string): Pr
400408
data: { repoName: repo.name }
401409
});
402410
try {
403-
const apps = await fetchAppsFromRepository($store, repo.name, clusterId);
411+
const apps = await fetchAppsFromRepository($store, repo.name);
404412
if (apps.length > 0) {
405413
repoApps[repo.name] = apps;
406414
logger.debug('Repository apps loaded', {

pkg/suse-ai-rancher-ext/services/chart-service.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,18 @@ export class ChartService {
6565
/**
6666
* Get repository index link
6767
*/
68-
private static async getRepoIndexLink($store: RancherStore, repoName: string, clusterId: string): Promise<string | null> {
68+
private static async getRepoIndexLink($store: RancherStore, repoName: string): Promise<string | null> {
69+
70+
const found = await getClusterContext($store, { repoName: repoName});
71+
if (!found) {
72+
logger.warn(`ClusterRepo "${repoName}" not found in any cluster`);
73+
return null;
74+
}
75+
const { baseApi } = found
76+
6977
try {
7078
const repo = encodeURIComponent(repoName);
71-
const url = `/k8s/clusters/${encodeURIComponent(clusterId)}/v1/catalog.cattle.io.clusterrepos/${repo}`;
79+
const url = `${baseApi}/catalog.cattle.io.clusterrepos/${repo}`;
7280
const res = await $store.dispatch('rancher/request', { url });
7381
const link = res?.data?.links?.index || res?.links?.index;
7482

@@ -89,8 +97,8 @@ export class ChartService {
8997
/**
9098
* Get repository index data
9199
*/
92-
private static async getRepoIndex($store: RancherStore, repoName: string, clusterId: string): Promise<RepositoryIndex | null> {
93-
const indexLink = await this.getRepoIndexLink($store, repoName, clusterId);
100+
private static async getRepoIndex($store: RancherStore, repoName: string): Promise<RepositoryIndex | null> {
101+
const indexLink = await this.getRepoIndexLink($store, repoName);
94102
if (!indexLink) return null;
95103

96104
try {
@@ -143,7 +151,7 @@ export class ChartService {
143151
slug: string
144152
): Promise<{ chartName: string; version: string } | null> {
145153
try {
146-
const index = await this.getRepoIndex($store, repoName,_repoClusterId);
154+
const index = await this.getRepoIndex($store, repoName);
147155
const names = index?.entries ? Object.keys(index.entries) : [];
148156
const match = names.find((n: string) => sameName(n, slug));
149157

@@ -182,7 +190,7 @@ export class ChartService {
182190
chartName: string
183191
): Promise<string[]> {
184192
try {
185-
const index = await this.getRepoIndex($store, repoName, _repoClusterId);
193+
const index = await this.getRepoIndex($store, repoName);
186194
const names = index?.entries ? Object.keys(index.entries) : [];
187195
const match = names.find((n: string) => sameName(n, chartName));
188196

@@ -239,14 +247,6 @@ export class ChartService {
239247
preferVersion?: string
240248
): Promise<string | null> {
241249
try {
242-
const clusterId = $store.getters?.['currentCluster']?.id;
243-
244-
if (!clusterId) {
245-
logger.warn('No selected cluster found', {
246-
component: 'ChartService'
247-
});
248-
return null;
249-
}
250250
const repos = await this.listClusterRepos($store);
251251
let best: string | null = null;
252252

@@ -255,7 +255,7 @@ export class ChartService {
255255
if (!name) continue;
256256

257257
try {
258-
const index = await this.getRepoIndex($store, name, clusterId);
258+
const index = await this.getRepoIndex($store, name);
259259
const entries = index?.entries || {};
260260
const foundKey = Object.keys(entries).find((k) => sameName(k, chartName));
261261
if (!foundKey) continue;

pkg/suse-ai-rancher-ext/services/rancher-apps.ts

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import type {
4141
ServiceAccount,
4242
isRancherError
4343
} from '../types/rancher-types';
44+
import { getClusterContext } from 'utils/cluster-operations';
4445

4546
export interface ChartRef {
4647
repoName: string; // ClusterRepo metadata.name
@@ -487,10 +488,16 @@ function semverDesc(a: string, b: string): number {
487488
}
488489
const SEMVER_CORE = /^\d+\.\d+\.\d+(\+up\d+\.\d+\.\d+)?$/; // show x.y.z or x.y.z+upA.B.C (Rancher chart format)
489490

490-
async function getRepoIndexLink($store: RancherStore, repoName: string, clusterId: string): Promise<string | null> {
491+
async function getRepoIndexLink($store: RancherStore, repoName: string): Promise<string | null> {
492+
const found = await getClusterContext($store, { repoName: repoName});
493+
if (!found) {
494+
logger.warn(`ClusterRepo "${repoName}" not found in any cluster`);
495+
return null;
496+
}
497+
const { baseApi } = found
491498
try {
492499
const repo = encodeURIComponent(repoName);
493-
const url = `/k8s/clusters/${encodeURIComponent(clusterId)}/v1/catalog.cattle.io.clusterrepos/${repo}`;
500+
const url = `${baseApi}/catalog.cattle.io.clusterrepos/${repo}`;
494501
const res = await $store.dispatch('rancher/request', { url });
495502
const link = res?.data?.links?.index || res?.links?.index;
496503
log('repo index link:', link);
@@ -500,14 +507,9 @@ async function getRepoIndexLink($store: RancherStore, repoName: string, clusterI
500507
}
501508
}
502509

503-
async function getRepoIndex($store: RancherStore, repoName: string, clusterId?: string): Promise<RepositoryIndex | null> {
504-
505-
const resolvedClusterId =
506-
clusterId ?? ($store.getters && $store.getters['currentCluster']?.id);
507-
508-
if (!resolvedClusterId) return null;
510+
async function getRepoIndex($store: RancherStore, repoName: string): Promise<RepositoryIndex | null> {
509511

510-
const indexLink = await getRepoIndexLink($store, repoName, resolvedClusterId);
512+
const indexLink = await getRepoIndexLink($store, repoName);
511513
if (!indexLink) return null;
512514

513515
const res = await $store.dispatch('rancher/request', { url: indexLink });
@@ -525,7 +527,7 @@ export async function findChartInRepo(
525527
repoName: string,
526528
slug: string
527529
): Promise<{ chartName: string; version: string } | null> {
528-
const index = await getRepoIndex($store, repoName, _repoClusterId);
530+
const index = await getRepoIndex($store, repoName);
529531
const names = index?.entries ? Object.keys(index.entries) : [];
530532
const match = names.find((n: string) => sameName(n, slug));
531533
if (match && index) {
@@ -542,7 +544,7 @@ export async function listChartVersions(
542544
repoName: string,
543545
chartName: string
544546
): Promise<string[]> {
545-
const index = await getRepoIndex($store, repoName, _repoClusterId);
547+
const index = await getRepoIndex($store, repoName);
546548
const names = index?.entries ? Object.keys(index.entries) : [];
547549
const match = names.find((n: string) => sameName(n, chartName));
548550
if (match && index) {

0 commit comments

Comments
 (0)