diff --git a/cluster/calcium/create.go b/cluster/calcium/create.go index 7565aa957..ec5bc3aca 100644 --- a/cluster/calcium/create.go +++ b/cluster/calcium/create.go @@ -8,6 +8,7 @@ import ( "time" "github.com/cornelk/hashmap" + "github.com/projecteru2/core/cluster" enginetypes "github.com/projecteru2/core/engine/types" "github.com/projecteru2/core/log" @@ -316,6 +317,11 @@ func (c *Calcium) doDeployOneWorkload( return errors.WithStack(err) } workload.ID = created.ID + + for key, value := range created.Labels { // add Labels + workload.Labels[key] = value + } + // We couldn't WAL the workload ID above VirtualizationCreate temporarily, // so there's a time gap window, once the core process crashes between // VirtualizationCreate and logCreateWorkload then the worload is leaky. diff --git a/engine/types/virtualization.go b/engine/types/virtualization.go index e987c6a74..a48070ecc 100644 --- a/engine/types/virtualization.go +++ b/engine/types/virtualization.go @@ -47,8 +47,9 @@ type VirtualizationCreateOptions struct { // VirtualizationCreated use for store name and ID type VirtualizationCreated struct { - ID string - Name string + ID string + Name string + Labels map[string]string } // VirtualizationInfo store virtualization info diff --git a/engine/virt/virt.go b/engine/virt/virt.go index 9d4f12622..31fbf774b 100644 --- a/engine/virt/virt.go +++ b/engine/virt/virt.go @@ -28,8 +28,6 @@ const ( HTTPPrefixKey = "virt://" // GRPCPrefixKey indicates grpc yavirtd GRPCPrefixKey = "virt-grpc://" - // DmiUUIDKey indicates the key within deploy info. - DmiUUIDKey = "DMIUUID" // ImageUserKey indicates the image's owner ImageUserKey = "ImageUser" // Type indicate type @@ -89,7 +87,7 @@ func (v *Virt) Ping(ctx context.Context) error { func (v *Virt) Execute(ctx context.Context, ID string, config *enginetypes.ExecConfig) (pid string, stdout, stderr io.ReadCloser, stdin io.WriteCloser, err error) { if config.Tty { flags := virttypes.AttachGuestFlags{Safe: true, Force: true} - stream, err := v.client.AttachGuest(ctx, ID, config.Cmd, flags) + _, stream, err := v.client.AttachGuest(ctx, ID, config.Cmd, flags) if err != nil { return "", nil, nil, nil, err } @@ -177,7 +175,7 @@ func (v *Virt) BuildContent(ctx context.Context, scm coresource.Source, opts *en } // VirtualizationCreate creates a guest. -func (v *Virt) VirtualizationCreate(ctx context.Context, opts *enginetypes.VirtualizationCreateOptions) (guest *enginetypes.VirtualizationCreated, err error) { +func (v *Virt) VirtualizationCreate(ctx context.Context, opts *enginetypes.VirtualizationCreateOptions) (*enginetypes.VirtualizationCreated, error) { vols, err := v.parseVolumes(opts.Volumes) if err != nil { return nil, err @@ -191,7 +189,6 @@ func (v *Virt) VirtualizationCreate(ctx context.Context, opts *enginetypes.Virtu Volumes: vols, Labels: opts.Labels, AncestorID: opts.AncestorWorkloadID, - DmiUUID: opts.Labels[DmiUUIDKey], Cmd: opts.Cmd, Lambda: opts.Lambda, Stdin: opts.Stdin, @@ -202,7 +199,11 @@ func (v *Virt) VirtualizationCreate(ctx context.Context, opts *enginetypes.Virtu return nil, err } - return &enginetypes.VirtualizationCreated{ID: resp.ID, Name: opts.Name}, nil + return &enginetypes.VirtualizationCreated{ + ID: resp.ID, + Name: opts.Name, + Labels: resp.Labels, + }, nil } // VirtualizationResourceRemap . @@ -249,18 +250,23 @@ func (v *Virt) VirtualizationInspect(ctx context.Context, ID string) (*enginetyp return nil, err } + info := &enginetypes.VirtualizationInfo{ + ID: guest.ID, + Image: guest.ImageName, + Running: guest.Status == "running", + Networks: guest.Networks, + Labels: guest.Labels, + } + content, err := json.Marshal(coretypes.LabelMeta{Publish: []string{"PORT"}}) if err != nil { return nil, err } - return &enginetypes.VirtualizationInfo{ - ID: guest.ID, - Image: guest.ImageName, - Running: guest.Status == "running", - Networks: guest.Networks, - Labels: map[string]string{cluster.LabelMeta: string(content), cluster.ERUMark: "1"}, - }, nil + info.Labels[cluster.LabelMeta] = string(content) + info.Labels[cluster.ERUMark] = "1" + + return info, nil } // VirtualizationLogs streams a specific guest's log. @@ -279,7 +285,7 @@ func (v *Virt) VirtualizationLogs(ctx context.Context, opts *enginetypes.Virtual // VirtualizationAttach attaches something to a guest. func (v *Virt) VirtualizationAttach(ctx context.Context, ID string, stream, openStdin bool) (stdout, stderr io.ReadCloser, stdin io.WriteCloser, err error) { flags := virttypes.AttachGuestFlags{Safe: true, Force: true} - attachGuest, err := v.client.AttachGuest(ctx, ID, []string{}, flags) + _, attachGuest, err := v.client.AttachGuest(ctx, ID, []string{}, flags) if err != nil { return nil, nil, nil, err } diff --git a/go.mod b/go.mod index bcb1d0c05..d12b43312 100644 --- a/go.mod +++ b/go.mod @@ -21,7 +21,7 @@ require ( github.com/opencontainers/image-spec v1.0.2 github.com/patrickmn/go-cache v2.1.0+incompatible github.com/pkg/errors v0.9.1 - github.com/projecteru2/libyavirt v0.0.0-20220112061300-ac7002c411ff + github.com/projecteru2/libyavirt v0.0.0-20220330115351-ec63a4a270d3 github.com/prometheus/client_golang v1.11.0 github.com/sanity-io/litter v1.5.1 github.com/sirupsen/logrus v1.8.1 @@ -34,6 +34,7 @@ require ( go.etcd.io/etcd/tests/v3 v3.5.0 go.uber.org/automaxprocs v1.3.0 golang.org/x/crypto v0.0.0-20210921155107-089bfa567519 + golang.org/x/exp v0.0.0-20220323204016-c86f0da35e87 golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f golang.org/x/sync v0.0.0-20210220032951-036812b2e83c google.golang.org/grpc v1.40.0 @@ -121,7 +122,6 @@ require ( go.uber.org/atomic v1.7.0 // indirect go.uber.org/multierr v1.6.0 // indirect go.uber.org/zap v1.17.0 // indirect - golang.org/x/exp v0.0.0-20220323204016-c86f0da35e87 // indirect golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 // indirect golang.org/x/mod v0.6.0-dev.0.20211013180041-c96bc1413d57 // indirect golang.org/x/sys v0.0.0-20211019181941-9d821ace8654 // indirect diff --git a/go.sum b/go.sum index 03e42edf5..a4a047247 100644 --- a/go.sum +++ b/go.sum @@ -455,8 +455,8 @@ github.com/pmezard/go-difflib v0.0.0-20151028094244-d8ed2627bdf0/go.mod h1:iKH77 github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI= -github.com/projecteru2/libyavirt v0.0.0-20220112061300-ac7002c411ff h1:0pRYgowqjxIxotfc2+xrOHstg/ii80GK0g0v2eAdArg= -github.com/projecteru2/libyavirt v0.0.0-20220112061300-ac7002c411ff/go.mod h1:FOc+hWBMLsMrmx5p3/moizKeSomedZPNwB6LhS+kEnE= +github.com/projecteru2/libyavirt v0.0.0-20220330115351-ec63a4a270d3 h1:VkvdAITJKfK2ccASGeQfp9dnaaufSmWZEWtJxL2VSVY= +github.com/projecteru2/libyavirt v0.0.0-20220330115351-ec63a4a270d3/go.mod h1:FOc+hWBMLsMrmx5p3/moizKeSomedZPNwB6LhS+kEnE= github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= github.com/prometheus/client_golang v0.9.3/go.mod h1:/TN21ttK/J9q6uSwhBd54HahCDft0ttaMvbicHlPoso= github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo= diff --git a/types/workload.go b/types/workload.go index 1cc05b67d..5302baea9 100644 --- a/types/workload.go +++ b/types/workload.go @@ -4,7 +4,7 @@ import ( "context" "time" - engine "github.com/projecteru2/core/engine" + "github.com/projecteru2/core/engine" enginetypes "github.com/projecteru2/core/engine/types" "github.com/pkg/errors"