From f9cf22a904150941b8c63ff1d8c3b184247c0ec9 Mon Sep 17 00:00:00 2001 From: Philipp Eberle Date: Tue, 17 Oct 2023 16:03:09 +0200 Subject: [PATCH 1/5] Update cloud-go --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 28f342c9..e72a8fc4 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,7 @@ require ( github.com/dcorbe/termui-dpc v0.0.0-20211125210512-9d2673a82dd6 github.com/dustin/go-humanize v1.0.1 github.com/fatih/color v1.15.0 - github.com/fi-ts/cloud-go v0.22.1 + github.com/fi-ts/cloud-go v0.22.2-0.20231017135944-39c1aeddd33d github.com/gardener/gardener v1.59.0 github.com/gardener/machine-controller-manager v0.49.3 github.com/go-openapi/strfmt v0.21.7 diff --git a/go.sum b/go.sum index e76cad8c..c01cee35 100644 --- a/go.sum +++ b/go.sum @@ -151,8 +151,8 @@ github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.m github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= github.com/fatih/color v1.15.0 h1:kOqh6YHBtK8aywxGerMG2Eq3H6Qgoqeo13Bk2Mv/nBs= github.com/fatih/color v1.15.0/go.mod h1:0h5ZqXfHYED7Bhv2ZJamyIOUej9KtShiJESRwBDUSsw= -github.com/fi-ts/cloud-go v0.22.1 h1:VKzwA5I8G+MNmBu4XTVjG1hahkk/7xcte6UvawXG0dk= -github.com/fi-ts/cloud-go v0.22.1/go.mod h1:BYrXp1jTvfxYRiL0B+LE+6ZDp3GF110y9Sr2tuRJo5c= +github.com/fi-ts/cloud-go v0.22.2-0.20231017135944-39c1aeddd33d h1:0+R+KP1RylwgH6Uj676gwoPV4GWVOESXdsQxHtBzQgM= +github.com/fi-ts/cloud-go v0.22.2-0.20231017135944-39c1aeddd33d/go.mod h1:BYrXp1jTvfxYRiL0B+LE+6ZDp3GF110y9Sr2tuRJo5c= github.com/frankban/quicktest v1.14.5 h1:dfYrrRyLtiqT9GyKXgdh+k4inNeTvmGbuSgZ3lx3GhA= github.com/frankban/quicktest v1.14.5/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0= github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY= From e4d8ce3d30da5e5fddbdac1b9023fec22ab82271 Mon Sep 17 00:00:00 2001 From: Philipp Eberle Date: Fri, 10 Nov 2023 14:33:09 +0100 Subject: [PATCH 2/5] Add support for postgres dedicated load balancer IPs (and the update subcommand) --- cmd/postgres.go | 178 +++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 169 insertions(+), 9 deletions(-) diff --git a/cmd/postgres.go b/cmd/postgres.go index ace19a90..a28a60e1 100644 --- a/cmd/postgres.go +++ b/cmd/postgres.go @@ -122,6 +122,14 @@ postgres=# }, PreRun: bindPFlags, } + postgresUpdateCmd := &cobra.Command{ + Use: "update", + Short: "update postgres", + RunE: func(cmd *cobra.Command, args []string) error { + return c.postgresUpdate(args) + }, + PreRun: bindPFlags, + } postgresAcceptRestoreCmd := &cobra.Command{ Use: "restore-accepted", Short: "confirm the restore of a database", @@ -253,6 +261,7 @@ postgres=# postgresCmd.AddCommand(postgresRestoreCmd) postgresCmd.AddCommand(postgresApplyCmd) postgresCmd.AddCommand(postgresEditCmd) + postgresCmd.AddCommand(postgresUpdateCmd) postgresCmd.AddCommand(postgresAcceptRestoreCmd) postgresCmd.AddCommand(postgresListCmd) postgresCmd.AddCommand(postgresListBackupsCmd) @@ -283,6 +292,9 @@ postgres=# postgresCreateCmd.Flags().StringP("backup-config", "", "", "backup to use") postgresCreateCmd.Flags().StringSliceP("maintenance", "", []string{"Sun:22:00-23:00"}, "time specification of the automatic maintenance in the form Weekday:HH:MM-HH-MM [optional]") postgresCreateCmd.Flags().BoolP("audit-logs", "", true, "enable audit logs for the database") + postgresCreateCmd.Flags().StringP("dedicated-load-balancer-ip", "", "", "an existing ip address for a dedicated load balancer [optional]") + postgresCreateCmd.Flags().StringP("auto-assign-ip-from", "", "", "a network used for auto-assigning an ip for a dedicated load balancer [optional]") + postgresCreateCmd.Flags().IntP("dedicated-load-balancer-port", "", 0, "a port for a dedicated load balancer [optional]") must(postgresCreateCmd.MarkFlagRequired("description")) must(postgresCreateCmd.MarkFlagRequired("project")) must(postgresCreateCmd.MarkFlagRequired("partition")) @@ -299,6 +311,9 @@ postgres=# postgresCreateStandbyCmd.Flags().StringSliceP("labels", "", []string{}, "labels to add to that postgres database") postgresCreateStandbyCmd.Flags().StringP("backup-config", "", "", "backup to use") postgresCreateStandbyCmd.Flags().StringSliceP("maintenance", "", []string{"Sun:22:00-23:00"}, "time specification of the automatic maintenance in the form Weekday:HH:MM-HH-MM [optional]") + postgresCreateStandbyCmd.Flags().StringP("dedicated-load-balancer-ip", "", "", "an existing ip address for a dedicated load balancer [optional]") + postgresCreateStandbyCmd.Flags().StringP("auto-assign-ip-from", "", "", "a network used for auto-assigning an ip for a dedicated load balancer [optional]") + postgresCreateStandbyCmd.Flags().IntP("dedicated-load-balancer-port", "", 0, "a port for a dedicated load balancer [optional]") must(postgresCreateStandbyCmd.MarkFlagRequired("primary-postgres-id")) must(postgresCreateStandbyCmd.MarkFlagRequired("description")) must(postgresCreateStandbyCmd.MarkFlagRequired("partition")) @@ -321,6 +336,18 @@ postgres=# must(postgresRestoreCmd.RegisterFlagCompletionFunc("source-postgres-id", c.comp.PostgresListCompletion)) must(postgresRestoreCmd.RegisterFlagCompletionFunc("partition", c.comp.PostgresListPartitionsCompletion)) + // Update + postgresUpdateCmd.Flags().IntP("replicas", "", 1, "replicas of the database [optional]") + postgresUpdateCmd.Flags().StringSliceP("sources", "", []string{"0.0.0.0/0"}, "networks which should be allowed to connect in CIDR notation [optional]") + postgresUpdateCmd.Flags().StringSliceP("labels", "", []string{}, "labels to add to that postgres database [optional]") + postgresUpdateCmd.Flags().StringP("cpu", "", "500m", "cpus for the database [optional]") + postgresUpdateCmd.Flags().StringP("buffer", "", "64Mi", "shared buffer for the database [optional]") + postgresUpdateCmd.Flags().StringP("storage", "", "10Gi", "storage for the database [optional]") + postgresUpdateCmd.Flags().BoolP("audit-logs", "", true, "enable audit logs for the database [optional]") + postgresUpdateCmd.Flags().StringP("dedicated-load-balancer-ip", "", "", "an existing ip address for a dedicated load balancer [optional]") + postgresUpdateCmd.Flags().StringP("auto-assign-ip-from", "", "", "a network used for auto-assigning an ip for a dedicated load balancer [optional]") + postgresUpdateCmd.Flags().IntP("dedicated-load-balancer-port", "", 0, "a port for a dedicated load balancer [optional]") + // List postgresListCmd.Flags().StringP("id", "", "", "postgres id to filter [optional]") postgresListCmd.Flags().StringP("description", "", "", "description to filter [optional]") @@ -394,6 +421,19 @@ func (c *config) postgresCreate() error { storage := viper.GetString("storage") maintenance := viper.GetStringSlice("maintenance") auditLogs := viper.GetBool("audit-logs") + lbIP := viper.GetString("dedicated-load-balancer-ip") + lbPort := viper.GetInt32("dedicated-load-balancer-port") + lbNet := viper.GetString("auto-assign-ip-from") + + var dedicatedloadbalancerip *string + if lbIP != "" { + dedicatedloadbalancerip = &lbIP + } + + var dedicatedloadbalancerport *int32 + if lbPort != 0 { + dedicatedloadbalancerport = &lbPort + } labelMap, err := helper.LabelsToMap(labels) if err != nil { @@ -414,10 +454,16 @@ func (c *config) postgresCreate() error { AccessList: &models.V1AccessList{ SourceRanges: sources, }, - Maintenance: maintenance, - Labels: labelMap, - AuditLogs: auditLogs, + Maintenance: maintenance, + Labels: labelMap, + AuditLogs: auditLogs, + Dedicatedloadbalancerip: dedicatedloadbalancerip, + Dedicatedloadbalancerport: dedicatedloadbalancerport, + } + if lbNet != "" { + pcr.Autoassigndedicatedlbipfrom = lbNet } + request := database.NewCreatePostgresParams() request.SetBody(pcr) @@ -436,18 +482,31 @@ func (c *config) postgresCreateStandby() error { labels := viper.GetStringSlice("labels") backupConfig := viper.GetString("backup-config") maintenance := viper.GetStringSlice("maintenance") + var dedicatedloadbalancerip *string + if lbIP := viper.GetString("dedicated-load-balancer-ip"); lbIP != "" { + dedicatedloadbalancerip = &lbIP + } + var dedicatedloadbalancerport *int32 + if lbPort := viper.GetInt32("dedicated-load-balancer-port"); lbPort != 0 { + dedicatedloadbalancerport = &lbPort + } labelMap, err := helper.LabelsToMap(labels) if err != nil { return err } pcsr := &models.V1PostgresCreateStandbyRequest{ - PrimaryID: &primaryPostgresID, - Description: desc, - PartitionID: partition, - Backup: backupConfig, - Maintenance: maintenance, - Labels: labelMap, + PrimaryID: &primaryPostgresID, + Description: desc, + PartitionID: partition, + Backup: backupConfig, + Maintenance: maintenance, + Labels: labelMap, + Dedicatedloadbalancerip: dedicatedloadbalancerip, + Dedicatedloadbalancerport: dedicatedloadbalancerport, + } + if lbNet := viper.GetString("auto-assign-ip-from"); lbNet != "" { + pcsr.Autoassigndedicatedlbipfrom = lbNet } request := database.NewCreatePostgresStandbyParams() request.SetBody(pcsr) @@ -686,6 +745,107 @@ func (c *config) postgresEdit(args []string) error { return helper.Edit(id, getFunc, updateFunc) } +func (c *config) postgresUpdate(args []string) error { + replicas := viper.GetInt32("replicas") + sources := viper.GetStringSlice("sources") + labels := viper.GetStringSlice("labels") + cpu := viper.GetString("cpu") + buffer := viper.GetString("buffer") + storage := viper.GetString("storage") + auditLogs := viper.GetBool("audit-logs") + lbIP := viper.GetString("dedicated-load-balancer-ip") + lbPort := viper.GetInt32("dedicated-load-balancer-port") + lbNet := viper.GetString("auto-assign-ip-from") + + id, err := c.postgresID("update", args) + if err != nil { + return err + } + + params := database.NewGetPostgresParams().WithID(id) + resp, err := c.cloud.Database.GetPostgres(params, nil) + if err != nil { + return err + } + current := resp.Payload + + // copy the (minimum) current config + pur := &models.V1PostgresUpdateRequest{ + ProjectID: current.ProjectID, + ID: current.ID, + Connection: current.Connection, + AuditLogs: current.AuditLogs, + PostgresParams: current.PostgresParams, + } + + // postgresUpdateCmd.Flags().IntP("replicas", "", 1, "replicas of the database [optional]") + if viper.IsSet("replicas") { + pur.NumberOfInstances = replicas + } + + // postgresUpdateCmd.Flags().StringSliceP("sources", "", []string{"0.0.0.0/0"}, "networks which should be allowed to connect in CIDR notation [optional]") + if viper.IsSet("sources") { + pur.AccessList = &models.V1AccessList{ + SourceRanges: sources, + } + } + + // postgresUpdateCmd.Flags().StringSliceP("labels", "", []string{}, "labels to add to that postgres database [optional]") + if viper.IsSet("labels") { + labelMap, err := helper.LabelsToMap(labels) + if err != nil { + return err + } + pur.Labels = labelMap + } + + pur.Size = &models.V1PostgresSize{} + + // postgresUpdateCmd.Flags().StringP("cpu", "", "500m", "cpus for the database [optional]") + if viper.IsSet("cpu") { + pur.Size.CPU = cpu + } + + // postgresUpdateCmd.Flags().StringP("buffer", "", "64Mi", "shared buffer for the database [optional]") + if viper.IsSet("buffer") { + pur.Size.SharedBuffer = buffer + } + + // postgresUpdateCmd.Flags().StringP("storage", "", "10Gi", "storage for the database [optional]") + if viper.IsSet("storage") { + pur.Size.StorageSize = storage + } + + // postgresUpdateCmd.Flags().BoolP("audit-logs", "", true, "enable audit logs for the database [optional]") + if viper.IsSet("audit-logs") { + pur.AuditLogs = auditLogs + } + + // postgresUpdateCmd.Flags().StringP("dedicated-load-balancer-ip", "", "", "an existing ip address for a dedicated load balancer [optional]") + if viper.IsSet("dedicated-load-balancer-ip") { + pur.Dedicatedloadbalancerip = &lbIP + } + + // postgresUpdateCmd.Flags().IntP("dedicated-load-balancer-port", "", 0, "a port for a dedicated load balancer [optional]") + if viper.IsSet("dedicated-load-balancer-port") { + pur.Dedicatedloadbalancerport = &lbPort + } + + // auto-assign lb ip + if viper.IsSet("auto-assign-ip-from") { + pur.Autoassigndedicatedlbipfrom = lbNet + } + + // send the update request + req := database.NewUpdatePostgresParams() + req.Body = pur + uresp, err := c.cloud.Database.UpdatePostgres(req, nil) + if err != nil { + return err + } + return output.New().Print(uresp.Payload) +} + func (c *config) postgresAcceptRestore(args []string) error { pg, err := c.getPostgresFromArgs(args) if err != nil { From dc5f8ca96061fdf7668317134cfe1f9ef316d6cd Mon Sep 17 00:00:00 2001 From: Philipp Eberle Date: Fri, 10 Nov 2023 14:33:52 +0100 Subject: [PATCH 3/5] Update cloud-go --- go.mod | 4 +++- go.sum | 2 -- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index e72a8fc4..75b40f51 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,7 @@ require ( github.com/dcorbe/termui-dpc v0.0.0-20211125210512-9d2673a82dd6 github.com/dustin/go-humanize v1.0.1 github.com/fatih/color v1.15.0 - github.com/fi-ts/cloud-go v0.22.2-0.20231017135944-39c1aeddd33d + github.com/fi-ts/cloud-go v0.22.2-0.20231017141213-71dc28f8dd22 github.com/gardener/gardener v1.59.0 github.com/gardener/machine-controller-manager v0.49.3 github.com/go-openapi/strfmt v0.21.7 @@ -204,3 +204,5 @@ require ( sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect tailscale.com v1.48.0 // indirect ) + +replace github.com/fi-ts/cloud-go => ../cloud-go diff --git a/go.sum b/go.sum index c01cee35..83ee8fef 100644 --- a/go.sum +++ b/go.sum @@ -151,8 +151,6 @@ github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.m github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= github.com/fatih/color v1.15.0 h1:kOqh6YHBtK8aywxGerMG2Eq3H6Qgoqeo13Bk2Mv/nBs= github.com/fatih/color v1.15.0/go.mod h1:0h5ZqXfHYED7Bhv2ZJamyIOUej9KtShiJESRwBDUSsw= -github.com/fi-ts/cloud-go v0.22.2-0.20231017135944-39c1aeddd33d h1:0+R+KP1RylwgH6Uj676gwoPV4GWVOESXdsQxHtBzQgM= -github.com/fi-ts/cloud-go v0.22.2-0.20231017135944-39c1aeddd33d/go.mod h1:BYrXp1jTvfxYRiL0B+LE+6ZDp3GF110y9Sr2tuRJo5c= github.com/frankban/quicktest v1.14.5 h1:dfYrrRyLtiqT9GyKXgdh+k4inNeTvmGbuSgZ3lx3GhA= github.com/frankban/quicktest v1.14.5/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0= github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY= From 1ce34ab2e04fb1ed84b48ec3adf3c93cac5c91c2 Mon Sep 17 00:00:00 2001 From: Philipp Eberle Date: Fri, 10 Nov 2023 14:39:55 +0100 Subject: [PATCH 4/5] Properly update cloud-go --- go.mod | 4 +--- go.sum | 2 ++ 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 75b40f51..5d93da82 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,7 @@ require ( github.com/dcorbe/termui-dpc v0.0.0-20211125210512-9d2673a82dd6 github.com/dustin/go-humanize v1.0.1 github.com/fatih/color v1.15.0 - github.com/fi-ts/cloud-go v0.22.2-0.20231017141213-71dc28f8dd22 + github.com/fi-ts/cloud-go v0.22.2-0.20231031073721-5c18225763a7 github.com/gardener/gardener v1.59.0 github.com/gardener/machine-controller-manager v0.49.3 github.com/go-openapi/strfmt v0.21.7 @@ -204,5 +204,3 @@ require ( sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect tailscale.com v1.48.0 // indirect ) - -replace github.com/fi-ts/cloud-go => ../cloud-go diff --git a/go.sum b/go.sum index 83ee8fef..698d78c5 100644 --- a/go.sum +++ b/go.sum @@ -151,6 +151,8 @@ github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.m github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= github.com/fatih/color v1.15.0 h1:kOqh6YHBtK8aywxGerMG2Eq3H6Qgoqeo13Bk2Mv/nBs= github.com/fatih/color v1.15.0/go.mod h1:0h5ZqXfHYED7Bhv2ZJamyIOUej9KtShiJESRwBDUSsw= +github.com/fi-ts/cloud-go v0.22.2-0.20231031073721-5c18225763a7 h1:g0cxmxZwXNRV3ghD94pg+HWvVJXPn5KMAr6ewgcBvZc= +github.com/fi-ts/cloud-go v0.22.2-0.20231031073721-5c18225763a7/go.mod h1:BYrXp1jTvfxYRiL0B+LE+6ZDp3GF110y9Sr2tuRJo5c= github.com/frankban/quicktest v1.14.5 h1:dfYrrRyLtiqT9GyKXgdh+k4inNeTvmGbuSgZ3lx3GhA= github.com/frankban/quicktest v1.14.5/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0= github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY= From 3593a6f7ef120cf1eefeea0eb590fb675f41d32d Mon Sep 17 00:00:00 2001 From: Philipp Eberle Date: Fri, 10 Nov 2023 14:48:45 +0100 Subject: [PATCH 5/5] Remove comments --- cmd/postgres.go | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/cmd/postgres.go b/cmd/postgres.go index a28a60e1..53151c42 100644 --- a/cmd/postgres.go +++ b/cmd/postgres.go @@ -778,19 +778,16 @@ func (c *config) postgresUpdate(args []string) error { PostgresParams: current.PostgresParams, } - // postgresUpdateCmd.Flags().IntP("replicas", "", 1, "replicas of the database [optional]") if viper.IsSet("replicas") { pur.NumberOfInstances = replicas } - // postgresUpdateCmd.Flags().StringSliceP("sources", "", []string{"0.0.0.0/0"}, "networks which should be allowed to connect in CIDR notation [optional]") if viper.IsSet("sources") { pur.AccessList = &models.V1AccessList{ SourceRanges: sources, } } - // postgresUpdateCmd.Flags().StringSliceP("labels", "", []string{}, "labels to add to that postgres database [optional]") if viper.IsSet("labels") { labelMap, err := helper.LabelsToMap(labels) if err != nil { @@ -800,38 +797,28 @@ func (c *config) postgresUpdate(args []string) error { } pur.Size = &models.V1PostgresSize{} - - // postgresUpdateCmd.Flags().StringP("cpu", "", "500m", "cpus for the database [optional]") if viper.IsSet("cpu") { pur.Size.CPU = cpu } - - // postgresUpdateCmd.Flags().StringP("buffer", "", "64Mi", "shared buffer for the database [optional]") if viper.IsSet("buffer") { pur.Size.SharedBuffer = buffer } - - // postgresUpdateCmd.Flags().StringP("storage", "", "10Gi", "storage for the database [optional]") if viper.IsSet("storage") { pur.Size.StorageSize = storage } - // postgresUpdateCmd.Flags().BoolP("audit-logs", "", true, "enable audit logs for the database [optional]") if viper.IsSet("audit-logs") { pur.AuditLogs = auditLogs } - // postgresUpdateCmd.Flags().StringP("dedicated-load-balancer-ip", "", "", "an existing ip address for a dedicated load balancer [optional]") if viper.IsSet("dedicated-load-balancer-ip") { pur.Dedicatedloadbalancerip = &lbIP } - // postgresUpdateCmd.Flags().IntP("dedicated-load-balancer-port", "", 0, "a port for a dedicated load balancer [optional]") if viper.IsSet("dedicated-load-balancer-port") { pur.Dedicatedloadbalancerport = &lbPort } - // auto-assign lb ip if viper.IsSet("auto-assign-ip-from") { pur.Autoassigndedicatedlbipfrom = lbNet }