Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,6 @@ export default [
*/
quotes: ['error', 'single', { allowTemplateLiterals: true }],

'capitalized-comments': 'error',

// disabled import/namespace rule as the plug-in is not fully compatible using the compat mode
'import/namespace': 'off',
'import/no-duplicates': 'error',
Expand All @@ -171,7 +169,8 @@ export default [
'vitest/consistent-test-filename': 'off',
'vitest/no-hooks': 'off',
'vitest/require-top-level-describe': 'off',
'import/no-unresolved': 'off'
'import/no-unresolved': 'off',
'sonarjs/no-nested-functions': 'off'
},
},

Expand Down
21 changes: 21 additions & 0 deletions packages/common/src/model/api-sender.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**********************************************************************
* Copyright (C) 2022-2024 Red Hat, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
***********************************************************************/

export type ApiSenderType = {
send: (channel: string, data?: unknown) => void;
};
31 changes: 31 additions & 0 deletions packages/common/src/model/kubernetes-contexts-healths.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**********************************************************************
* Copyright (C) 2024 Red Hat, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
***********************************************************************/

export interface ContextHealth {
contextName: string;
// is the health of the cluster being checked?
checking: boolean;
// was the health check successful?
reachable: boolean;
// is one of the informers marked offline (disconnect after being connected, the cache still being populated)
offline: boolean;
// description in case of error (other than health check)
// currently detected errors:
// - user.exec.command not found
errorMessage?: string;
}
35 changes: 35 additions & 0 deletions packages/common/src/model/kubernetes-contexts-permissions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**********************************************************************
* Copyright (C) 2024 Red Hat, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
***********************************************************************/

export interface ContextPermission {
contextName: string;
// the resource name is a generic string type and not a string literal type, as we want to handle CRDs names
resourceName: string;
// permitted if allowed and not denied
// > When multiple authorization modules are configured, each is checked in sequence.
// > If any authorizer approves or denies a request, that decision is immediately returned
// > and no other authorizer is consulted. If all modules have no opinion on the request,
// > then the request is denied. An overall deny verdict means that the API server rejects
// > the request and responds with an HTTP 403 (Forbidden) status.
// (source: https://kubernetes.io/docs/reference/access-authn-authz/authorization/)
permitted: boolean;
// A free-form and optional text reason for the resource being allowed or denied.
// We cannot rely on having a reason for every request.
// For exemple on Kind cluster, a reason is given only when the access is allowed, no reason is done for denial.
reason?: string;
}
59 changes: 59 additions & 0 deletions packages/common/src/model/kubernetes-contexts-states.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/**********************************************************************
* Copyright (C) 2024 Red Hat, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
***********************************************************************/

export const NO_CURRENT_CONTEXT_ERROR = 'no current context';

// CheckingState indicates the state of the check for a context
export interface CheckingState {
state: 'waiting' | 'checking' | 'gaveup';
}

// A selection of resources, to indicate the 'general' status of a context
type selectedResources = ['pods', 'deployments'];

// resources managed by podman desktop, excepted the primary ones
// This is where to add new resources when adding new informers
export const secondaryResources = [
'services',
'ingresses',
'routes',
'configmaps',
'secrets',
'nodes',
'persistentvolumeclaims',
'events',
'cronjobs',
'jobs',
] as const;

export type SecondaryResourceName = (typeof secondaryResources)[number];
export type ResourceName = SelectedResourceName | SecondaryResourceName;

export type SelectedResourceName = selectedResources[number];

export type SelectedResourcesCount = {
[resourceName in SelectedResourceName]: number;
};

// information sent: status and count of selected resources
export interface ContextGeneralState {
checking?: CheckingState;
error?: string;
reachable: boolean;
resources: SelectedResourcesCount;
}
23 changes: 23 additions & 0 deletions packages/common/src/model/kubernetes-resource-count.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**********************************************************************
* Copyright (C) 2024 Red Hat, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
***********************************************************************/

export interface ResourceCount {
contextName: string;
resourceName: string;
count: number;
}
24 changes: 24 additions & 0 deletions packages/common/src/model/kubernetes-resources.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**********************************************************************
* Copyright (C) 2025 Red Hat, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
***********************************************************************/

import type { KubernetesObject } from '@kubernetes/client-node';

export interface KubernetesContextResources {
contextName: string;
items: readonly KubernetesObject[];
}
43 changes: 43 additions & 0 deletions packages/common/src/model/kubernetes-troubleshooting.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**********************************************************************
* Copyright (C) 2025 Red Hat, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
***********************************************************************/

export interface KubernetesTroubleshootingInformation {
healthCheckers: KubernetesTroubleshootingHealthChecker[];
permissionCheckers: KubernetesTroubleshootingPermissionChecker[];
informers: KubernetesTroubleshootingInformer[];
}

export interface KubernetesTroubleshootingHealthChecker {
contextName: string;
checking: boolean;
reachable: boolean;
}

export interface KubernetesTroubleshootingPermissionChecker {
contextName: string;
resourceName: string;
permitted: boolean;
reason?: string;
}

export interface KubernetesTroubleshootingInformer {
contextName: string;
resourceName: string;
isOffline: boolean;
objectsCount?: number;
}
49 changes: 49 additions & 0 deletions packages/common/src/model/openshift-types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/**********************************************************************
* Copyright (C) 2022 Red Hat, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
***********************************************************************/

import type { V1ManagedFieldsEntry } from '@kubernetes/client-node';

export type V1Route = {
apiVersion?: string;
kind?: string;
metadata: {
name: string;
namespace: string;
annotations?: { [key: string]: string };
labels?: { [key: string]: string };
managedFields?: Array<V1ManagedFieldsEntry>;
creationTimestamp?: Date;
};
spec: {
host: string;
port?: {
targetPort: string;
};
path?: string;
tls: {
insecureEdgeTerminationPolicy: string;
termination: string;
};
to: {
kind: string;
name: string;
weight: number;
};
wildcardPolicy: string;
};
};
1 change: 1 addition & 0 deletions packages/extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"vitest": "^3.1"
},
"dependencies": {
"@kubernetes/client-node": "^1.3.0",
"ansi_up": "^6.0.5",
"inversify": "^7.5.1",
"reflect-metadata": "^0.2.2"
Expand Down
Loading