Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 4 additions & 46 deletions internal/database/convert_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ func InternalToCosmosCluster(internalObj *api.HCPOpenShiftCluster) (*HCPCluster,
ResourceType: internalObj.ID.ResourceType.String(),
},
HCPClusterProperties: HCPClusterProperties{
HCPOpenShiftCluster: *internalObj,
CosmosMetadata: api.CosmosMetadata{
ResourceID: internalObj.ID,
},
Expand All @@ -47,7 +48,7 @@ func InternalToCosmosCluster(internalObj *api.HCPOpenShiftCluster) (*HCPCluster,
InternalID: ptr.Deref(internalObj.ServiceProviderProperties.ClusterServiceID, api.InternalID{}),
ActiveOperationID: internalObj.ServiceProviderProperties.ActiveOperationID,
ProvisioningState: internalObj.ServiceProviderProperties.ProvisioningState,
Identity: toCosmosIdentity(internalObj.Identity),
Identity: internalObj.Identity.DeepCopy(),
SystemData: internalObj.SystemData,
Tags: copyTags(internalObj.Tags),
},
Expand All @@ -57,52 +58,9 @@ func InternalToCosmosCluster(internalObj *api.HCPOpenShiftCluster) (*HCPCluster,
},
}

// some pieces of data in the internalCluster conflict with ResourceDocument fields. We may evolve over time, but for
// now avoid persisting those.
cosmosObj.InternalState.InternalAPI.TrackedResource = arm.TrackedResource{
Location: internalObj.Location, // this is the only TrackedResource value not present elsewhere in ResourceDcoument
}
cosmosObj.InternalState.InternalAPI.Identity = nil
cosmosObj.InternalState.InternalAPI.SystemData = nil
cosmosObj.InternalState.InternalAPI.Tags = nil
cosmosObj.InternalState.InternalAPI.ServiceProviderProperties.ProvisioningState = ""
// we do this to keep serialization the same so that we can go to n-1 where this field isn't a pointer.
// on the reading side, we handle the pointer as expected.
cosmosObj.InternalState.InternalAPI.ServiceProviderProperties.ClusterServiceID = &api.InternalID{}
cosmosObj.InternalState.InternalAPI.ServiceProviderProperties.ActiveOperationID = ""

return cosmosObj, nil
}

func toCosmosIdentity(src *arm.ManagedServiceIdentity) *arm.ManagedServiceIdentity {
if src == nil {
return nil
}
tempIdentity := *src
if src.UserAssignedIdentities != nil {
tempIdentity.UserAssignedIdentities = make(map[string]*arm.UserAssignedIdentity, len(src.UserAssignedIdentities))
for k, v := range src.UserAssignedIdentities {
if v != nil {
tempIdentity.UserAssignedIdentities[k] = v.DeepCopy()
} else {
tempIdentity.UserAssignedIdentities[k] = nil
}
}
}
return &tempIdentity
}

func toInternalIdentity(src *arm.ManagedServiceIdentity) *arm.ManagedServiceIdentity {
if src == nil {
return nil
}

// at this point we still haven't restored the UserAssignedIdentities values, only the keys. The values are looked up on azure somehow in the frontend
// this means that backend reads lack this data
tempIdentity := *src
return &tempIdentity
}

