Skip to content

Commit 23ef72c

Browse files
committed
feat: provider id changes & add microvm proxy
Changed the machine reconciliation so that it uses the standard format for the provider id with uses a prefix. The prefix for this provider is `microvm://`. The provider id is parsed when looking up the status of the microvm. Additionally, the ability to explicitly set a proxy server for the microvm service has been added to the APIs. This is for scenarios where you don't want to use the HTTP[S]_PROXY env vars. Signed-off-by: Richard Case <richard@weave.works>
1 parent d4363fd commit 23ef72c

16 files changed

Lines changed: 142 additions & 37 deletions

api/v1alpha1/microvmcluster_types.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ type MicrovmClusterSpec struct {
2525
// Placement specifies how machines for the cluster should be placed onto hosts (i.e. where the microvms are created).
2626
// +kubebuilder:validation:Required
2727
Placement Placement `json:"placement"`
28+
// MicrovmProxy is the proxy server details to use when calling the microvm service. This is an
29+
// alteranative to using the http proxy environment variables and applied purely to the grpc service.
30+
MicrovmProxy *Proxy `json:"microvmProxy,omitempty"`
2831
}
2932

3033
// MicrovmClusterStatus defines the observed state of MicrovmCluster.

api/v1alpha1/types.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,3 +163,9 @@ type MicrovmHost struct {
163163
// +kubebuilder:default=true
164164
ControlPlaneAllowed bool `json:"controlplaneAllowed"`
165165
}
166+
167+
// Proxy represents a proxy server.
168+
type Proxy struct {
169+
// Endpoint is the address of the proxy.
170+
Endpoint string `json:"endpoint"`
171+
}

api/v1alpha1/zz_generated.deepcopy.go

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

config/crd/bases/infrastructure.cluster.x-k8s.io_microvmclusters.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,18 @@ spec:
6969
- host
7070
- port
7171
type: object
72+
microvmProxy:
73+
description: MicrovmProxy is the proxy server details to use when
74+
calling the microvm service. This is an alteranative to using the
75+
http proxy environment variables and applied purely to the grpc
76+
service.
77+
properties:
78+
endpoint:
79+
description: Endpoint is the address of the proxy.
80+
type: string
81+
required:
82+
- endpoint
83+
type: object
7284
placement:
7385
description: Placement specifies how machines for the cluster should
7486
be placed onto hosts (i.e. where the microvms are created).

