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

Check labels after create #571

Merged
merged 1 commit into from
Mar 31, 2022
Merged
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
6 changes: 6 additions & 0 deletions cluster/calcium/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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.
Expand Down
5 changes: 3 additions & 2 deletions engine/types/virtualization.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
34 changes: 20 additions & 14 deletions engine/virt/virt.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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 .
Expand Down Expand Up @@ -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.
Expand All @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
2 changes: 1 addition & 1 deletion types/workload.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down