Skip to content

Commit 9f2d700

Browse files
committed
Remove unnecessary use of multierr
1 parent 46f9186 commit 9f2d700

File tree

3 files changed

+36
-44
lines changed

3 files changed

+36
-44
lines changed

pkg/cloud/affinity_groups.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ func (c *client) FetchAffinityGroup(group *AffinityGroup) (reterr error) {
4545
if group.ID != "" {
4646
affinityGroup, count, err := c.cs.AffinityGroup.GetAffinityGroupByID(group.ID, cloudstack.WithProject(c.user.Project.ID))
4747
if err != nil {
48-
// handle via multierr
4948
c.customMetrics.EvaluateErrorAndIncrementAcsReconciliationErrorCounter(err)
5049
return err
5150
} else if count > 1 {
@@ -59,7 +58,6 @@ func (c *client) FetchAffinityGroup(group *AffinityGroup) (reterr error) {
5958
if group.Name != "" {
6059
affinityGroup, count, err := c.cs.AffinityGroup.GetAffinityGroupByName(group.Name, cloudstack.WithProject(c.user.Project.ID))
6160
if err != nil {
62-
// handle via multierr
6361
c.customMetrics.EvaluateErrorAndIncrementAcsReconciliationErrorCounter(err)
6462
return err
6563
} else if count > 1 {

pkg/cloud/instance.go

Lines changed: 34 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import (
2828
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
2929

3030
"github.com/apache/cloudstack-go/v2/cloudstack"
31-
"github.com/hashicorp/go-multierror"
3231
"github.com/pkg/errors"
3332
corev1 "k8s.io/api/core/v1"
3433
infrav1 "sigs.k8s.io/cluster-api-provider-cloudstack/api/v1beta3"
@@ -91,27 +90,27 @@ func (c *client) ResolveServiceOffering(csMachine *infrav1.CloudStackMachine, zo
9190
csOffering, count, err := c.cs.ServiceOffering.GetServiceOfferingByID(csMachine.Spec.Offering.ID, cloudstack.WithProject(c.user.Project.ID))
9291
if err != nil {
9392
c.customMetrics.EvaluateErrorAndIncrementAcsReconciliationErrorCounter(err)
94-
return cloudstack.ServiceOffering{}, multierror.Append(retErr, errors.Wrapf(
95-
err, "could not get Service Offering by ID %s", csMachine.Spec.Offering.ID))
93+
return cloudstack.ServiceOffering{}, errors.Wrapf(
94+
err, "could not get Service Offering by ID %s", csMachine.Spec.Offering.ID)
9695
} else if count != 1 {
97-
return *csOffering, multierror.Append(retErr, errors.Errorf(
98-
"expected 1 Service Offering with UUID %s, but got %d", csMachine.Spec.Offering.ID, count))
96+
return *csOffering, errors.Errorf(
97+
"expected 1 Service Offering with UUID %s, but got %d", csMachine.Spec.Offering.ID, count)
9998
}
10099

101100
if len(csMachine.Spec.Offering.Name) > 0 && csMachine.Spec.Offering.Name != csOffering.Name {
102-
return *csOffering, multierror.Append(retErr, errors.Errorf(
103-
"offering name %s does not match name %s returned using UUID %s", csMachine.Spec.Offering.Name, csOffering.Name, csMachine.Spec.Offering.ID))
101+
return *csOffering, errors.Errorf(
102+
"offering name %s does not match name %s returned using UUID %s", csMachine.Spec.Offering.Name, csOffering.Name, csMachine.Spec.Offering.ID)
104103
}
105104
return *csOffering, nil
106105
}
107106
csOffering, count, err := c.cs.ServiceOffering.GetServiceOfferingByName(csMachine.Spec.Offering.Name, cloudstack.WithZone(zoneID), cloudstack.WithProject(c.user.Project.ID))
108107
if err != nil {
109108
c.customMetrics.EvaluateErrorAndIncrementAcsReconciliationErrorCounter(err)
110-
return cloudstack.ServiceOffering{}, multierror.Append(retErr, errors.Wrapf(
111-
err, "could not get Service Offering ID from %s in zone %s", csMachine.Spec.Offering.Name, zoneID))
109+
return cloudstack.ServiceOffering{}, errors.Wrapf(
110+
err, "could not get Service Offering ID from %s in zone %s", csMachine.Spec.Offering.Name, zoneID)
112111
} else if count != 1 {
113-
return *csOffering, multierror.Append(retErr, errors.Errorf(
114-
"expected 1 Service Offering with name %s in zone %s, but got %d", csMachine.Spec.Offering.Name, zoneID, count))
112+
return *csOffering, errors.Errorf(
113+
"expected 1 Service Offering with name %s in zone %s, but got %d", csMachine.Spec.Offering.Name, zoneID, count)
115114
}
116115
return *csOffering, nil
117116
}
@@ -124,27 +123,25 @@ func (c *client) ResolveTemplate(
124123
csTemplate, count, err := c.cs.Template.GetTemplateByID(csMachine.Spec.Template.ID, "executable", cloudstack.WithProject(c.user.Project.ID))
125124
if err != nil {
126125
c.customMetrics.EvaluateErrorAndIncrementAcsReconciliationErrorCounter(err)
127-
return "", multierror.Append(retErr, errors.Wrapf(
128-
err, "could not get Template by ID %s", csMachine.Spec.Template.ID))
126+
return "", errors.Wrapf(err, "could not get Template by ID %s", csMachine.Spec.Template.ID)
129127
} else if count != 1 {
130-
return "", multierror.Append(retErr, errors.Errorf(
131-
"expected 1 Template with UUID %s, but got %d", csMachine.Spec.Template.ID, count))
128+
return "", errors.Errorf(
129+
"expected 1 Template with UUID %s, but got %d", csMachine.Spec.Template.ID, count)
132130
}
133131

134132
if len(csMachine.Spec.Template.Name) > 0 && csMachine.Spec.Template.Name != csTemplate.Name {
135-
return "", multierror.Append(retErr, errors.Errorf(
136-
"template name %s does not match name %s returned using UUID %s", csMachine.Spec.Template.Name, csTemplate.Name, csMachine.Spec.Template.ID))
133+
return "", errors.Errorf(
134+
"template name %s does not match name %s returned using UUID %s", csMachine.Spec.Template.Name, csTemplate.Name, csMachine.Spec.Template.ID)
137135
}
138136
return csMachine.Spec.Template.ID, nil
139137
}
140138
templateID, count, err := c.cs.Template.GetTemplateID(csMachine.Spec.Template.Name, "executable", zoneID, cloudstack.WithProject(c.user.Project.ID))
141139
if err != nil {
142140
c.customMetrics.EvaluateErrorAndIncrementAcsReconciliationErrorCounter(err)
143-
return "", multierror.Append(retErr, errors.Wrapf(
144-
err, "could not get Template ID from %s", csMachine.Spec.Template.Name))
141+
return "", errors.Wrapf(err, "could not get Template ID from %s", csMachine.Spec.Template.Name)
145142
} else if count != 1 {
146-
return "", multierror.Append(retErr, errors.Errorf(
147-
"expected 1 Template with name %s, but got %d", csMachine.Spec.Template.Name, count))
143+
return "", errors.Errorf(
144+
"expected 1 Template with name %s, but got %d", csMachine.Spec.Template.Name, count)
148145
}
149146
return templateID, nil
150147
}
@@ -158,50 +155,48 @@ func (c *client) ResolveDiskOffering(csMachine *infrav1.CloudStackMachine, zoneI
158155
diskID, count, err := c.cs.DiskOffering.GetDiskOfferingID(csMachine.Spec.DiskOffering.Name, cloudstack.WithZone(zoneID), cloudstack.WithProject(c.user.Project.ID))
159156
if err != nil {
160157
c.customMetrics.EvaluateErrorAndIncrementAcsReconciliationErrorCounter(err)
161-
return "", multierror.Append(retErr, errors.Wrapf(
162-
err, "could not get DiskOffering ID from %s", csMachine.Spec.DiskOffering.Name))
158+
return "", errors.Wrapf(err, "could not get DiskOffering ID from %s", csMachine.Spec.DiskOffering.Name)
163159
} else if count != 1 {
164-
return "", multierror.Append(retErr, errors.Errorf(
165-
"expected 1 DiskOffering with name %s in zone %s, but got %d", csMachine.Spec.DiskOffering.Name, zoneID, count))
160+
return "", errors.Errorf(
161+
"expected 1 DiskOffering with name %s in zone %s, but got %d", csMachine.Spec.DiskOffering.Name, zoneID, count)
166162
} else if len(csMachine.Spec.DiskOffering.ID) > 0 && diskID != csMachine.Spec.DiskOffering.ID {
167-
return "", multierror.Append(retErr, errors.Errorf(
163+
return "", errors.Errorf(
168164
"diskOffering ID %s does not match ID %s returned using name %s in zone %s",
169-
csMachine.Spec.DiskOffering.ID, diskID, csMachine.Spec.DiskOffering.Name, zoneID))
165+
csMachine.Spec.DiskOffering.ID, diskID, csMachine.Spec.DiskOffering.Name, zoneID)
170166
} else if len(diskID) == 0 {
171-
return "", multierror.Append(retErr, errors.Errorf(
167+
return "", errors.Errorf(
172168
"empty diskOffering ID %s returned using name %s in zone %s",
173-
diskID, csMachine.Spec.DiskOffering.Name, zoneID))
169+
diskID, csMachine.Spec.DiskOffering.Name, zoneID)
174170
}
175171
diskOfferingID = diskID
176172
}
177173
if len(diskOfferingID) == 0 {
178174
return "", nil
179175
}
180176

181-
return verifyDiskoffering(csMachine, c, diskOfferingID, retErr)
177+
return verifyDiskoffering(csMachine, c, diskOfferingID)
182178
}
183179

184-
func verifyDiskoffering(csMachine *infrav1.CloudStackMachine, c *client, diskOfferingID string, retErr error) (string, error) {
180+
func verifyDiskoffering(csMachine *infrav1.CloudStackMachine, c *client, diskOfferingID string) (string, error) {
185181
csDiskOffering, count, err := c.cs.DiskOffering.GetDiskOfferingByID(diskOfferingID, cloudstack.WithProject(c.user.Project.ID))
186182
if err != nil {
187183
c.customMetrics.EvaluateErrorAndIncrementAcsReconciliationErrorCounter(err)
188-
return "", multierror.Append(retErr, errors.Wrapf(
189-
err, "could not get DiskOffering by ID %s", diskOfferingID))
184+
return "", errors.Wrapf(err, "could not get DiskOffering by ID %s", diskOfferingID)
190185
} else if count != 1 {
191-
return "", multierror.Append(retErr, errors.Errorf(
192-
"expected 1 DiskOffering with UUID %s, but got %d", diskOfferingID, count))
186+
return "", errors.Errorf(
187+
"expected 1 DiskOffering with UUID %s, but got %d", diskOfferingID, count)
193188
}
194189

195190
if csDiskOffering.Iscustomized && csMachine.Spec.DiskOffering.CustomSize == 0 {
196-
return "", multierror.Append(retErr, errors.Errorf(
191+
return "", errors.Errorf(
197192
"diskOffering with UUID %s is customized, disk size can not be 0 GB",
198-
diskOfferingID))
193+
diskOfferingID)
199194
}
200195

201196
if !csDiskOffering.Iscustomized && csMachine.Spec.DiskOffering.CustomSize > 0 {
202-
return "", multierror.Append(retErr, errors.Errorf(
197+
return "", errors.Errorf(
203198
"diskOffering with UUID %s is not customized, disk size can not be specified",
204-
diskOfferingID))
199+
diskOfferingID)
205200
}
206201
return diskOfferingID, nil
207202
}

pkg/cloud/isolated_network.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
"strings"
2222

2323
"github.com/apache/cloudstack-go/v2/cloudstack"
24-
"github.com/hashicorp/go-multierror"
2524
"github.com/pkg/errors"
2625
infrav1 "sigs.k8s.io/cluster-api-provider-cloudstack/api/v1beta3"
2726
)
@@ -168,8 +167,8 @@ func (c *client) OpenFirewallRules(isoNet *infrav1.CloudStackIsolatedNetwork) (r
168167
!strings.Contains(strings.ToLower(err.Error()), "there is already") &&
169168
// Ignore errors regarding already existing fw rule for ICMP
170169
!strings.Contains(strings.ToLower(err.Error()), "new rule conflicts with existing rule") {
171-
retErr = multierror.Append(retErr, errors.Wrapf(
172-
err, "failed creating egress firewall rule for network ID %s protocol %s", isoNet.Spec.ID, proto))
170+
retErr = errors.Wrapf(
171+
err, "failed creating egress firewall rule for network ID %s protocol %s", isoNet.Spec.ID, proto)
173172
}
174173
}
175174
c.customMetrics.EvaluateErrorAndIncrementAcsReconciliationErrorCounter(retErr)

0 commit comments

Comments
 (0)