@@ -10,7 +10,6 @@ import (
1010 "sigs.k8s.io/cluster-api-provider-vsphere/pkg/session"
1111
1212 "github.com/openshift/installer/pkg/asset/installconfig"
13- "github.com/openshift/installer/pkg/asset/rhcos"
1413 "github.com/openshift/installer/pkg/infrastructure/clusterapi"
1514 "github.com/openshift/installer/pkg/rhcos/cache"
1615 "github.com/openshift/installer/pkg/types/vsphere"
@@ -28,58 +27,59 @@ func (p Provider) Name() string {
2827 return vsphere .Name
2928}
3029
31- func initializeFoldersAndTemplates (ctx context.Context , rhcosImage * rhcos. Image , installConfig * installconfig. InstallConfig , session * session.Session , clusterID , server , tagID string ) error {
30+ func initializeFoldersAndTemplates (ctx context.Context , cachedImage string , failureDomain vsphere. FailureDomain , session * session.Session , diskType vsphere. DiskType , clusterID , tagID string ) error {
3231 finder := session .Finder
3332
34- platform := installConfig .Config .VSphere
35- failureDomains := platform .FailureDomains
36-
37- for _ , failureDomain := range failureDomains {
38- dc , err := finder .Datacenter (ctx , failureDomain .Topology .Datacenter )
39- if err != nil {
40- return err
41- }
42- dcFolders , err := dc .Folders (ctx )
43- if err != nil {
44- return fmt .Errorf ("unable to get datacenter folder: %w" , err )
45- }
46-
47- folderPath := path .Join (dcFolders .VmFolder .InventoryPath , clusterID )
33+ dc , err := finder .Datacenter (ctx , failureDomain .Topology .Datacenter )
34+ if err != nil {
35+ return err
36+ }
37+ dcFolders , err := dc .Folders (ctx )
38+ if err != nil {
39+ return fmt .Errorf ("unable to get datacenter folder: %w" , err )
40+ }
4841
49- // we must set the Folder to the infraId somewhere, we will need to remove that.
50- // if we are overwriting folderPath it needs to have a slash (path)
51- folder := failureDomain .Topology .Folder
52- if strings .Contains (folder , "/" ) {
53- folderPath = folder
54- }
42+ folderPath := path .Join (dcFolders .VmFolder .InventoryPath , clusterID )
5543
56- folderMo , err := createFolder (ctx , folderPath , session )
57- if err != nil {
58- return fmt .Errorf ("unable to create folder: %w" , err )
59- }
44+ // we must set the Folder to the infraId somewhere, we will need to remove that.
45+ // if we are overwriting folderPath it needs to have a slash (path)
46+ folder := failureDomain .Topology .Folder
47+ if strings .Contains (folder , "/" ) {
48+ folderPath = folder
49+ }
6050
61- cachedImage , err := cache . DownloadImageFile ( string ( * rhcosImage ), cache . InstallerApplicationName )
62- if err != nil {
63- return fmt .Errorf ("failed to use cached vsphere image : %w" , err )
64- }
51+ folderMo , err := createFolder ( ctx , folderPath , session )
52+ if err != nil {
53+ return fmt .Errorf ("unable to create folder : %w" , err )
54+ }
6555
66- // if the template is empty, the ova must be imported
67- if len (failureDomain .Topology .Template ) == 0 {
68- if err = importRhcosOva (ctx , session , folderMo ,
69- cachedImage , clusterID , tagID , string (platform .DiskType ), failureDomain ); err != nil {
70- return fmt .Errorf ("failed to import ova: %w" , err )
71- }
56+ // if the template is empty, the ova must be imported
57+ if len (failureDomain .Topology .Template ) == 0 {
58+ if err = importRhcosOva (ctx , session , folderMo ,
59+ cachedImage , clusterID , tagID , string (diskType ), failureDomain ); err != nil {
60+ return fmt .Errorf ("failed to import ova: %w" , err )
7261 }
7362 }
7463 return nil
7564}
7665
7766// PreProvision creates the vCenter objects required prior to running capv.
7867func (p Provider ) PreProvision (ctx context.Context , in clusterapi.PreProvisionInput ) error {
68+ /*
69+ * one locally cached image
70+ * one tag and tag category per vcenter
71+ * one folder per datacenter
72+ * one template per region/zone aka failuredomain
73+ */
7974 installConfig := in .InstallConfig
8075 clusterID := & installconfig.ClusterID {InfraID : in .InfraID }
8176 var tagID string
8277
78+ cachedImage , err := cache .DownloadImageFile (string (* in .RhcosImage ), cache .InstallerApplicationName )
79+ if err != nil {
80+ return fmt .Errorf ("failed to use cached vsphere image: %w" , err )
81+ }
82+
8383 for _ , vcenter := range installConfig .Config .VSphere .VCenters {
8484 server := vcenter .Server
8585 vctrSession , err := installConfig .VSphere .Session (context .TODO (), server )
@@ -105,7 +105,8 @@ func (p Provider) PreProvision(ctx context.Context, in clusterapi.PreProvisionIn
105105 if failureDomain .Server != server {
106106 continue
107107 }
108- if err = initializeFoldersAndTemplates (ctx , in .RhcosImage , installConfig , vctrSession , clusterID .InfraID , server , tagID ); err != nil {
108+
109+ if err = initializeFoldersAndTemplates (ctx , cachedImage , failureDomain , vctrSession , installConfig .Config .VSphere .DiskType , clusterID .InfraID , tagID ); err != nil {
109110 return fmt .Errorf ("unable to initialize folders and templates: %w" , err )
110111 }
111112 }
0 commit comments