func copyTags(src map[string]string) map[string]string {
if src == nil {
return nil
Expand Down Expand Up @@ -141,8 +99,8 @@ func CosmosToInternalCluster(cosmosObj *HCPCluster) (*api.HCPOpenShiftCluster, e
// we carry over the CosmosETag from the cosmos object to the internal object into a
// temporary field until we have inlined and serialized CosmosMetadata in
// HCPOpenShiftCluster.
internalObj.CosmosETag = cosmosObj.CosmosETag
internalObj.Identity = toInternalIdentity(resourceDoc.Identity)
internalObj.CosmosETag = cosmosObj.BaseDocument.CosmosETag
internalObj.Identity = resourceDoc.Identity.DeepCopy()
internalObj.SystemData = resourceDoc.SystemData
internalObj.Tags = copyTags(resourceDoc.Tags)
internalObj.ServiceProviderProperties.ExistingCosmosUID = cosmosObj.ID
Expand Down
4 changes: 2 additions & 2 deletions internal/database/convert_nodepool.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func InternalToCosmosNodePool(internalObj *api.HCPOpenShiftClusterNodePool) (*No
InternalID: internalObj.ServiceProviderProperties.ClusterServiceID,
ActiveOperationID: internalObj.ServiceProviderProperties.ActiveOperationID,
ProvisioningState: internalObj.Properties.ProvisioningState,
Identity: toCosmosIdentity(internalObj.Identity),
Identity: internalObj.Identity.DeepCopy(),
SystemData: internalObj.SystemData,
Tags: copyTags(internalObj.Tags),
},
Expand Down Expand Up @@ -98,7 +98,7 @@ func CosmosToInternalNodePool(cosmosObj *NodePool) (*api.HCPOpenShiftClusterNode
// temporary field until we have inlined and serialized CosmosMetadata in
// HCPOpenShiftClusterNodePool.
internalObj.CosmosETag = cosmosObj.CosmosETag
internalObj.Identity = toInternalIdentity(resourceDoc.Identity)
internalObj.Identity = resourceDoc.Identity.DeepCopy()
internalObj.Properties.ProvisioningState = resourceDoc.ProvisioningState
internalObj.SystemData = resourceDoc.SystemData
internalObj.Tags = copyTags(resourceDoc.Tags)
Expand Down
8 changes: 7 additions & 1 deletion internal/database/types_hcpcluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,14 @@ type HCPCluster struct {
}

type HCPClusterProperties struct {
// HCPOpenShiftCluster is where we're migrating to. It is compatible with a GenericDocument[api.HCPOpenShiftCluster]
// which is where we want to end up.
// * to be compatible with prior versions, we must continue writing all previous fields and this new field
// * to be compatible with prior versions, we must continue reading only from previous fields
api.HCPOpenShiftCluster `json:",inline"`

// when we switch to inlining the internalObj, this will be in the right spot. We add it now so that we can switch our
// queries to select on cosmosMetata.ResourceID instead of resourceId
// queries to select on cosmosMetadata.ResourceID instead of resourceId
CosmosMetadata api.CosmosMetadata `json:"cosmosMetadata"`

// IntermediateResourceDoc exists so that we can stop inlining the resource document so that we can directly
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
"id": "68bc6026-a8a9-5706-92c5-25d3313bcabb",
"partitionKey": "0465bc32-c654-41b8-8d87-9815d7abe8f6",
"properties": {
"cosmosMetadata": {
"resourceID": "/subscriptions/0465bc32-c654-41b8-8d87-9815d7abe8f6/resourceGroups/some-resource-group/providers/Microsoft.RedHatOpenShift/hcpOpenShiftClusters/some-hcp-cluster"
},
"id": "/subscriptions/0465bc32-c654-41b8-8d87-9815d7abe8f6/resourceGroups/some-resource-group/providers/Microsoft.RedHatOpenShift/hcpOpenShiftClusters/some-hcp-cluster",
"identity": {
"type": "UserAssigned"
},
"intermediateResourceDoc": {
"identity": {
"type": "UserAssigned"
Expand All @@ -16,12 +23,33 @@
},
"internalState": {
"internalAPI": {
"id": "/subscriptions/0465bc32-c654-41b8-8d87-9815d7abe8f6/resourceGroups/some-resource-group/providers/Microsoft.RedHatOpenShift/hcpOpenShiftClusters/some-hcp-cluster",
"identity": {
"type": "UserAssigned"
},
"location": "eastus",
"name": "some-hcp-cluster",
"serviceProviderProperties": {
"clusterServiceID": ""
}
"clusterServiceID": "/api/aro_hcp/v1alpha1/clusters/fixed-value",
"provisioningState": "Succeeded"
},
"tags": {
"foo": "bar"
},
"type": "Microsoft.RedHatOpenShift/hcpOpenShiftClusters"
}
}
},
"location": "eastus",
"name": "some-hcp-cluster",
"serviceProviderProperties": {
"clusterServiceID": "/api/aro_hcp/v1alpha1/clusters/fixed-value",
"provisioningState": "Succeeded"
},
"tags": {
"foo": "bar"
},
"type": "Microsoft.RedHatOpenShift/hcpOpenShiftClusters"
},
"resourceID": "/subscriptions/0465bc32-c654-41b8-8d87-9815d7abe8f6/resourceGroups/some-resource-group/providers/Microsoft.RedHatOpenShift/hcpOpenShiftClusters/some-hcp-cluster",
"resourceType": "Microsoft.RedHatOpenShift/hcpOpenShiftClusters"
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
"id": "68bc6026-a8a9-5706-92c5-25d3313bcabb",
"partitionKey": "0465bc32-c654-41b8-8d87-9815d7abe8f6",
"properties": {
"cosmosMetadata": {
"resourceID": "/subscriptions/0465bc32-c654-41b8-8d87-9815d7abe8f6/resourceGroups/some-resource-group/providers/Microsoft.RedHatOpenShift/hcpOpenShiftClusters/some-hcp-cluster"
},
"id": "/subscriptions/0465bc32-c654-41b8-8d87-9815d7abe8f6/resourceGroups/some-resource-group/providers/Microsoft.RedHatOpenShift/hcpOpenShiftClusters/some-hcp-cluster",
"identity": {
"type": "UserAssigned"
},
"intermediateResourceDoc": {
"identity": {
"type": "UserAssigned"
Expand All @@ -21,12 +28,44 @@
},
"internalState": {
"internalAPI": {
"id": "/subscriptions/0465bc32-c654-41b8-8d87-9815d7abe8f6/resourceGroups/some-resource-group/providers/Microsoft.RedHatOpenShift/hcpOpenShiftClusters/some-hcp-cluster",
"identity": {
"type": "UserAssigned"
},
"location": "eastus",
"name": "some-hcp-cluster",
"serviceProviderProperties": {
"clusterServiceID": ""
}
"clusterServiceID": "/api/aro_hcp/v1alpha1/clusters/fixed-value",
"provisioningState": "Succeeded"
},
"systemData": {
"createdBy": "Unknown-ARO-HCP-frontend",
"createdByType": "Application",
"lastModifiedBy": "Unknown-ARO-HCP-frontend",
"lastModifiedByType": "Application"
},
"tags": {
"foo": "bar"
},
"type": "Microsoft.RedHatOpenShift/hcpOpenShiftClusters"
}
}
},
"location": "eastus",
"name": "some-hcp-cluster",
"serviceProviderProperties": {
"clusterServiceID": "/api/aro_hcp/v1alpha1/clusters/fixed-value",
"provisioningState": "Succeeded"
},
"systemData": {
"createdBy": "Unknown-ARO-HCP-frontend",
"createdByType": "Application",
"lastModifiedBy": "Unknown-ARO-HCP-frontend",
"lastModifiedByType": "Application"
},
"tags": {
"foo": "bar"
},
"type": "Microsoft.RedHatOpenShift/hcpOpenShiftClusters"
},
"resourceID": "/subscriptions/0465bc32-c654-41b8-8d87-9815d7abe8f6/resourceGroups/some-resource-group/providers/Microsoft.RedHatOpenShift/hcpOpenShiftClusters/some-hcp-cluster",
"resourceType": "Microsoft.RedHatOpenShift/hcpOpenShiftClusters"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
"id": "68bc6026-a8a9-5706-92c5-25d3313bcabb",
"partitionKey": "0465bc32-c654-41b8-8d87-9815d7abe8f6",
"properties": {
"cosmosMetadata": {
"resourceID": "/subscriptions/0465bc32-c654-41b8-8d87-9815d7abe8f6/resourceGroups/some-resource-group/providers/Microsoft.RedHatOpenShift/hcpOpenShiftClusters/some-hcp-cluster"
},
"id": "/subscriptions/0465bc32-c654-41b8-8d87-9815d7abe8f6/resourceGroups/some-resource-group/providers/Microsoft.RedHatOpenShift/hcpOpenShiftClusters/some-hcp-cluster",
"identity": {
"type": "UserAssigned"
},
"intermediateResourceDoc": {
"identity": {
"type": "UserAssigned"
Expand All @@ -21,12 +28,44 @@
},
"internalState": {
"internalAPI": {
"id": "/subscriptions/0465bc32-c654-41b8-8d87-9815d7abe8f6/resourceGroups/some-resource-group/providers/Microsoft.RedHatOpenShift/hcpOpenShiftClusters/some-hcp-cluster",
"identity": {
"type": "UserAssigned"
},
"location": "eastus",
"name": "some-hcp-cluster",
"serviceProviderProperties": {
"clusterServiceID": ""
}
"clusterServiceID": "/api/aro_hcp/v1alpha1/clusters/fixed-value",
"provisioningState": "Succeeded"
},
"systemData": {
"createdBy": "Unknown-ARO-HCP-frontend",
"createdByType": "Application",
"lastModifiedBy": "Unknown-ARO-HCP-frontend",
"lastModifiedByType": "Application"
},
"tags": {
"foo": "bar"
},
"type": "Microsoft.RedHatOpenShift/hcpOpenShiftClusters"
}
}
},
"location": "eastus",
"name": "some-hcp-cluster",
"serviceProviderProperties": {
"clusterServiceID": "/api/aro_hcp/v1alpha1/clusters/fixed-value",
"provisioningState": "Succeeded"
},
"systemData": {
"createdBy": "Unknown-ARO-HCP-frontend",
"createdByType": "Application",
"lastModifiedBy": "Unknown-ARO-HCP-frontend",
"lastModifiedByType": "Application"
},
"tags": {
"foo": "bar"
},
"type": "Microsoft.RedHatOpenShift/hcpOpenShiftClusters"
},
"resourceID": "/subscriptions/0465bc32-c654-41b8-8d87-9815d7abe8f6/resourceGroups/some-resource-group/providers/Microsoft.RedHatOpenShift/hcpOpenShiftClusters/some-hcp-cluster",
"resourceType": "Microsoft.RedHatOpenShift/hcpOpenShiftClusters"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
"id": "68bc6026-a8a9-5706-92c5-25d3313bcabb",
"partitionKey": "0465bc32-c654-41b8-8d87-9815d7abe8f6",
"properties": {
"cosmosMetadata": {
"resourceID": "/subscriptions/0465bc32-c654-41b8-8d87-9815d7abe8f6/resourceGroups/some-resource-group/providers/Microsoft.RedHatOpenShift/hcpOpenShiftClusters/some-hcp-cluster"
},
"id": "/subscriptions/0465bc32-c654-41b8-8d87-9815d7abe8f6/resourceGroups/some-resource-group/providers/Microsoft.RedHatOpenShift/hcpOpenShiftClusters/some-hcp-cluster",
"identity": {
"type": "UserAssigned"
},
"intermediateResourceDoc": {
"identity": {
"type": "UserAssigned"
Expand All @@ -21,12 +28,44 @@
},
"internalState": {
"internalAPI": {
"id": "/subscriptions/0465bc32-c654-41b8-8d87-9815d7abe8f6/resourceGroups/some-resource-group/providers/Microsoft.RedHatOpenShift/hcpOpenShiftClusters/some-hcp-cluster",
"identity": {
"type": "UserAssigned"
},
"location": "eastus",
"name": "some-hcp-cluster",
"serviceProviderProperties": {
"clusterServiceID": ""
}
"clusterServiceID": "/api/aro_hcp/v1alpha1/clusters/fixed-value",
"provisioningState": "Succeeded"
},
"systemData": {
"createdBy": "Unknown-ARO-HCP-frontend",
"createdByType": "Application",
"lastModifiedBy": "Unknown-ARO-HCP-frontend",
"lastModifiedByType": "Application"
},
"tags": {
"foo": "bar"
},
"type": "Microsoft.RedHatOpenShift/hcpOpenShiftClusters"
}
}
},
"location": "eastus",
"name": "some-hcp-cluster",
"serviceProviderProperties": {
"clusterServiceID": "/api/aro_hcp/v1alpha1/clusters/fixed-value",
"provisioningState": "Succeeded"
},
"systemData": {
"createdBy": "Unknown-ARO-HCP-frontend",
"createdByType": "Application",
"lastModifiedBy": "Unknown-ARO-HCP-frontend",
"lastModifiedByType": "Application"
},
"tags": {
"foo": "bar"
},
"type": "Microsoft.RedHatOpenShift/hcpOpenShiftClusters"
},
"resourceID": "/subscriptions/0465bc32-c654-41b8-8d87-9815d7abe8f6/resourceGroups/some-resource-group/providers/Microsoft.RedHatOpenShift/hcpOpenShiftClusters/some-hcp-cluster",
"resourceType": "Microsoft.RedHatOpenShift/hcpOpenShiftClusters"
Expand Down
Loading
Loading