Skip to content

Commit

Permalink
update routes after cluster reassignment
Browse files Browse the repository at this point in the history
  • Loading branch information
johannes94 committed Oct 8, 2024
1 parent c73b10d commit 678895b
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 31 deletions.
14 changes: 8 additions & 6 deletions internal/dinosaur/pkg/services/dinosaur.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ var (
// CentralRoutesAction ...
type CentralRoutesAction string

// CentralRoutesActionCreate ...
const CentralRoutesActionCreate CentralRoutesAction = "CREATE"
// CentralRoutesActionUpsert ...
const CentralRoutesActionUpsert CentralRoutesAction = "UPSERT"

// CentralRoutesActionDelete ...
const CentralRoutesActionDelete CentralRoutesAction = "DELETE"
Expand Down Expand Up @@ -899,13 +899,15 @@ func (k *dinosaurService) AssignCluster(ctx context.Context, centralID string, c
central.ClusterID = clusterID
central.RoutesCreated = false
central.Routes = nil
central.RoutesCreationID = ""
central.Status = dinosaurConstants.CentralRequestStatusProvisioning.String()

return k.Updates(central, map[string]interface{}{
"cluster_id": central.ClusterID,
"routes_created": central.RoutesCreated,
"routes": central.Routes,
"status": central.Status,
"cluster_id": central.ClusterID,
"routes_created": central.RoutesCreated,
"routes": central.Routes,
"status": central.Status,
"routes_creation_id": central.RoutesCreationID,
})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (k *CentralRoutesCNAMEManager) Reconcile() []error {
if central.RoutesCreationID == "" {
glog.Infof("creating CNAME records for central %s", central.ID)

changeOutput, err := k.centralService.ChangeCentralCNAMErecords(central, services.CentralRoutesActionCreate)
changeOutput, err := k.centralService.ChangeCentralCNAMErecords(central, services.CentralRoutesActionUpsert)

if err != nil {
errs = append(errs, err)
Expand Down
51 changes: 27 additions & 24 deletions internal/dinosaur/test/integration/admin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,32 +44,34 @@ func TestAssignCluster(t *testing.T) {

centrals := []*dbapi.CentralRequest{
{
MultiAZ: clusters[0].MultiAZ,
Owner: "assigclusteruser1",
Region: clusters[0].Region,
CloudProvider: clusters[0].CloudProvider,
Name: "assign-cluster-central",
OrganisationID: orgID,
Status: constants2.CentralRequestStatusReady.String(),
InstanceType: clusters[0].SupportedInstanceType,
ClusterID: clusters[0].ClusterID,
Meta: api.Meta{ID: api.NewID()},
RoutesCreated: true,
Routes: dummyRoutesJSON,
MultiAZ: clusters[0].MultiAZ,
Owner: "assigclusteruser1",
Region: clusters[0].Region,
CloudProvider: clusters[0].CloudProvider,
Name: "assign-cluster-central",
OrganisationID: orgID,
Status: constants2.CentralRequestStatusReady.String(),
InstanceType: clusters[0].SupportedInstanceType,
ClusterID: clusters[0].ClusterID,
Meta: api.Meta{ID: api.NewID()},
RoutesCreated: true,
Routes: dummyRoutesJSON,
RoutesCreationID: "dummy-route-creation-id",
},
{
MultiAZ: clusters[0].MultiAZ,
Owner: "assigclusteruser2",
Region: clusters[0].Region,
CloudProvider: clusters[0].CloudProvider,
Name: "assign-cluster-central-2",
OrganisationID: orgID,
Status: constants2.CentralRequestStatusReady.String(),
InstanceType: clusters[0].SupportedInstanceType,
ClusterID: clusters[0].ClusterID,
Meta: api.Meta{ID: api.NewID()},
RoutesCreated: true,
Routes: dummyRoutesJSON,
MultiAZ: clusters[0].MultiAZ,
Owner: "assigclusteruser2",
Region: clusters[0].Region,
CloudProvider: clusters[0].CloudProvider,
Name: "assign-cluster-central-2",
OrganisationID: orgID,
Status: constants2.CentralRequestStatusReady.String(),
InstanceType: clusters[0].SupportedInstanceType,
ClusterID: clusters[0].ClusterID,
Meta: api.Meta{ID: api.NewID()},
RoutesCreated: true,
Routes: dummyRoutesJSON,
RoutesCreationID: "dummy-route-creation-id",
},
}

Expand Down Expand Up @@ -97,6 +99,7 @@ func TestAssignCluster(t *testing.T) {
require.Equal(t, "new-cluster-1234", cr.ClusterID, "ClusterID was not set properly.")
require.False(t, cr.RoutesCreated, "RoutesCreated shout be reset to false.")
require.Nil(t, cr.Routes, "Stored Routes content should be nil.")
require.Empty(t, cr.RoutesCreationID, "Stored RoutesCreationID should be reset to empty string")
require.Equal(t, constants2.CentralRequestStatusProvisioning.String(), cr.Status, "Status should change from ready to provisioning.")
}

Expand Down

0 comments on commit 678895b

Please sign in to comment.