Skip to content

Commit 41d792b

Browse files
authored
Merge branch 'kubernetes-sigs:main' into main
2 parents 79bfddd + e4c0653 commit 41d792b

15 files changed

+193
-14
lines changed

Makefile

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# Image URL to use all building/pushing image targets
2-
IMG ?= public.ecr.aws/a4z9h2b1/cluster-api-provider-capc:latest
3-
IMG_LOCAL ?= localhost:5000/cluster-api-provider-cloudstack:latest
2+
STAGING_REGISTRY := gcr.io/k8s-staging-capi-cloudstack
3+
REGISTRY ?= $(STAGING_REGISTRY)
4+
IMAGE_NAME ?= capi-cloudstack-controller
5+
TAG ?= dev
6+
IMG ?= $(REGISTRY)/$(IMAGE_NAME):$(TAG)
7+
IMG_LOCAL ?= localhost:5000/$(IMAGE_NAME):$(TAG)
48

59
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
610
ifeq (,$(shell go env GOBIN))
@@ -45,7 +49,7 @@ help: ## Display this help.
4549
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
4650

4751
MANIFEST_GEN_INPUTS=$(shell find ./api ./controllers -type f -name "*test*" -prune -o -name "*zz_generated*" -prune -o -print)
48-
52+
4953
# Using a flag file here as config output is too complicated to be a target.
5054
# The following triggers manifest building if $(IMG) differs from that found in config/default/manager_image_patch.yaml.
5155
$(shell grep -qs "$(IMG)" config/default/manager_image_patch_edited.yaml || rm -f config/.flag.mk)
@@ -58,7 +62,7 @@ config/.flag.mk: bin/controller-gen $(MANIFEST_GEN_INPUTS)
5862

5963
.PHONY: release-manifests
6064
RELEASE_MANIFEST_TARGETS=$(RELEASE_DIR)/infrastructure-components.yaml $(RELEASE_DIR)/metadata.yaml
61-
RELEASE_MANIFEST_INPUTS=bin/kustomize config/.flag.mk $(shell find config)
65+
RELEASE_MANIFEST_INPUTS=bin/kustomize config/.flag.mk $(shell find config)
6266
release-manifests: $(RELEASE_MANIFEST_TARGETS) ## Create kustomized release manifest in $RELEASE_DIR (defaults to out).
6367
$(RELEASE_DIR)/%: $(RELEASE_MANIFEST_INPUTS)
6468
@mkdir -p $(RELEASE_DIR)
@@ -146,7 +150,7 @@ bin/golangci-lint: ## Install golangci-lint to bin.
146150
bin/staticcheck: ## Install staticcheck to bin.
147151
GOBIN=$(PROJECT_DIR)/bin go install honnef.co/go/tools/cmd/[email protected]
148152
bin/ginkgo: bin/ginkgo_v1 bin/ginkgo_v2 ## Install ginkgo to bin.
149-
bin/ginkgo_v2:
153+
bin/ginkgo_v2:
150154
GOBIN=$(PROJECT_DIR)/bin go install github.com/onsi/ginkgo/v2/[email protected]
151155
mv $(PROJECT_DIR)/bin/ginkgo $(PROJECT_DIR)/bin/ginkgo_v2
152156
bin/ginkgo_v1:
@@ -180,15 +184,15 @@ test: generate-mocks lint bin/ginkgo bin/kubectl bin/kube-apiserver bin/etcd ##
180184
@# The following is a slightly funky way to make sure the ginkgo statements are removed regardless the test results.
181185
@ginkgo_v2 --label-filter="!integ" --cover -coverprofile cover.out --covermode=atomic -v ./api/... ./controllers/... ./pkg/...; EXIT_STATUS=$$?;\
182186
./hack/testing_ginkgo_recover_statements.sh --remove; exit $$EXIT_STATUS
183-
187+
184188
.PHONY: generate-mocks
185189
generate-mocks: bin/mockgen generate-deepcopy pkg/mocks/mock_client.go $(shell find ./pkg/mocks -type f -name "mock*.go") ## Generate mocks needed for testing. Primarily mocks of the cloud package.
186190
pkg/mocks/mock%.go: $(shell find ./pkg/cloud -type f -name "*test*" -prune -o -print)
187191
go generate ./...
188192

