-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add deployment and stateful set resource viewers (#84)
This change adds the Deployment and Stateful Set resource viewers.
- Loading branch information
1 parent
029a910
commit c456a8c
Showing
7 changed files
with
319 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
...ourceViewerDialog/components/FirstClassViewers/StructuredMetadata/resources/deployment.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { Deployment } from '../../../../../../types/Deployment'; | ||
import { KubernetesResource } from '../../../../../../types/KubernetesResource'; | ||
import { Metadata } from '../StructuredMetadata'; | ||
import { getPodTemplatedStructuredMetadata } from './podTemplate'; | ||
|
||
export const getDeploymentStructuredMetadata = ( | ||
resource: KubernetesResource, | ||
): Metadata => { | ||
const deployment = resource as Deployment; | ||
|
||
const podMetadata: Metadata = getPodTemplatedStructuredMetadata( | ||
deployment.spec.template, | ||
); | ||
|
||
return { | ||
replicas: deployment.spec.replicas, | ||
serviceAccountName: deployment.spec.template.spec.serviceAccountName, | ||
...podMetadata, | ||
}; | ||
}; |
78 changes: 78 additions & 0 deletions
78
...urceViewerDialog/components/FirstClassViewers/StructuredMetadata/resources/podTemplate.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/** | ||
* 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 { | ||
ContainerPort, | ||
PodTemplateSpec, | ||
VolumeMount, | ||
} from '../../../../../../types/Pod'; | ||
import { Metadata } from '../StructuredMetadata'; | ||
|
||
export const getPodTemplatedStructuredMetadata = ( | ||
podTemplate: PodTemplateSpec, | ||
): Metadata => { | ||
const customMetadata: Metadata = { | ||
serviceAccountName: podTemplate.spec.serviceAccountName, | ||
podLabels: podTemplate.metadata.labels, | ||
podAnnotations: podTemplate.metadata.annotations, | ||
}; | ||
|
||
const getPortDescription = (port: ContainerPort): string => | ||
`exposes ${port.protocol || 'TCP'} port ${port.containerPort} ${ | ||
port.name ? `as ${port.name}` : '' | ||
}`; | ||
|
||
const getVolumeMountDescription = (volumeMount: VolumeMount): string => | ||
`${volumeMount.mountPath} → ${volumeMount.name} volume ${ | ||
volumeMount.readOnly ? '(readonly)' : '' | ||
}`; | ||
|
||
const templateContainers = podTemplate.spec.containers; | ||
for (const [index, container] of templateContainers.entries()) { | ||
const name = | ||
templateContainers.length > 1 ? `container${index + 1}` : 'container'; | ||
|
||
const containerDetails: string[] = [ | ||
`name: ${container.name}`, | ||
`image: ${container.image}`, | ||
...(container.ports ?? []).map(getPortDescription), | ||
...(container.volumeMounts ?? []).map(getVolumeMountDescription), | ||
]; | ||
|
||
customMetadata[name] = containerDetails; | ||
} | ||
|
||
const volumes = podTemplate.spec.volumes ?? []; | ||
for (const [index, volume] of volumes.entries()) { | ||
const name = volumes.length > 1 ? `volume${index + 1}` : 'volume'; | ||
|
||
const volumeSource = (): string => { | ||
if (volume.configMap) { | ||
return `${volume.configMap.name} config map`; | ||
} | ||
if (volume.persistentVolumeClaim) { | ||
return `${volume.persistentVolumeClaim?.claimName} persistent volume claim`; | ||
} | ||
return ''; | ||
}; | ||
|
||
const volumeDescription = `${volume.name} → ${volumeSource()}`; | ||
|
||
customMetadata[name] = volumeDescription; | ||
} | ||
|
||
return customMetadata; | ||
}; |
52 changes: 52 additions & 0 deletions
52
...urceViewerDialog/components/FirstClassViewers/StructuredMetadata/resources/statefulSet.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/** | ||
* 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 { KubernetesResource } from '../../../../../../types/KubernetesResource'; | ||
import { StatefulSet } from '../../../../../../types/StatefulSet'; | ||
import { Metadata } from '../StructuredMetadata'; | ||
import { getPersistentVolumeClaimStructuredMetadata } from './persistentVolumeClaim'; | ||
import { getPodTemplatedStructuredMetadata } from './podTemplate'; | ||
|
||
export const getStatefulSetStructuredMetadata = ( | ||
resource: KubernetesResource, | ||
): Metadata => { | ||
const statefulSet = resource as StatefulSet; | ||
|
||
const podMetadata: Metadata = getPodTemplatedStructuredMetadata( | ||
statefulSet.spec.template, | ||
); | ||
|
||
const volumeClaimMetadata: Metadata = {}; | ||
|
||
const volumeClaimTemplates = statefulSet.spec.volumeClaimTemplates ?? []; | ||
for (const [index, volumeClaim] of volumeClaimTemplates.entries()) { | ||
const name = | ||
volumeClaimTemplates.length > 1 | ||
? `volumeClaim${index + 1}` | ||
: `volumeClaim`; | ||
|
||
volumeClaimMetadata[name] = | ||
getPersistentVolumeClaimStructuredMetadata(volumeClaim).volumeClaim; | ||
} | ||
|
||
return { | ||
replicas: statefulSet.spec.replicas, | ||
serviceName: statefulSet.spec.serviceName, | ||
serviceAccountName: statefulSet.spec.template.spec.serviceAccountName, | ||
...podMetadata, | ||
...volumeClaimMetadata, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/** | ||
* 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'; | ||
import { PodTemplateSpec } from './Pod'; | ||
|
||
export type Deployment = { | ||
apiVersion: string; | ||
kind: string; | ||
metadata: DeploymentMetadata; | ||
spec: DeploymentSpec; | ||
}; | ||
|
||
export type DeploymentMetadata = { | ||
name: string; | ||
namespace?: string; | ||
labels?: KubernetesKeyValueObject; | ||
annotations?: KubernetesKeyValueObject; | ||
}; | ||
|
||
export type DeploymentSpec = { | ||
replicas?: number; | ||
template: PodTemplateSpec; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/** | ||
* 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 PodTemplateSpec = { | ||
metadata: PodMetadata; | ||
spec: PodSpec; | ||
}; | ||
|
||
export type PodMetadata = { | ||
name: string; | ||
namespace?: string; | ||
labels?: KubernetesKeyValueObject; | ||
annotations?: KubernetesKeyValueObject; | ||
}; | ||
|
||
export type PodSpec = { | ||
serviceAccountName?: string; | ||
volumes: Volume[]; | ||
containers: Container[]; | ||
}; | ||
|
||
export type Volume = { | ||
name: string; | ||
persistentVolumeClaim?: PersistentVolumeClaimVolumeSource; | ||
configMap?: ConfigMapVolumeSource; | ||
}; | ||
|
||
export type PersistentVolumeClaimVolumeSource = { | ||
claimName: string; | ||
}; | ||
|
||
export type ConfigMapVolumeSource = { | ||
name: string; | ||
}; | ||
|
||
export type Container = { | ||
name: string; | ||
image?: string; | ||
ports?: ContainerPort[]; | ||
volumeMounts?: VolumeMount[]; | ||
}; | ||
|
||
export type ContainerPort = { | ||
name: string; | ||
containerPort: number; | ||
protocol?: string; | ||
}; | ||
|
||
export type VolumeMount = { | ||
name: string; | ||
mountPath: string; | ||
readOnly?: boolean; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/** | ||
* 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'; | ||
import { PersistentVolumeClaim } from './PersistentVolumeClaim'; | ||
import { PodTemplateSpec } from './Pod'; | ||
|
||
export type StatefulSet = { | ||
apiVersion: string; | ||
kind: string; | ||
metadata: StatefulSetMetadata; | ||
spec: StatefulSetSpec; | ||
}; | ||
|
||
export type StatefulSetMetadata = { | ||
name: string; | ||
namespace?: string; | ||
labels?: KubernetesKeyValueObject; | ||
annotations?: KubernetesKeyValueObject; | ||
}; | ||
|
||
export type StatefulSetSpec = { | ||
serviceName: string; | ||
replicas?: number; | ||
template: PodTemplateSpec; | ||
volumeClaimTemplates?: PersistentVolumeClaim[]; | ||
}; |