func()

in pkg/api/admin/openshiftcluster_convert.go [253:431]


func (c openShiftClusterConverter) ToInternal(_oc interface{}, out *api.OpenShiftCluster) {
	oc := _oc.(*OpenShiftCluster)

	out.ID = oc.ID
	out.Name = oc.Name
	out.Type = oc.Type
	out.Location = oc.Location
	out.Tags = nil
	if oc.Tags != nil {
		out.Tags = make(map[string]string, len(oc.Tags))
		for k, v := range oc.Tags {
			out.Tags[k] = v
		}
	}
	if oc.Identity != nil {
		out.Identity.Type = api.ManagedServiceIdentityType(oc.Identity.Type)
		out.Identity.PrincipalID = oc.Identity.PrincipalID
		out.Identity.TenantID = oc.Identity.TenantID
		out.Identity.UserAssignedIdentities = make(map[string]api.UserAssignedIdentity, len(oc.Identity.UserAssignedIdentities))
		for k := range oc.Identity.UserAssignedIdentities {
			var temp api.UserAssignedIdentity
			temp.ClientID = oc.Identity.UserAssignedIdentities[k].ClientID
			temp.PrincipalID = oc.Identity.UserAssignedIdentities[k].PrincipalID
			out.Identity.UserAssignedIdentities[k] = temp
		}
	}
	out.Properties.ArchitectureVersion = api.ArchitectureVersion(oc.Properties.ArchitectureVersion)
	out.Properties.InfraID = oc.Properties.InfraID
	out.Properties.HiveProfile.Namespace = oc.Properties.HiveProfile.Namespace
	out.Properties.HiveProfile.CreatedByHive = oc.Properties.HiveProfile.CreatedByHive
	out.Properties.ProvisioningState = api.ProvisioningState(oc.Properties.ProvisioningState)
	out.Properties.LastProvisioningState = api.ProvisioningState(oc.Properties.LastProvisioningState)
	out.Properties.FailedProvisioningState = api.ProvisioningState(oc.Properties.FailedProvisioningState)
	out.Properties.LastAdminUpdateError = oc.Properties.LastAdminUpdateError
	out.Properties.MaintenanceTask = api.MaintenanceTask(oc.Properties.MaintenanceTask)
	out.Properties.OperatorFlags = api.OperatorFlags(oc.Properties.OperatorFlags)
	out.Properties.OperatorVersion = oc.Properties.OperatorVersion
	out.Properties.CreatedBy = oc.Properties.CreatedBy
	out.Properties.ProvisionedBy = oc.Properties.ProvisionedBy
	out.Properties.MaintenanceState = api.MaintenanceState(oc.Properties.MaintenanceState)
	out.Properties.ClusterProfile.Domain = oc.Properties.ClusterProfile.Domain
	out.Properties.ClusterProfile.FipsValidatedModules = api.FipsValidatedModules(oc.Properties.ClusterProfile.FipsValidatedModules)
	out.Properties.ClusterProfile.Version = oc.Properties.ClusterProfile.Version
	out.Properties.ClusterProfile.ResourceGroupID = oc.Properties.ClusterProfile.ResourceGroupID
	out.Properties.FeatureProfile.GatewayEnabled = oc.Properties.FeatureProfile.GatewayEnabled
	out.Properties.ConsoleProfile.URL = oc.Properties.ConsoleProfile.URL
	if oc.Properties.ServicePrincipalProfile != nil {
		out.Properties.ServicePrincipalProfile = &api.ServicePrincipalProfile{
			ClientID:     oc.Properties.ServicePrincipalProfile.ClientID,
			SPObjectID:   oc.Properties.ServicePrincipalProfile.SPObjectID,
			ClientSecret: api.SecureString(oc.Properties.ServicePrincipalProfile.ClientSecret),
		}
	}
	if oc.Properties.PlatformWorkloadIdentityProfile != nil && oc.Properties.PlatformWorkloadIdentityProfile.PlatformWorkloadIdentities != nil {
		out.Properties.PlatformWorkloadIdentityProfile = &api.PlatformWorkloadIdentityProfile{}
		out.Properties.PlatformWorkloadIdentityProfile.PlatformWorkloadIdentities = make(map[string]api.PlatformWorkloadIdentity, len(oc.Properties.PlatformWorkloadIdentityProfile.PlatformWorkloadIdentities))

		for name, pwi := range oc.Properties.PlatformWorkloadIdentityProfile.PlatformWorkloadIdentities {
			if outPwi, exists := out.Properties.PlatformWorkloadIdentityProfile.PlatformWorkloadIdentities[name]; exists {
				outPwi.ResourceID = pwi.ResourceID
				out.Properties.PlatformWorkloadIdentityProfile.PlatformWorkloadIdentities[name] = outPwi
			} else {
				out.Properties.PlatformWorkloadIdentityProfile.PlatformWorkloadIdentities[name] = api.PlatformWorkloadIdentity{
					ResourceID: pwi.ResourceID,
					ClientID:   pwi.ClientID,
					ObjectID:   pwi.ObjectID,
				}
			}
		}
	}
	out.Properties.NetworkProfile.PodCIDR = oc.Properties.NetworkProfile.PodCIDR
	out.Properties.NetworkProfile.ServiceCIDR = oc.Properties.NetworkProfile.ServiceCIDR
	out.Properties.NetworkProfile.MTUSize = api.MTUSize(oc.Properties.NetworkProfile.MTUSize)
	out.Properties.NetworkProfile.OutboundType = api.OutboundType(oc.Properties.NetworkProfile.OutboundType)
	out.Properties.NetworkProfile.SoftwareDefinedNetwork = api.SoftwareDefinedNetwork(oc.Properties.NetworkProfile.SoftwareDefinedNetwork)
	out.Properties.NetworkProfile.APIServerPrivateEndpointIP = oc.Properties.NetworkProfile.APIServerPrivateEndpointIP
	out.Properties.NetworkProfile.GatewayPrivateEndpointIP = oc.Properties.NetworkProfile.GatewayPrivateEndpointIP
	out.Properties.NetworkProfile.GatewayPrivateLinkID = oc.Properties.NetworkProfile.GatewayPrivateLinkID
	out.Properties.NetworkProfile.PreconfiguredNSG = api.PreconfiguredNSG(oc.Properties.NetworkProfile.PreconfiguredNSG)
	if oc.Properties.NetworkProfile.LoadBalancerProfile != nil {
		loadBalancerProfile := api.LoadBalancerProfile{}

		// EffectiveOutboundIPs is a read-only field, so it will never be present in requests.
		// Preserve the slice from the pre-existing internal object.
		if out.Properties.NetworkProfile.LoadBalancerProfile != nil {
			loadBalancerProfile.EffectiveOutboundIPs = make([]api.EffectiveOutboundIP, len(out.Properties.NetworkProfile.LoadBalancerProfile.EffectiveOutboundIPs))
			copy(loadBalancerProfile.EffectiveOutboundIPs, out.Properties.NetworkProfile.LoadBalancerProfile.EffectiveOutboundIPs)
		}

		out.Properties.NetworkProfile.LoadBalancerProfile = &loadBalancerProfile

		if oc.Properties.NetworkProfile.LoadBalancerProfile.AllocatedOutboundPorts != nil {
			out.Properties.NetworkProfile.LoadBalancerProfile.AllocatedOutboundPorts = oc.Properties.NetworkProfile.LoadBalancerProfile.AllocatedOutboundPorts
		}

		if oc.Properties.NetworkProfile.LoadBalancerProfile.ManagedOutboundIPs != nil {
			out.Properties.NetworkProfile.LoadBalancerProfile.ManagedOutboundIPs = &api.ManagedOutboundIPs{
				Count: oc.Properties.NetworkProfile.LoadBalancerProfile.ManagedOutboundIPs.Count,
			}
		}
		if oc.Properties.NetworkProfile.LoadBalancerProfile.OutboundIPs != nil {
			out.Properties.NetworkProfile.LoadBalancerProfile.OutboundIPs = make([]api.OutboundIP, len(oc.Properties.NetworkProfile.LoadBalancerProfile.OutboundIPs))
			for i := range oc.Properties.NetworkProfile.LoadBalancerProfile.OutboundIPs {
				out.Properties.NetworkProfile.LoadBalancerProfile.OutboundIPs[i].ID = oc.Properties.NetworkProfile.LoadBalancerProfile.OutboundIPs[i].ID
			}
		}
		if oc.Properties.NetworkProfile.LoadBalancerProfile.OutboundIPPrefixes != nil {
			out.Properties.NetworkProfile.LoadBalancerProfile.OutboundIPPrefixes = make([]api.OutboundIPPrefix, len(oc.Properties.NetworkProfile.LoadBalancerProfile.OutboundIPPrefixes))
			for i := range oc.Properties.NetworkProfile.LoadBalancerProfile.OutboundIPPrefixes {
				out.Properties.NetworkProfile.LoadBalancerProfile.OutboundIPPrefixes[i].ID = oc.Properties.NetworkProfile.LoadBalancerProfile.OutboundIPPrefixes[i].ID
			}
		}
		if oc.Properties.NetworkProfile.LoadBalancerProfile.EffectiveOutboundIPs != nil {
			out.Properties.NetworkProfile.LoadBalancerProfile.EffectiveOutboundIPs = make([]api.EffectiveOutboundIP, len(oc.Properties.NetworkProfile.LoadBalancerProfile.EffectiveOutboundIPs))
			for i := range oc.Properties.NetworkProfile.LoadBalancerProfile.EffectiveOutboundIPs {
				out.Properties.NetworkProfile.LoadBalancerProfile.EffectiveOutboundIPs[i].ID = oc.Properties.NetworkProfile.LoadBalancerProfile.EffectiveOutboundIPs[i].ID
			}
		}
	}

	out.Properties.MasterProfile.VMSize = api.VMSize(oc.Properties.MasterProfile.VMSize)
	out.Properties.MasterProfile.SubnetID = oc.Properties.MasterProfile.SubnetID
	out.Properties.MasterProfile.EncryptionAtHost = api.EncryptionAtHost(oc.Properties.MasterProfile.EncryptionAtHost)
	out.Properties.MasterProfile.DiskEncryptionSetID = oc.Properties.MasterProfile.DiskEncryptionSetID
	out.Properties.StorageSuffix = oc.Properties.StorageSuffix
	out.Properties.ImageRegistryStorageAccountName = oc.Properties.ImageRegistryStorageAccountName
	out.Properties.WorkerProfiles = nil
	if oc.Properties.WorkerProfiles != nil {
		out.Properties.WorkerProfiles = make([]api.WorkerProfile, len(oc.Properties.WorkerProfiles))
		for i := range oc.Properties.WorkerProfiles {
			out.Properties.WorkerProfiles[i].Name = oc.Properties.WorkerProfiles[i].Name
			out.Properties.WorkerProfiles[i].VMSize = api.VMSize(oc.Properties.WorkerProfiles[i].VMSize)
			out.Properties.WorkerProfiles[i].DiskSizeGB = oc.Properties.WorkerProfiles[i].DiskSizeGB
			out.Properties.WorkerProfiles[i].SubnetID = oc.Properties.WorkerProfiles[i].SubnetID
			out.Properties.WorkerProfiles[i].Count = oc.Properties.WorkerProfiles[i].Count
			out.Properties.WorkerProfiles[i].EncryptionAtHost = api.EncryptionAtHost(oc.Properties.WorkerProfiles[i].EncryptionAtHost)
			out.Properties.WorkerProfiles[i].DiskEncryptionSetID = oc.Properties.WorkerProfiles[i].DiskEncryptionSetID
		}
	}
	out.Properties.WorkerProfilesStatus = nil
	if oc.Properties.WorkerProfilesStatus != nil {
		out.Properties.WorkerProfilesStatus = make([]api.WorkerProfile, len(oc.Properties.WorkerProfilesStatus))
		for i := range oc.Properties.WorkerProfilesStatus {
			out.Properties.WorkerProfilesStatus[i].Name = oc.Properties.WorkerProfilesStatus[i].Name
			out.Properties.WorkerProfilesStatus[i].VMSize = api.VMSize(oc.Properties.WorkerProfilesStatus[i].VMSize)
			out.Properties.WorkerProfilesStatus[i].DiskSizeGB = oc.Properties.WorkerProfilesStatus[i].DiskSizeGB
			out.Properties.WorkerProfilesStatus[i].SubnetID = oc.Properties.WorkerProfilesStatus[i].SubnetID
			out.Properties.WorkerProfilesStatus[i].Count = oc.Properties.WorkerProfilesStatus[i].Count
			out.Properties.WorkerProfilesStatus[i].EncryptionAtHost = api.EncryptionAtHost(oc.Properties.WorkerProfilesStatus[i].EncryptionAtHost)
			out.Properties.WorkerProfilesStatus[i].DiskEncryptionSetID = oc.Properties.WorkerProfilesStatus[i].DiskEncryptionSetID
		}
	}
	out.Properties.APIServerProfile.Visibility = api.Visibility(oc.Properties.APIServerProfile.Visibility)
	out.Properties.APIServerProfile.URL = oc.Properties.APIServerProfile.URL
	out.Properties.APIServerProfile.IP = oc.Properties.APIServerProfile.IP
	out.Properties.APIServerProfile.IntIP = oc.Properties.APIServerProfile.IntIP
	out.Properties.IngressProfiles = nil
	if oc.Properties.IngressProfiles != nil {
		out.Properties.IngressProfiles = make([]api.IngressProfile, len(oc.Properties.IngressProfiles))
		for i := range oc.Properties.IngressProfiles {
			out.Properties.IngressProfiles[i].Name = oc.Properties.IngressProfiles[i].Name
			out.Properties.IngressProfiles[i].Visibility = api.Visibility(oc.Properties.IngressProfiles[i].Visibility)
			out.Properties.IngressProfiles[i].IP = oc.Properties.IngressProfiles[i].IP
		}
	}

	out.Properties.Install = nil
	if oc.Properties.Install != nil {
		out.Properties.Install = &api.Install{
			Now:   oc.Properties.Install.Now,
			Phase: api.InstallPhase(oc.Properties.Install.Phase),
		}
	}

	// out.Properties.RegistryProfiles is not converted. The field is immutable and does not have to be converted.
	// Other fields are converted and this breaks the pattern, however this converting this field creates an issue
	// with filling the out.Properties.RegistryProfiles[i].Password as default is "" which erases the original value.
	// Workaround would be filling the password when receiving request, but it is array and the logic would be to complex.
}