diff --git a/docs/functions.rst b/docs/functions.rst index 5404bd5de4..16a274abd9 100644 --- a/docs/functions.rst +++ b/docs/functions.rst @@ -990,6 +990,7 @@ Arguments: `databases`, No, `[]string`, list of databases to take backup of `securityGroupID`, No, `[]string`, list of ``securityGroupID`` to be passed to temporary RDS instance. () `dbSubnetGroup`, No, `string`, DB Subnet Group to be passed to temporary RDS instance + `image`, No, `string`, kanister-tools image to be used for running export job .. note:: - If ``databases`` argument is not set, backup of all the databases will be taken. @@ -1080,6 +1081,7 @@ Arguments: `namespace`, No, `string`, namespace in which to execute. Required if ``snapshotID`` is nil `dbEngine`, No, `string`, one of the RDS db engines. Supported engines: ``PostgreSQL`` ``aurora`` ``aurora-mysql`` and ``aurora-postgresql``. Required if ``snapshotID`` is nil or Aurora is run in RDS instance `dbSubnetGroup`, No, `string`, DB Subnet Group to be passed to restored RDS instance + `image`, No, `string`, kanister-tools image to be used for running restore. Only relevant when restoring from data dump (if `snapshotID` is empty) .. note:: - If ``snapshotID`` is not set, restore will be done from data dump. In that case ``backupID`` `arg` is required. diff --git a/docs_new/functions.md b/docs_new/functions.md index c86145464e..1c57106fcc 100644 --- a/docs_new/functions.md +++ b/docs_new/functions.md @@ -859,6 +859,7 @@ Arguments: | databases | No | []string | list of databases to take backup of | | securityGroupID | No | []string | list of `securityGroupID` to be passed to temporary RDS instance | | dbSubnetGroup | No | string | DB Subnet Group to be passed to temporary RDS instance | + | image | No | string | kanister-tools image to be used for running export job | ::: tip NOTE @@ -954,6 +955,7 @@ Arguments: | namespace | No | string | namespace in which to execute. Required if `snapshotID` is nil | | dbEngine | No | string | one of the RDS db engines. Supported engines: `PostgreSQL`, `aurora`, `aurora-mysql` and `aurora-postgresql`. Required if `snapshotID` is nil or Aurora is run in RDS instance | | dbSubnetGroup | No | string | DB Subnet Group to be passed to restored RDS instance | + | image | No | string | kanister-tools image to be used for running restore, only relevant when restoring from data dump (if `snapshotID` is empty) | ::: tip NOTE diff --git a/pkg/function/export_rds_snapshot_location.go b/pkg/function/export_rds_snapshot_location.go index c937da7086..31a6405082 100644 --- a/pkg/function/export_rds_snapshot_location.go +++ b/pkg/function/export_rds_snapshot_location.go @@ -59,13 +59,14 @@ const ( ExportRDSSnapshotToLocSecGrpIDArg = "securityGroupID" ExportRDSSnapshotToLocBackupID = "backupID" ExportRDSSnapshotToLocDBSubnetGroupArg = "dbSubnetGroup" + ExportRDSSnapshotToLocImageArg = "image" PostgrSQLEngine RDSDBEngine = "PostgreSQL" BackupAction RDSAction = "backup" RestoreAction RDSAction = "restore" - postgresToolsImage = "ghcr.io/kanisterio/postgres-kanister-tools:0.110.0" + defaultPostgresToolsImage = "ghcr.io/kanisterio/postgres-kanister-tools:0.110.0" ) type exportRDSSnapshotToLocationFunc struct { @@ -95,6 +96,7 @@ func exportRDSSnapshotToLoc( dbEngine RDSDBEngine, sgIDs []string, profile *param.Profile, + postgresToolsImage string, ) (map[string]interface{}, error) { // Validate profilextractDumpFromDBe if err := ValidateProfile(profile); err != nil { @@ -150,7 +152,7 @@ func exportRDSSnapshotToLoc( } // Extract dump from DB - output, err := execDumpCommand(ctx, dbEngine, BackupAction, namespace, dbEndpoint, username, password, databases, backupPrefix, backupID, profile, dbEngineVersion) + output, err := execDumpCommand(ctx, dbEngine, BackupAction, namespace, dbEndpoint, username, password, databases, backupPrefix, backupID, profile, dbEngineVersion, postgresToolsImage) if err != nil { return nil, errors.Wrap(err, "Unable to extract and push db dump to location") } @@ -174,7 +176,7 @@ func (e *exportRDSSnapshotToLocationFunc) Exec(ctx context.Context, tp param.Tem e.progressPercent = progress.StartedPercent defer func() { e.progressPercent = progress.CompletedPercent }() - var namespace, instanceID, snapshotID, username, password, dbSubnetGroup, backupArtifact string + var namespace, instanceID, snapshotID, username, password, dbSubnetGroup, backupArtifact, postgresToolsImage string var dbEngine RDSDBEngine if err := Arg(args, ExportRDSSnapshotToLocNamespaceArg, &namespace); err != nil { @@ -201,6 +203,9 @@ func (e *exportRDSSnapshotToLocationFunc) Exec(ctx context.Context, tp param.Tem if err := OptArg(args, ExportRDSSnapshotToLocDBSubnetGroupArg, &dbSubnetGroup, "default"); err != nil { return nil, err } + if err := OptArg(args, ExportRDSSnapshotToLocImageArg, &postgresToolsImage, defaultPostgresToolsImage); err != nil { + return nil, err + } // Find databases databases, err := GetYamlList(args, ExportRDSSnapshotToLocDatabasesArg) if err != nil { @@ -213,7 +218,7 @@ func (e *exportRDSSnapshotToLocationFunc) Exec(ctx context.Context, tp param.Tem return nil, err } - return exportRDSSnapshotToLoc(ctx, namespace, instanceID, snapshotID, username, password, databases, dbSubnetGroup, backupArtifact, dbEngine, sgIDs, tp.Profile) + return exportRDSSnapshotToLoc(ctx, namespace, instanceID, snapshotID, username, password, databases, dbSubnetGroup, backupArtifact, dbEngine, sgIDs, tp.Profile, postgresToolsImage) } func (*exportRDSSnapshotToLocationFunc) RequiredArgs() []string { @@ -269,13 +274,14 @@ func execDumpCommand( backupID string, profile *param.Profile, dbEngineVersion string, + postgresToolsImage string, ) (map[string]interface{}, error) { // Trim "\n" from creds username = strings.TrimSpace(username) password = strings.TrimSpace(password) // Prepare and execute command with kubetask - command, image, err := prepareCommand(ctx, dbEngine, action, dbEndpoint, username, password, databases, backupPrefix, backupID, profile, dbEngineVersion) + command, err := prepareCommand(ctx, dbEngine, action, dbEndpoint, username, password, databases, backupPrefix, backupID, profile, dbEngineVersion) if err != nil { return nil, err } @@ -299,7 +305,7 @@ func execDumpCommand( } }() - return kubeTask(ctx, cli, namespace, image, command, injectPostgresSecrets(secretName)) + return kubeTask(ctx, cli, namespace, postgresToolsImage, command, injectPostgresSecrets(secretName)) } func prepareCommand( @@ -314,11 +320,11 @@ func prepareCommand( backupID string, profile *param.Profile, dbEngineVersion string, -) ([]string, string, error) { +) ([]string, error) { // Convert profile object into json profileJSON, err := json.Marshal(profile) if err != nil { - return nil, "", err + return nil, err } if dbEngine == PostgrSQLEngine { @@ -328,17 +334,17 @@ func prepareCommand( if dbList == nil { dbList, err = findDBList(ctx, dbEndpoint, username, password) if err != nil { - return nil, "", err + return nil, err } } command, err := postgresBackupCommand(dbEndpoint, username, password, dbList, backupPrefix, backupID, profileJSON) - return command, postgresToolsImage, err + return command, err case RestoreAction: command, err := postgresRestoreCommand(dbEndpoint, username, password, backupPrefix, backupID, profileJSON, dbEngineVersion) - return command, postgresToolsImage, err + return command, err } } - return nil, "", errors.New("Invalid RDSDBEngine or RDSAction") + return nil, errors.New("Invalid RDSDBEngine or RDSAction") } func findDBList(ctx context.Context, dbEndpoint, username, password string) ([]string, error) { diff --git a/pkg/function/rds_functions_test.go b/pkg/function/rds_functions_test.go index d8e7becc06..b6a78c22df 100644 --- a/pkg/function/rds_functions_test.go +++ b/pkg/function/rds_functions_test.go @@ -128,7 +128,7 @@ func (s *RDSFunctionsTest) TestPrepareCommand(c *C) { } for _, tc := range testCases { - outCommand, _, err := prepareCommand(context.Background(), tc.dbEngine, tc.action, tc.dbEndpoint, tc.username, tc.password, tc.dbList, tc.backupPrefix, tc.backupID, tc.tp.Profile, tc.dbEngineVersion) + outCommand, err := prepareCommand(context.Background(), tc.dbEngine, tc.action, tc.dbEndpoint, tc.username, tc.password, tc.dbList, tc.backupPrefix, tc.backupID, tc.tp.Profile, tc.dbEngineVersion) c.Check(err, tc.errChecker, Commentf("Case %s failed", tc.name)) c.Assert(outCommand, DeepEquals, tc.command) diff --git a/pkg/function/restore_rds_snapshot.go b/pkg/function/restore_rds_snapshot.go index 33cdbd7deb..a9f3752d98 100644 --- a/pkg/function/restore_rds_snapshot.go +++ b/pkg/function/restore_rds_snapshot.go @@ -70,6 +70,8 @@ const ( RestoreRDSSnapshotUsername = "username" // RestoreRDSSnapshotPassword stores the password of the database RestoreRDSSnapshotPassword = "password" + // RestoreRDSSnapshotImage provides the image of the container with required tools + RestoreRDSSnapshotImage = "image" // PostgreSQLEngine stores the postgres appname PostgreSQLEngine RDSDBEngine = "PostgreSQL" @@ -119,7 +121,7 @@ func (r *restoreRDSSnapshotFunc) Exec(ctx context.Context, tp param.TemplatePara r.progressPercent = progress.StartedPercent defer func() { r.progressPercent = progress.CompletedPercent }() - var namespace, instanceID, subnetGroup, snapshotID, backupArtifactPrefix, backupID, username, password string + var namespace, instanceID, subnetGroup, snapshotID, backupArtifactPrefix, backupID, username, password, postgresToolsImage string var dbEngine RDSDBEngine if err := Arg(args, RestoreRDSSnapshotInstanceID, &instanceID); err != nil { @@ -136,6 +138,9 @@ func (r *restoreRDSSnapshotFunc) Exec(ctx context.Context, tp param.TemplatePara if err := OptArg(args, RestoreRDSSnapshotDBSubnetGroup, &subnetGroup, "default"); err != nil { return nil, err } + if err := OptArg(args, RestoreRDSSnapshotImage, &postgresToolsImage, defaultPostgresToolsImage); err != nil { + return nil, err + } // Find security groups sgIDs, err := GetYamlList(args, RestoreRDSSnapshotSecGrpID) if err != nil { @@ -162,7 +167,7 @@ func (r *restoreRDSSnapshotFunc) Exec(ctx context.Context, tp param.TemplatePara } } - return restoreRDSSnapshot(ctx, namespace, instanceID, subnetGroup, snapshotID, backupArtifactPrefix, backupID, username, password, dbEngine, sgIDs, tp.Profile) + return restoreRDSSnapshot(ctx, namespace, instanceID, subnetGroup, snapshotID, backupArtifactPrefix, backupID, username, password, dbEngine, sgIDs, tp.Profile, postgresToolsImage) } func (r *restoreRDSSnapshotFunc) ExecutionProgress() (crv1alpha1.PhaseProgress, error) { @@ -186,6 +191,7 @@ func restoreRDSSnapshot( dbEngine RDSDBEngine, sgIDs []string, profile *param.Profile, + postgresToolsImage string, ) (map[string]interface{}, error) { // Validate profile if err := ValidateProfile(profile); err != nil { @@ -233,7 +239,7 @@ func restoreRDSSnapshot( return nil, errors.Wrapf(err, "Couldn't find DBInstance Version") } - if _, err = execDumpCommand(ctx, dbEngine, RestoreAction, namespace, dbEndpoint, username, password, nil, backupArtifactPrefix, backupID, profile, dbEngineVersion); err != nil { + if _, err = execDumpCommand(ctx, dbEngine, RestoreAction, namespace, dbEndpoint, username, password, nil, backupArtifactPrefix, backupID, profile, dbEngineVersion, postgresToolsImage); err != nil { return nil, errors.Wrapf(err, "Failed to restore RDS from dump. InstanceID=%s", instanceID) } diff --git a/releasenotes/notes/postgress-tools-image-override-4882c70780e8a496.yaml b/releasenotes/notes/postgress-tools-image-override-4882c70780e8a496.yaml new file mode 100644 index 0000000000..8a2ccd56af --- /dev/null +++ b/releasenotes/notes/postgress-tools-image-override-4882c70780e8a496.yaml @@ -0,0 +1,2 @@ +--- +features: Support ``image`` argument for ``ExportRDSSnapshotToLocation`` and ``RestoreRDSSnapshot`` functions to override default postgres-kanister-tools image.