diff --git a/go.mod b/go.mod index 68e7056..8fba3a4 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index 5b993f9..006e48f 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/internal/services/microvm/convert.go b/internal/services/microvm/convert.go index 579c7e1..c4d471b 100644 --- a/internal/services/microvm/convert.go +++ b/internal/services/microvm/convert.go @@ -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{ @@ -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 } diff --git a/internal/services/microvm/service.go b/internal/services/microvm/service.go index 4b52522..8c229d8 100644 --- a/internal/services/microvm/service.go +++ b/internal/services/microvm/service.go @@ -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 {