diff --git a/cli/cmd/cluster_addon.go b/cli/cmd/cluster_addon.go index 1fd48b09..c0dbbc01 100644 --- a/cli/cmd/cluster_addon.go +++ b/cli/cmd/cluster_addon.go @@ -22,17 +22,11 @@ You can use various subcommands to create, list, remove, or check the status of # Remove an add-on from a cluster replicated cluster addon rm CLUSTER_ID --id ADDON_ID - # Create a Postgres database add-on for a cluster - replicated cluster addon create postgres CLUSTER_ID --version 13 --disk 100 --instance-type db.t3.micro - # Create an object store bucket add-on for a cluster replicated cluster addon create object-store CLUSTER_ID --bucket-prefix mybucket # List add-ons with JSON output - replicated cluster addon ls CLUSTER_ID --output json - - # Create a Postgres add-on and wait for it to be ready - replicated cluster addon create postgres CLUSTER_ID --version 13 --wait 5m`, + replicated cluster addon ls CLUSTER_ID --output json`, } parent.AddCommand(cmd) diff --git a/cli/cmd/cluster_addon_create.go b/cli/cmd/cluster_addon_create.go index 5538b73b..0d5e8c45 100644 --- a/cli/cmd/cluster_addon_create.go +++ b/cli/cmd/cluster_addon_create.go @@ -9,15 +9,9 @@ func (r *runners) InitClusterAddonCreate(parent *cobra.Command) *cobra.Command { Use: "create", Short: "Create cluster add-ons.", Long: `Create new add-ons for a cluster. This command allows you to add functionality or services to a cluster by provisioning the required add-ons.`, - Example: ` # Create a Postgres database add-on for a cluster - replicated cluster addon create postgres CLUSTER_ID --version 13 --disk 100 --instance-type db.t3.micro - - # Create an object store bucket add-on for a cluster + Example: ` # Create an object store bucket add-on for a cluster replicated cluster addon create object-store CLUSTER_ID --bucket-prefix mybucket - # Create a Postgres add-on and wait for it to be ready - replicated cluster addon create postgres CLUSTER_ID --version 13 --wait 5m - # Perform a dry run for creating an object store add-on replicated cluster addon create object-store CLUSTER_ID --bucket-prefix mybucket --dry-run`, } diff --git a/cli/cmd/cluster_addon_create_postgres.go b/cli/cmd/cluster_addon_create_postgres.go deleted file mode 100644 index 348cbab4..00000000 --- a/cli/cmd/cluster_addon_create_postgres.go +++ /dev/null @@ -1,124 +0,0 @@ -package cmd - -import ( - "fmt" - "os" - "time" - - "github.com/pkg/errors" - "github.com/replicatedhq/replicated/cli/print" - "github.com/replicatedhq/replicated/pkg/kotsclient" - "github.com/replicatedhq/replicated/pkg/platformclient" - "github.com/replicatedhq/replicated/pkg/types" - "github.com/spf13/cobra" -) - -type clusterAddonCreatePostgresArgs struct { - version string - diskGiB int64 - instanceType string - - clusterID string - waitDuration time.Duration - dryRun bool - outputFormat string -} - -func (r *runners) InitClusterAddonCreatePostgres(parent *cobra.Command) *cobra.Command { - args := clusterAddonCreatePostgresArgs{} - - cmd := &cobra.Command{ - Use: "postgres CLUSTER_ID", - Short: "Create a Postgres database for a cluster.", - Long: `Creates a Postgres database instance for the specified cluster, provisioning it with a specified version, disk size, and instance type. This allows you to attach a managed Postgres instance to your cluster for database functionality. - -Examples: - # Create a Postgres database with default settings - replicated cluster addon create postgres CLUSTER_ID - - # Create a Postgres 13 database with 500GB disk and a larger instance type - replicated cluster addon create postgres CLUSTER_ID --version 13 --disk 500 --instance-type db.t3.large - - # Perform a dry run to validate inputs without creating the database - replicated cluster addon create postgres CLUSTER_ID --dry-run - - # Create a Postgres database and wait for it to be ready (up to 10 minutes) - replicated cluster addon create postgres CLUSTER_ID --wait 10m - - # Create a Postgres database and output the result in JSON format - replicated cluster addon create postgres CLUSTER_ID --output json`, - Args: cobra.ExactArgs(1), - RunE: func(_ *cobra.Command, cmdArgs []string) error { - args.clusterID = cmdArgs[0] - return r.clusterAddonCreatePostgresCreateRun(args) - }, - ValidArgsFunction: r.completeClusterIDs, - } - parent.AddCommand(cmd) - - err := clusterAddonCreatePostgresFlags(cmd, &args) - if err != nil { - panic(err) - } - - return cmd -} - -func clusterAddonCreatePostgresFlags(cmd *cobra.Command, args *clusterAddonCreatePostgresArgs) error { - cmd.Flags().StringVar(&args.version, "version", "", "The Postgres version to create") - cmd.Flags().Int64Var(&args.diskGiB, "disk", 200, "Disk Size (GiB) for the Postgres database") - cmd.Flags().StringVar(&args.instanceType, "instance-type", "db.t3.micro", "The type of instance to use for the Postgres database") - - cmd.Flags().DurationVar(&args.waitDuration, "wait", 0, "Wait duration for add-on to be ready before exiting (leave empty to not wait)") - cmd.Flags().BoolVar(&args.dryRun, "dry-run", false, "Simulate creation to verify that your inputs are valid without actually creating an add-on") - cmd.Flags().StringVar(&args.outputFormat, "output", "table", "The output format to use. One of: json|table|wide (default: table)") - return nil -} - -func (r *runners) clusterAddonCreatePostgresCreateRun(args clusterAddonCreatePostgresArgs) error { - opts := kotsclient.CreateClusterAddonPostgresOpts{ - ClusterID: args.clusterID, - Version: args.version, - DiskGiB: args.diskGiB, - InstanceType: args.instanceType, - DryRun: args.dryRun, - } - - addon, err := r.createAndWaitForClusterAddonCreatePostgres(opts, args.waitDuration) - if err != nil { - if errors.Cause(err) == ErrWaitDurationExceeded { - defer func() { - os.Exit(124) - }() - } else { - return err - } - } - - if opts.DryRun { - _, err := fmt.Fprintln(r.w, "Dry run succeeded.") - return err - } - - return print.Addon(args.outputFormat, r.w, addon) -} - -func (r *runners) createAndWaitForClusterAddonCreatePostgres(opts kotsclient.CreateClusterAddonPostgresOpts, waitDuration time.Duration) (*types.ClusterAddon, error) { - addon, err := r.kotsAPI.CreateClusterAddonPostgres(opts) - if errors.Cause(err) == platformclient.ErrForbidden { - return nil, ErrCompatibilityMatrixTermsNotAccepted - } else if err != nil { - return nil, errors.Wrap(err, "create cluster add-on postgres") - } - - if opts.DryRun { - return addon, nil - } - - // if the wait flag was provided, we poll the api until the add-on is ready, or a timeout - if waitDuration > 0 { - return waitForAddon(r.kotsAPI, opts.ClusterID, addon.ID, waitDuration) - } - - return addon, nil -} diff --git a/cli/cmd/root.go b/cli/cmd/root.go index 305a8ec4..678a3c6d 100644 --- a/cli/cmd/root.go +++ b/cli/cmd/root.go @@ -241,7 +241,6 @@ func Execute(rootCmd *cobra.Command, stdin io.Reader, stdout io.Writer, stderr i runCmds.InitClusterAddonRm(clusterAddonCmd) clusterAddonCreateCmd := runCmds.InitClusterAddonCreate(clusterAddonCmd) runCmds.InitClusterAddonCreateObjectStore(clusterAddonCreateCmd) - runCmds.InitClusterAddonCreatePostgres(clusterAddonCreateCmd) clusterPortCmd := runCmds.InitClusterPort(clusterCmd) runCmds.InitClusterPortLs(clusterPortCmd) diff --git a/cli/print/cluster_addons.go b/cli/print/cluster_addons.go index 16cddfa1..09787e33 100644 --- a/cli/print/cluster_addons.go +++ b/cli/print/cluster_addons.go @@ -81,8 +81,6 @@ func addonData(addon *types.ClusterAddon) string { switch { case addon.ObjectStore != nil: return addonObjectStoreData(*addon.ObjectStore) - case addon.Postgres != nil: - return addonPostgresData(*addon.Postgres) default: return "" } @@ -95,11 +93,3 @@ func addonObjectStoreData(data types.ClusterAddonObjectStore) string { } return string(b) } - -func addonPostgresData(data types.ClusterAddonPostgres) string { - b, err := json.Marshal(data) - if err != nil { - log.Printf("failed to marshal postgres data: %v", err) - } - return string(b) -} diff --git a/pkg/kotsclient/cluster_addon_postgres_create.go b/pkg/kotsclient/cluster_addon_postgres_create.go deleted file mode 100644 index 751fca16..00000000 --- a/pkg/kotsclient/cluster_addon_postgres_create.go +++ /dev/null @@ -1,61 +0,0 @@ -package kotsclient - -import ( - "context" - "encoding/json" - "fmt" - "net/http" - - "github.com/pkg/errors" - "github.com/replicatedhq/replicated/pkg/platformclient" - "github.com/replicatedhq/replicated/pkg/types" -) - -type CreateClusterAddonPostgresOpts struct { - ClusterID string - Version string - DiskGiB int64 - InstanceType string - DryRun bool -} - -type CreateClusterAddonPostgresRequest struct { - Version string `json:"version"` - DiskGiB int64 `json:"disk_gib"` - InstanceType string `json:"instance_type"` -} - -func (c *VendorV3Client) CreateClusterAddonPostgres(opts CreateClusterAddonPostgresOpts) (*types.ClusterAddon, error) { - req := CreateClusterAddonPostgresRequest{ - Version: opts.Version, - DiskGiB: opts.DiskGiB, - InstanceType: opts.InstanceType, - } - return c.doCreateClusterAddonPostgresRequest(opts.ClusterID, req, opts.DryRun) -} - -func (c *VendorV3Client) doCreateClusterAddonPostgresRequest(clusterID string, req CreateClusterAddonPostgresRequest, dryRun bool) (*types.ClusterAddon, error) { - resp := CreateClusterAddonObjectStoreResponse{} - endpoint := fmt.Sprintf("/v3/cluster/%s/addons/postgres", clusterID) - if dryRun { - endpoint = fmt.Sprintf("%s?dry-run=true", endpoint) - } - err := c.DoJSON(context.TODO(), "POST", endpoint, http.StatusCreated, req, &resp) - if err != nil { - // if err is APIError and the status code is 400, then we have a validation error - // and we can return the validation error - if apiErr, ok := errors.Cause(err).(platformclient.APIError); ok { - if apiErr.StatusCode == http.StatusBadRequest { - errResp := &CreateClusterAddonErrorResponse{} - if jsonErr := json.Unmarshal(apiErr.Body, errResp); jsonErr != nil { - return nil, fmt.Errorf("unmarshal error response: %w", err) - } - return nil, errors.New(errResp.Message) - } - } - - return nil, err - } - - return resp.Addon, nil -} diff --git a/pkg/types/cluster.go b/pkg/types/cluster.go index ba94cf35..4a4bd923 100644 --- a/pkg/types/cluster.go +++ b/pkg/types/cluster.go @@ -101,7 +101,6 @@ type ClusterAddon struct { CreatedAt time.Time `json:"created_at"` ObjectStore *ClusterAddonObjectStore `json:"object_store,omitempty"` - Postgres *ClusterAddonPostgres `json:"postgres,omitempty"` } type ClusterAddonObjectStore struct { @@ -112,20 +111,10 @@ type ClusterAddonObjectStore struct { ServiceAccountNameReadOnly string `json:"service_account_name_read_only,omitempty"` } -type ClusterAddonPostgres struct { - Version string `json:"version"` - DiskGiB int64 `json:"disk_gib"` - InstanceType string `json:"instance_type"` - - URI string `json:"uri,omitempty"` -} - func (addon *ClusterAddon) TypeName() string { switch { case addon.ObjectStore != nil: return "Object Store" - case addon.Postgres != nil: - return "Postgres" default: return "Unknown" }