Skip to content

Commit

Permalink
feat: Make create return full Microvm object (#361)
Browse files Browse the repository at this point in the history
Previously this was just the spec, but it is useful to have more so that
we can get things like the provider ID.
  • Loading branch information
Callisto13 authored Jan 25, 2022
1 parent 48a1ae5 commit 95e8687
Show file tree
Hide file tree
Showing 9 changed files with 108 additions and 104 deletions.
178 changes: 89 additions & 89 deletions api/services/microvm/v1alpha1/microvms.pb.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion api/services/microvm/v1alpha1/microvms.proto
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ message CreateMicroVMRequest {
}

message CreateMicroVMResponse {
flintlock.types.MicroVMSpec microvm = 1;
flintlock.types.MicroVM microvm = 1;
}

message DeleteMicroVMRequest {
Expand Down
2 changes: 1 addition & 1 deletion api/services/microvm/v1alpha1/microvms.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@
"type": "object",
"properties": {
"microvm": {
"$ref": "#/definitions/typesMicroVMSpec"
"$ref": "#/definitions/typesMicroVM"
}
}
},
Expand Down
6 changes: 3 additions & 3 deletions buf.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ deps:
owner: googleapis
repository: googleapis
branch: main
commit: 0039142542b74d11b0ae5a1e9fd4d523
digest: b1-AzPoqjtlLpx5dVojvgRauI1re5i4LPsghzU0KO-16o4=
create_time: 2022-01-05T15:03:17.46488Z
commit: 6f119269f95240afb69b052c93992f46
digest: b1-FqoWvdt8ivSWpqSHtadcv6cG7ZzejzQHuj7G5CAUg80=
create_time: 2022-01-22T15:05:34.236772Z
- remote: buf.build
owner: grpc-ecosystem
repository: grpc-gateway
Expand Down
2 changes: 1 addition & 1 deletion infrastructure/grpc/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func convertVolumeToModel(volume *types.Volume) *models.Volume {
return convertedVol
}

func convertModelToMicroVM(mvm *models.MicroVM) *types.MicroVMSpec {
func convertModelToMicroVMSpec(mvm *models.MicroVM) *types.MicroVMSpec {
converted := &types.MicroVMSpec{
Id: mvm.ID.Name(),
Namespace: mvm.ID.Namespace(),
Expand Down
12 changes: 8 additions & 4 deletions infrastructure/grpc/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,11 @@ func (s *server) CreateMicroVM(
logger.Trace("converting model to response")

resp := &mvmv1.CreateMicroVMResponse{
Microvm: convertModelToMicroVM(createdModel),
Microvm: &types.MicroVM{
Version: int32(createdModel.Version),
Spec: convertModelToMicroVMSpec(createdModel),
Status: convertModelToMicroVMStatus(createdModel),
},
}

return resp, nil
Expand Down Expand Up @@ -130,7 +134,7 @@ func (s *server) GetMicroVM(ctx context.Context, req *mvmv1.GetMicroVMRequest) (
resp := &mvmv1.GetMicroVMResponse{
Microvm: &types.MicroVM{
Version: int32(foundMicrovm.Version),
Spec: convertModelToMicroVM(foundMicrovm),
Spec: convertModelToMicroVMSpec(foundMicrovm),
Status: convertModelToMicroVMStatus(foundMicrovm),
},
}
Expand Down Expand Up @@ -168,7 +172,7 @@ func (s *server) ListMicroVMs(ctx context.Context,
for _, mvm := range foundMicrovms {
converted := &types.MicroVM{
Version: int32(mvm.Version),
Spec: convertModelToMicroVM(mvm),
Spec: convertModelToMicroVMSpec(mvm),
Status: convertModelToMicroVMStatus(mvm),
}
resp.Microvm = append(resp.Microvm, converted)
Expand Down Expand Up @@ -206,7 +210,7 @@ func (s *server) ListMicroVMsStream(
resp := &mvmv1.ListMessage{
Microvm: &types.MicroVM{
Version: int32(mvm.Version),
Spec: convertModelToMicroVM(mvm),
Spec: convertModelToMicroVMSpec(mvm),
Status: convertModelToMicroVMStatus(mvm),
},
}
Expand Down
4 changes: 2 additions & 2 deletions infrastructure/grpc/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ func TestServer_CreateMicroVM(t *testing.T) {
Expect(err).To(HaveOccurred())
} else {
Expect(err).NotTo(HaveOccurred())
Expect(resp.Microvm.Id).To(Equal("mvm1"))
Expect(resp.Microvm.Namespace).To(Equal("default"))
Expect(resp.Microvm.Spec.Id).To(Equal("mvm1"))
Expect(resp.Microvm.Spec.Namespace).To(Equal("default"))
}
})
}
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func TestE2E(t *testing.T) {

log.Println("TEST STEP: creating MicroVM")
created := u.CreateMVM(flintlockClient, mvmID, mvmNS)
Expect(created.Microvm.Id).To(Equal(mvmID))
Expect(created.Microvm.Spec.Id).To(Equal(mvmID))

log.Println("TEST STEP: getting (and verifying) existing MicroVM")
Eventually(func(g Gomega) error {
Expand All @@ -65,7 +65,7 @@ func TestE2E(t *testing.T) {

log.Println("TEST STEP: creating a second MicroVM")
created = u.CreateMVM(flintlockClient, secondMvmID, mvmNS)
Expect(created.Microvm.Id).To(Equal(secondMvmID))
Expect(created.Microvm.Spec.Id).To(Equal(secondMvmID))

log.Println("TEST STEP: listing all MicroVMs")
Eventually(func(g Gomega) error {
Expand Down
2 changes: 1 addition & 1 deletion userdocs/docs/grpc/services/microvm/v1alpha1/proto.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@

| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| microvm | [flintlock.types.MicroVMSpec](#flintlock.types.MicroVMSpec) | | |
| microvm | [flintlock.types.MicroVM](#flintlock.types.MicroVM) | | |



Expand Down

0 comments on commit 95e8687

Please sign in to comment.