-
Notifications
You must be signed in to change notification settings - Fork 37
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
Conversation
Codecov Report
@@ 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
Continue to review full report at Codecov.
|
There was a problem hiding this 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.
core/application/app_test.go
Outdated
"errors" | ||
"testing" | ||
"time" | ||
|
||
"github.com/golang/mock/gomock" | ||
. "github.com/onsi/gomega" | ||
"github.com/spf13/afero" | ||
"gopkg.in/yaml.v2" |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
core/application/commands.go
Outdated
@@ -60,6 +65,10 @@ func (a *app) CreateMicroVM(ctx context.Context, mvm *models.MicroVM) (*models.M | |||
} | |||
} | |||
|
|||
if addErr := a.addInstanceData(mvm, logger); addErr != nil { |
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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
core/application/commands.go
Outdated
instanceData := &cloudinit.Metadata{} | ||
|
||
meta, ok := vm.Spec.Metadata["meta-data"] | ||
if ok { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added.
where?
infrastructure/grpc/convert.go
Outdated
@@ -32,6 +32,7 @@ func convertMicroVMToModel(spec *types.MicroVMSpec) (*models.MicroVM, error) { | |||
}, | |||
VCPU: int64(spec.Vcpu), | |||
MemoryInMb: int64(spec.MemoryInMb), | |||
Metadata: map[string]string{}, |
There was a problem hiding this comment.
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
There was a problem hiding this 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?
I'm going to change CAPMVM to use them :) |
ah fab |
im[k] = v | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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.
There was a problem hiding this 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 <[email protected]>
9aae37c
instance.WithPlatform(testPlatformName), | ||
) | ||
Expect(m).NotTo(BeNil()) | ||
Expect(m).To(HaveLen(5)) |
There was a problem hiding this comment.
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).
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 microvmWhich 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: