Skip to content

Commit 551e084

Browse files
committed
check labels after create
1 parent 79ebe29 commit 551e084

File tree

6 files changed

+34
-21
lines changed

6 files changed

+34
-21
lines changed

cluster/calcium/create.go

+6
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"time"
99

1010
"github.com/cornelk/hashmap"
11+
1112
"github.com/projecteru2/core/cluster"
1213
enginetypes "github.com/projecteru2/core/engine/types"
1314
"github.com/projecteru2/core/log"
@@ -316,6 +317,11 @@ func (c *Calcium) doDeployOneWorkload(
316317
return errors.WithStack(err)
317318
}
318319
workload.ID = created.ID
320+
321+
for key, value := range created.Labels { // add Labels
322+
workload.Labels[key] = value
323+
}
324+
319325
// We couldn't WAL the workload ID above VirtualizationCreate temporarily,
320326
// so there's a time gap window, once the core process crashes between
321327
// VirtualizationCreate and logCreateWorkload then the worload is leaky.

engine/types/virtualization.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,9 @@ type VirtualizationCreateOptions struct {
4747

4848
// VirtualizationCreated use for store name and ID
4949
type VirtualizationCreated struct {
50-
ID string
51-
Name string
50+
ID string
51+
Name string
52+
Labels map[string]string
5253
}
5354

5455
// VirtualizationInfo store virtualization info

engine/virt/virt.go

+20-14
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ const (
2828
HTTPPrefixKey = "virt://"
2929
// GRPCPrefixKey indicates grpc yavirtd
3030
GRPCPrefixKey = "virt-grpc://"
31-
// DmiUUIDKey indicates the key within deploy info.
32-
DmiUUIDKey = "DMIUUID"
3331
// ImageUserKey indicates the image's owner
3432
ImageUserKey = "ImageUser"
3533
// Type indicate type
@@ -89,7 +87,7 @@ func (v *Virt) Ping(ctx context.Context) error {
8987
func (v *Virt) Execute(ctx context.Context, ID string, config *enginetypes.ExecConfig) (pid string, stdout, stderr io.ReadCloser, stdin io.WriteCloser, err error) {
9088
if config.Tty {
9189
flags := virttypes.AttachGuestFlags{Safe: true, Force: true}
92-
stream, err := v.client.AttachGuest(ctx, ID, config.Cmd, flags)
90+
_, stream, err := v.client.AttachGuest(ctx, ID, config.Cmd, flags)
9391
if err != nil {
9492
return "", nil, nil, nil, err
9593
}
@@ -177,7 +175,7 @@ func (v *Virt) BuildContent(ctx context.Context, scm coresource.Source, opts *en
177175
}
178176

179177
// VirtualizationCreate creates a guest.
180-
func (v *Virt) VirtualizationCreate(ctx context.Context, opts *enginetypes.VirtualizationCreateOptions) (guest *enginetypes.VirtualizationCreated, err error) {
178+
func (v *Virt) VirtualizationCreate(ctx context.Context, opts *enginetypes.VirtualizationCreateOptions) (*enginetypes.VirtualizationCreated, error) {
181179
vols, err := v.parseVolumes(opts.Volumes)
182180
if err != nil {
183181
return nil, err
@@ -191,7 +189,6 @@ func (v *Virt) VirtualizationCreate(ctx context.Context, opts *enginetypes.Virtu
191189
Volumes: vols,
192190
Labels: opts.Labels,
193191
AncestorID: opts.AncestorWorkloadID,
194-
DmiUUID: opts.Labels[DmiUUIDKey],
195192
Cmd: opts.Cmd,
196193
Lambda: opts.Lambda,
197194
Stdin: opts.Stdin,
@@ -202,7 +199,11 @@ func (v *Virt) VirtualizationCreate(ctx context.Context, opts *enginetypes.Virtu
202199
return nil, err
203200
}
204201

205-
return &enginetypes.VirtualizationCreated{ID: resp.ID, Name: opts.Name}, nil
202+
return &enginetypes.VirtualizationCreated{
203+
ID: resp.ID,
204+
Name: opts.Name,
205+
Labels: resp.Labels,
206+
}, nil
206207
}
207208

208209
// VirtualizationResourceRemap .
@@ -249,18 +250,23 @@ func (v *Virt) VirtualizationInspect(ctx context.Context, ID string) (*enginetyp
249250
return nil, err
250251
}
251252

253+
info := &enginetypes.VirtualizationInfo{
254+
ID: guest.ID,
255+
Image: guest.ImageName,
256+
Running: guest.Status == "running",
257+
Networks: guest.Networks,
258+
Labels: guest.Labels,
259+
}
260+
252261
content, err := json.Marshal(coretypes.LabelMeta{Publish: []string{"PORT"}})
253262
if err != nil {
254263
return nil, err
255264
}
256265

257-
return &enginetypes.VirtualizationInfo{
258-
ID: guest.ID,
259-
Image: guest.ImageName,
260-
Running: guest.Status == "running",
261-
Networks: guest.Networks,
262-
Labels: map[string]string{cluster.LabelMeta: string(content), cluster.ERUMark: "1"},
263-
}, nil
266+
info.Labels[cluster.LabelMeta] = string(content)
267+
info.Labels[cluster.ERUMark] = "1"
268+
269+
return info, nil
264270
}
265271

266272
// VirtualizationLogs streams a specific guest's log.
@@ -279,7 +285,7 @@ func (v *Virt) VirtualizationLogs(ctx context.Context, opts *enginetypes.Virtual
279285
// VirtualizationAttach attaches something to a guest.
280286
func (v *Virt) VirtualizationAttach(ctx context.Context, ID string, stream, openStdin bool) (stdout, stderr io.ReadCloser, stdin io.WriteCloser, err error) {
281287
flags := virttypes.AttachGuestFlags{Safe: true, Force: true}
282-
attachGuest, err := v.client.AttachGuest(ctx, ID, []string{}, flags)
288+
_, attachGuest, err := v.client.AttachGuest(ctx, ID, []string{}, flags)
283289
if err != nil {
284290
return nil, nil, nil, err
285291
}

go.mod

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ require (
2121
github.com/opencontainers/image-spec v1.0.2
2222
github.com/patrickmn/go-cache v2.1.0+incompatible
2323
github.com/pkg/errors v0.9.1
24-
github.com/projecteru2/libyavirt v0.0.0-20220112061300-ac7002c411ff
24+
github.com/projecteru2/libyavirt v0.0.0-20220330115351-ec63a4a270d3
2525
github.com/prometheus/client_golang v1.11.0
2626
github.com/sanity-io/litter v1.5.1
2727
github.com/sirupsen/logrus v1.8.1
@@ -34,6 +34,7 @@ require (
3434
go.etcd.io/etcd/tests/v3 v3.5.0
3535
go.uber.org/automaxprocs v1.3.0
3636
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519
37+
golang.org/x/exp v0.0.0-20220323204016-c86f0da35e87
3738
golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f
3839
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
3940
google.golang.org/grpc v1.40.0
@@ -121,7 +122,6 @@ require (
121122
go.uber.org/atomic v1.7.0 // indirect
122123
go.uber.org/multierr v1.6.0 // indirect
123124
go.uber.org/zap v1.17.0 // indirect
124-
golang.org/x/exp v0.0.0-20220323204016-c86f0da35e87 // indirect
125125
golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 // indirect
126126
golang.org/x/mod v0.6.0-dev.0.20211013180041-c96bc1413d57 // indirect
127127
golang.org/x/sys v0.0.0-20211019181941-9d821ace8654 // indirect

go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -455,8 +455,8 @@ github.com/pmezard/go-difflib v0.0.0-20151028094244-d8ed2627bdf0/go.mod h1:iKH77
455455
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
456456
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
457457
github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI=
458-
github.com/projecteru2/libyavirt v0.0.0-20220112061300-ac7002c411ff h1:0pRYgowqjxIxotfc2+xrOHstg/ii80GK0g0v2eAdArg=
459-
github.com/projecteru2/libyavirt v0.0.0-20220112061300-ac7002c411ff/go.mod h1:FOc+hWBMLsMrmx5p3/moizKeSomedZPNwB6LhS+kEnE=
458+
github.com/projecteru2/libyavirt v0.0.0-20220330115351-ec63a4a270d3 h1:VkvdAITJKfK2ccASGeQfp9dnaaufSmWZEWtJxL2VSVY=
459+
github.com/projecteru2/libyavirt v0.0.0-20220330115351-ec63a4a270d3/go.mod h1:FOc+hWBMLsMrmx5p3/moizKeSomedZPNwB6LhS+kEnE=
460460
github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
461461
github.com/prometheus/client_golang v0.9.3/go.mod h1:/TN21ttK/J9q6uSwhBd54HahCDft0ttaMvbicHlPoso=
462462
github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo=

types/workload.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"context"
55
"time"
66

7-
engine "github.com/projecteru2/core/engine"
7+
"github.com/projecteru2/core/engine"
88
enginetypes "github.com/projecteru2/core/engine/types"
99

1010
"github.com/pkg/errors"

0 commit comments

Comments
 (0)