Skip to content

Commit 6d16c1a

Browse files
openstack: Small refactor of PreProvision
Adjust debug and error messages, scope variables more tightly for clarity.
1 parent c2f06a6 commit 6d16c1a

File tree

3 files changed

+26
-20
lines changed

3 files changed

+26
-20
lines changed

pkg/infrastructure/openstack/clusterapi/clusterapi.go

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -35,37 +35,43 @@ var _ clusterapi.PreProvider = Provider{}
3535
// PreProvision tags the VIP ports and creates the security groups that are needed during CAPI provisioning.
3636
func (p Provider) PreProvision(ctx context.Context, in clusterapi.PreProvisionInput) error {
3737
var (
38-
infraID = in.InfraID
39-
installConfig = in.InstallConfig
40-
rhcosImage = string(*in.RhcosImage)
41-
mastersSchedulable bool
38+
infraID = in.InfraID
39+
installConfig = in.InstallConfig
40+
rhcosImage = string(*in.RhcosImage)
41+
manifestsAsset = in.ManifestsAsset
4242
)
4343

44-
for _, f := range in.ManifestsAsset.Files() {
45-
if f.Filename == manifests.SchedulerCfgFilename {
46-
schedulerConfig := configv1.Scheduler{}
47-
if err := yaml.Unmarshal(f.Data, &schedulerConfig); err != nil {
48-
return fmt.Errorf("unable to decode the scheduler manifest: %w", err)
49-
}
50-
mastersSchedulable = schedulerConfig.Spec.MastersSchedulable
51-
break
52-
}
53-
}
54-
5544
if err := preprovision.TagVIPPorts(ctx, installConfig, infraID); err != nil {
56-
return err
45+
return fmt.Errorf("failed to tag VIP ports: %w", err)
5746
}
5847

5948
// upload the corresponding image to Glance if rhcosImage contains a
6049
// URL. If rhcosImage contains a name, then that points to an existing
6150
// Glance image.
6251
if imageName, isURL := rhcos.GenerateOpenStackImageName(rhcosImage, infraID); isURL {
6352
if err := preprovision.UploadBaseImage(ctx, installConfig.Config.Platform.OpenStack.Cloud, rhcosImage, imageName, infraID, installConfig.Config.Platform.OpenStack.ClusterOSImageProperties); err != nil {
64-
return err
53+
return fmt.Errorf("failed to upload the RHCOS base image: %w", err)
54+
}
55+
}
56+
57+
{
58+
var mastersSchedulable bool
59+
for _, f := range manifestsAsset.Files() {
60+
if f.Filename == manifests.SchedulerCfgFilename {
61+
schedulerConfig := configv1.Scheduler{}
62+
if err := yaml.Unmarshal(f.Data, &schedulerConfig); err != nil {
63+
return fmt.Errorf("unable to decode the scheduler manifest: %w", err)
64+
}
65+
mastersSchedulable = schedulerConfig.Spec.MastersSchedulable
66+
break
67+
}
68+
}
69+
if err := preprovision.SecurityGroups(ctx, installConfig, infraID, mastersSchedulable); err != nil {
70+
return fmt.Errorf("failed to create security groups: %w", err)
6571
}
6672
}
6773

68-
return preprovision.SecurityGroups(ctx, installConfig, infraID, mastersSchedulable)
74+
return nil
6975
}
7076

7177
var _ clusterapi.InfraReadyProvider = Provider{}

pkg/infrastructure/openstack/preprovision/rhcosimage.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ func UploadBaseImage(ctx context.Context, cloud string, rhcosImage string, image
7676
if res.Err != nil {
7777
return err
7878
}
79-
logrus.Debugf("The data was uploaded.")
79+
logrus.Debugf("RHCOS image upload completed.")
8080

8181
return nil
8282
}

pkg/infrastructure/openstack/preprovision/securitygroups.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ func SecurityGroups(ctx context.Context, installConfig *installconfig.InstallCon
8181
}
8282
}
8383

84+
logrus.Debugf("Creating the security group rules")
8485
var (
8586
machineV4CIDRs = make([]string, 0, len(installConfig.Config.Networking.MachineNetwork))
8687
machineV6CIDRs = make([]string, 0, len(installConfig.Config.Networking.MachineNetwork))
@@ -211,7 +212,6 @@ func SecurityGroups(ctx context.Context, installConfig *installconfig.InstallCon
211212
addRules(ctx, r, workerGroup.ID, serviceIKENat, rules.EtherType4, machineV4CIDRs)
212213
}()
213214

214-
logrus.Debugf("Creating the security group rules")
215215
for ruleCreateOpts := range r {
216216
if _, err := rules.Create(networkClient, ruleCreateOpts).Extract(); err != nil {
217217
return fmt.Errorf("failed to create the security group rule on group %q for %s %s on ports %d-%d: %w", ruleCreateOpts.SecGroupID, ruleCreateOpts.EtherType, ruleCreateOpts.Protocol, ruleCreateOpts.PortRangeMin, ruleCreateOpts.PortRangeMax, err)

0 commit comments

Comments
 (0)