Skip to content

Commit f7d7aef

Browse files
authored
feat: import contexts-manager from podman-desktop (#9)
* feat: import contexts-manager from podman-desktop Signed-off-by: Philippe Martin <[email protected]> * feat: add contexts-state-dispatcher Signed-off-by: Philippe Martin <[email protected]> * fix: pnpm-lock Signed-off-by: Philippe Martin <[email protected]> --------- Signed-off-by: Philippe Martin <[email protected]>
1 parent d2a8305 commit f7d7aef

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+6671
-3
lines changed

eslint.config.mjs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,6 @@ export default [
159159
*/
160160
quotes: ['error', 'single', { allowTemplateLiterals: true }],
161161

162-
'capitalized-comments': 'error',
163-
164162
// disabled import/namespace rule as the plug-in is not fully compatible using the compat mode
165163
'import/namespace': 'off',
166164
'import/no-duplicates': 'error',
@@ -171,7 +169,8 @@ export default [
171169
'vitest/consistent-test-filename': 'off',
172170
'vitest/no-hooks': 'off',
173171
'vitest/require-top-level-describe': 'off',
174-
'import/no-unresolved': 'off'
172+
'import/no-unresolved': 'off',
173+
'sonarjs/no-nested-functions': 'off'
175174
},
176175
},
177176

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**********************************************************************
2+
* Copyright (C) 2022-2024 Red Hat, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
* SPDX-License-Identifier: Apache-2.0
17+
***********************************************************************/
18+
19+
export type ApiSenderType = {
20+
send: (channel: string, data?: unknown) => void;
21+
};
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/**********************************************************************
2+
* Copyright (C) 2024 Red Hat, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
* SPDX-License-Identifier: Apache-2.0
17+
***********************************************************************/
18+
19+
export interface ContextHealth {
20+
contextName: string;
21+
// is the health of the cluster being checked?
22+
checking: boolean;
23+
// was the health check successful?
24+
reachable: boolean;
25+
// is one of the informers marked offline (disconnect after being connected, the cache still being populated)
26+
offline: boolean;
27+
// description in case of error (other than health check)
28+
// currently detected errors:
29+
// - user.exec.command not found
30+
errorMessage?: string;
31+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/**********************************************************************
2+
* Copyright (C) 2024 Red Hat, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
* SPDX-License-Identifier: Apache-2.0
17+
***********************************************************************/
18+
19+
export interface ContextPermission {
20+
contextName: string;
21+
// the resource name is a generic string type and not a string literal type, as we want to handle CRDs names
22+
resourceName: string;
23+
// permitted if allowed and not denied
24+
// > When multiple authorization modules are configured, each is checked in sequence.
25+
// > If any authorizer approves or denies a request, that decision is immediately returned
26+
// > and no other authorizer is consulted. If all modules have no opinion on the request,
27+
// > then the request is denied. An overall deny verdict means that the API server rejects
28+
// > the request and responds with an HTTP 403 (Forbidden) status.
29+
// (source: https://kubernetes.io/docs/reference/access-authn-authz/authorization/)
30+
permitted: boolean;
31+
// A free-form and optional text reason for the resource being allowed or denied.
32+
// We cannot rely on having a reason for every request.
33+
// For exemple on Kind cluster, a reason is given only when the access is allowed, no reason is done for denial.
34+
reason?: string;
35+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/**********************************************************************
2+
* Copyright (C) 2024 Red Hat, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
* SPDX-License-Identifier: Apache-2.0
17+
***********************************************************************/
18+
19+
export const NO_CURRENT_CONTEXT_ERROR = 'no current context';
20+
21+
// CheckingState indicates the state of the check for a context
22+
export interface CheckingState {
23+
state: 'waiting' | 'checking' | 'gaveup';
24+
}
25+
26+
// A selection of resources, to indicate the 'general' status of a context
27+
type selectedResources = ['pods', 'deployments'];
28+
29+
// resources managed by podman desktop, excepted the primary ones
30+
// This is where to add new resources when adding new informers
31+
export const secondaryResources = [
32+
'services',
33+
'ingresses',
34+
'routes',
35+
'configmaps',
36+
'secrets',
37+
'nodes',
38+
'persistentvolumeclaims',
39+
'events',
40+
'cronjobs',
41+
'jobs',
42+
] as const;
43+
44+
export type SecondaryResourceName = (typeof secondaryResources)[number];
45+
export type ResourceName = SelectedResourceName | SecondaryResourceName;
46+
47+
export type SelectedResourceName = selectedResources[number];
48+
49+
export type SelectedResourcesCount = {
50+
[resourceName in SelectedResourceName]: number;
51+
};
52+
53+
// information sent: status and count of selected resources
54+
export interface ContextGeneralState {
55+
checking?: CheckingState;
56+
error?: string;
57+
reachable: boolean;
58+
resources: SelectedResourcesCount;
59+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**********************************************************************
2+
* Copyright (C) 2024 Red Hat, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
* SPDX-License-Identifier: Apache-2.0
17+
***********************************************************************/
18+
19+
export interface ResourceCount {
20+
contextName: string;
21+
resourceName: string;
22+
count: number;
23+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**********************************************************************
2+
* Copyright (C) 2025 Red Hat, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
* SPDX-License-Identifier: Apache-2.0
17+
***********************************************************************/
18+
19+
import type { KubernetesObject } from '@kubernetes/client-node';
20+
21+
export interface KubernetesContextResources {
22+
contextName: string;
23+
items: readonly KubernetesObject[];
24+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/**********************************************************************
2+
* Copyright (C) 2025 Red Hat, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
* SPDX-License-Identifier: Apache-2.0
17+
***********************************************************************/
18+
19+
export interface KubernetesTroubleshootingInformation {
20+
healthCheckers: KubernetesTroubleshootingHealthChecker[];
21+
permissionCheckers: KubernetesTroubleshootingPermissionChecker[];
22+
informers: KubernetesTroubleshootingInformer[];
23+
}
24+
25+
export interface KubernetesTroubleshootingHealthChecker {
26+
contextName: string;
27+
checking: boolean;
28+
reachable: boolean;
29+
}
30+
31+
export interface KubernetesTroubleshootingPermissionChecker {
32+
contextName: string;
33+
resourceName: string;
34+
permitted: boolean;
35+
reason?: string;
36+
}
37+
38+
export interface KubernetesTroubleshootingInformer {
39+
contextName: string;
40+
resourceName: string;
41+
isOffline: boolean;
42+
objectsCount?: number;
43+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/**********************************************************************
2+
* Copyright (C) 2022 Red Hat, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
* SPDX-License-Identifier: Apache-2.0
17+
***********************************************************************/
18+
19+
import type { V1ManagedFieldsEntry } from '@kubernetes/client-node';
20+
21+
export type V1Route = {
22+
apiVersion?: string;
23+
kind?: string;
24+
metadata: {
25+
name: string;
26+
namespace: string;
27+
annotations?: { [key: string]: string };
28+
labels?: { [key: string]: string };
29+
managedFields?: Array<V1ManagedFieldsEntry>;
30+
creationTimestamp?: Date;
31+
};
32+
spec: {
33+
host: string;
34+
port?: {
35+
targetPort: string;
36+
};
37+
path?: string;
38+
tls: {
39+
insecureEdgeTerminationPolicy: string;
40+
termination: string;
41+
};
42+
to: {
43+
kind: string;
44+
name: string;
45+
weight: number;
46+
};
47+
wildcardPolicy: string;
48+
};
49+
};

packages/extension/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
"vitest": "^3.1"
4141
},
4242
"dependencies": {
43+
"@kubernetes/client-node": "^1.3.0",
4344
"ansi_up": "^6.0.5",
4445
"inversify": "^7.5.1",
4546
"reflect-metadata": "^0.2.2"

0 commit comments

Comments
 (0)