Skip to content

Commit

Permalink
feat: add api service resource viewer (#114)
Browse files Browse the repository at this point in the history
This changes add the API Service resource viewer.
  • Loading branch information
ChristopherFry committed Aug 17, 2022
1 parent 056d892 commit cdbda94
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/

import React from 'react';
import { getAPIServiceStructuredMetadata } from './FirstClassViewers/StructuredMetadata/resources/apiService';
import { getApplyReplacementsStructuredMetadata } from './FirstClassViewers/StructuredMetadata/resources/applyReplacements';
import { getClusterIssuerStructuredMetadata } from './FirstClassViewers/StructuredMetadata/resources/clusterIssuer';
import { getConfigMapStructuredMetadata } from './FirstClassViewers/StructuredMetadata/resources/configMap';
Expand Down Expand Up @@ -53,6 +54,9 @@ const getCustomMetadataFn = (
case 'apiextensions.k8s.io/v1/CustomResourceDefinition':
return getCustomResourceDefinitionStructuredMetadata;

case 'apiregistration.k8s.io/v1/APIService':
return getAPIServiceStructuredMetadata;

case 'apps/v1/Deployment':
return getDeploymentStructuredMetadata;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* Copyright 2022 Google LLC
*
* 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.
*/

import { APIService } from '../../../../../../types/APIService';
import { KubernetesResource } from '../../../../../../types/KubernetesResource';
import { Metadata } from '../StructuredMetadata';

export const getAPIServiceStructuredMetadata = (
resource: KubernetesResource,
): Metadata => {
const apiService = resource as APIService;

const serviceSpec = apiService.spec.service;

const groupVersion = `${apiService.spec.group}/${apiService.spec.version}`;
const service = `${serviceSpec.namespace}/${serviceSpec.name}:${
serviceSpec.port ?? 443
}`;

return {
apiService: `${groupVersion}${service}`,
};
};
45 changes: 45 additions & 0 deletions plugins/cad/src/types/APIService.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/**
* Copyright 2022 Google LLC
*
* 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.
*/

import { KubernetesKeyValueObject } from './KubernetesResource';

export type APIService = {
apiVersion: string;
kind: string;
metadata: APIServiceMetadata;
spec: APIServiceSpec;
};

export type APIServiceMetadata = {
name: string;
labels?: KubernetesKeyValueObject;
annotations?: KubernetesKeyValueObject;
};

export type APIServiceSpec = {
service: ServiceReference;
group: string;
version: string;
insecureSkipTLSVerify?: boolean;
groupPriorityMinimum?: number;
versionPriority?: number;
};

export type ServiceReference = {
namespace: string;
name: string;
port?: number;
};

0 comments on commit cdbda94

Please sign in to comment.