controllers/helpers_test.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package controllers_test
66
import (
77
"context"
88
"encoding/base64"
9+
"fmt"
910

1011
. "github.com/onsi/gomega"
1112
"gopkg.in/yaml.v2"
@@ -29,7 +30,7 @@ import (
2930
"github.com/weaveworks/cluster-api-provider-microvm/internal/services/microvm/mock_client"
3031
flintlockv1 "github.com/weaveworks/flintlock/api/services/microvm/v1alpha1"
3132
flintlocktypes "github.com/weaveworks/flintlock/api/types"
32-
"github.com/weaveworks/flintlock/client/cloudinit"
33+
"github.com/weaveworks/flintlock/client/cloudinit/userdata"
3334
)
3435

3536
const (
@@ -86,7 +87,7 @@ func (co clusterObjects) AsRuntimeObjects() []runtime.Object {
8687
func reconcileMachine(client client.Client, mockAPIClient microvm.Client) (ctrl.Result, error) {
8788
machineController := &controllers.MicrovmMachineReconciler{
8889
Client: client,
89-
MvmClientFunc: func(address string) (microvm.Client, error) {
90+
MvmClientFunc: func(address string, proxy *infrav1.Proxy) (microvm.Client, error) {
9091
return mockAPIClient, nil
9192
},
9293
}
@@ -363,7 +364,8 @@ func assertMachineReconciled(g *WithT, reconciled *infrav1.MicrovmMachine) {
363364
assertMachineVMState(g, reconciled, infrav1.VMStateRunning)
364365
assertMachineFinalizer(g, reconciled)
365366
g.Expect(reconciled.Spec.ProviderID).ToNot(BeNil())
366-
g.Expect(*reconciled.Spec.ProviderID).To(Equal(testMachineUID))
367+
expectedProviderID := fmt.Sprintf("microvm://%s", testMachineUID)
368+
g.Expect(*reconciled.Spec.ProviderID).To(Equal(expectedProviderID))
367369
g.Expect(reconciled.Status.Ready).To(BeTrue(), "The Ready property must be true when the machine has been reconciled")
368370
}
369371

@@ -401,7 +403,7 @@ func assertVendorData(g *WithT, vendorDataRaw string, expectedSSHKey string) {
401403
g.Expect(err).NotTo(HaveOccurred(), "expect vendor data to be base64 encoded")
402404

403405
if expectedSSHKey != "" {
404-
vendorData := &cloudinit.UserData{}
406+
vendorData := &userdata.UserData{}
405407

406408
unmarshallErr := yaml.Unmarshal(data, vendorData)
407409
g.Expect(unmarshallErr).NotTo(HaveOccurred(), "expect vendor data to unmarshall to cloud-init userdata")

controllers/microvmmachine_controller.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,9 @@ func (r *MicrovmMachineReconciler) reconcileNormal(
243243

244244
var microvm *flintlocktypes.MicroVM
245245

246-
if machineScope.MvmMachine.Spec.ProviderID != nil {
246+
providerID := machineScope.GetProviderID()
247+
248+
if providerID != "" {
247249
var err error
248250

249251
microvm, err = mvmSvc.Get(ctx)
@@ -302,7 +304,7 @@ func (r *MicrovmMachineReconciler) getMicrovmService(machineScope *scope.Machine
302304
return nil, err
303305
}
304306

305-
client, err := r.MvmClientFunc(addr)
307+
client, err := r.MvmClientFunc(addr, machineScope.MvmCluster.Spec.MicrovmProxy)
306308
if err != nil {
307309
return nil, fmt.Errorf("creating microvm client: %w", err)
308310
}

controllers/microvmmachine_controller_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package controllers_test
66
import (
77
"encoding/base64"
88
"errors"
9+
"fmt"
910
"testing"
1011
"time"
1112

@@ -274,7 +275,8 @@ func TestMachineReconcileNoVmCreateSucceeds(t *testing.T) {
274275
reconciled, err := getMicrovmMachine(client, testMachineName, testClusterNamespace)
275276
g.Expect(err).NotTo(HaveOccurred(), "Getting microvm machine should not fail")
276277

277-
g.Expect(reconciled.Spec.ProviderID).To(Equal(pointer.String(testMachineUID)))
278+
expectedProviderID := fmt.Sprintf("microvm://%s", testMachineUID)
279+
g.Expect(reconciled.Spec.ProviderID).To(Equal(pointer.String(expectedProviderID)))
278280
g.Expect(reconciled.Spec.FailureDomain).To(Equal(pointer.String("127.0.0.1:9090")))
279281

280282
assertConditionFalse(g, reconciled, infrav1.MicrovmReadyCondition, infrav1.MicrovmPendingReason)

docs/compatibility.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22

33
This table shows the compatibility between CAPMVM and Flintlock versions.
44

5-
| CAPMVM | Flintlock |
6-
| ----------- | ----------- |
5+
| CAPMVM | Flintlock |
6+
| ----------- | ---------------------- |
7+
| `v0.4.0` | `v0.1.0-alpha.8` |
78
| `v0.3.0` | `v0.1.0-alpha.6` |
89
| `v0.2.2` | `v0.1.0-alpha.5` |
910

go.mod

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ go 1.17
44

55
require (
66
github.com/go-logr/logr v0.4.0
7-
github.com/onsi/gomega v1.17.0
7+
github.com/onsi/gomega v1.18.1
88
github.com/spf13/pflag v1.0.5
99
github.com/weaveworks/flintlock/api v0.0.0-20220126090930-054c6c3be154
10-
github.com/weaveworks/flintlock/client v0.0.0-20220126090930-054c6c3be154
10+
github.com/weaveworks/flintlock/client v0.0.0-20220221140503-8032d3ff7d2c
1111
github.com/yitsushi/macpot v1.0.2
12-
google.golang.org/grpc v1.42.0
12+
google.golang.org/grpc v1.44.0
1313
google.golang.org/protobuf v1.27.1
1414
gopkg.in/yaml.v2 v2.4.0
1515
k8s.io/api v0.22.4
@@ -63,7 +63,7 @@ require (
6363
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 // indirect
6464
golang.org/x/net v0.0.0-20210520170846-37e1c6afe023 // indirect
6565
golang.org/x/oauth2 v0.0.0-20210819190943-2bc19b11175f // indirect
66-
golang.org/x/sys v0.0.0-20210823070655-63515b42dcdf // indirect
66+
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e // indirect
6767
golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d // indirect
6868
golang.org/x/text v0.3.6 // indirect
6969
golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac // indirect

go.sum

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,7 @@ github.com/google/pprof v0.0.0-20201023163331-3e6fc7fc9c4c/go.mod h1:kpwsk12EmLe
283283
github.com/google/pprof v0.0.0-20201203190320-1bf35d6f28c2/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
284284
github.com/google/pprof v0.0.0-20210122040257-d980be63207e/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
285285
github.com/google/pprof v0.0.0-20210226084205-cbba55b83ad5/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
286+
github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
286287
github.com/google/pprof v0.0.0-20210601050228-01bbb1931b22/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
287288
github.com/google/pprof v0.0.0-20210609004039-a478d1d731e9/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
288289
github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
@@ -438,13 +439,16 @@ github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108
438439
github.com/onsi/ginkgo v1.14.0/go.mod h1:iSB4RoI2tjJc9BBv4NKIKWKya62Rps+oPG/Lv9klQyY=
439440
github.com/onsi/ginkgo v1.16.4 h1:29JGrr5oVBm5ulCWet69zQkzWipVXIol6ygQUe/EzNc=
440441
github.com/onsi/ginkgo v1.16.4/go.mod h1:dX+/inL/fNMqNlz0e9LfyB9TswhZpCVdJM/Z6Vvnwo0=
442+
github.com/onsi/ginkgo/v2 v2.0.0/go.mod h1:vw5CSIxN1JObi/U8gcbwft7ZxR2dgaR70JSE3/PpL4c=
441443
github.com/onsi/gomega v0.0.0-20170829124025-dcabb60a477c/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA=
442444
github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY=
443445
github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo=
444446
github.com/onsi/gomega v1.15.0/go.mod h1:cIuvLEne0aoVhAgh/O6ac0Op8WWw9H6eYCriF+tEHG0=
445447
github.com/onsi/gomega v1.16.0/go.mod h1:HnhC7FXeEQY45zxNK3PPoIUhzk/80Xly9PcubAlGdZY=
446448
github.com/onsi/gomega v1.17.0 h1:9Luw4uT5HTjHTN8+aNcSThgH1vdXnmdJ8xIfZ4wyTRE=
447449
github.com/onsi/gomega v1.17.0/go.mod h1:HnhC7FXeEQY45zxNK3PPoIUhzk/80Xly9PcubAlGdZY=
450+
github.com/onsi/gomega v1.18.1 h1:M1GfJqGRrBrrGGsbxzV5dqM2U2ApXefZCQpkukxYRLE=
451+
github.com/onsi/gomega v1.18.1/go.mod h1:0q+aL8jAiMXy9hbwj2mr5GziHiwhAIQpFmmtT5hitRs=
448452
github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U=
449453
github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
450454
github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o=
@@ -546,6 +550,8 @@ github.com/weaveworks/flintlock/api v0.0.0-20220126090930-054c6c3be154 h1:ReCeLg
546550
github.com/weaveworks/flintlock/api v0.0.0-20220126090930-054c6c3be154/go.mod h1:RFgQ7RSa7zGNxxR+dS6NRDCQ/IAN23WCfXg4+L6fclI=
547551
github.com/weaveworks/flintlock/client v0.0.0-20220126090930-054c6c3be154 h1:LbMhm60d/6/MkhwXSJaf960JcNK986r5YzC75vNqylc=
548552
github.com/weaveworks/flintlock/client v0.0.0-20220126090930-054c6c3be154/go.mod h1:1jiepUOR2kxAdoxXXyNQ0LnOeT2gOUSnWGuXh9akjDw=
553+
github.com/weaveworks/flintlock/client v0.0.0-20220221140503-8032d3ff7d2c h1:997um3xki94Qmho3WiuuzfFGsxCn96X7T4PAfLR33kE=
554+
github.com/weaveworks/flintlock/client v0.0.0-20220221140503-8032d3ff7d2c/go.mod h1:4G/IetnXREmEo1agCWLwYScjw4+ElzKcDLjJ4seZJ6k=
549555
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
550556
github.com/xlab/treeprint v0.0.0-20181112141820-a009c3971eca/go.mod h1:ce1O1j6UtZfjr22oyGxGLbauSBp2YVXpARAosm7dHBg=
551557
github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q=
@@ -798,6 +804,8 @@ golang.org/x/sys v0.0.0-20210806184541-e5e7981a1069/go.mod h1:oPkhp1MJrh7nUepCBc
798804
golang.org/x/sys v0.0.0-20210817190340-bfb29a6856f2/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
799805
golang.org/x/sys v0.0.0-20210823070655-63515b42dcdf h1:2ucpDCmfkl8Bd/FsLtiD653Wf96cW37s+iGx93zsu4k=
800806
golang.org/x/sys v0.0.0-20210823070655-63515b42dcdf/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
807+
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e h1:fLOSk5Q00efkSvAm+4xcoXD+RRmLmmulPn5I3Y9F2EM=
808+
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
801809
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
802810
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
803811
golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d h1:SZxvLBoTP5yHO3Frd4z4vrF+DBX9vMVanchswa69toE=
@@ -1009,6 +1017,8 @@ google.golang.org/grpc v1.40.0/go.mod h1:ogyxbiOoUXAkP+4+xa6PZSE9DZgIHtSpzjDTB9K
10091017
google.golang.org/grpc v1.41.0/go.mod h1:U3l9uK9J0sini8mHphKoXyaqDA/8VyGnDee1zzIUK6k=
10101018
google.golang.org/grpc v1.42.0 h1:XT2/MFpuPFsEX2fWh3YQtHkZ+WYZFQRfaUgLZYj/p6A=
10111019
google.golang.org/grpc v1.42.0/go.mod h1:k+4IHHFw41K8+bbowsex27ge2rCb65oeWqe4jJ590SU=
1020+
google.golang.org/grpc v1.44.0 h1:weqSxi/TMs1SqFRMHCtBgXRs8k3X39QIDEZ0pRcttUg=
1021+
google.golang.org/grpc v1.44.0/go.mod h1:k+4IHHFw41K8+bbowsex27ge2rCb65oeWqe4jJ590SU=
10121022
google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.1.0/go.mod h1:6Kw0yEErY5E/yWrBtf03jp27GLLJujG4z/JK95pnjjw=
10131023
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
10141024
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=

0 commit comments

Comments
 (0)