Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set instance_id in flintlock #394

Merged
merged 1 commit into from
Feb 21, 2022
Merged

Set instance_id in flintlock #394

merged 1 commit into from
Feb 21, 2022

Conversation

richardcase
Copy link
Member

What this PR does / why we need it:

This change will set the instance_id in the metadata if its not set to the UID for the microvm

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Fixes #

Special notes for your reviewer:

Checklist:

  • squashed commits into logical changes
  • includes documentation
  • adds unit tests
  • adds or updates e2e tests

@richardcase richardcase added the kind/feature New feature or request label Feb 15, 2022
@codecov-commenter
Copy link

codecov-commenter commented Feb 15, 2022

Codecov Report

Merging #394 (29fc4f2) into main (f9607be) will increase coverage by 0.17%.
The diff coverage is 57.57%.

❗ Current head 29fc4f2 differs from pull request most recent head 9aae37c. Consider uploading reports for the commit 9aae37c to get more accurate results

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #394      +/-   ##
==========================================
+ Coverage   56.71%   56.89%   +0.17%     
==========================================
  Files          52       52              
  Lines        2599     2626      +27     
==========================================
+ Hits         1474     1494      +20     
- Misses       1001     1005       +4     
- Partials      124      127       +3     
Impacted Files Coverage Δ
infrastructure/firecracker/config.go 0.00% <0.00%> (ø)
core/application/commands.go 71.57% <69.23%> (-0.89%) ⬇️
infrastructure/grpc/convert.go 42.30% <100.00%> (+0.31%) ⬆️
pkg/process/process.go 39.62% <0.00%> (+1.88%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f9607be...9aae37c. Read the comment docs.

@richardcase richardcase marked this pull request as ready for review February 15, 2022 18:01
@richardcase richardcase changed the title [WIP] Set instance_id in flintlock Set instance_id in flintlock Feb 15, 2022
Copy link

@bigkevmcd bigkevmcd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, nothing major.

"errors"
"testing"
"time"

"github.com/golang/mock/gomock"
. "github.com/onsi/gomega"
"github.com/spf13/afero"
"gopkg.in/yaml.v2"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd probably use https://pkg.go.dev/sigs.k8s.io/yaml instead of v2 of go-yaml

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to use this wrapper.

@@ -60,6 +65,10 @@ func (a *app) CreateMicroVM(ctx context.Context, mvm *models.MicroVM) (*models.M
}
}

if addErr := a.addInstanceData(mvm, logger); addErr != nil {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure there's any benefit in addErr here?

You've already returned if err wasn't nil earlier, which implies you don't want to retain the value ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was a mistake but i have changed this to reuse err

instanceData := &cloudinit.Metadata{}

meta, ok := vm.Spec.Metadata["meta-data"]
if ok {
Copy link

@bigkevmcd bigkevmcd Feb 16, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you drop the comma, ok mechanism here, and check for vm.Spec.Metadata["meta-data"] not being ""?

You can decode "" but it would fail the YAML decoding, which implies that "" is not considered a valid value

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed the logic here based on your suggestion


meta, ok := vm.Spec.Metadata["meta-data"]
if ok {
logger.Info("Instance metadata exists")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any extra logging data that could come out here? the MicroVM ID perhaps?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added.

where?

@@ -32,6 +32,7 @@ func convertMicroVMToModel(spec *types.MicroVMSpec) (*models.MicroVM, error) {
},
VCPU: int64(spec.Vcpu),
MemoryInMb: int64(spec.MemoryInMb),
Metadata: map[string]string{},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could technically be an instance.New() i guess

Callisto13
Callisto13 previously approved these changes Feb 18, 2022
Copy link
Member

@Callisto13 Callisto13 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the plan for those MetadataOption funcs?

@richardcase
Copy link
Member Author

What's the plan for those MetadataOption funcs?

I'm going to change CAPMVM to use them :)

@Callisto13
Copy link
Member

ah fab

im[k] = v
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a custom WithKeyVaue or WithCustomField would be useful. Right now we are not using anything else, but in production ppl might want to define more data.

func WithKeyValue(key, value string) MetadataOption {
	return func(im Metadata) {
		im[key] = value
	}
}

potentially all WithXXX can use that as well, so if we need validation we can do it in one place (like don't add if the value is empty)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thats a good point. Let me change that.

yitsushi
yitsushi previously approved these changes Feb 18, 2022
Copy link
Contributor

@yitsushi yitsushi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's funny to see my original map solution comes back and says "hi" 😄

When a request is made to create a microvm we will automatically add the
UID of the microvm to the instance meta-data with the instance_id key if
its not already set.

Small refactor of the cloudinit package.

Signed-off-by: Richard Case <richard@weave.works>
@richardcase richardcase dismissed stale reviews from yitsushi and Callisto13 via 9aae37c February 18, 2022 17:08
instance.WithPlatform(testPlatformName),
)
Expect(m).NotTo(BeNil())
Expect(m).To(HaveLen(5))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could simplify this to just HaveLen(5) because it can't be both nil and have len 5

The one above is fine (NotTo(BeNil())) because you want to ensure that it's a len 0 slice, and nil has len 0.

(There is another below).

@richardcase richardcase merged commit 66f81a6 into liquidmetal-dev:main Feb 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants