Skip to content

Commit a291314

Browse files
committed
feat: add some tables
1 parent fdb9a0b commit a291314

11 files changed

+1554
-0
lines changed

cloudql/kubernetes/plugin.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@ func Plugin(ctx context.Context) *plugin.Plugin {
2222
"kubernetes_node": tableKubernetesNode(ctx),
2323
"kubernetes_persistent_volume_claim": tableKubernetesPersistentVolumeClaim(ctx),
2424
"kubernetes_persistent_volume": tableKubernetesPersistentVolume(ctx),
25+
"kubernetes_pod": tableKubernetesPod(ctx),
26+
"kubernetes_service": tableKubernetesService(ctx),
27+
"kubernetes_secret": tableKubernetesSecret(ctx),
28+
"kubernetes_deployment": tableKubernetesDeployment(ctx),
29+
"kubernetes_stateful_set": tableKubernetesStatefulSet(ctx),
30+
"kubernetes_config_map": tableKubernetesConfigMap(ctx),
31+
"kubernetes_service_account": tableKubernetesServiceAccount(ctx),
2532
},
2633
}
2734
for key, table := range p.TableMap {
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package kubernetes
2+
3+
import (
4+
"context"
5+
opengovernance "github.com/opengovern/og-describer-kubernetes/discovery/pkg/es"
6+
"github.com/turbot/steampipe-plugin-sdk/v5/grpc/proto"
7+
"github.com/turbot/steampipe-plugin-sdk/v5/plugin"
8+
"github.com/turbot/steampipe-plugin-sdk/v5/plugin/transform"
9+
)
10+
11+
func tableKubernetesConfigMap(ctx context.Context) *plugin.Table {
12+
return &plugin.Table{
13+
Name: "kubernetes_config_map",
14+
Description: "Config Map can be used to store fine-grained information like individual properties or coarse-grained information like entire config files or JSON blobs.",
15+
Get: &plugin.GetConfig{
16+
Hydrate: opengovernance.GetKubernetesConfigMap,
17+
},
18+
List: &plugin.ListConfig{
19+
Hydrate: opengovernance.ListKubernetesConfigMap,
20+
},
21+
// ClusterRole, is a non-namespaced resource.
22+
Columns: commonColumns([]*plugin.Column{
23+
{
24+
Name: "immutable",
25+
Type: proto.ColumnType_BOOL,
26+
Description: "If set to true, ensures that data stored in the ConfigMap cannot be updated (only object metadata can be modified). If not set to true, the field can be modified at any time. Defaulted to nil.",
27+
Transform: transform.FromField("Description.ConfigMap.Immutable"),
28+
},
29+
//// Steampipe Standard Columns
30+
{
31+
Name: "title",
32+
Type: proto.ColumnType_STRING,
33+
Description: ColumnDescriptionTitle,
34+
Transform: transform.FromField("Description.ConfigMap.Name"),
35+
},
36+
{
37+
Name: "tags",
38+
Type: proto.ColumnType_JSON,
39+
Description: ColumnDescriptionTags,
40+
Transform: transform.From(transformConfigMapTags),
41+
},
42+
}),
43+
}
44+
}
45+
46+
func transformConfigMapTags(_ context.Context, d *transform.TransformData) (interface{}, error) {
47+
obj := d.HydrateItem.(opengovernance.KubernetesConfigMap).Description.ConfigMap
48+
return mergeTags(obj.Labels, obj.Annotations), nil
49+
}
Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
package kubernetes
2+
3+
import (
4+
"context"
5+
opengovernance "github.com/opengovern/og-describer-kubernetes/discovery/pkg/es"
6+
"github.com/turbot/steampipe-plugin-sdk/v5/grpc/proto"
7+
"github.com/turbot/steampipe-plugin-sdk/v5/plugin"
8+
"github.com/turbot/steampipe-plugin-sdk/v5/plugin/transform"
9+
)
10+
11+
func tableKubernetesDeployment(ctx context.Context) *plugin.Table {
12+
return &plugin.Table{
13+
Name: "kubernetes_deployment",
14+
Description: "Kubernetes Deployment enables declarative updates for Pods and ReplicaSets.",
15+
Get: &plugin.GetConfig{
16+
Hydrate: opengovernance.GetKubernetesDeployment,
17+
},
18+
List: &plugin.ListConfig{
19+
Hydrate: opengovernance.ListKubernetesDeployment,
20+
},
21+
Columns: commonColumns([]*plugin.Column{
22+
//// Spec Columns
23+
{
24+
Name: "replicas",
25+
Type: proto.ColumnType_INT,
26+
Description: "Number of desired pods. Defaults to 1.",
27+
Transform: transform.FromField("Description.Deployment.Spec.Replicas"),
28+
},
29+
{
30+
Name: "selector_query",
31+
Type: proto.ColumnType_STRING,
32+
Description: "A query string representation of the selector.",
33+
Transform: transform.FromField("Description.Deployment.Spec.Selector").Transform(labelSelectorToString),
34+
},
35+
{
36+
Name: "selector",
37+
Type: proto.ColumnType_JSON,
38+
Description: "Label selector for pods. A label selector is a label query over a set of resources.",
39+
Transform: transform.FromField("Description.Deployment.Spec.Selector"),
40+
},
41+
{
42+
Name: "template",
43+
Type: proto.ColumnType_JSON,
44+
Description: "Template describes the pods that will be created.",
45+
Transform: transform.FromField("Description.Deployment.Spec.Template"),
46+
},
47+
{
48+
Name: "strategy",
49+
Type: proto.ColumnType_JSON,
50+
Description: "The deployment strategy to use to replace existing pods with new ones.",
51+
Transform: transform.FromField("Description.Deployment.Spec.Strategy"),
52+
},
53+
{
54+
Name: "min_ready_seconds",
55+
Type: proto.ColumnType_INT,
56+
Description: "Minimum number of seconds for which a newly created pod should be ready without any of its container crashing, for it to be considered available. Defaults to 0.",
57+
Transform: transform.FromField("Description.Deployment.Spec.MinReadySeconds"),
58+
},
59+
{
60+
Name: "revision_history_limit",
61+
Type: proto.ColumnType_INT,
62+
Description: "The number of old ReplicaSets to retain to allow rollback.",
63+
Transform: transform.FromField("Description.Deployment.Spec.RevisionHistoryLimit"),
64+
},
65+
{
66+
Name: "paused",
67+
Type: proto.ColumnType_BOOL,
68+
Description: "Indicates that the deployment is paused.",
69+
Transform: transform.FromField("Description.Deployment.Spec.Paused"),
70+
},
71+
{
72+
Name: "progress_deadline_seconds",
73+
Type: proto.ColumnType_INT,
74+
Description: "The maximum time in seconds for a deployment to make progress before it is considered to be failed.",
75+
Transform: transform.FromField("Description.Deployment.Spec.ProgressDeadlineSeconds"),
76+
},
77+
78+
//// Status Columns
79+
{
80+
Name: "observed_generation",
81+
Type: proto.ColumnType_INT,
82+
Description: "The generation observed by the deployment controller.",
83+
Transform: transform.FromField("Description.Deployment.Status.ObservedGeneration"),
84+
},
85+
{
86+
Name: "status_replicas",
87+
Type: proto.ColumnType_INT,
88+
Description: "Total number of non-terminated pods targeted by this deployment (their labels match the selector).",
89+
Transform: transform.FromField("Description.Deployment.Status.Replicas"),
90+
},
91+
{
92+
Name: "updated_replicas",
93+
Type: proto.ColumnType_INT,
94+
Description: "Total number of non-terminated pods targeted by this deployment that have the desired template spec.",
95+
Transform: transform.FromField("Description.Deployment.Status.UpdatedReplicas"),
96+
},
97+
{
98+
Name: "ready_replicas",
99+
Type: proto.ColumnType_INT,
100+
Description: "Total number of ready pods targeted by this deployment.",
101+
Transform: transform.FromField("Description.Deployment.Status.ReadyReplicas"),
102+
},
103+
{
104+
Name: "available_replicas",
105+
Type: proto.ColumnType_INT,
106+
Description: "Total number of available pods (ready for at least minReadySeconds) targeted by this deployment.",
107+
Transform: transform.FromField("Description.Deployment.Status.AvailableReplicas"),
108+
},
109+
{
110+
Name: "unavailable_replicas",
111+
Type: proto.ColumnType_INT,
112+
Description: "Total number of unavailable pods targeted by this deployment.",
113+
Transform: transform.FromField("Description.Deployment.Status.UnavailableReplicas"),
114+
},
115+
{
116+
Name: "conditions",
117+
Type: proto.ColumnType_JSON,
118+
Description: "Represents the latest available observations of a deployment's current state.",
119+
Transform: transform.FromField("Description.Deployment.Status.Conditions"),
120+
},
121+
{
122+
Name: "collision_count",
123+
Type: proto.ColumnType_INT,
124+
Description: "Count of hash collisions for the Deployment. The Deployment controller uses this field as a collision avoidance mechanism when it needs to create the name for the newest ReplicaSet.",
125+
Transform: transform.FromField("Description.Deployment.Status.CollisionCount"),
126+
},
127+
{
128+
Name: "title",
129+
Type: proto.ColumnType_STRING,
130+
Description: ColumnDescriptionTitle,
131+
Transform: transform.FromField("Description.Deployment.Name"),
132+
},
133+
{
134+
Name: "tags",
135+
Type: proto.ColumnType_JSON,
136+
Description: ColumnDescriptionTags,
137+
Transform: transform.From(transformDeploymentTags),
138+
},
139+
}),
140+
}
141+
}
142+
143+
func transformDeploymentTags(_ context.Context, d *transform.TransformData) (interface{}, error) {
144+
obj := d.HydrateItem.(opengovernance.KubernetesDeployment).Description.Deployment
145+
return mergeTags(obj.Labels, obj.Annotations), nil
146+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package kubernetes
2+
3+
import (
4+
"context"
5+
opengovernance "github.com/opengovern/og-describer-kubernetes/discovery/pkg/es"
6+
"github.com/turbot/steampipe-plugin-sdk/v5/grpc/proto"
7+
"github.com/turbot/steampipe-plugin-sdk/v5/plugin"
8+
"github.com/turbot/steampipe-plugin-sdk/v5/plugin/transform"
9+
)
10+
11+
func tableKubernetesServiceAccount(ctx context.Context) *plugin.Table {
12+
return &plugin.Table{
13+
Name: "kubernetes_service_account",
14+
Description: "A service account provides an identity for processes that run in a Pod.",
15+
Get: &plugin.GetConfig{
16+
Hydrate: opengovernance.GetKubernetesServiceAccount,
17+
},
18+
List: &plugin.ListConfig{
19+
Hydrate: opengovernance.ListKubernetesServiceAccount,
20+
},
21+
// Service Account, is namespaced resource.
22+
Columns: commonColumns([]*plugin.Column{
23+
{
24+
Name: "automount_service_account_token",
25+
Type: proto.ColumnType_BOOL,
26+
Description: "Indicates whether pods running as this service account should have an API token automatically mounted. Can be overridden at the pod level.",
27+
Transform: transform.FromField("Description.ServiceAccount.AutomountServiceAccountToken"),
28+
},
29+
{
30+
Name: "image_pull_secrets",
31+
Type: proto.ColumnType_JSON,
32+
Description: "List of references to secrets in the same namespace to use for pulling any images in pods that reference this ServiceAccount. ImagePullSecrets are distinct from Secrets because Secrets can be mounted in the pod, but ImagePullSecrets are only accessed by the kubelet.",
33+
Transform: transform.FromField("Description.ServiceAccount.ImagePullSecrets"),
34+
},
35+
{
36+
Name: "secrets",
37+
Type: proto.ColumnType_JSON,
38+
Description: "Secrets is the list of secrets allowed to be used by pods running using this ServiceAccount.",
39+
Transform: transform.FromField("Description.ServiceAccount.Secrets"),
40+
},
41+
{
42+
Name: "title",
43+
Type: proto.ColumnType_STRING,
44+
Description: ColumnDescriptionTitle,
45+
Transform: transform.FromField("Description.ServiceAccount.Name"),
46+
},
47+
{
48+
Name: "tags",
49+
Type: proto.ColumnType_JSON,
50+
Description: ColumnDescriptionTags,
51+
Transform: transform.From(transformServiceAccountTags),
52+
},
53+
}),
54+
}
55+
}
56+
57+
func transformServiceAccountTags(_ context.Context, d *transform.TransformData) (interface{}, error) {
58+
obj := d.HydrateItem.(opengovernance.KubernetesServiceAccount).Description.ServiceAccount
59+
return mergeTags(obj.Labels, obj.Annotations), nil
60+
}

0 commit comments

Comments
 (0)