-
Notifications
You must be signed in to change notification settings - Fork 713
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Kartikay <[email protected]>
- Loading branch information
1 parent
c176aa8
commit 09b3b07
Showing
14 changed files
with
187 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
chaoscenter/upgrade-agents/control-plane/versions/v2.4.0/manager.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
chaoscenter/upgrade-agents/control-plane/versions/v2.6.0/manager.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 17 additions & 22 deletions
39
chaoscenter/upgrade-agents/control-plane/versions/v3.4.0/manager.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,26 @@ | ||
package v3_4_0 | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"go.mongodb.org/mongo-driver/bson" | ||
log "github.com/sirupsen/logrus" | ||
"go.mongodb.org/mongo-driver/mongo" | ||
"go.mongodb.org/mongo-driver/mongo/options" | ||
"go.uber.org/zap" | ||
) | ||
|
||
// upgradeWorkflowCollection updated the index related changes in workflow-collection | ||
func upgradeWorkflowCollection(logger *zap.Logger, dbClient *mongo.Client) error { | ||
workflowCollection := dbClient.Database("litmus").Collection("environment") | ||
|
||
//delete the existing workflow_name index | ||
_, err := workflowCollection.Indexes().DropOne(context.Background(), "environment_id") | ||
if err != nil { | ||
fmt.Errorf("error: %w", err) | ||
} | ||
// VersionManager implements IVersionManger | ||
type VersionManager struct { | ||
Logger *log.Logger | ||
DBClient *mongo.Client | ||
} | ||
|
||
//create a new workflow index with partial filter expression | ||
_, err = workflowCollection.Indexes().CreateOne(context.Background(), | ||
mongo.IndexModel{Keys: bson.M{"environment_id": 1}, | ||
Options: options.Index().SetUnique(true).SetPartialFilterExpression(bson.D{{ | ||
"isRemoved", false, | ||
}})}) | ||
// NewVersionManger provides a new instance of a new VersionManager | ||
func NewVersionManger(logger *log.Logger, dbClient *mongo.Client) *VersionManager { | ||
return &VersionManager{Logger: logger, DBClient: dbClient} | ||
} | ||
|
||
return err | ||
// Run executes all the steps required for the Version Manger | ||
// to upgrade from the previous version to `this` version | ||
func (vm VersionManager) Run() error { | ||
if err := upgradeExecutor(vm.Logger, vm.DBClient); err != nil { | ||
return nil | ||
} | ||
return nil | ||
} |
47 changes: 30 additions & 17 deletions
47
chaoscenter/upgrade-agents/control-plane/versions/v3.4.0/upgrade.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,39 @@ | ||
package v3_4_0 | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"go.mongodb.org/mongo-driver/bson" | ||
"go.mongodb.org/mongo-driver/mongo" | ||
"go.uber.org/zap" | ||
) | ||
"go.mongodb.org/mongo-driver/mongo/options" | ||
|
||
// VersionManager implements IVersionManger | ||
type VersionManager struct { | ||
Logger *zap.Logger | ||
DBClient *mongo.Client | ||
} | ||
log "github.com/sirupsen/logrus" | ||
) | ||
|
||
// NewVersionManger provides a new instance of a new VersionManager | ||
func NewVersionManger(logger *zap.Logger, dbClient *mongo.Client) *VersionManager { | ||
return &VersionManager{Logger: logger, DBClient: dbClient} | ||
} | ||
func upgradeExecutor(logger *log.Logger, dbClient *mongo.Client) error { | ||
workflowCollection := dbClient.Database("litmus").Collection("environment") | ||
|
||
// Run executes all the steps required for the Version Manger | ||
// to upgrade from the previous version to `this` version | ||
func (vm VersionManager) Run() error { | ||
if err := upgradeWorkflowCollection(vm.Logger, vm.DBClient); err != nil { | ||
return nil | ||
//delete the existing workflow_name index | ||
_, err := workflowCollection.Indexes().DropOne(context.Background(), "environment_id") | ||
if err != nil { | ||
fmt.Errorf("error: %w", err) | ||
} | ||
return nil | ||
|
||
logger.WithFields(log.Fields{ | ||
"version": "3.4.0", | ||
}).Info("Deleted an existing index environment while upgrading to intermediate v3.4.0") | ||
|
||
//create a new workflow index with partial filter expression | ||
_, err = workflowCollection.Indexes().CreateOne(context.Background(), | ||
mongo.IndexModel{Keys: bson.M{"environment_id": 1}, | ||
Options: options.Index().SetUnique(true).SetPartialFilterExpression(bson.D{{ | ||
"isRemoved", false, | ||
}})}) | ||
|
||
log.WithFields(log.Fields{ | ||
"version": "3.4.0", | ||
}).Info("Created a new index with partial filter expresion environment_id while upgrading to intermediate v3.4.0") | ||
|
||
return err | ||
} |
Oops, something went wrong.