Skip to content

Commit 0e9e40d

Browse files
Merge pull request #3825 from Azure/revert-3787-cs-97-pull-in-cluster-service-data
Revert "Migrate all clusters, nodepools, and externalauth to contain all fields"
2 parents 31701d9 + 4c2a702 commit 0e9e40d

File tree

54 files changed

+316
-1415
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+316
-1415
lines changed

frontend/pkg/frontend/cluster.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -818,17 +818,13 @@ func mergeToInternalCluster(csCluster *arohcpv1alpha1.Cluster, internalCluster *
818818
// merges the states together, and returns the internal representation.
819819
// TODO remove the header it takes and collapse that to some general error handling.
820820
func (f *Frontend) readInternalClusterFromClusterService(ctx context.Context, oldInternalCluster *api.HCPOpenShiftCluster) (*api.HCPOpenShiftCluster, error) {
821-
return readInternalClusterFromClusterService(ctx, f.clusterServiceClient, oldInternalCluster, f.azureLocation)
822-
}
823-
824-
func readInternalClusterFromClusterService(ctx context.Context, clusterServiceClient ocm.ClusterServiceClientSpec, oldInternalCluster *api.HCPOpenShiftCluster, azureLocation string) (*api.HCPOpenShiftCluster, error) {
825-
oldClusterServiceCluster, err := clusterServiceClient.GetCluster(ctx, oldInternalCluster.ServiceProviderProperties.ClusterServiceID)
821+
oldClusterServiceCluster, err := f.clusterServiceClient.GetCluster(ctx, oldInternalCluster.ServiceProviderProperties.ClusterServiceID)
826822
if err != nil {
827823
return nil, utils.TrackError(err)
828824
}
829825

830826
// TODO this overwrite will transformed into a "set" function as we transition fields to ownership in cosmos
831-
oldInternalCluster, err = mergeToInternalCluster(oldClusterServiceCluster, oldInternalCluster, azureLocation)
827+
oldInternalCluster, err = mergeToInternalCluster(oldClusterServiceCluster, oldInternalCluster, f.azureLocation)
832828
if err != nil {
833829
return nil, utils.TrackError(err)
834830
}

frontend/pkg/frontend/external_auth.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -723,11 +723,7 @@ func (f *Frontend) getInternalExternalAuthFromStorage(ctx context.Context, resou
723723
// readInternalExternalAuthFromClusterService takes an internal ExternalAuth read from cosmos, retrieves the corresponding cluster-service data,
724724
// merges the states together, and returns the internal representation.
725725
func (f *Frontend) readInternalExternalAuthFromClusterService(ctx context.Context, oldInternalExternalAuth *api.HCPOpenShiftClusterExternalAuth) (*api.HCPOpenShiftClusterExternalAuth, error) {
726-
return readInternalExternalAuthFromClusterService(ctx, f.clusterServiceClient, oldInternalExternalAuth, f.azureLocation)
727-
}
728-
729-
func readInternalExternalAuthFromClusterService(ctx context.Context, clusterServiceClient ocm.ClusterServiceClientSpec, oldInternalExternalAuth *api.HCPOpenShiftClusterExternalAuth, azureLocation string) (*api.HCPOpenShiftClusterExternalAuth, error) {
730-
oldClusterServiceExternalAuth, err := clusterServiceClient.GetExternalAuth(ctx, oldInternalExternalAuth.ServiceProviderProperties.ClusterServiceID)
726+
oldClusterServiceExternalAuth, err := f.clusterServiceClient.GetExternalAuth(ctx, oldInternalExternalAuth.ServiceProviderProperties.ClusterServiceID)
731727
if err != nil {
732728
return nil, utils.TrackError(err)
733729
}

frontend/pkg/frontend/frontend.go

Lines changed: 83 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ func (f *Frontend) Run(ctx context.Context, stop <-chan struct{}) {
139139
// before we start the http handler (this should ensure we readiness checks until this is complete), we will do a cosmos
140140
// data migration to our new storage keys.
141141
logger.Info("starting cosmos data migration")
142-
MigrateCosmosOrDie(ctx, f.dbClient, f.clusterServiceClient, f.azureLocation)
142+
MigrateCosmosOrDie(ctx, f.dbClient)
143143
logger.Info("completed cosmos data migration")
144144

145145
logger.Info(fmt.Sprintf("listening on %s", f.listener.Addr().String()))
@@ -163,6 +163,88 @@ func (f *Frontend) Run(ctx context.Context, stop <-chan struct{}) {
163163
}
164164
}
165165

166+
// MigrateCosmosOrDie if migration fails, we panic and exit the process. This makes it very detectable.
167+
func MigrateCosmosOrDie(ctx context.Context, cosmosClient database.DBClient) {
168+
// This is a temporary change. Once deployed to production, we will remove this content and leave it empty
169+
// for the next small migration we need to do. Once datasets are large, we will start doing this inside of the backend.
170+
171+
subscriptionIterator, err := cosmosClient.Subscriptions().List(ctx, nil)
172+
if err != nil {
173+
panic(err)
174+
}
175+
for _, subscription := range subscriptionIterator.Items(ctx) {
176+
if _, err := cosmosClient.Subscriptions().Get(ctx, subscription.ResourceID.Name); err != nil {
177+
panic(err)
178+
}
179+
}
180+
if err := subscriptionIterator.GetError(); err != nil {
181+
panic(err)
182+
}
183+
184+
subscriptionIterator, err = cosmosClient.Subscriptions().List(ctx, nil)
185+
if err != nil {
186+
panic(err)
187+
}
188+
for _, subscription := range subscriptionIterator.Items(ctx) {
189+
clusterIterator, err := cosmosClient.HCPClusters(subscription.ResourceID.Name, "").List(ctx, nil)
190+
if err != nil {
191+
panic(err)
192+
}
193+
for _, cluster := range clusterIterator.Items(ctx) {
194+
_, err := cosmosClient.HCPClusters(cluster.ID.SubscriptionID, cluster.ID.ResourceGroupName).Get(ctx, cluster.ID.Name)
195+
if err != nil {
196+
panic(err)
197+
}
198+
199+
nodePoolIterator, err := cosmosClient.HCPClusters(cluster.ID.SubscriptionID, cluster.ID.ResourceGroupName).NodePools(cluster.ID.Name).List(ctx, nil)
200+
if err != nil {
201+
panic(err)
202+
}
203+
for _, nodePool := range nodePoolIterator.Items(ctx) {
204+
_, err := cosmosClient.HCPClusters(nodePool.ID.SubscriptionID, nodePool.ID.ResourceGroupName).NodePools(nodePool.ID.Parent.Name).Get(ctx, nodePool.ID.Name)
205+
if err != nil {
206+
panic(err)
207+
}
208+
}
209+
if err := nodePoolIterator.GetError(); err != nil {
210+
panic(err)
211+
}
212+
213+
externalAuthIterator, err := cosmosClient.HCPClusters(cluster.ID.SubscriptionID, cluster.ID.ResourceGroupName).ExternalAuth(cluster.ID.Name).List(ctx, nil)
214+
if err != nil {
215+
panic(err)
216+
}
217+
for _, externalAuth := range externalAuthIterator.Items(ctx) {
218+
_, err := cosmosClient.HCPClusters(externalAuth.ID.SubscriptionID, externalAuth.ID.ResourceGroupName).ExternalAuth(externalAuth.ID.Parent.Name).Get(ctx, externalAuth.ID.Name)
219+
if err != nil {
220+
panic(err)
221+
}
222+
}
223+
if err := externalAuthIterator.GetError(); err != nil {
224+
panic(err)
225+
}
226+
}
227+
if err := clusterIterator.GetError(); err != nil {
228+
panic(err)
229+
}
230+
231+
operationIterator, err := cosmosClient.Operations(subscription.ResourceID.Name).List(ctx, nil)
232+
if err != nil {
233+
panic(err)
234+
}
235+
for _, operation := range operationIterator.Items(ctx) {
236+
_, err := cosmosClient.Operations(operation.ResourceID.SubscriptionID).Get(ctx, operation.ResourceID.Name)
237+
if err != nil {
238+
panic(err)
239+
}
240+
}
241+
if err := operationIterator.GetError(); err != nil {
242+
panic(err)
243+
}
244+
}
245+
246+
}
247+
166248
func (f *Frontend) Join() {
167249
<-f.done
168250
}

frontend/pkg/frontend/migrate_cosmos.go

Lines changed: 0 additions & 172 deletions
This file was deleted.

frontend/pkg/frontend/node_pool.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -771,17 +771,13 @@ func (f *Frontend) getInternalNodePoolFromStorage(ctx context.Context, resourceI
771771
// readInternalNodePoolFromClusterService takes an internal NodePool read from cosmos, retrieves the corresponding cluster-service data,
772772
// merges the states together, and returns the internal representation.
773773
func (f *Frontend) readInternalNodePoolFromClusterService(ctx context.Context, oldInternalNodePool *api.HCPOpenShiftClusterNodePool) (*api.HCPOpenShiftClusterNodePool, error) {
774-
return readInternalNodePoolFromClusterService(ctx, f.clusterServiceClient, oldInternalNodePool, f.azureLocation)
775-
}
776-
777-
func readInternalNodePoolFromClusterService(ctx context.Context, clusterServiceClient ocm.ClusterServiceClientSpec, oldInternalNodePool *api.HCPOpenShiftClusterNodePool, azureLocation string) (*api.HCPOpenShiftClusterNodePool, error) {
778-
oldClusterServiceNodePool, err := clusterServiceClient.GetNodePool(ctx, oldInternalNodePool.ServiceProviderProperties.ClusterServiceID)
774+
oldClusterServiceNodePool, err := f.clusterServiceClient.GetNodePool(ctx, oldInternalNodePool.ServiceProviderProperties.ClusterServiceID)
779775
if err != nil {
780776
return nil, utils.TrackError(err)
781777
}
782778

783779
// TODO this overwrite will transformed into a "set" function as we transition fields to ownership in cosmos
784-
oldInternalNodePool, err = mergeToInternalNodePool(oldClusterServiceNodePool, oldInternalNodePool, azureLocation)
780+
oldInternalNodePool, err = mergeToInternalNodePool(oldClusterServiceNodePool, oldInternalNodePool, f.azureLocation)
785781
if err != nil {
786782
return nil, utils.TrackError(err)
787783
}

internal/database/convert_cluster.go

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
package database
1616

1717
import (
18-
"fmt"
1918
"strings"
2019

2120
"github.com/Azure/ARO-HCP/internal/api"
@@ -37,7 +36,7 @@ func InternalToCosmosCluster(internalObj *api.HCPOpenShiftCluster) (*HCPCluster,
3736
ResourceType: internalObj.ID.ResourceType.String(),
3837
},
3938
HCPClusterProperties: HCPClusterProperties{
40-
ResourceDocument: &ResourceDocument{
39+
ResourceDocument: ResourceDocument{
4140
ResourceID: internalObj.ID,
4241
InternalID: internalObj.ServiceProviderProperties.ClusterServiceID,
4342
ActiveOperationID: internalObj.ServiceProviderProperties.ActiveOperationID,
@@ -51,7 +50,6 @@ func InternalToCosmosCluster(internalObj *api.HCPOpenShiftCluster) (*HCPCluster,
5150
},
5251
},
5352
}
54-
cosmosObj.IntermediateResourceDoc = cosmosObj.ResourceDocument
5553

5654
// some pieces of data in the internalCluster conflict with ResourceDocument fields. We may evolve over time, but for
5755
// now avoid persisting those.
@@ -118,35 +116,28 @@ func CosmosToInternalCluster(cosmosObj *HCPCluster) (*api.HCPOpenShiftCluster, e
118116
if cosmosObj == nil {
119117
return nil, nil
120118
}
121-
resourceDoc := cosmosObj.ResourceDocument
122-
if resourceDoc == nil {
123-
resourceDoc = cosmosObj.IntermediateResourceDoc
124-
}
125-
if resourceDoc == nil {
126-
return nil, fmt.Errorf("resource document cannot be nil")
127-
}
128119

129120
tempInternalAPI := cosmosObj.InternalState.InternalAPI
130121
internalObj := &tempInternalAPI
131122

132123
// some pieces of data are stored on the ResourceDocument, so we need to restore that data
133124
internalObj.TrackedResource = arm.TrackedResource{
134125
Resource: arm.Resource{
135-
ID: resourceDoc.ResourceID,
136-
Name: resourceDoc.ResourceID.Name,
137-
Type: resourceDoc.ResourceID.ResourceType.String(),
138-
SystemData: resourceDoc.SystemData,
126+
ID: cosmosObj.ResourceID,
127+
Name: cosmosObj.ResourceID.Name,
128+
Type: cosmosObj.ResourceID.ResourceType.String(),
129+
SystemData: cosmosObj.SystemData,
139130
},
140131
Location: cosmosObj.InternalState.InternalAPI.Location,
141-
Tags: resourceDoc.Tags,
132+
Tags: cosmosObj.Tags,
142133
}
143-
internalObj.Identity = toInternalIdentity(resourceDoc.Identity)
144-
internalObj.SystemData = resourceDoc.SystemData
145-
internalObj.Tags = copyTags(resourceDoc.Tags)
146-
internalObj.ServiceProviderProperties.ProvisioningState = resourceDoc.ProvisioningState
134+
internalObj.Identity = toInternalIdentity(cosmosObj.Identity)
135+
internalObj.SystemData = cosmosObj.SystemData
136+
internalObj.Tags = copyTags(cosmosObj.Tags)
137+
internalObj.ServiceProviderProperties.ProvisioningState = cosmosObj.ProvisioningState
147138
internalObj.ServiceProviderProperties.CosmosUID = cosmosObj.ID
148-
internalObj.ServiceProviderProperties.ClusterServiceID = resourceDoc.InternalID
149-
internalObj.ServiceProviderProperties.ActiveOperationID = resourceDoc.ActiveOperationID
139+
internalObj.ServiceProviderProperties.ClusterServiceID = cosmosObj.InternalID
140+
internalObj.ServiceProviderProperties.ActiveOperationID = cosmosObj.ActiveOperationID
150141

151142
// This is not the place for validation, but during such a transition we need to ensure we fail quickly and certainly
152143
// This flow happens when reading both old and new data. The old data should *always* have the internalID set

0 commit comments

Comments
 (0)