Skip to content

Commit 9229d1e

Browse files
Merge pull request #87 from JoelSpeed/max-concurrent-reconciles
OCPBUGS-23544: Improving performance of creating VMs in Azure
2 parents ee267f0 + 48d0322 commit 9229d1e

File tree

108 files changed

+7647
-241
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

108 files changed

+7647
-241
lines changed

cmd/manager/main.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,12 @@ func main() {
9393
"The duration that non-leader candidates will wait after observing a leadership renewal until attempting to acquire leadership of a led but unrenewed leader slot. This is effectively the maximum duration that a leader can be stopped before it is replaced by another candidate. This is only applicable if leader election is enabled.",
9494
)
9595

96+
maxConcurrentReconciles := flag.Int(
97+
"max-concurrent-reconciles",
98+
1,
99+
"Maximum number of concurrent reconciles per controller instance.",
100+
)
101+
96102
klog.InitFlags(nil)
97103
flag.Set("logtostderr", "true")
98104
flag.Parse()
@@ -173,7 +179,9 @@ func main() {
173179
klog.Fatal(err)
174180
}
175181

176-
if err := machine.AddWithActuator(mgr, machineActuator); err != nil {
182+
if err := machine.AddWithActuatorOpts(mgr, machineActuator, controller.Options{
183+
MaxConcurrentReconciles: *maxConcurrentReconciles,
184+
}); err != nil {
177185
klog.Fatal(err)
178186
}
179187

go.mod

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ require (
1515
github.com/mitchellh/mapstructure v1.5.0
1616
github.com/onsi/ginkgo/v2 v2.12.1
1717
github.com/onsi/gomega v1.28.0
18-
github.com/openshift/api v0.0.0-20230928105710-23b54c280f99
19-
github.com/openshift/machine-api-operator v0.2.1-0.20230929171041-2cc7fcf262f3
18+
github.com/openshift/api v0.0.0-20231120222239-b86761094ee3
19+
github.com/openshift/machine-api-operator v0.2.1-0.20240116103101-9ee88ebc3723
2020
github.com/pkg/errors v0.9.1
2121
github.com/spf13/cobra v1.7.0
2222
golang.org/x/crypto v0.14.0
@@ -38,7 +38,7 @@ require (
3838
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.6.0
3939
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.3.0
4040
github.com/jongio/azidext/go/azidext v0.4.0
41-
github.com/openshift/client-go v0.0.0-20230926161409-848405da69e1
41+
github.com/openshift/client-go v0.0.0-20231121143148-910ca30a1a9a
4242
github.com/openshift/library-go v0.0.0-20230927113136-405c34317fa4
4343
)
4444

go.sum

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -289,14 +289,14 @@ github.com/onsi/ginkgo/v2 v2.12.1 h1:uHNEO1RP2SpuZApSkel9nEh1/Mu+hmQe7Q+Pepg5OYA
289289
github.com/onsi/ginkgo/v2 v2.12.1/go.mod h1:TE309ZR8s5FsKKpuB1YAQYBzCaAfUgatB/xlT/ETL/o=
290290
github.com/onsi/gomega v1.28.0 h1:i2rg/p9n/UqIDAMFUJ6qIUUMcsqOuUHgbpbu235Vr1c=
291291
github.com/onsi/gomega v1.28.0/go.mod h1:A1H2JE76sI14WIP57LMKj7FVfCHx3g3BcZVjJG8bjX8=
292-
github.com/openshift/api v0.0.0-20230928105710-23b54c280f99 h1:Af0gMLdVtRwzOREh3Ghw362KXzalKQeR/DWpDEf6ZBk=
293-
github.com/openshift/api v0.0.0-20230928105710-23b54c280f99/go.mod h1:qNtV0315F+f8ld52TLtPvrfivZpdimOzTi3kn9IVbtU=
294-
github.com/openshift/client-go v0.0.0-20230926161409-848405da69e1 h1:W1N/3nVciqmjPjn2xldHjb0AwwCQzlGxLvX5BCgE8H4=
295-
github.com/openshift/client-go v0.0.0-20230926161409-848405da69e1/go.mod h1:ihUJrhBcYAGYQrJu/gP2OMgfVds5f5z5kbeLNBqjHLo=
292+
github.com/openshift/api v0.0.0-20231120222239-b86761094ee3 h1:nLhV2lbWrJ3E3hx0/97G3ZZvppC67cNwo+CLp7/PAbA=
293+
github.com/openshift/api v0.0.0-20231120222239-b86761094ee3/go.mod h1:qNtV0315F+f8ld52TLtPvrfivZpdimOzTi3kn9IVbtU=
294+
github.com/openshift/client-go v0.0.0-20231121143148-910ca30a1a9a h1:4FVrw8hz0Wb3izbf6JfOEK+pJTYpEvteRR73mCh2g/A=
295+
github.com/openshift/client-go v0.0.0-20231121143148-910ca30a1a9a/go.mod h1:arApQobmOjZqtxw44TwnQdUCH+t9DgZ8geYPFqksHws=
296296
github.com/openshift/library-go v0.0.0-20230927113136-405c34317fa4 h1:nNPH6wOCPP6XLDyHECflAlgW7xLorcUq7wl0vqyRQ34=
297297
github.com/openshift/library-go v0.0.0-20230927113136-405c34317fa4/go.mod h1:hl8bxWuFMM72N4YH7FKLGWtYhDz/A0xwvaa8Yr5fxYU=
298-
github.com/openshift/machine-api-operator v0.2.1-0.20230929171041-2cc7fcf262f3 h1:9nIeQjMOOTNHucCmjxVWZHOg364HYDGjl5rp2CQ+A0I=
299-
github.com/openshift/machine-api-operator v0.2.1-0.20230929171041-2cc7fcf262f3/go.mod h1:NxAKfWiKFTYsLeR/jVrPTqlGty66apTYjUTEhT1olMw=
298+
github.com/openshift/machine-api-operator v0.2.1-0.20240116103101-9ee88ebc3723 h1:OwL32bxSXZD56rF4+Pa6EhAw8a5HIsbVQXyl5m4v+cI=
299+
github.com/openshift/machine-api-operator v0.2.1-0.20240116103101-9ee88ebc3723/go.mod h1:Qb9z7lDje2fNZQwds153HNs16CpSYqnZd9R3LfMOD4M=
300300
github.com/peterbourgon/diskv v2.0.1+incompatible h1:UBdAOUP5p4RWqPBg048CAvpKN+vxiaj6gdUUzhl4XmI=
301301
github.com/peterbourgon/diskv v2.0.1+incompatible/go.mod h1:uqqh8zWWbv1HBMNONnaR/tNboyR3/BZd58JJSHlUSCU=
302302
github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 h1:KoWmjvw+nsYOo29YJK9vDA65RGE3NrOnUtO7a+RF9HU=

pkg/cloud/azure/actuators/machine/actuator_test.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -343,8 +343,9 @@ func TestReconcileVMSuceededState(t *testing.T) {
343343
t.Errorf("failed to create machine: %+v", err)
344344
}
345345

346-
if fakeVMService.GetCallCount != 1 {
347-
t.Errorf("expected get to be called just once")
346+
if fakeVMService.GetCallCount != 2 {
347+
// One call for create, and one for the update that happens when the create is successful.
348+
t.Errorf("expected get to be called exactly twice")
348349
}
349350

350351
if fakeVMService.DeleteCallCount != 0 {
@@ -359,11 +360,18 @@ func TestReconcileVMSuceededState(t *testing.T) {
359360
// FakeVMCheckZonesService generic fake vm zone service
360361
type FakeVMCheckZonesService struct {
361362
checkZones []string
363+
created bool
362364
}
363365

364366
// Get returns fake success.
365367
func (s *FakeVMCheckZonesService) Get(ctx context.Context, spec azure.Spec) (interface{}, error) {
366-
return nil, errors.New("vm not found")
368+
if !s.created {
369+
return nil, errors.New("vm not found")
370+
}
371+
372+
return &compute.VirtualMachine{
373+
VirtualMachineProperties: &compute.VirtualMachineProperties{},
374+
}, nil
367375
}
368376

369377
// CreateOrUpdate returns fake success.
@@ -374,10 +382,12 @@ func (s *FakeVMCheckZonesService) CreateOrUpdate(ctx context.Context, spec azure
374382
}
375383

376384
if len(s.checkZones) <= 0 {
385+
s.created = true
377386
return nil
378387
}
379388
for _, zone := range s.checkZones {
380389
if strings.EqualFold(zone, vmSpec.Zone) {
390+
s.created = true
381391
return nil
382392
}
383393
}

pkg/cloud/azure/actuators/machine/reconciler.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727

2828
"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2021-11-01/compute"
2929
"github.com/Azure/go-autorest/autorest"
30+
autorestazure "github.com/Azure/go-autorest/autorest/azure"
3031
machinev1 "github.com/openshift/api/machine/v1beta1"
3132
machinecontroller "github.com/openshift/machine-api-operator/pkg/controller/machine"
3233
"github.com/openshift/machine-api-operator/pkg/metrics"
@@ -139,6 +140,13 @@ func (s *Reconciler) CreateMachine(ctx context.Context) error {
139140
return fmt.Errorf("failed to create vm %s: %w", s.scope.Machine.Name, err)
140141
}
141142

143+
// Once we have created the machine, attempt to update it.
144+
// This should set the network addresses and provider ID which should be set as soon
145+
// as the machine is created, moving it to the provisioned phase.
146+
if err := s.Update(ctx); err != nil {
147+
return fmt.Errorf("failed to update machine %s: %w", s.scope.Machine.Name, err)
148+
}
149+
142150
return nil
143151
}
144152

@@ -700,8 +708,8 @@ func (s *Reconciler) createVirtualMachine(ctx context.Context, nicName, asName s
700708
vmSpec.CustomData = userData
701709
}
702710

703-
err = s.virtualMachinesSvc.CreateOrUpdate(ctx, vmSpec)
704-
if err != nil {
711+
// If we get an AsynOpIncompleteError, this means the VM is being created and we completed the request successfully.
712+
if err := s.virtualMachinesSvc.CreateOrUpdate(ctx, vmSpec); err != nil && !errors.Is(err, autorestazure.NewAsyncOpIncompleteError("compute.VirtualMachinesCreateOrUpdateFuture")) {
705713
metrics.RegisterFailedInstanceCreate(&metrics.MachineLabels{
706714
Name: s.scope.Machine.Name,
707715
Namespace: s.scope.Machine.Namespace,
@@ -712,6 +720,7 @@ func (s *Reconciler) createVirtualMachine(ctx context.Context, nicName, asName s
712720
if errors.As(err, &detailedError) && detailedError.Message == "Failure sending request" {
713721
return machinecontroller.InvalidMachineConfiguration("failure sending request for machine %s: %v", s.scope.Machine.Name, err)
714722
}
723+
715724
return fmt.Errorf("failed to create VM: %w", err)
716725
}
717726
} else if err != nil {

vendor/github.com/openshift/api/Dockerfile.rhel8

Lines changed: 3 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/openshift/api/OWNERS

Lines changed: 0 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/openshift/api/README.md

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/openshift/api/build/v1/consts.go

Lines changed: 4 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/openshift/api/config/v1/0000_00_cluster-version-operator_01_clusterversion.crd.yaml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)