diff --git a/create/keyvaluestore.go b/create/keyvaluestore.go index e5a33ec..b5af565 100644 --- a/create/keyvaluestore.go +++ b/create/keyvaluestore.go @@ -19,7 +19,7 @@ type keyValueStoreCmd struct { Location string `default:"nine-es34" help:"Location where the KeyValueStore instance is created."` MemorySize string `help:"MemorySize configures KeyValueStore to use a specified amount of memory for the data set." placeholder:"1Gi"` MaxMemoryPolicy storage.KeyValueStoreMaxMemoryPolicy `help:"MaxMemoryPolicy specifies the exact behavior KeyValueStore follows when the maxmemory limit is reached." placeholder:"allkeys-lru"` - AllowedCidrs []storage.IPv4CIDR `help:"AllowedCIDRs specify the allowed IP addresses, connecting to the instance." placeholder:"0.0.0.0/0"` + AllowedCidrs []meta.IPv4CIDR `help:"AllowedCIDRs specify the allowed IP addresses, connecting to the instance." placeholder:"0.0.0.0/0"` Wait bool `default:"true" help:"Wait until KeyValueStore is created."` WaitTimeout time.Duration `default:"600s" help:"Duration to wait for KeyValueStore getting ready. Only relevant if --wait is set."` } diff --git a/create/keyvaluestore_test.go b/create/keyvaluestore_test.go index cb28c6e..7f0cb95 100644 --- a/create/keyvaluestore_test.go +++ b/create/keyvaluestore_test.go @@ -6,6 +6,7 @@ import ( "testing" "time" + meta "github.com/ninech/apis/meta/v1alpha1" storage "github.com/ninech/apis/storage/v1alpha1" "github.com/ninech/nctl/api" "k8s.io/apimachinery/pkg/api/resource" @@ -35,8 +36,8 @@ func TestKeyValueStore(t *testing.T) { }, { "allowedCIDRs", - keyValueStoreCmd{AllowedCidrs: []storage.IPv4CIDR{storage.IPv4CIDR("0.0.0.0/0")}}, - storage.KeyValueStoreParameters{AllowedCIDRs: []storage.IPv4CIDR{storage.IPv4CIDR("0.0.0.0/0")}}, + keyValueStoreCmd{AllowedCidrs: []meta.IPv4CIDR{meta.IPv4CIDR("0.0.0.0/0")}}, + storage.KeyValueStoreParameters{AllowedCIDRs: []meta.IPv4CIDR{meta.IPv4CIDR("0.0.0.0/0")}}, false, }, { diff --git a/create/mysql.go b/create/mysql.go index 7ccca35..01f5121 100644 --- a/create/mysql.go +++ b/create/mysql.go @@ -23,7 +23,7 @@ type mySQLCmd struct { Name string `arg:"" default:"" help:"Name of the MySQL instance. A random name is generated if omitted."` Location string `placeholder:"${mysql_location_default}" help:"Location where the MySQL instance is created. Available locations are: ${mysql_location_options}"` MachineType infra.MachineType `placeholder:"${mysql_machine_default}" help:"Defines the sizing for a particular MySQL instance. Available types: ${mysql_machine_types}"` - AllowedCidrs []storage.IPv4CIDR `placeholder:"0.0.0.0/0" help:"Specifies the IP addresses allowed to connect to the instance." ` + AllowedCidrs []meta.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."` SQLMode *[]storage.MySQLMode `placeholder:"\"MODE1, MODE2, ...\"" help:"Configures the sql_mode setting. Modes affect the SQL syntax MySQL supports and the data validation checks it performs. Defaults to: ${mysql_mode}"` @@ -89,8 +89,8 @@ func (cmd *mySQLCmd) newMySQL(namespace string) *storage.MySQL { ForProvider: storage.MySQLParameters{ Location: meta.LocationName(cmd.Location), MachineType: cmd.MachineType, - AllowedCIDRs: []storage.IPv4CIDR{}, // avoid missing parameter error - SSHKeys: []storage.SSHKey{}, // avoid missing parameter error + AllowedCIDRs: []meta.IPv4CIDR{}, // avoid missing parameter error + SSHKeys: []storage.SSHKey{}, // avoid missing parameter error SQLMode: cmd.SQLMode, CharacterSet: storage.MySQLCharacterSet{ Name: cmd.CharacterSetName, diff --git a/create/mysql_test.go b/create/mysql_test.go index 3014c05..8cba942 100644 --- a/create/mysql_test.go +++ b/create/mysql_test.go @@ -8,6 +8,7 @@ import ( "time" infra "github.com/ninech/apis/infrastructure/v1alpha1" + meta "github.com/ninech/apis/meta/v1alpha1" storage "github.com/ninech/apis/storage/v1alpha1" "github.com/ninech/nctl/api" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -57,8 +58,8 @@ func TestMySQL(t *testing.T) { }, { name: "allowedCIDRs", - create: mySQLCmd{AllowedCidrs: []storage.IPv4CIDR{storage.IPv4CIDR("0.0.0.0/0")}}, - want: storage.MySQLParameters{AllowedCIDRs: []storage.IPv4CIDR{storage.IPv4CIDR("0.0.0.0/0")}}, + create: mySQLCmd{AllowedCidrs: []meta.IPv4CIDR{meta.IPv4CIDR("0.0.0.0/0")}}, + want: storage.MySQLParameters{AllowedCIDRs: []meta.IPv4CIDR{meta.IPv4CIDR("0.0.0.0/0")}}, }, { name: "characterSet", @@ -118,7 +119,7 @@ func TestMySQL(t *testing.T) { // we set defaults for the slices if tt.want.AllowedCIDRs == nil { - tt.want.AllowedCIDRs = []storage.IPv4CIDR{} + tt.want.AllowedCIDRs = []meta.IPv4CIDR{} } if tt.want.SSHKeys == nil { tt.want.SSHKeys = []storage.SSHKey{} diff --git a/create/postgres.go b/create/postgres.go index 4b07742..818af29 100644 --- a/create/postgres.go +++ b/create/postgres.go @@ -23,7 +23,7 @@ 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." ` + AllowedCidrs []meta.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."` PostgresVersion storage.PostgresVersion `placeholder:"${postgres_version_default}" help:"Release version with which the PostgreSQL instance is created"` @@ -84,8 +84,8 @@ func (cmd *postgresCmd) newPostgres(namespace string) *storage.Postgres { ForProvider: storage.PostgresParameters{ Location: meta.LocationName(cmd.Location), MachineType: cmd.MachineType, - AllowedCIDRs: []storage.IPv4CIDR{}, // avoid missing parameter error - SSHKeys: []storage.SSHKey{}, // avoid missing parameter error + AllowedCIDRs: []meta.IPv4CIDR{}, // avoid missing parameter error + SSHKeys: []storage.SSHKey{}, // avoid missing parameter error Version: cmd.PostgresVersion, KeepDailyBackups: cmd.KeepDailyBackups, }, diff --git a/create/postgres_test.go b/create/postgres_test.go index 1e6224c..ab4df25 100644 --- a/create/postgres_test.go +++ b/create/postgres_test.go @@ -8,6 +8,7 @@ import ( "time" infra "github.com/ninech/apis/infrastructure/v1alpha1" + meta "github.com/ninech/apis/meta/v1alpha1" storage "github.com/ninech/apis/storage/v1alpha1" "github.com/ninech/nctl/api" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -52,8 +53,8 @@ func TestPostgres(t *testing.T) { }, { name: "allowedCIDRs", - create: postgresCmd{AllowedCidrs: []storage.IPv4CIDR{storage.IPv4CIDR("0.0.0.0/0")}}, - want: storage.PostgresParameters{AllowedCIDRs: []storage.IPv4CIDR{storage.IPv4CIDR("0.0.0.0/0")}}, + create: postgresCmd{AllowedCidrs: []meta.IPv4CIDR{meta.IPv4CIDR("0.0.0.0/0")}}, + want: storage.PostgresParameters{AllowedCIDRs: []meta.IPv4CIDR{meta.IPv4CIDR("0.0.0.0/0")}}, }, { name: "version", @@ -98,7 +99,7 @@ func TestPostgres(t *testing.T) { // we set defaults for the slices if tt.want.AllowedCIDRs == nil { - tt.want.AllowedCIDRs = []storage.IPv4CIDR{} + tt.want.AllowedCIDRs = []meta.IPv4CIDR{} } if tt.want.SSHKeys == nil { tt.want.SSHKeys = []storage.SSHKey{} diff --git a/update/keyvaluestore.go b/update/keyvaluestore.go index 313e8d7..c153ca4 100644 --- a/update/keyvaluestore.go +++ b/update/keyvaluestore.go @@ -5,6 +5,7 @@ import ( "fmt" "github.com/crossplane/crossplane-runtime/pkg/resource" + meta "github.com/ninech/apis/meta/v1alpha1" storage "github.com/ninech/apis/storage/v1alpha1" "github.com/ninech/nctl/api" kresource "k8s.io/apimachinery/pkg/api/resource" @@ -15,7 +16,7 @@ type keyValueStoreCmd struct { Name string `arg:"" default:"" help:"Name of the KeyValueStore instance to update."` MemorySize *string `help:"MemorySize configures KeyValueStore to use a specified amount of memory for the data set." placeholder:"1Gi"` MaxMemoryPolicy *storage.KeyValueStoreMaxMemoryPolicy `help:"MaxMemoryPolicy specifies the exact behavior KeyValueStore follows when the maxmemory limit is reached." placeholder:"allkeys-lru"` - AllowedCidrs *[]storage.IPv4CIDR `help:"AllowedCIDRs specify the allowed IP addresses, connecting to the instance." placeholder:"0.0.0.0/0"` + AllowedCidrs *[]meta.IPv4CIDR `help:"AllowedCIDRs specify the allowed IP addresses, connecting to the instance." placeholder:"0.0.0.0/0"` } func (cmd *keyValueStoreCmd) Run(ctx context.Context, client *api.Client) error { diff --git a/update/keyvaluestore_test.go b/update/keyvaluestore_test.go index 4958f2e..35b8eb5 100644 --- a/update/keyvaluestore_test.go +++ b/update/keyvaluestore_test.go @@ -5,6 +5,7 @@ import ( "reflect" "testing" + meta "github.com/ninech/apis/meta/v1alpha1" storage "github.com/ninech/apis/storage/v1alpha1" "github.com/ninech/nctl/api" "github.com/ninech/nctl/internal/test" @@ -61,22 +62,22 @@ func TestKeyValueStore(t *testing.T) { { "allowedCIDRs", storage.KeyValueStoreParameters{}, - keyValueStoreCmd{AllowedCidrs: &[]storage.IPv4CIDR{storage.IPv4CIDR("0.0.0.0/0")}}, - storage.KeyValueStoreParameters{AllowedCIDRs: []storage.IPv4CIDR{storage.IPv4CIDR("0.0.0.0/0")}}, + keyValueStoreCmd{AllowedCidrs: &[]meta.IPv4CIDR{meta.IPv4CIDR("0.0.0.0/0")}}, + storage.KeyValueStoreParameters{AllowedCIDRs: []meta.IPv4CIDR{meta.IPv4CIDR("0.0.0.0/0")}}, false, }, { "allowedCIDRs", - storage.KeyValueStoreParameters{AllowedCIDRs: []storage.IPv4CIDR{"192.168.0.1/24"}}, - keyValueStoreCmd{AllowedCidrs: &[]storage.IPv4CIDR{storage.IPv4CIDR("0.0.0.0/0")}}, - storage.KeyValueStoreParameters{AllowedCIDRs: []storage.IPv4CIDR{storage.IPv4CIDR("0.0.0.0/0")}}, + storage.KeyValueStoreParameters{AllowedCIDRs: []meta.IPv4CIDR{"192.168.0.1/24"}}, + keyValueStoreCmd{AllowedCidrs: &[]meta.IPv4CIDR{meta.IPv4CIDR("0.0.0.0/0")}}, + storage.KeyValueStoreParameters{AllowedCIDRs: []meta.IPv4CIDR{meta.IPv4CIDR("0.0.0.0/0")}}, false, }, { "allowedCIDRs", - storage.KeyValueStoreParameters{AllowedCIDRs: []storage.IPv4CIDR{"0.0.0.0/0"}}, + storage.KeyValueStoreParameters{AllowedCIDRs: []meta.IPv4CIDR{"0.0.0.0/0"}}, keyValueStoreCmd{MemorySize: ptr.To("1G")}, - storage.KeyValueStoreParameters{MemorySize: memorySize("1G"), AllowedCIDRs: []storage.IPv4CIDR{storage.IPv4CIDR("0.0.0.0/0")}}, + storage.KeyValueStoreParameters{MemorySize: memorySize("1G"), AllowedCIDRs: []meta.IPv4CIDR{meta.IPv4CIDR("0.0.0.0/0")}}, false, }, } diff --git a/update/mysql.go b/update/mysql.go index ac2c44f..61cf16d 100644 --- a/update/mysql.go +++ b/update/mysql.go @@ -6,6 +6,7 @@ import ( "github.com/crossplane/crossplane-runtime/pkg/resource" infra "github.com/ninech/apis/infrastructure/v1alpha1" + meta "github.com/ninech/apis/meta/v1alpha1" storage "github.com/ninech/apis/storage/v1alpha1" "github.com/ninech/nctl/api" "github.com/ninech/nctl/internal/file" @@ -15,7 +16,7 @@ import ( type mySQLCmd struct { Name string `arg:"" default:"" help:"Name of the MySQL instance to update."` MachineType *infra.MachineType `placeholder:"${mysql_machine_default}" help:"Defines the sizing for a particular MySQL instance. Available types: ${mysql_machine_types}"` - AllowedCidrs *[]storage.IPv4CIDR `placeholder:"0.0.0.0/0" help:"Specifies the IP addresses allowed to connect to the instance." ` + AllowedCidrs *[]meta.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."` SQLMode *[]storage.MySQLMode `placeholder:"\"MODE1, MODE2, ...\"" help:"Configures the sql_mode setting. Modes affect the SQL syntax MySQL supports and the data validation checks it performs. Defaults to: ${mysql_mode}"` diff --git a/update/mysql_test.go b/update/mysql_test.go index 0eba1ef..6f993b8 100644 --- a/update/mysql_test.go +++ b/update/mysql_test.go @@ -6,6 +6,7 @@ import ( "testing" infra "github.com/ninech/apis/infrastructure/v1alpha1" + meta "github.com/ninech/apis/meta/v1alpha1" storage "github.com/ninech/apis/storage/v1alpha1" "github.com/ninech/nctl/api" "github.com/ninech/nctl/internal/test" @@ -78,20 +79,20 @@ func TestMySQL(t *testing.T) { }, { name: "allowedCIDRs-nothing-set-initially", - update: mySQLCmd{AllowedCidrs: &[]storage.IPv4CIDR{storage.IPv4CIDR("0.0.0.0/0")}}, - want: storage.MySQLParameters{AllowedCIDRs: []storage.IPv4CIDR{storage.IPv4CIDR("0.0.0.0/0")}}, + update: mySQLCmd{AllowedCidrs: &[]meta.IPv4CIDR{meta.IPv4CIDR("0.0.0.0/0")}}, + want: storage.MySQLParameters{AllowedCIDRs: []meta.IPv4CIDR{meta.IPv4CIDR("0.0.0.0/0")}}, }, { name: "allowedCIDRs-set-initially", - create: storage.MySQLParameters{AllowedCIDRs: []storage.IPv4CIDR{"192.168.0.1/24"}}, - update: mySQLCmd{AllowedCidrs: &[]storage.IPv4CIDR{storage.IPv4CIDR("0.0.0.0/0")}}, - want: storage.MySQLParameters{AllowedCIDRs: []storage.IPv4CIDR{storage.IPv4CIDR("0.0.0.0/0")}}, + create: storage.MySQLParameters{AllowedCIDRs: []meta.IPv4CIDR{"192.168.0.1/24"}}, + update: mySQLCmd{AllowedCidrs: &[]meta.IPv4CIDR{meta.IPv4CIDR("0.0.0.0/0")}}, + want: storage.MySQLParameters{AllowedCIDRs: []meta.IPv4CIDR{meta.IPv4CIDR("0.0.0.0/0")}}, }, { name: "multi-update", - create: storage.MySQLParameters{AllowedCIDRs: []storage.IPv4CIDR{"0.0.0.0/0"}}, + create: storage.MySQLParameters{AllowedCIDRs: []meta.IPv4CIDR{"0.0.0.0/0"}}, update: mySQLCmd{MachineType: ptr.To(infra.MachineType("nine-standard-1"))}, - want: storage.MySQLParameters{MachineType: infra.MachineType("nine-standard-1"), AllowedCIDRs: []storage.IPv4CIDR{storage.IPv4CIDR("0.0.0.0/0")}}, + want: storage.MySQLParameters{MachineType: infra.MachineType("nine-standard-1"), AllowedCIDRs: []meta.IPv4CIDR{meta.IPv4CIDR("0.0.0.0/0")}}, }, } for _, tt := range tests { diff --git a/update/postgres.go b/update/postgres.go index 74815d1..063997f 100644 --- a/update/postgres.go +++ b/update/postgres.go @@ -6,6 +6,7 @@ import ( "github.com/crossplane/crossplane-runtime/pkg/resource" infra "github.com/ninech/apis/infrastructure/v1alpha1" + meta "github.com/ninech/apis/meta/v1alpha1" storage "github.com/ninech/apis/storage/v1alpha1" "github.com/ninech/nctl/api" "github.com/ninech/nctl/internal/file" @@ -13,12 +14,12 @@ import ( ) type postgresCmd struct { - Name string `arg:"" default:"" help:"Name of the PostgreSQL instance to update."` - 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."` - 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."` + Name string `arg:"" default:"" help:"Name of the PostgreSQL instance to update."` + MachineType *infra.MachineType `placeholder:"${postgres_machine_default}" help:"Defines the sizing for a particular PostgreSQL instance. Available types: ${postgres_machine_types}"` + AllowedCidrs *[]meta.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."` + 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."` } func (cmd *postgresCmd) Run(ctx context.Context, client *api.Client) error { diff --git a/update/postgres_test.go b/update/postgres_test.go index 1a24e91..7620a70 100644 --- a/update/postgres_test.go +++ b/update/postgres_test.go @@ -6,6 +6,7 @@ import ( "testing" infra "github.com/ninech/apis/infrastructure/v1alpha1" + meta "github.com/ninech/apis/meta/v1alpha1" storage "github.com/ninech/apis/storage/v1alpha1" "github.com/ninech/nctl/api" "github.com/ninech/nctl/internal/test" @@ -47,20 +48,20 @@ func TestPostgres(t *testing.T) { }, { name: "allowedCIDRs-nothing-set-initially", - update: postgresCmd{AllowedCidrs: &[]storage.IPv4CIDR{storage.IPv4CIDR("0.0.0.0/0")}}, - want: storage.PostgresParameters{AllowedCIDRs: []storage.IPv4CIDR{storage.IPv4CIDR("0.0.0.0/0")}}, + update: postgresCmd{AllowedCidrs: &[]meta.IPv4CIDR{meta.IPv4CIDR("0.0.0.0/0")}}, + want: storage.PostgresParameters{AllowedCIDRs: []meta.IPv4CIDR{meta.IPv4CIDR("0.0.0.0/0")}}, }, { name: "allowedCIDRs-set-initially", - create: storage.PostgresParameters{AllowedCIDRs: []storage.IPv4CIDR{"192.168.0.1/24"}}, - update: postgresCmd{AllowedCidrs: &[]storage.IPv4CIDR{storage.IPv4CIDR("0.0.0.0/0")}}, - want: storage.PostgresParameters{AllowedCIDRs: []storage.IPv4CIDR{storage.IPv4CIDR("0.0.0.0/0")}}, + create: storage.PostgresParameters{AllowedCIDRs: []meta.IPv4CIDR{"192.168.0.1/24"}}, + update: postgresCmd{AllowedCidrs: &[]meta.IPv4CIDR{meta.IPv4CIDR("0.0.0.0/0")}}, + want: storage.PostgresParameters{AllowedCIDRs: []meta.IPv4CIDR{meta.IPv4CIDR("0.0.0.0/0")}}, }, { name: "multi-update", - create: storage.PostgresParameters{AllowedCIDRs: []storage.IPv4CIDR{"0.0.0.0/0"}}, + create: storage.PostgresParameters{AllowedCIDRs: []meta.IPv4CIDR{"0.0.0.0/0"}}, update: postgresCmd{MachineType: ptr.To(infra.MachineType("nine-standard-1"))}, - want: storage.PostgresParameters{MachineType: infra.MachineType("nine-standard-1"), AllowedCIDRs: []storage.IPv4CIDR{storage.IPv4CIDR("0.0.0.0/0")}}, + want: storage.PostgresParameters{MachineType: infra.MachineType("nine-standard-1"), AllowedCIDRs: []meta.IPv4CIDR{meta.IPv4CIDR("0.0.0.0/0")}}, }, } for _, tt := range tests {