189193
##@ Tilt
190194

191-
.PHONY: tilt-up
195+
.PHONY: tilt-up
192196
tilt-up: cluster-api kind-cluster cluster-api/tilt-settings.json manifests cloud-config ## Setup and run tilt for development.
193197
export CLOUDSTACK_B64ENCODED_SECRET=$$(base64 -w0 -i cloud-config 2>/dev/null || base64 -b 0 -i cloud-config) && cd cluster-api && tilt up
194198

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ require (
1111
github.com/onsi/gomega v1.19.0
1212
github.com/pkg/errors v0.9.1
1313
github.com/smallfish/simpleyaml v0.1.0
14+
github.com/prometheus/client_golang v1.11.0
1415
github.com/spf13/pflag v1.0.5
1516
gopkg.in/ini.v1 v1.63.2
1617
k8s.io/api v0.23.0

pkg/cloud/affinity_groups.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ func (c *client) FetchAffinityGroup(group *AffinityGroup) (reterr error) {
4545
affinityGroup, count, err := c.cs.AffinityGroup.GetAffinityGroupByID(group.ID)
4646
if err != nil {
4747
// handle via multierr
48+
c.customMetrics.EvaluateErrorAndIncrementAcsReconciliationErrorCounter(err)
4849
return err
4950
} else if count > 1 {
5051
// handle via creating a new error.
@@ -59,6 +60,7 @@ func (c *client) FetchAffinityGroup(group *AffinityGroup) (reterr error) {
5960
affinityGroup, count, err := c.cs.AffinityGroup.GetAffinityGroupByName(group.Name)
6061
if err != nil {
6162
// handle via multierr
63+
c.customMetrics.EvaluateErrorAndIncrementAcsReconciliationErrorCounter(err)
6264
return err
6365
} else if count > 1 {
6466
// handle via creating a new error.
@@ -78,6 +80,7 @@ func (c *client) GetOrCreateAffinityGroup(group *AffinityGroup) (retErr error) {
7880
p.SetName(group.Name)
7981
resp, err := c.cs.AffinityGroup.CreateAffinityGroup(p)
8082
if err != nil {
83+
c.customMetrics.EvaluateErrorAndIncrementAcsReconciliationErrorCounter(err)
8184
return err
8285
}
8386
group.ID = resp.Id
@@ -90,6 +93,7 @@ func (c *client) DeleteAffinityGroup(group *AffinityGroup) (retErr error) {
9093
setIfNotEmpty(group.ID, p.SetId)
9194
setIfNotEmpty(group.Name, p.SetName)
9295
_, retErr = c.cs.AffinityGroup.DeleteAffinityGroup(p)
96+
c.customMetrics.EvaluateErrorAndIncrementAcsReconciliationErrorCounter(retErr)
9397
return retErr
9498
}
9599

@@ -98,6 +102,7 @@ type affinityGroups []AffinityGroup
98102
func (c *client) getCurrentAffinityGroups(csMachine *infrav1.CloudStackMachine) (affinityGroups, error) {
99103
// Start by fetching VM details which includes an array of currently associated affinity groups.
100104
if virtM, count, err := c.cs.VirtualMachine.GetVirtualMachineByID(*csMachine.Spec.InstanceID); err != nil {
105+
c.customMetrics.EvaluateErrorAndIncrementAcsReconciliationErrorCounter(err)
101106
return nil, err
102107
} else if count > 1 {
103108
return nil, errors.Errorf("found more than one VM for ID: %s", *csMachine.Spec.InstanceID)
@@ -149,15 +154,18 @@ func (c *client) stopAndModifyAffinityGroups(csMachine *infrav1.CloudStackMachin
149154

150155
p1 := c.cs.VirtualMachine.NewStopVirtualMachineParams(string(*csMachine.Spec.InstanceID))
151156
if _, err := c.cs.VirtualMachine.StopVirtualMachine(p1); err != nil {
157+
c.customMetrics.EvaluateErrorAndIncrementAcsReconciliationErrorCounter(err)
152158
return err
153159
}
154160

155161
if _, err := c.cs.AffinityGroup.UpdateVMAffinityGroup(agp); err != nil {
162+
c.customMetrics.EvaluateErrorAndIncrementAcsReconciliationErrorCounter(err)
156163
return err
157164
}
158165

159166
p2 := c.cs.VirtualMachine.NewStartVirtualMachineParams(string(*csMachine.Spec.InstanceID))
160167
_, err := c.cs.VirtualMachine.StartVirtualMachine(p2)
168+
c.customMetrics.EvaluateErrorAndIncrementAcsReconciliationErrorCounter(err)
161169
return err
162170
}
163171

pkg/cloud/affinity_groups_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ var _ = Describe("AffinityGroup Unit Tests", func() {
8888
// Make the created VM go away quickly by force stopping it.
8989
p := realCSClient.VirtualMachine.NewStopVirtualMachineParams(*dummies.CSMachine1.Spec.InstanceID)
9090
p.SetForced(true)
91-
Ω(realCSClient.VirtualMachine.StopVirtualMachine(p)).Should(Succeed())
91+
_, err := realCSClient.VirtualMachine.StopVirtualMachine(p)
92+
Ω(err).ShouldNot(HaveOccurred())
9293
})
9394

9495
It("Creates and deletes an affinity group.", func() {

pkg/cloud/client.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package cloud
1818

1919
import (
20+
"sigs.k8s.io/cluster-api-provider-cloudstack/pkg/metrics"
2021
"strings"
2122

2223
"github.com/apache/cloudstack-go/v2/cloudstack"
@@ -40,9 +41,10 @@ type Client interface {
4041
}
4142

4243
type client struct {
43-
cs *cloudstack.CloudStackClient
44-
csAsync *cloudstack.CloudStackClient
45-
config Config
44+
cs *cloudstack.CloudStackClient
45+
csAsync *cloudstack.CloudStackClient
46+
config Config
47+
customMetrics metrics.ACSCustomMetrics
4648
}
4749

4850
// cloud-config ini structure.
@@ -68,6 +70,7 @@ func NewClient(ccPath string) (Client, error) {
6870
// comments for more details
6971
c.cs = cloudstack.NewAsyncClient(c.config.APIURL, c.config.APIKey, c.config.SecretKey, c.config.VerifySSL)
7072
c.csAsync = cloudstack.NewClient(c.config.APIURL, c.config.APIKey, c.config.SecretKey, c.config.VerifySSL)
73+
c.customMetrics = metrics.NewCustomMetrics()
7174

7275
_, err := c.cs.APIDiscovery.ListApis(c.cs.APIDiscovery.NewListApisParams())
7376
if err != nil && strings.Contains(strings.ToLower(err.Error()), "i/o timeout") {
@@ -91,6 +94,7 @@ func (origC *client) NewClientFromSpec(cfg Config) (Client, error) {
9194
// comments for more details
9295
newC.cs = cloudstack.NewAsyncClient(newC.config.APIURL, newC.config.APIKey, newC.config.SecretKey, newC.config.VerifySSL)
9396
newC.csAsync = cloudstack.NewClient(newC.config.APIURL, newC.config.APIKey, newC.config.SecretKey, newC.config.VerifySSL)
97+
newC.customMetrics = metrics.NewCustomMetrics()
9498

9599
_, err := newC.cs.APIDiscovery.ListApis(newC.cs.APIDiscovery.NewListApisParams())
96100
if err != nil && strings.Contains(strings.ToLower(err.Error()), "i/o timeout") {
@@ -100,6 +104,6 @@ func (origC *client) NewClientFromSpec(cfg Config) (Client, error) {
100104
}
101105

102106
func NewClientFromCSAPIClient(cs *cloudstack.CloudStackClient) Client {
103-
c := &client{cs: cs, csAsync: cs}
107+
c := &client{cs: cs, csAsync: cs, customMetrics: metrics.NewCustomMetrics()}
104108
return c
105109
}

pkg/cloud/instance.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ func (c *client) ResolveVMInstanceDetails(csMachine *infrav1.CloudStackMachine)
5656
if csMachine.Spec.InstanceID != nil {
5757
vmResp, count, err := c.cs.VirtualMachine.GetVirtualMachinesMetricByID(*csMachine.Spec.InstanceID)
5858
if err != nil && !strings.Contains(strings.ToLower(err.Error()), "no match found") {
59+
c.customMetrics.EvaluateErrorAndIncrementAcsReconciliationErrorCounter(err)
5960
return err
6061
} else if count > 1 {
6162
return fmt.Errorf("found more than one VM Instance with ID %s", *csMachine.Spec.InstanceID)
@@ -69,6 +70,7 @@ func (c *client) ResolveVMInstanceDetails(csMachine *infrav1.CloudStackMachine)
6970
if csMachine.Name != "" {
7071
vmResp, count, err := c.cs.VirtualMachine.GetVirtualMachinesMetricByName(csMachine.Name) // add opts usage
7172
if err != nil && !strings.Contains(strings.ToLower(err.Error()), "no match") {
73+
c.customMetrics.EvaluateErrorAndIncrementAcsReconciliationErrorCounter(err)
7274
return err
7375
} else if count > 1 {
7476
return fmt.Errorf("found more than one VM Instance with name %s", csMachine.Name)
@@ -84,6 +86,7 @@ func (c *client) ResolveServiceOffering(csMachine *infrav1.CloudStackMachine) (o
8486
if len(csMachine.Spec.Offering.ID) > 0 {
8587
csOffering, count, err := c.cs.ServiceOffering.GetServiceOfferingByID(csMachine.Spec.Offering.ID)
8688
if err != nil {
89+
c.customMetrics.EvaluateErrorAndIncrementAcsReconciliationErrorCounter(err)
8790
return "", multierror.Append(retErr, errors.Wrapf(
8891
err, "could not get Service Offering by ID %s", csMachine.Spec.Offering.ID))
8992
} else if count != 1 {
@@ -99,6 +102,7 @@ func (c *client) ResolveServiceOffering(csMachine *infrav1.CloudStackMachine) (o
99102
}
100103
offeringID, count, err := c.cs.ServiceOffering.GetServiceOfferingID(csMachine.Spec.Offering.Name)
101104
if err != nil {
105+
c.customMetrics.EvaluateErrorAndIncrementAcsReconciliationErrorCounter(err)
102106
return "", multierror.Append(retErr, errors.Wrapf(
103107
err, "could not get Service Offering ID from %s", csMachine.Spec.Offering.Name))
104108
} else if count != 1 {
@@ -116,6 +120,7 @@ func (c *client) ResolveTemplate(
116120
if len(csMachine.Spec.Template.ID) > 0 {
117121
csTemplate, count, err := c.cs.Template.GetTemplateByID(csMachine.Spec.Template.ID, "executable")
118122
if err != nil {
123+
c.customMetrics.EvaluateErrorAndIncrementAcsReconciliationErrorCounter(err)
119124
return "", multierror.Append(retErr, errors.Wrapf(
120125
err, "could not get Template by ID %s", csMachine.Spec.Template.ID))
121126
} else if count != 1 {
@@ -131,6 +136,7 @@ func (c *client) ResolveTemplate(
131136
}
132137
templateID, count, err := c.cs.Template.GetTemplateID(csMachine.Spec.Template.Name, "executable", zoneID)
133138
if err != nil {
139+
c.customMetrics.EvaluateErrorAndIncrementAcsReconciliationErrorCounter(err)
134140
return "", multierror.Append(retErr, errors.Wrapf(
135141
err, "could not get Template ID from %s", csMachine.Spec.Template.Name))
136142
} else if count != 1 {
@@ -148,6 +154,7 @@ func (c *client) ResolveDiskOffering(csMachine *infrav1.CloudStackMachine) (disk
148154
if len(csMachine.Spec.DiskOffering.Name) > 0 {
149155
diskID, count, err := c.cs.DiskOffering.GetDiskOfferingID(csMachine.Spec.DiskOffering.Name)
150156
if err != nil {
157+
c.customMetrics.EvaluateErrorAndIncrementAcsReconciliationErrorCounter(err)
151158
return "", multierror.Append(retErr, errors.Wrapf(
152159
err, "could not get DiskOffering ID from %s", csMachine.Spec.DiskOffering.Name))
153160
} else if count != 1 {
@@ -174,6 +181,7 @@ func (c *client) ResolveDiskOffering(csMachine *infrav1.CloudStackMachine) (disk
174181
func verifyDiskoffering(csMachine *infrav1.CloudStackMachine, c *client, diskOfferingID string, retErr error) (string, error) {
175182
csDiskOffering, count, err := c.cs.DiskOffering.GetDiskOfferingByID(diskOfferingID)
176183
if err != nil {
184+
c.customMetrics.EvaluateErrorAndIncrementAcsReconciliationErrorCounter(err)
177185
return "", multierror.Append(retErr, errors.Wrapf(
178186
err, "could not get DiskOffering by ID %s", diskOfferingID))
179187
} else if count != 1 {
@@ -255,6 +263,8 @@ func (c *client) GetOrCreateVMInstance(
255263

256264
deployVMResp, err := c.cs.VirtualMachine.DeployVirtualMachine(p)
257265
if err != nil {
266+
c.customMetrics.EvaluateErrorAndIncrementAcsReconciliationErrorCounter(err)
267+
258268
// Just because an error was returned doesn't mean a (failed) VM wasn't created and will need to be dealt with.
259269
// Regretfully the deployVMResp may be nil, so we need to get the VM ID with a separate query, so we
260270
// can return it to the caller, so they can clean it up.
@@ -265,6 +275,8 @@ func (c *client) GetOrCreateVMInstance(
265275
listVirtualMachineParams.SetName(csMachine.Name)
266276
if listVirtualMachinesResponse, err2 := c.cs.VirtualMachine.ListVirtualMachines(listVirtualMachineParams); err2 == nil && listVirtualMachinesResponse.Count > 0 {
267277
csMachine.Spec.InstanceID = pointer.StringPtr(listVirtualMachinesResponse.VirtualMachines[0].Id)
278+
} else {
279+
c.customMetrics.EvaluateErrorAndIncrementAcsReconciliationErrorCounter(err2)
268280
}
269281
return err
270282
}
@@ -290,6 +302,7 @@ func (c *client) DestroyVMInstance(csMachine *infrav1.CloudStackMachine) error {
290302
// VM doesn't exist. Success...
291303
return nil
292304
} else if err != nil {
305+
c.customMetrics.EvaluateErrorAndIncrementAcsReconciliationErrorCounter(err)
293306
return err
294307
}
295308

@@ -316,6 +329,7 @@ func (c *client) listVMInstanceDatadiskVolumeIDs(instanceID string) ([]string, e
316329

317330
listVOLResp, err := c.csAsync.Volume.ListVolumes(p)
318331
if err != nil {
332+
c.customMetrics.EvaluateErrorAndIncrementAcsReconciliationErrorCounter(err)
319333
return nil, err
320334
}
321335

pkg/cloud/isolated_network.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ type IsoNetworkIface interface {
4444
func (c *client) getOfferingID() (string, error) {
4545
offeringID, count, retErr := c.cs.NetworkOffering.GetNetworkOfferingID(NetOffering)
4646
if retErr != nil {
47+
c.customMetrics.EvaluateErrorAndIncrementAcsReconciliationErrorCounter(retErr)
4748
return "", retErr
4849
} else if count != 1 {
4950
return "", errors.New("found more than one network offering")
@@ -76,6 +77,7 @@ func (c *client) AssociatePublicIPAddress(
7677
p.SetIpaddress(isoNet.Spec.ControlPlaneEndpoint.Host)
7778
p.SetNetworkid(isoNet.Spec.ID)
7879
if _, err := c.cs.Address.AssociateIpAddress(p); err != nil {
80+
c.customMetrics.EvaluateErrorAndIncrementAcsReconciliationErrorCounter(err)
7981
return errors.Wrapf(err,
8082
"associating public IP address with ID %s to network with ID %s",
8183
publicAddress.Id, isoNet.Spec.ID)
@@ -101,6 +103,7 @@ func (c *client) CreateIsolatedNetwork(zone *capcv1.CloudStackZone, isoNet *capc
101103
p := c.cs.Network.NewCreateNetworkParams(isoNet.Spec.Name, isoNet.Spec.Name, offeringID, zone.Spec.ID)
102104
resp, err := c.cs.Network.CreateNetwork(p)
103105
if err != nil {
106+
c.customMetrics.EvaluateErrorAndIncrementAcsReconciliationErrorCounter(err)
104107
return errors.Wrapf(err, "creating network with name %s", isoNet.Spec.Name)
105108
}
106109
isoNet.Spec.ID = resp.Id
@@ -114,6 +117,7 @@ func (c *client) OpenFirewallRules(isoNet *capcv1.CloudStackIsolatedNetwork) (re
114117
if retErr != nil && strings.Contains(strings.ToLower(retErr.Error()), "there is already") { // Already a firewall rule here.
115118
retErr = nil
116119
}
120+
c.customMetrics.EvaluateErrorAndIncrementAcsReconciliationErrorCounter(retErr)
117121
return retErr
118122
}
119123

@@ -131,6 +135,7 @@ func (c *client) GetPublicIP(
131135
setIfNotEmpty(ip, p.SetIpaddress)
132136
publicAddresses, err := c.cs.Address.ListPublicIpAddresses(p)
133137
if err != nil {
138+
c.customMetrics.EvaluateErrorAndIncrementAcsReconciliationErrorCounter(err)
134139
return nil, err
135140
} else if ip != "" && publicAddresses.Count == 1 { // Endpoint specified and IP found.
136141
// Ignore already allocated here since the IP was specified.
@@ -156,6 +161,7 @@ func (c *client) GetPublicIP(
156161
func (c *client) GetIsolatedNetwork(isoNet *capcv1.CloudStackIsolatedNetwork) (retErr error) {
157162
netDetails, count, err := c.cs.Network.GetNetworkByName(isoNet.Spec.Name)
158163
if err != nil {
164+
c.customMetrics.EvaluateErrorAndIncrementAcsReconciliationErrorCounter(err)
159165
retErr = multierror.Append(retErr, errors.Wrapf(err, "could not get Network ID from %s", isoNet.Spec.Name))
160166
} else if count != 1 {
161167
retErr = multierror.Append(retErr, errors.Errorf(
@@ -167,6 +173,7 @@ func (c *client) GetIsolatedNetwork(isoNet *capcv1.CloudStackIsolatedNetwork) (r
167173

168174
netDetails, count, err = c.cs.Network.GetNetworkByID(isoNet.Spec.ID)
169175
if err != nil {
176+
c.customMetrics.EvaluateErrorAndIncrementAcsReconciliationErrorCounter(err)
170177
return multierror.Append(retErr, errors.Wrapf(err, "could not get Network by ID %s", isoNet.Spec.ID))
171178
} else if count != 1 {
172179
return multierror.Append(retErr, errors.Errorf("expected 1 Network with UUID %s, but got %d", isoNet.Spec.ID, count))
@@ -185,6 +192,7 @@ func (c *client) ResolveLoadBalancerRuleDetails(
185192
p.SetPublicipid(isoNet.Status.PublicIPID)
186193
loadBalancerRules, err := c.cs.LoadBalancer.ListLoadBalancerRules(p)
187194
if err != nil {
195+
c.customMetrics.EvaluateErrorAndIncrementAcsReconciliationErrorCounter(err)
188196
return errors.Wrap(err, "listing load balancer rules")
189197
}
190198
for _, rule := range loadBalancerRules.LoadBalancerRules {
@@ -229,6 +237,7 @@ func (c *client) GetOrCreateLoadBalancerRule(
229237
p.SetProtocol(NetworkProtocolTCP)
230238
resp, err := c.cs.LoadBalancer.CreateLoadBalancerRule(p)
231239
if err != nil {
240+
c.customMetrics.EvaluateErrorAndIncrementAcsReconciliationErrorCounter(err)
232241
return err
233242
}
234243
isoNet.Status.LBRuleID = resp.Id
@@ -278,6 +287,7 @@ func (c *client) AssignVMToLoadBalancerRule(isoNet *capcv1.CloudStackIsolatedNet
278287
lbRuleInstances, retErr := c.cs.LoadBalancer.ListLoadBalancerRuleInstances(
279288
c.cs.LoadBalancer.NewListLoadBalancerRuleInstancesParams(isoNet.Status.LBRuleID))
280289
if retErr != nil {
290+
c.customMetrics.EvaluateErrorAndIncrementAcsReconciliationErrorCounter(retErr)
281291
return retErr
282292
}
283293
for _, instance := range lbRuleInstances.LoadBalancerRuleInstances {
@@ -290,12 +300,14 @@ func (c *client) AssignVMToLoadBalancerRule(isoNet *capcv1.CloudStackIsolatedNet
290300
p := c.cs.LoadBalancer.NewAssignToLoadBalancerRuleParams(isoNet.Status.LBRuleID)
291301
p.SetVirtualmachineids([]string{instanceID})
292302
_, retErr = c.cs.LoadBalancer.AssignToLoadBalancerRule(p)
303+
c.customMetrics.EvaluateErrorAndIncrementAcsReconciliationErrorCounter(retErr)
293304
return retErr
294305
}
295306

296307
// DeleteNetwork deletes an isolated network.
297308
func (c *client) DeleteNetwork(net capcv1.Network) error {
298309
_, err := c.cs.Network.DeleteNetwork(c.cs.Network.NewDeleteNetworkParams(net.ID))
310+
c.customMetrics.EvaluateErrorAndIncrementAcsReconciliationErrorCounter(err)
299311
return errors.Wrapf(err, "deleting network with id %s", net.ID)
300312
}
301313

@@ -350,6 +362,7 @@ func (c *client) DisassociatePublicIPAddressIfNotInUse(isoNet *capcv1.CloudStack
350362
if tagsAllowDisposal, err := c.DoClusterTagsAllowDisposal(ResourceTypeIPAddress, isoNet.Status.PublicIPID); err != nil {
351363
return err
352364
} else if publicIP, _, err := c.cs.Address.GetPublicIpAddressByID(isoNet.Status.PublicIPID); err != nil {
365+
c.customMetrics.EvaluateErrorAndIncrementAcsReconciliationErrorCounter(err)
353366
return err
354367
} else if publicIP == nil || publicIP.Issourcenat { // Can't disassociate an address if it's the source NAT address.
355368
return nil
@@ -369,5 +382,6 @@ func (c *client) DisassociatePublicIPAddress(isoNet *capcv1.CloudStackIsolatedNe
369382

370383
p := c.cs.Address.NewDisassociateIpAddressParams(isoNet.Status.PublicIPID)
371384
_, retErr = c.cs.Address.DisassociateIpAddress(p)
385+
c.customMetrics.EvaluateErrorAndIncrementAcsReconciliationErrorCounter(retErr)
372386
return retErr
373387
}

0 commit comments

Comments
 (0)