Skip to content

Commit 77e226d

Browse files
committed
add more properties to gke cluster
1 parent e5ddd49 commit 77e226d

7 files changed

Lines changed: 143 additions & 131 deletions

File tree

cmd/ctrlc/root/sync/google/bigtable/bigtable.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import (
1919
// BigtableInstance represents a Google Cloud Bigtable instance
2020
type BigtableInstance struct {
2121
ID string `json:"id"`
22-
Name string `json:"name"`
22+
Name string `json:"name"`
2323
ConnectionMethod ConnectionMethod `json:"connectionMethod"`
2424
}
2525

@@ -125,7 +125,7 @@ func processInstances(ctx context.Context, adminClient *bigtableadmin.Service, p
125125
// processInstance handles processing of a single Bigtable instance
126126
func processInstance(ctx context.Context, adminClient *bigtableadmin.Service, instance *bigtableadmin.Instance, project string) (api.AgentResource, error) {
127127
metadata := initInstanceMetadata(instance, project)
128-
128+
129129
// Process clusters
130130
locations, err := processClusters(adminClient, instance, metadata)
131131
if err != nil {
@@ -171,10 +171,10 @@ func initInstanceMetadata(instance *bigtableadmin.Instance, project string) map[
171171
instance.Name, project)
172172

173173
return map[string]string{
174-
"database/type": "bigtable",
175-
"database/host": instance.Name,
176-
"database/port": "443",
177-
"google/project": project,
174+
"database/type": "bigtable",
175+
"database/host": instance.Name,
176+
"database/port": "443",
177+
"google/project": project,
178178
"google/instance-type": "bigtable",
179179
"google/console-url": consoleUrl,
180180
"google/state": strings.ToLower(instance.State),
@@ -185,7 +185,7 @@ func initInstanceMetadata(instance *bigtableadmin.Instance, project string) map[
185185
// processClusters handles processing of Bigtable clusters
186186
func processClusters(adminClient *bigtableadmin.Service, instance *bigtableadmin.Instance, metadata map[string]string) ([]string, error) {
187187
log.Info("Listing clusters", "name", instance.Name)
188-
188+
189189
clusters, err := adminClient.Projects.Instances.Clusters.List(instance.Name).Do()
190190
if err != nil {
191191
return nil, err
@@ -194,16 +194,16 @@ func processClusters(adminClient *bigtableadmin.Service, instance *bigtableadmin
194194
locations := []string{}
195195
if clusters != nil {
196196
metadata["google/bigtable/cluster-count"] = strconv.FormatInt(int64(len(clusters.Clusters)), 10)
197-
197+
198198
for _, cluster := range clusters.Clusters {
199199
name := strings.ReplaceAll(cluster.Name, instance.Name+"/clusters/", "")
200200
location := strings.ReplaceAll(cluster.Location, "projects/"+instance.Name+"/locations/", "")
201-
201+
202202
metadata[fmt.Sprintf("google/bigtable/cluster/%s", name)] = "true"
203203
metadata[fmt.Sprintf("google/bigtable/cluster/%s/location", name)] = location
204204
metadata[fmt.Sprintf("google/bigtable/cluster/%s/state", name)] = cluster.State
205205
metadata[fmt.Sprintf("google/bigtable/cluster/%s/serve-nodes", name)] = strconv.FormatInt(cluster.ServeNodes, 10)
206-
206+
207207
if !slices.Contains(locations, location) {
208208
locations = append(locations, location)
209209
}
@@ -216,7 +216,7 @@ func processClusters(adminClient *bigtableadmin.Service, instance *bigtableadmin
216216
// processTables handles processing of Bigtable tables
217217
func processTables(adminClient *bigtableadmin.Service, instance *bigtableadmin.Instance, metadata map[string]string) error {
218218
log.Info("Listing tables", "name", instance.Name)
219-
219+
220220
tables, err := adminClient.Projects.Instances.Tables.List(instance.Name).Do()
221221
if err != nil {
222222
return err
@@ -225,15 +225,15 @@ func processTables(adminClient *bigtableadmin.Service, instance *bigtableadmin.I
225225
if tables != nil {
226226
tableNames := []string{}
227227
totalSizeBytes := int64(0)
228-
228+
229229
metadata["google/bigtable/table-count"] = strconv.FormatInt(int64(len(tables.Tables)), 10)
230-
230+
231231
for _, table := range tables.Tables {
232232
name := strings.ReplaceAll(table.Name, instance.Name+"/tables/", "")
233233
tableNames = append(tableNames, name)
234-
234+
235235
metadata[fmt.Sprintf("google/bigtable/table/%s", name)] = "true"
236-
236+
237237
if table.Stats != nil {
238238
totalSizeBytes += table.Stats.LogicalDataBytes
239239
metadata[fmt.Sprintf("google/bigtable/table/%s/row-count", name)] = strconv.FormatInt(table.Stats.RowCount, 10)
@@ -276,4 +276,4 @@ func upsertToCtrlplane(ctx context.Context, resources []api.AgentResource, proje
276276

277277
log.Info("Response from upserting resources", "status", upsertResp.Status)
278278
return nil
279-
}
279+
}

cmd/ctrlc/root/sync/google/buckets/buckets.go

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ import (
1818

1919
// StorageBucket represents a Google Cloud Storage bucket
2020
type StorageBucket struct {
21-
Name string `json:"name"`
22-
Location string `json:"location"`
21+
Name string `json:"name"`
22+
Location string `json:"location"`
2323
}
2424

2525
// NewSyncBucketsCmd creates a new cobra command for syncing Storage buckets
@@ -117,13 +117,13 @@ func processBuckets(ctx context.Context, storageClient *storage.Service, project
117117
// processBucket handles processing of a single Storage bucket
118118
func processBucket(_ context.Context, storageClient *storage.Service, bucket *storage.Bucket, project string) (api.AgentResource, error) {
119119
metadata := initBucketMetadata(bucket, project)
120-
120+
121121
// Process IAM policy if available
122122
err := processIamPolicy(storageClient, bucket, metadata)
123123
if err != nil {
124124
log.Error("Error processing IAM policy", "error", err)
125125
}
126-
126+
127127
// Process bucket details
128128
processStorageDetails(bucket, metadata)
129129

@@ -143,11 +143,11 @@ func processBucket(_ context.Context, storageClient *storage.Service, bucket *st
143143
Config: map[string]any{
144144
"name": bucket.Name,
145145
"googleStorage": map[string]any{
146-
"project": project,
147-
"location": bucket.Location,
148-
"storageClass": bucket.StorageClass,
146+
"project": project,
147+
"location": bucket.Location,
148+
"storageClass": bucket.StorageClass,
149149
"retentionPolicy": bucket.RetentionPolicy != nil,
150-
"versioning": bucket.Versioning != nil && bucket.Versioning.Enabled,
150+
"versioning": bucket.Versioning != nil && bucket.Versioning.Enabled,
151151
},
152152
},
153153
Metadata: metadata,
@@ -180,23 +180,23 @@ func initBucketMetadata(bucket *storage.Bucket, project string) map[string]strin
180180

181181
metadata := map[string]string{
182182
// Storage namespace
183-
"storage/type": "google-bucket",
184-
"storage/bucket": bucket.Name,
185-
"storage/location": bucket.Location,
186-
"storage/location-type": bucket.LocationType,
187-
"storage/storage-class": bucket.StorageClass,
188-
"storage/created": created,
189-
"storage/updated": updated,
190-
"storage/versioning": fmt.Sprintf("%v", bucket.Versioning != nil && bucket.Versioning.Enabled),
191-
183+
"storage/type": "google-bucket",
184+
"storage/bucket": bucket.Name,
185+
"storage/location": bucket.Location,
186+
"storage/location-type": bucket.LocationType,
187+
"storage/storage-class": bucket.StorageClass,
188+
"storage/created": created,
189+
"storage/updated": updated,
190+
"storage/versioning": fmt.Sprintf("%v", bucket.Versioning != nil && bucket.Versioning.Enabled),
191+
192192
// Google namespace
193-
"google/project": project,
194-
"google/location": bucket.Location,
195-
"google/location-type": bucket.LocationType,
196-
"google/storage-class": bucket.StorageClass,
197-
"google/console-url": consoleUrl,
198-
"google/resource-type": "storage.googleapis.com/Bucket",
199-
"google/metageneration": strconv.FormatInt(bucket.Metageneration, 10),
193+
"google/project": project,
194+
"google/location": bucket.Location,
195+
"google/location-type": bucket.LocationType,
196+
"google/storage-class": bucket.StorageClass,
197+
"google/console-url": consoleUrl,
198+
"google/resource-type": "storage.googleapis.com/Bucket",
199+
"google/metageneration": strconv.FormatInt(bucket.Metageneration, 10),
200200
}
201201

202202
if bucket.Etag != "" {
@@ -232,7 +232,7 @@ func initBucketMetadata(bucket *storage.Bucket, project string) map[string]strin
232232
// Add public access prevention information
233233
if bucket.IamConfiguration != nil && bucket.IamConfiguration.PublicAccessPrevention != "" {
234234
metadata["storage/public-access-prevention"] = bucket.IamConfiguration.PublicAccessPrevention
235-
235+
236236
// Add uniform bucket-level access information
237237
if bucket.IamConfiguration.UniformBucketLevelAccess != nil {
238238
metadata["storage/uniform-bucket-access"] = strconv.FormatBool(bucket.IamConfiguration.UniformBucketLevelAccess.Enabled)
@@ -288,7 +288,7 @@ func initBucketMetadata(bucket *storage.Bucket, project string) map[string]strin
288288
metadata["storage/cors-methods"] = strings.Join(methodList, ",")
289289
}
290290
}
291-
291+
292292
return metadata
293293
}
294294

@@ -301,7 +301,7 @@ func processIamPolicy(storageClient *storage.Service, bucket *storage.Bucket, me
301301

302302
if policy != nil && policy.Bindings != nil {
303303
roleUsers := make(map[string][]string)
304-
304+
305305
for _, binding := range policy.Bindings {
306306
if binding.Members != nil {
307307
roleUsers[binding.Role] = append(roleUsers[binding.Role], binding.Members...)
@@ -321,17 +321,17 @@ func processIamPolicy(storageClient *storage.Service, bucket *storage.Bucket, me
321321
if roleCount >= 10 {
322322
break
323323
}
324-
324+
325325
// Simplify role name for metadata
326326
shortRole := role
327327
if strings.HasPrefix(role, "roles/") {
328328
shortRole = strings.TrimPrefix(role, "roles/")
329329
}
330-
330+
331331
// Sort members for consistent output
332332
members := roleUsers[role]
333333
sort.Strings(members)
334-
334+
335335
// Add role and members to metadata
336336
metadata[fmt.Sprintf("google/storage/iam/%s", shortRole)] = strings.Join(members, ",")
337337
roleCount++
@@ -356,17 +356,17 @@ func processStorageDetails(bucket *storage.Bucket, metadata map[string]string) {
356356
// Handle lifecycle rules
357357
if bucket.Lifecycle != nil && bucket.Lifecycle.Rule != nil {
358358
metadata["storage/lifecycle-rules"] = strconv.Itoa(len(bucket.Lifecycle.Rule))
359-
359+
360360
// Extract some details about lifecycle rules
361361
for i, rule := range bucket.Lifecycle.Rule {
362362
if rule.Action != nil && rule.Action.Type != "" {
363363
metadata[fmt.Sprintf("storage/lifecycle/%d/action", i)] = rule.Action.Type
364-
364+
365365
if rule.Action.Type == "SetStorageClass" && rule.Action.StorageClass != "" {
366366
metadata[fmt.Sprintf("storage/lifecycle/%d/storage-class", i)] = rule.Action.StorageClass
367367
}
368368
}
369-
369+
370370
// Add conditions if present
371371
if rule.Condition != nil {
372372
if rule.Condition.Age != nil && *rule.Condition.Age > 0 {
@@ -395,12 +395,12 @@ func processStorageDetails(bucket *storage.Bucket, metadata map[string]string) {
395395
if bucket.RetentionPolicy != nil {
396396
metadata["storage/retention-policy"] = "enabled"
397397
metadata["storage/retention-period"] = strconv.FormatInt(bucket.RetentionPolicy.RetentionPeriod, 10)
398-
398+
399399
retentionDays := bucket.RetentionPolicy.RetentionPeriod / 86400 // Convert seconds to days
400400
if retentionDays > 0 {
401401
metadata["storage/retention-days"] = strconv.FormatInt(retentionDays, 10)
402402
}
403-
403+
404404
if bucket.RetentionPolicy.EffectiveTime != "" {
405405
metadata["storage/retention-effective-time"] = bucket.RetentionPolicy.EffectiveTime
406406
}
@@ -421,7 +421,7 @@ func processStorageDetails(bucket *storage.Bucket, metadata map[string]string) {
421421
}
422422
metadata["google/storage/label-count"] = strconv.Itoa(len(bucket.Labels))
423423
}
424-
424+
425425
// Handle autoclass if set
426426
if bucket.Autoclass != nil {
427427
metadata["storage/autoclass-enabled"] = strconv.FormatBool(bucket.Autoclass.Enabled)
@@ -481,4 +481,4 @@ func upsertToCtrlplane(ctx context.Context, resources []api.AgentResource, proje
481481

482482
log.Info("Response from upserting resources", "status", upsertResp.Status)
483483
return nil
484-
}
484+
}

cmd/ctrlc/root/sync/google/cloudsql/cloudsql.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ func NewSyncCloudSQLCmd() *cobra.Command {
126126
"google/state": strings.ToLower(instance.State),
127127

128128
"google/disk-type": instance.Settings.DataDiskType,
129-
"google/disk-size-gb": strconv.FormatInt(instance.Settings.DataDiskSizeGb, 10),
129+
"google/disk-size-gb": strconv.FormatInt(instance.Settings.DataDiskSizeGb, 10),
130130
"google/disk-iops": strconv.FormatInt(instance.Settings.DataDiskProvisionedIops, 10),
131131
"google/disk-provisioned-iops": strconv.FormatInt(instance.Settings.DataDiskProvisionedIops, 10),
132132
"google/disk-provisioned-throughput": strconv.FormatInt(instance.Settings.DataDiskProvisionedThroughput, 10),

0 commit comments

Comments
 (0)