Skip to content

Commit

Permalink
Fixed addons_config -> 'httpLoadBalancing' and network_config -> 'Ena…
Browse files Browse the repository at this point in the history
…bleIntraNodeVisibility' cloumns in table gcp_kubernetes_cluster Closes #527 #526 (#530)
  • Loading branch information
ParthaI authored Jan 3, 2024
1 parent 233743d commit f4ca8fa
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 22 deletions.
40 changes: 20 additions & 20 deletions docs/tables/gcp_kubernetes_cluster.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,22 +103,22 @@ Identify instances where clusters are using the default service account in Googl
select
name,
location_type,
node_config ->> 'serviceAccount' service_account
node_config ->> 'ServiceAccount' service_account
from
gcp_kubernetes_cluster
where
node_config ->> 'serviceAccount' = 'default';
node_config ->> 'ServiceAccount' = 'default';
```

```sql+sqlite
select
name,
location_type,
json_extract(node_config, '$.serviceAccount') service_account
json_extract(node_config, '$.ServiceAccount') service_account
from
gcp_kubernetes_cluster
where
json_extract(node_config, '$.serviceAccount') = 'default';
json_extract(node_config, '$.ServiceAccount') = 'default';
```

### List clusters with legacy authorization enabled
Expand Down Expand Up @@ -200,29 +200,29 @@ Explore the configuration settings of your clusters to understand their disk siz
```sql+postgres
select
name,
node_config ->> 'diskSizeGb' as disk_size_gb,
node_config ->> 'diskType' as disk_type,
node_config ->> 'imageType' as image_type,
node_config ->> 'machineType' as machine_type,
node_config ->> 'diskType' as disk_type,
node_config -> 'metadata' ->> 'disable-legacy-endpoints' as disable_legacy_endpoints,
node_config ->> 'serviceAccount' as service_account,
node_config -> 'shieldedInstanceConfig' ->> 'enableIntegrityMonitoring' as enable_integrity_monitoring
node_config ->> 'Disksizegb' as disk_size_gb,
node_config ->> 'Disktype' as disk_type,
node_config ->> 'Imagetype' as image_type,
node_config ->> 'Machinetype' as machine_type,
node_config ->> 'Disktype' as disk_type,
node_config -> 'Metadata' ->> 'disable-legacy-endpoints' as disable_legacy_endpoints,
node_config ->> 'Serviceaccount' as service_account,
node_config -> 'Shieldedinstanceconfig' ->> 'EnableIntegrityMonitoring' as enable_integrity_monitoring
from
gcp_kubernetes_cluster;
```

```sql+sqlite
select
name,
json_extract(node_config, '$.diskSizeGb') as disk_size_gb,
json_extract(node_config, '$.diskType') as disk_type,
json_extract(node_config, '$.imageType') as image_type,
json_extract(node_config, '$.machineType') as machine_type,
json_extract(node_config, '$.diskType') as disk_type,
json_extract(json_extract(node_config, '$.metadata'), '$.disable-legacy-endpoints') as disable_legacy_endpoints,
json_extract(node_config, '$.serviceAccount') as service_account,
json_extract(json_extract(node_config, '$.shieldedInstanceConfig'), '$.enableIntegrityMonitoring') as enable_integrity_monitoring
json_extract(node_config, '$.Disksizegb') as disk_size_gb,
json_extract(node_config, '$.Disktype') as disk_type,
json_extract(node_config, '$.Imagetype') as image_type,
json_extract(node_config, '$.Machinetype') as machine_type,
json_extract(node_config, '$.Disktype') as disk_type,
json_extract(json_extract(node_config, '$.Metadata'), '$.disable-legacy-endpoints') as disable_legacy_endpoints,
json_extract(node_config, '$.ServiceAccount') as service_account,
json_extract(json_extract(node_config, '$.ShieldedInstanceConfig'), '$.EnableIntegrityMonitoring') as enable_integrity_monitoring
from
gcp_kubernetes_cluster;
```
Original file line number Diff line number Diff line change
@@ -1 +1 @@
null
[]
Original file line number Diff line number Diff line change
@@ -1 +1 @@
null
[]
73 changes: 73 additions & 0 deletions gcp/table_gcp_kubernetes_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package gcp

import (
"context"
"encoding/json"
"reflect"
"strings"

"github.com/turbot/steampipe-plugin-sdk/v5/grpc/proto"
Expand Down Expand Up @@ -201,6 +203,7 @@ func tableGcpKubernetesCluster(ctx context.Context) *plugin.Table {
Name: "addons_config",
Description: "Configurations for the various addons available to run in the cluster.",
Type: proto.ColumnType_JSON,
Transform: transform.From(gcpKubernetesClusterAddonConfig),
},
{
Name: "authenticator_groups_config",
Expand Down Expand Up @@ -256,6 +259,7 @@ func tableGcpKubernetesCluster(ctx context.Context) *plugin.Table {
Name: "network_config",
Description: "Configuration for cluster networking.",
Type: proto.ColumnType_JSON,
Transform: transform.From(gcpKubernetesClusterNetworkConfig),
},
{
Name: "network_policy",
Expand All @@ -266,6 +270,7 @@ func tableGcpKubernetesCluster(ctx context.Context) *plugin.Table {
Name: "node_config",
Description: "Parameters used in creating the cluster's nodes.",
Type: proto.ColumnType_JSON,
Transform: transform.From(gcpKubernetesClusterNodeConfig),
},
{
Name: "node_pools",
Expand Down Expand Up @@ -428,6 +433,36 @@ func gcpKubernetesClusterTurbotData(ctx context.Context, d *transform.TransformD
return result[d.Param.(string)], nil
}

func gcpKubernetesClusterAddonConfig(ctx context.Context, d *transform.TransformData) (interface{}, error) {
cluster := d.HydrateItem.(*container.Cluster)

result := make(map[string]interface{})
extractNonNilFields(reflect.ValueOf(cluster.AddonsConfig), result)
jsonResult, _ := json.MarshalIndent(result, "", " ")

return string(jsonResult), nil
}

func gcpKubernetesClusterNetworkConfig(ctx context.Context, d *transform.TransformData) (interface{}, error) {
cluster := d.HydrateItem.(*container.Cluster)

result := make(map[string]interface{})
extractNonNilFields(reflect.ValueOf(cluster.NetworkConfig), result)
jsonResult, _ := json.MarshalIndent(result, "", " ")

return string(jsonResult), nil
}

func gcpKubernetesClusterNodeConfig(ctx context.Context, d *transform.TransformData) (interface{}, error) {
cluster := d.HydrateItem.(*container.Cluster)

result := make(map[string]interface{})
extractNonNilFields(reflect.ValueOf(cluster.NodeConfig), result)
jsonResult, _ := json.MarshalIndent(result, "", " ")

return string(jsonResult), nil
}

func gcpKubernetesClusterLocationType(ctx context.Context, d *transform.TransformData) (interface{}, error) {
plugin.Logger(ctx).Trace("gcpKubernetesClusterLocationType")
cluster := d.HydrateItem.(*container.Cluster)
Expand All @@ -439,3 +474,41 @@ func gcpKubernetesClusterLocationType(ctx context.Context, d *transform.Transfor
}
return "ZONAL", nil
}

//// UTILITY FUNCTION

func extractNonNilFields(val reflect.Value, result map[string]interface{}) {
if val.Kind() == reflect.Ptr {
val = val.Elem()
}

if val.Kind() != reflect.Struct {
return
}

for i := 0; i < val.NumField(); i++ {
field := val.Field(i)
typeField := val.Type().Field(i)

fieldName := typeField.Name

if field.Kind() == reflect.Ptr {
if !field.IsNil() {
// Create a nested map for each non-nil struct
nestedMap := make(map[string]interface{})
result[fieldName] = nestedMap
extractNonNilFields(field, nestedMap)
} else {
if fieldName != "NullFields" && fieldName != "ForceSendFields" {
// If the pointer is nil, create an empty map
result[fieldName] = make(map[string]interface{})
}
}
} else {
if fieldName != "NullFields" && fieldName != "ForceSendFields" {
// For non-pointer types, add directly to the map
result[fieldName] = field.Interface()
}
}
}
}

0 comments on commit f4ca8fa

Please sign in to comment.