1919 errNotFound = errors .New ("not found" )
2020)
2121
22- func getDNSZoneName (ctx context.Context , ic * installconfig.InstallConfig , isPublic bool ) (string , error ) {
22+ func getDNSZoneName (ctx context.Context , ic * installconfig.InstallConfig , clusterID string , isPublic bool ) (string , error ) {
2323 ctx , cancel := context .WithTimeout (ctx , time .Minute * 1 )
2424 defer cancel ()
2525
@@ -31,11 +31,16 @@ func getDNSZoneName(ctx context.Context, ic *installconfig.InstallConfig, isPubl
3131 cctx , ccancel := context .WithTimeout (ctx , time .Minute * 1 )
3232 defer ccancel ()
3333
34- domain := ic .Config .BaseDomain
35- project := ic .Config .GCP .ProjectID
36- if ! isPublic {
37- project , _ = manifests .GetPrivateDNSZoneAndProject (ic )
38- domain = ic .Config .ClusterDomain ()
34+ params , err := manifests .GetGCPPrivateZoneInfo (ctx , client , ic , clusterID )
35+ if err != nil {
36+ return "" , fmt .Errorf ("failed to get private zone info: %w" , err )
37+ }
38+
39+ domain := params .BaseDomain
40+ project := params .Project
41+ if isPublic {
42+ project = ic .Config .GCP .ProjectID
43+ domain = ic .Config .BaseDomain
3944 }
4045
4146 zone , err := client .GetDNSZone (cctx , project , domain , isPublic )
@@ -57,20 +62,20 @@ type recordSet struct {
5762}
5863
5964// createRecordSets will create a list of records that will be created during the install.
60- func createRecordSets (ctx context.Context , ic * installconfig.InstallConfig , clusterID , apiIP , apiIntIP string ) ([]recordSet , error ) {
65+ func createRecordSets (ctx context.Context , client * gcpic. Client , ic * installconfig.InstallConfig , clusterID , apiIP , apiIntIP string ) ([]recordSet , error ) {
6166 ctx , cancel := context .WithTimeout (ctx , time .Minute * 1 )
6267 defer cancel ()
6368
64- project , privateZoneName := manifests .GetPrivateDNSZoneAndProject ( ic )
65- if privateZoneName == "" {
66- privateZoneName = manifests . GCPDefaultPrivateZoneID ( clusterID )
69+ privateZoneParams , err := manifests .GetGCPPrivateZoneInfo ( ctx , client , ic , clusterID )
70+ if err != nil {
71+ return nil , fmt . Errorf ( "failed to get private zone info for record creation: %w" , err )
6772 }
6873
6974 records := []recordSet {
7075 {
7176 // api_internal
72- projectID : project ,
73- zoneName : privateZoneName ,
77+ projectID : privateZoneParams . Project ,
78+ zoneName : privateZoneParams . Name ,
7479 record : & dns.ResourceRecordSet {
7580 Name : fmt .Sprintf ("api-int.%s." , ic .Config .ClusterDomain ()),
7681 Type : "A" ,
@@ -80,8 +85,8 @@ func createRecordSets(ctx context.Context, ic *installconfig.InstallConfig, clus
8085 },
8186 {
8287 // api_external_internal_zone
83- projectID : project ,
84- zoneName : privateZoneName ,
88+ projectID : privateZoneParams . Project ,
89+ zoneName : privateZoneParams . Name ,
8590 record : & dns.ResourceRecordSet {
8691 Name : fmt .Sprintf ("api.%s." , ic .Config .ClusterDomain ()),
8792 Type : "A" ,
@@ -92,7 +97,7 @@ func createRecordSets(ctx context.Context, ic *installconfig.InstallConfig, clus
9297 }
9398
9499 if ic .Config .Publish == types .ExternalPublishingStrategy {
95- existingPublicZoneName , err := getDNSZoneName (ctx , ic , true )
100+ existingPublicZoneName , err := getDNSZoneName (ctx , ic , clusterID , true )
96101 if err != nil {
97102 return nil , fmt .Errorf ("failed to find a public zone: %w" , err )
98103 }
@@ -114,14 +119,14 @@ func createRecordSets(ctx context.Context, ic *installconfig.InstallConfig, clus
114119}
115120
116121// createDNSRecords will get the list of records to be created and execute their creation through the gcp dns api.
117- func createDNSRecords (ctx context.Context , ic * installconfig.InstallConfig , clusterID , apiIP , apiIntIP string ) error {
122+ func createDNSRecords (ctx context.Context , client * gcpic. Client , ic * installconfig.InstallConfig , clusterID , apiIP , apiIntIP string ) error {
118123 // TODO: use the opts for the service to restrict scopes see google.golang.org/api/option.WithScopes
119124 dnsService , err := gcpic .GetDNSService (ctx , ic .Config .GCP .ServiceEndpoints )
120125 if err != nil {
121126 return fmt .Errorf ("failed to create the gcp dns service: %w" , err )
122127 }
123128
124- records , err := createRecordSets (ctx , ic , clusterID , apiIP , apiIntIP )
129+ records , err := createRecordSets (ctx , client , ic , clusterID , apiIP , apiIntIP )
125130 if err != nil {
126131 return err
127132 }
@@ -147,25 +152,23 @@ func createPrivateManagedZone(ctx context.Context, ic *installconfig.InstallConf
147152 return err
148153 }
149154
150- privateZoneID := manifests .GCPDefaultPrivateZoneID (clusterID )
155+ params , err := manifests .GetGCPPrivateZoneInfo (ctx , client , ic , clusterID )
156+ if err != nil {
157+ return err
158+ }
159+
151160 if ic .Config .GCP .NetworkProjectID != "" {
152- privateZoneName , shouldCreateZone , err := manifests .GetGCPPrivateZoneName (ctx , client , ic , clusterID )
153- if err != nil {
154- return err
155- }
156- if ! shouldCreateZone {
157- logrus .Debugf ("found private zone %s, skipping creation of private zone" , privateZoneName )
158- privateZoneProject , _ := manifests .GetPrivateDNSZoneAndProject (ic )
161+ if ! params .InstallerCreated {
162+ logrus .Debugf ("found private zone %s, skipping creation of private zone" , params .Name )
159163 // The private zone already exists, so we need to add the shared label to the zone.
160164 labels := mergeLabels (ic , clusterID , sharedLabelValue )
161- if err := client .UpdateDNSPrivateZoneLabels (ctx , ic .Config .ClusterDomain (), privateZoneProject , privateZoneName , labels ); err != nil {
165+ if err := client .UpdateDNSPrivateZoneLabels (ctx , ic .Config .ClusterDomain (), params . Project , params . Name , labels ); err != nil {
162166 return fmt .Errorf ("failed to update dns private zone labels: %w" , err )
163167 }
164168 return nil
165169 }
166- privateZoneID = privateZoneName
167170 }
168- logrus .Debugf ("creating private zone %s" , privateZoneID )
171+ logrus .Debugf ("creating private zone %s" , params . Name )
169172
170173 // TODO: use the opts for the service to restrict scopes see google.golang.org/api/option.WithScopes
171174 dnsService , err := gcpic .GetDNSService (ctx , ic .Config .GCP .ServiceEndpoints )
@@ -174,7 +177,7 @@ func createPrivateManagedZone(ctx context.Context, ic *installconfig.InstallConf
174177 }
175178
176179 managedZone := & dns.ManagedZone {
177- Name : privateZoneID ,
180+ Name : params . Name ,
178181 Description : resourceDescription ,
179182 DnsName : fmt .Sprintf ("%s." , ic .Config .ClusterDomain ()),
180183 Visibility : "private" ,
@@ -191,8 +194,7 @@ func createPrivateManagedZone(ctx context.Context, ic *installconfig.InstallConf
191194 ctx , cancel := context .WithTimeout (ctx , time .Minute * 1 )
192195 defer cancel ()
193196
194- project , _ := manifests .GetPrivateDNSZoneAndProject (ic )
195- if _ , err = dnsService .ManagedZones .Create (project , managedZone ).Context (ctx ).Do (); err != nil {
197+ if _ , err = dnsService .ManagedZones .Create (params .Project , managedZone ).Context (ctx ).Do (); err != nil {
196198 return fmt .Errorf ("failed to create private managed zone: %w" , err )
197199 }
198200
0 commit comments