Skip to content

Commit

Permalink
feat(postgres): Add resource
Browse files Browse the repository at this point in the history
Implements ninech/managed-services/backlog#581
  • Loading branch information
9marco committed May 24, 2024
1 parent 7667085 commit d4e7df2
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 0 deletions.
1 change: 1 addition & 0 deletions create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type Cmd struct {
Config configCmd `cmd:"" group:"deplo.io" name:"config" help:"Create a new deplo.io Project Configuration. (Beta - requires access)"`
Application applicationCmd `cmd:"" group:"deplo.io" name:"application" aliases:"app" help:"Create a new deplo.io Application. (Beta - requires access)"`
MySQL mySQLCmd `cmd:"" group:"storage.nine.ch" name:"mysql" help:"Create a new MySQL instance."`
Postgres postgresCmd `cmd:"" group:"storage.nine.ch" name:"postgres" help:"Create a new PostgreSQL instance."`
KeyValueStore keyValueStoreCmd `cmd:"" group:"storage.nine.ch" name:"keyvaluestore" aliases:"kvs" help:"Create a new KeyValueStore instance"`
CloudVirtualMachine cloudVMCmd `cmd:"" group:"infrastructure.nine.ch" name:"cloudvirtualmachine" aliases:"cloudvm" help:"Create a new CloudVM."`
}
Expand Down
55 changes: 55 additions & 0 deletions create/postgres.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package create

import (
"context"
"fmt"
"strings"
"time"

"github.com/alecthomas/kong"
infra "github.com/ninech/apis/infrastructure/v1alpha1"
storage "github.com/ninech/apis/storage/v1alpha1"

"github.com/ninech/nctl/api"
)

type postgresCmd struct {
Name string `arg:"" default:"" help:"Name of the PostgreSQL instance. A random name is generated if omitted."`
Location string `placeholder:"${postgres_location_default}" help:"Location where the PostgreSQL instance is created. Available locations are: ${postgres_location_options}"`
MachineType infra.MachineType `placeholder:"${postgres_machine_default}" help:"Defines the sizing for a particular PostgreSQL instance. Available types: ${postgres_machine_types}"`
AllowedCidrs []storage.IPv4CIDR `placeholder:"0.0.0.0/0" help:"Specifies the IP addresses allowed to connect to the instance." `
SSHKeys []storage.SSHKey `help:"Contains a list of SSH public keys, allowed to connect to the db server, in order to up-/download and directly restore database backups."`
SSHKeysFile string `help:"Path to a file containing a list of SSH public keys (see above), separated by newlines."`
Version string `placeholder:"${postgrees_version_default}" help:"Release version with which the PostgreSQL instance is created"`
KeepDailyBackups *int `placeholder:"${postgres_backup_retention_days}" help:"Number of daily database backups to keep. Note that setting this to 0, backup will be disabled and existing dumps deleted immediately."`
Wait bool `default:"true" help:"Wait until PostgreSQL instance is created."`
WaitTimeout time.Duration `default:"25m" help:"Duration to wait for PostgreSQL getting ready. Only relevant if --wait is set."`
}

func (cmd *postgresCmd) Run(ctx context.Context, client *api.Client) error {
return nil
}

func (cmd *postgresCmd) newPostgres(namespace string) *storage.Postgres {

Check failure on line 33 in create/postgres.go

View workflow job for this annotation

GitHub Actions / lint

func `(*postgresCmd).newPostgres` is unused (unused)
return nil
}

// ApplicationKongVars returns all variables which are used in the application
// create command
func PostgresKongVars() kong.Vars {
vmTypes := make([]string, len(infra.MachineTypes))
for i, machineType := range infra.MachineTypes {
vmTypes[i] = string(machineType)
}

result := make(kong.Vars)
result["postgres_machine_types"] = strings.Join(vmTypes, ", ")
result["postgres_machine_default"] = string(infra.MachineTypes[0])
result["postgres_location_options"] = strings.Join(storage.PostgresLocationOptions, ", ")
result["postgres_location_default"] = string(storage.PostgresLocationDefault)
result["postgres_version_default"] = string(storage.PostgresVersionDefault)
result["postgres_user"] = storage.PostgresUser
result["postgres_backup_retention_days"] = fmt.Sprintf("%d", storage.PostgresBackupRetentionDaysDefault)

return result
}
1 change: 1 addition & 0 deletions create/postgres_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package create
1 change: 1 addition & 0 deletions delete/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type Cmd struct {
MySQL mySQLCmd `cmd:"" group:"storage.nine.ch" name:"mysql" help:"Delete a MySQL instance."`
KeyValueStore keyValueStoreCmd `cmd:"" group:"storage.nine.ch" name:"keyvaluestore" aliases:"kvs" help:"Delete a KeyValueStore instance."`
CloudVirtualMachine cloudVMCmd `cmd:"" group:"infrastructure.nine.ch" name:"cloudvirtualmachine" aliases:"cloudvm" help:"Delete a CloudVM."`
//Postgres postgresCmd `cmd:"" group:"storage.nine.ch" name:"postgres" help:"Delete a PostgreSQL instance."`
}

// cleanupFunc is called after the resource has been deleted in order to do
Expand Down
1 change: 1 addition & 0 deletions get/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type Cmd struct {
All allCmd `cmd:"" name:"all" help:"Get project content"`
CloudVirtualMachine cloudVMCmd `cmd:"" group:"infrastructure.nine.ch" name:"cloudvirtualmachine" aliases:"cloudvm" help:"Get a CloudVM."`
opts []runtimeclient.ListOption
//Postgres postgresCmd `cmd:"" group:"storage.nine.ch" name:"postgres" help:"Get PostgreSQL instances."`
}

type output string
Expand Down
1 change: 1 addition & 0 deletions update/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type Cmd struct {
MySQL mySQLCmd `cmd:"" group:"storage.nine.ch" name:"mysql" help:"Update an existing MySQL instance."`
KeyValueStore keyValueStoreCmd `cmd:"" group:"storage.nine.ch" name:"keyvaluestore" aliases:"kvs" help:"Update an existing KeyValueStore instance"`
CloudVirtualMachine cloudVMCmd `cmd:"" group:"infrastructure.nine.ch" name:"cloudvirtualmachine" aliases:"cloudvm" help:"Update a CloudVM."`
//Postgres postgresCmd `cmd:"" group:"storage.nine.ch" name:"postgres" help:"Update an existing PostgreSQL instance."`
}

type updater struct {
Expand Down

0 comments on commit d4e7df2

Please sign in to comment.