in frontend/pkg/frontend/ocm.go [112:196]
func ConvertCStoHCPOpenShiftCluster(resourceID *azcorearm.ResourceID, cluster *arohcpv1alpha1.Cluster) *api.HCPOpenShiftCluster {
// A word about ProvisioningState:
// ProvisioningState is stored in Cosmos and is applied to the
// HCPOpenShiftCluster struct along with the ARM metadata that
// is also stored in Cosmos. We could convert the ClusterState
// from Cluster Service to a ProvisioningState, but instead we
// defer that to the backend pod so that the ProvisioningState
// stays consistent with the Status of any active non-terminal
// operation on the cluster.
hcpcluster := &api.HCPOpenShiftCluster{
TrackedResource: arm.TrackedResource{
Location: cluster.Region().ID(),
Resource: arm.Resource{
ID: resourceID.String(),
Name: resourceID.Name,
Type: resourceID.ResourceType.String(),
},
},
Properties: api.HCPOpenShiftClusterProperties{
Version: api.VersionProfile{
ID: cluster.Version().ID(),
ChannelGroup: cluster.Version().ChannelGroup(),
AvailableUpgrades: cluster.Version().AvailableUpgrades(),
},
DNS: api.DNSProfile{
BaseDomain: cluster.DNS().BaseDomain(),
BaseDomainPrefix: cluster.DomainPrefix(),
},
Network: api.NetworkProfile{
NetworkType: api.NetworkType(cluster.Network().Type()),
PodCIDR: cluster.Network().PodCIDR(),
ServiceCIDR: cluster.Network().ServiceCIDR(),
MachineCIDR: cluster.Network().MachineCIDR(),
HostPrefix: int32(cluster.Network().HostPrefix()),
},
Console: api.ConsoleProfile{
URL: cluster.Console().URL(),
},
API: api.APIProfile{
URL: cluster.API().URL(),
Visibility: convertListeningToVisibility(cluster.API().Listening()),
},
Platform: api.PlatformProfile{
ManagedResourceGroup: cluster.Azure().ManagedResourceGroupName(),
SubnetID: cluster.Azure().SubnetResourceID(),
OutboundType: convertOutboundTypeCSToRP(cluster.Azure().NodesOutboundConnectivity().OutboundType()),
NetworkSecurityGroupID: cluster.Azure().NetworkSecurityGroupResourceID(),
IssuerURL: "",
},
Capabilities: convertClusterCapabilitiesToRP(cluster),
},
}
// Each managed identity retrieved from Cluster Service needs to be added
// to the HCPOpenShiftCluster in two places:
// - The top-level Identity.UserAssignedIdentities map will need both the
// resourceID (as keys) and principal+client IDs (as values).
// - The operator-specific maps under OperatorsAuthentication mimics the
// Cluster Service maps but just has operator-to-resourceID pairings.
if cluster.Azure().OperatorsAuthentication() != nil {
if mi, ok := cluster.Azure().OperatorsAuthentication().GetManagedIdentities(); ok {
hcpcluster.Identity.UserAssignedIdentities = make(map[string]*arm.UserAssignedIdentity)
hcpcluster.Properties.Platform.OperatorsAuthentication.UserAssignedIdentities.ControlPlaneOperators = make(map[string]string)
hcpcluster.Properties.Platform.OperatorsAuthentication.UserAssignedIdentities.DataPlaneOperators = make(map[string]string)
for operatorName, operatorIdentity := range mi.ControlPlaneOperatorsManagedIdentities() {
clientID, _ := operatorIdentity.GetClientID()
principalID, _ := operatorIdentity.GetPrincipalID()
hcpcluster.Identity.UserAssignedIdentities[operatorIdentity.ResourceID()] = &arm.UserAssignedIdentity{ClientID: &clientID,
PrincipalID: &principalID}
hcpcluster.Properties.Platform.OperatorsAuthentication.UserAssignedIdentities.ControlPlaneOperators[operatorName] = operatorIdentity.ResourceID()
}
for operatorName, operatorIdentity := range mi.DataPlaneOperatorsManagedIdentities() {
// Skip adding to hcpcluster.Identity.UserAssignedIdentities map as it is not needed for the dataplane operator MIs.
hcpcluster.Properties.Platform.OperatorsAuthentication.UserAssignedIdentities.DataPlaneOperators[operatorName] = operatorIdentity.ResourceID()
}
clientID, _ := mi.ServiceManagedIdentity().GetClientID()
principalID, _ := mi.ServiceManagedIdentity().GetPrincipalID()
hcpcluster.Identity.UserAssignedIdentities[mi.ServiceManagedIdentity().ResourceID()] = &arm.UserAssignedIdentity{ClientID: &clientID,
PrincipalID: &principalID}
hcpcluster.Properties.Platform.OperatorsAuthentication.UserAssignedIdentities.ServiceManagedIdentity = mi.ServiceManagedIdentity().ResourceID()
}
}
return hcpcluster
}