|
| 1 | +package kubernetes |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + opengovernance "github.com/opengovern/og-describer-kubernetes/discovery/pkg/es" |
| 6 | + |
| 7 | + "github.com/turbot/steampipe-plugin-sdk/v5/grpc/proto" |
| 8 | + "github.com/turbot/steampipe-plugin-sdk/v5/plugin" |
| 9 | + "github.com/turbot/steampipe-plugin-sdk/v5/plugin/transform" |
| 10 | +) |
| 11 | + |
| 12 | +func tableKubernetesPersistentVolume(ctx context.Context) *plugin.Table { |
| 13 | + return &plugin.Table{ |
| 14 | + Name: "kubernetes_persistent_volume", |
| 15 | + Description: "A PersistentVolume (PV) is a piece of storage in the cluster that has been provisioned by an administrator or dynamically provisioned using Storage Classes. PVs are volume plugins like Volumes, but have a lifecycle independent of any individual Pod that uses the PV.", |
| 16 | + Get: &plugin.GetConfig{ |
| 17 | + Hydrate: opengovernance.GetKubernetesPersistentVolume, |
| 18 | + }, |
| 19 | + List: &plugin.ListConfig{ |
| 20 | + Hydrate: opengovernance.ListKubernetesPersistentVolume, |
| 21 | + }, |
| 22 | + Columns: commonColumns([]*plugin.Column{ |
| 23 | + //// PersistentVolumeSpec columns |
| 24 | + { |
| 25 | + Name: "storage_class", |
| 26 | + Type: proto.ColumnType_STRING, |
| 27 | + Description: "Name of StorageClass to which this persistent volume belongs. Empty value means that this volume does not belong to any StorageClass.", |
| 28 | + Transform: transform.FromField("Description.PV.Spec.StorageClassName"), |
| 29 | + }, |
| 30 | + { |
| 31 | + Name: "volume_mode", |
| 32 | + Type: proto.ColumnType_STRING, |
| 33 | + Description: "Defines if a volume is intended to be used with a formatted filesystem or to remain in raw block state.", |
| 34 | + Transform: transform.FromField("Description.PV.Spec.VolumeMode"), |
| 35 | + }, |
| 36 | + { |
| 37 | + Name: "persistent_volume_reclaim_policy", |
| 38 | + Type: proto.ColumnType_STRING, |
| 39 | + Description: "What happens to a persistent volume when released from its claim. Valid options are Retain (default for manually created PersistentVolumes), Delete (default for dynamically provisioned PersistentVolumes), and Recycle (deprecated). Recycle must be supported by the volume plugin underlying this PersistentVolume.", |
| 40 | + Transform: transform.FromField("Description.PV.Spec.PersistentVolumeReclaimPolicy"), |
| 41 | + }, |
| 42 | + { |
| 43 | + Name: "access_modes", |
| 44 | + Type: proto.ColumnType_JSON, |
| 45 | + Description: "List of ways the volume can be mounted.", |
| 46 | + Transform: transform.FromField("Description.PV.Spec.AccessModes"), |
| 47 | + }, |
| 48 | + { |
| 49 | + Name: "capacity", |
| 50 | + Type: proto.ColumnType_JSON, |
| 51 | + Description: "A description of the persistent volume's resources and capacity.", |
| 52 | + Transform: transform.FromField("Description.PV.Spec.Capacity"), |
| 53 | + }, |
| 54 | + { |
| 55 | + Name: "claim_ref", |
| 56 | + Type: proto.ColumnType_JSON, |
| 57 | + Description: "ClaimRef is part of a bi-directional binding between PersistentVolume and PersistentVolumeClaim. Expected to be non-nil when bound.", |
| 58 | + Transform: transform.FromField("Description.PV.Spec.ClaimRef"), |
| 59 | + }, |
| 60 | + { |
| 61 | + Name: "mount_options", |
| 62 | + Type: proto.ColumnType_JSON, |
| 63 | + Description: "A list of mount options, e.g. [\"ro\", \"soft\"].", |
| 64 | + Transform: transform.FromField("Description.PV.Spec.MountOptions"), |
| 65 | + }, |
| 66 | + { |
| 67 | + Name: "node_affinity", |
| 68 | + Type: proto.ColumnType_JSON, |
| 69 | + Description: "Defines constraints that limit what nodes this volume can be accessed from.", |
| 70 | + Transform: transform.FromField("Description.PV.Spec.NodeAffinity"), |
| 71 | + }, |
| 72 | + { |
| 73 | + Name: "persistent_volume_source", |
| 74 | + Type: proto.ColumnType_JSON, |
| 75 | + Description: "The actual volume backing the persistent volume.", |
| 76 | + Transform: transform.FromField("Description.PV.Spec.PersistentVolumeSource"), |
| 77 | + }, |
| 78 | + |
| 79 | + //// PersistentVolumeStatus columns |
| 80 | + { |
| 81 | + Name: "phase", |
| 82 | + Type: proto.ColumnType_STRING, |
| 83 | + Description: "Phase indicates if a volume is available, bound to a claim, or released by a claim.", |
| 84 | + Transform: transform.FromField("Description.PV.Status.Phase"), |
| 85 | + }, |
| 86 | + { |
| 87 | + Name: "message", |
| 88 | + Type: proto.ColumnType_STRING, |
| 89 | + Description: "A human-readable message indicating details about why the volume is in this state.", |
| 90 | + Transform: transform.FromField("Description.PV.Status.Message"), |
| 91 | + }, |
| 92 | + { |
| 93 | + Name: "reason", |
| 94 | + Type: proto.ColumnType_STRING, |
| 95 | + Description: "Reason is a brief CamelCase string that describes any failure and is meant for machine parsing and tidy display in the CLI.", |
| 96 | + Transform: transform.FromField("Description.PV.Status.Reason"), |
| 97 | + }, |
| 98 | + { |
| 99 | + Name: "title", |
| 100 | + Type: proto.ColumnType_STRING, |
| 101 | + Description: ColumnDescriptionTitle, |
| 102 | + Transform: transform.FromField("Description.PV.Name"), |
| 103 | + }, |
| 104 | + { |
| 105 | + Name: "tags", |
| 106 | + Type: proto.ColumnType_JSON, |
| 107 | + Description: ColumnDescriptionTags, |
| 108 | + Transform: transform.From(transformPVTags), |
| 109 | + }, |
| 110 | + }), |
| 111 | + } |
| 112 | +} |
| 113 | + |
| 114 | +//// TRANSFORM FUNCTIONS |
| 115 | + |
| 116 | +func transformPVTags(_ context.Context, d *transform.TransformData) (interface{}, error) { |
| 117 | + obj := d.HydrateItem.(opengovernance.KubernetesPersistentVolume).Description.PV |
| 118 | + return mergeTags(obj.Labels, obj.Annotations), nil |
| 119 | +} |
0 commit comments