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

feat: populate meta-data for microvms #57

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ require (
github.com/onsi/gomega v1.17.0
github.com/spf13/pflag v1.0.5
github.com/weaveworks/flintlock/api v0.0.0-20211124154423-21a022445576
github.com/weaveworks/flintlock/client v0.0.0-20211213114330-12eb53621738
github.com/yitsushi/macpot v1.0.2
google.golang.org/grpc v1.42.0
google.golang.org/protobuf v1.27.1
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,8 @@ github.com/tmc/grpc-websocket-proxy v0.0.0-20201229170055-e5319fda7802/go.mod h1
github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGrc=
github.com/weaveworks/flintlock/api v0.0.0-20211124154423-21a022445576 h1:f5QFSzuYSgpzgKkrS/sXTwr+ZnPzP9oR40na9nzgotg=
github.com/weaveworks/flintlock/api v0.0.0-20211124154423-21a022445576/go.mod h1:RFgQ7RSa7zGNxxR+dS6NRDCQ/IAN23WCfXg4+L6fclI=
github.com/weaveworks/flintlock/client v0.0.0-20211213114330-12eb53621738 h1:UyKUaJYf/dN8zcq7OWy15ISSjOjqwOyXe4acWOt7NdM=
github.com/weaveworks/flintlock/client v0.0.0-20211213114330-12eb53621738/go.mod h1:1jiepUOR2kxAdoxXXyNQ0LnOeT2gOUSnWGuXh9akjDw=
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
github.com/xlab/treeprint v0.0.0-20181112141820-a009c3971eca/go.mod h1:ce1O1j6UtZfjr22oyGxGLbauSBp2YVXpARAosm7dHBg=
github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q=
Expand Down
25 changes: 23 additions & 2 deletions internal/services/microvm/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,20 @@
package microvm

import (
"encoding/base64"
"fmt"

flintlocktypes "github.com/weaveworks/flintlock/api/types"
flcloudinit "github.com/weaveworks/flintlock/client/cloudinit"
"gopkg.in/yaml.v3"

"github.com/weaveworks/cluster-api-provider-microvm/api/v1alpha1"
"github.com/weaveworks/cluster-api-provider-microvm/internal/scope"
)

func convertToFlintlockAPI(machineScope *scope.MachineScope) *flintlocktypes.MicroVMSpec {
const platformLiquidMetal = "liquid_metal"

func convertToFlintlockAPI(machineScope *scope.MachineScope) (*flintlocktypes.MicroVMSpec, error) {
mvmSpec := machineScope.MvmMachine.Spec

apiVM := &flintlocktypes.MicroVMSpec{
Expand Down Expand Up @@ -82,5 +89,19 @@ func convertToFlintlockAPI(machineScope *scope.MachineScope) *flintlocktypes.Mic
apiVM.Interfaces = append(apiVM.Interfaces, apiIface)
}

return apiVM
userMetadata := flcloudinit.Metadata{
InstanceID: fmt.Sprintf("%s/%s", machineScope.Namespace(), machineScope.Name()),
LocalHostname: machineScope.Name(),
Platform: platformLiquidMetal,
ClusterName: machineScope.ClusterName(),
}

userMeta, err := yaml.Marshal(userMetadata)
if err != nil {
return apiVM, fmt.Errorf("unable to marshal metadata: %w", err)
}

apiVM.Metadata["meta-data"] = base64.StdEncoding.EncodeToString(userMeta)

return apiVM, nil
}
5 changes: 4 additions & 1 deletion internal/services/microvm/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ func New(scope *scope.MachineScope, client Client) *Service {
func (s *Service) Create(ctx context.Context) error {
s.scope.V(defaults.LogLevelDebug).Info("Creating microvm", "machine-name", s.scope.Name(), "cluster-name", s.scope.ClusterName())

apiMicroVM := convertToFlintlockAPI(s.scope)
apiMicroVM, err := convertToFlintlockAPI(s.scope)
if err != nil {
return err
}

bootstrapData, err := s.scope.GetRawBootstrapData()
if err != nil {
Expand Down