Skip to content

Commit

Permalink
fix(cloud): Several changes to volume commands (#1846)
Browse files Browse the repository at this point in the history
Reviewed-by: Alexander Jung <alex@unikraft.io>
Approved-by: Alexander Jung <alex@unikraft.io>
  • Loading branch information
nderjung authored Aug 14, 2024
2 parents 9942c63 + 0123a40 commit 207e5ec
Show file tree
Hide file tree
Showing 8 changed files with 144 additions and 57 deletions.
12 changes: 6 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ require (
github.com/fsnotify/fsnotify v1.7.0
github.com/go-git/go-git/v5 v5.12.0
github.com/gobwas/glob v0.2.3
github.com/google/go-containerregistry v0.20.1
github.com/google/go-containerregistry v0.20.2
github.com/google/go-github/v32 v32.1.0
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510
github.com/google/uuid v1.6.0
Expand Down Expand Up @@ -72,7 +72,7 @@ require (
github.com/xeipuuv/gojsonschema v1.2.0
github.com/xlab/treeprint v1.2.0
golang.org/x/oauth2 v0.21.0
golang.org/x/sync v0.7.0
golang.org/x/sync v0.8.0
golang.org/x/sys v0.24.0
golang.org/x/term v0.23.0
google.golang.org/grpc v1.64.1
Expand All @@ -82,7 +82,7 @@ require (
k8s.io/apimachinery v0.30.3
k8s.io/apiserver v0.30.3
oras.land/oras-go/v2 v2.5.0
sdk.kraft.cloud v0.5.10-0.20240723104228-555a014860c8
sdk.kraft.cloud v0.5.10-0.20240813111748-eabe84d65f02
sigs.k8s.io/kustomize/kyaml v0.17.2
)

Expand Down Expand Up @@ -266,10 +266,10 @@ require (
go.opentelemetry.io/otel/sdk v1.27.0 // indirect
go.opentelemetry.io/otel/trace v1.27.0 // indirect
go.opentelemetry.io/proto/otlp v1.2.0 // indirect
golang.org/x/crypto v0.25.0 // indirect
golang.org/x/crypto v0.26.0 // indirect
golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842 // indirect
golang.org/x/net v0.27.0 // indirect
golang.org/x/text v0.16.0 // indirect
golang.org/x/net v0.28.0 // indirect
golang.org/x/text v0.17.0 // indirect
golang.org/x/time v0.5.0 // indirect
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d // indirect
google.golang.org/genproto v0.0.0-20240311173647-c811ad7063a7 // indirect
Expand Down
24 changes: 12 additions & 12 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -663,8 +663,8 @@ github.com/google/go-cmp v0.5.7/go.mod h1:n+brtR0CgQNWTVd5ZUFpTBC8YFBDLK/h/bpaJ8
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/go-containerregistry v0.20.1 h1:eTgx9QNYugV4DN5mz4U8hiAGTi1ybXn0TPi4Smd8du0=
github.com/google/go-containerregistry v0.20.1/go.mod h1:YCMFNQeeXeLF+dnhhWkqDItx/JSkH01j1Kis4PsjzFI=
github.com/google/go-containerregistry v0.20.2 h1:B1wPJ1SN/S7pB+ZAimcciVD+r+yV/l/DSArMxlbwseo=
github.com/google/go-containerregistry v0.20.2/go.mod h1:z38EKdKh4h7IP2gSfUUqEvalZBqs6AoLeWfUy34nQC8=
github.com/google/go-github/v32 v32.1.0 h1:GWkQOdXqviCPx7Q7Fj+KyPoGm4SwHRh8rheoPhd27II=
github.com/google/go-github/v32 v32.1.0/go.mod h1:rIEpZD9CTDQwDK9GDrtMTycQNA4JU3qBsCizh3q2WCI=
github.com/google/go-intervals v0.0.2 h1:FGrVEiUnTRKR8yE04qzXYaJMtnIYqobR5QbblK3ixcM=
Expand Down Expand Up @@ -1331,8 +1331,8 @@ golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0
golang.org/x/crypto v0.3.1-0.20221117191849-2c476679df9a/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4=
golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU=
golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU=
golang.org/x/crypto v0.25.0 h1:ypSNr+bnYL2YhwoMt2zPxHFmbAN1KZs/njMG3hxUp30=
golang.org/x/crypto v0.25.0/go.mod h1:T+wALwcMOSE0kXgUAnPAHqTLW+XHgcELELW8VaDgm/M=
golang.org/x/crypto v0.26.0 h1:RrRspgV4mU+YwB4FYnuBoKsUapNIL5cohGAmSH3azsw=
golang.org/x/crypto v0.26.0/go.mod h1:GY7jblb9wI+FOo5y8/S2oY4zWP07AkOJ4+jxCqdqn54=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8=
Expand Down Expand Up @@ -1414,8 +1414,8 @@ golang.org/x/net v0.2.0/go.mod h1:KqCZLdyyvdV855qA2rE3GC2aiw5xGR5TEjj8smXukLY=
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc=
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
golang.org/x/net v0.27.0 h1:5K3Njcw06/l2y9vpGCSdcxWOYHOUk3dVNGDXN+FvAys=
golang.org/x/net v0.27.0/go.mod h1:dDi0PyhWNoiUOrAS8uXv/vnScO4wnHQO4mj9fn/RytE=
golang.org/x/net v0.28.0 h1:a9JDOJc5GMUJ0+UDqmLT86WiEy7iWyIhz8gz8E4e5hE=
golang.org/x/net v0.28.0/go.mod h1:yqtgsTWOOnlGLG9GFRrK3++bGOUEkNBoHZc8MEDWPNg=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
Expand All @@ -1436,8 +1436,8 @@ golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJ
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M=
golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ=
golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
Expand Down Expand Up @@ -1555,8 +1555,8 @@ golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4=
golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI=
golang.org/x/text v0.17.0 h1:XtiM5bkSOt+ewxlOE/aE/AKEHibwj/6gvWMl9Rsh0Qc=
golang.org/x/text v0.17.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
Expand Down Expand Up @@ -1788,8 +1788,8 @@ oras.land/oras-go/v2 v2.5.0/go.mod h1:z4eisnLP530vwIOUOJeBIj0aGI0L1C3d53atvCBqZH
rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8=
rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0=
rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA=
sdk.kraft.cloud v0.5.10-0.20240723104228-555a014860c8 h1:YzWtxAU3vc5qELuSe/YGgpqG9M9jZlQZX91zbeUiQBE=
sdk.kraft.cloud v0.5.10-0.20240723104228-555a014860c8/go.mod h1:ZBU6uESv9oxEarZdlFAuKEb9B9feTQTZnkMDpsAm7Ro=
sdk.kraft.cloud v0.5.10-0.20240813111748-eabe84d65f02 h1:cprG5U2yYk188KvEVtr2Lho93a/xiN3XW/CVia8F7NI=
sdk.kraft.cloud v0.5.10-0.20240813111748-eabe84d65f02/go.mod h1:7Q1tBqVp8r7vtqUQhgRan26cUSx/A1uEYXhjQ/bqhiw=
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.0.14/go.mod h1:LEScyzhFmoF5pso/YSeBstl57mOzx9xlU9n85RGrDQg=
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.0.15/go.mod h1:LEScyzhFmoF5pso/YSeBstl57mOzx9xlU9n85RGrDQg=
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.29.0 h1:/U5vjBbQn3RChhv7P11uhYvCSm5G2GaIi5AIGBS6r4c=
Expand Down
7 changes: 6 additions & 1 deletion internal/cli/kraft/cloud/compose/down/down.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,14 @@ func (opts *DownOptions) Run(ctx context.Context, args []string) error {
return fmt.Errorf("getting instances: %w", err)
}

insts, err := instResp.AllOrErr()
if err != nil {
return fmt.Errorf("getting instances: %w", err)
}

instances = []string{}

for _, instance := range instResp.Data.Entries {
for _, instance := range insts {
if instance.Message != "" {
log.G(ctx).Error(instance.Message)
continue
Expand Down
35 changes: 25 additions & 10 deletions internal/cli/kraft/cloud/compose/up/up.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ func Up(ctx context.Context, opts *UpOptions, args ...string) error {
return err
}

instResps := kcclient.ServiceResponse[kcinstances.GetResponseItem]{}
insts := []kcinstances.GetResponseItem{}

for _, serviceName := range args {
service, ok := opts.Project.Services[serviceName]
Expand Down Expand Up @@ -223,10 +223,13 @@ func Up(ctx context.Context, opts *UpOptions, args ...string) error {
}

instResp, err := opts.Client.Instances().WithMetro(opts.Metro).Get(ctx, service.Name)
if err == nil && len(instResp.Data.Entries) == 1 && instResp.Data.Entries[0].Error == nil {
instResps.Data.Entries = append(instResps.Data.Entries, instResp.Data.Entries...)
log.G(ctx).WithField("name", service.Name).Info("service already exists")
continue
if err == nil {
inst, err := instResp.FirstOrErr()
if err == nil && inst != nil {
insts = append(insts, *inst)
log.G(ctx).WithField("name", service.Name).Info("service already exists")
continue
}
}

// Handle environmental variables.
Expand Down Expand Up @@ -256,12 +259,17 @@ func Up(ctx context.Context, opts *UpOptions, args ...string) error {

var volumes []string
for _, volume := range service.Volumes {
vol, ok := volResps[volume.Source]
volResp, ok := volResps[volume.Source]
if !ok {
continue
}

volumes = append(volumes, fmt.Sprintf("%s:%s", vol.Data.Entries[0].UUID, volume.Target))
vol, err := volResp.FirstOrErr()
if err != nil {
continue
}

volumes = append(volumes, fmt.Sprintf("%s:%s", vol.UUID, volume.Target))
}

name := strings.ReplaceAll(fmt.Sprintf("%s-%s", opts.Project.Name, service.Name), "_", "-")
Expand Down Expand Up @@ -335,14 +343,19 @@ func Up(ctx context.Context, opts *UpOptions, args ...string) error {
Volumes: volumes,
}, service.Command...)
if err != nil {
return err
return fmt.Errorf("creating instance: %w", err)
}

inst, err := instResp.FirstOrErr()
if err != nil || inst == nil {
return fmt.Errorf("creating instance: %w", err)
}

instResps.Data.Entries = append(instResps.Data.Entries, instResp.Data.Entries...)
insts = append(insts, *inst)
}

var instances []string
for _, inst := range instResps.Data.Entries {
for _, inst := range insts {
instances = append(instances, inst.Name)
}

Expand Down Expand Up @@ -370,6 +383,8 @@ func Up(ctx context.Context, opts *UpOptions, args ...string) error {
Output: "table",
}, instances...)
} else {
instResps := kcclient.ServiceResponse[kcinstances.GetResponseItem]{}
instResps.Data.Entries = insts
return utils.PrintInstances(ctx, "table", instResps)
}
}
Expand Down
18 changes: 14 additions & 4 deletions internal/cli/kraft/cloud/instance/remove/remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,18 @@ func Remove(ctx context.Context, opts *RemoveOptions, args ...string) error {
return fmt.Errorf("could not list instances: %w", err)
}

if len(instListResp.Data.Entries) == 0 {
instList, err := instListResp.AllOrErr()
if err != nil {
return fmt.Errorf("could not list instances: %w", err)
}

if len(instList) == 0 {
log.G(ctx).Info("no instances found")
return nil
}

uuids := make([]string, 0, len(instListResp.Data.Entries))
for _, instItem := range instListResp.Data.Entries {
uuids := make([]string, 0, len(instList))
for _, instItem := range instList {
uuids = append(uuids, instItem.UUID)
}

Expand All @@ -131,8 +136,13 @@ func Remove(ctx context.Context, opts *RemoveOptions, args ...string) error {
return fmt.Errorf("could not get instances: %w", err)
}

instInfos, err := instInfosResp.AllOrErr()
if err != nil {
return fmt.Errorf("could not get instances: %w", err)
}

var stoppedUuids []string
for _, instInfo := range instInfosResp.Data.Entries {
for _, instInfo := range instInfos {
if kcinstances.State(instInfo.State) == kcinstances.StateStopped {
stoppedUuids = append(stoppedUuids, instInfo.UUID)
}
Expand Down
9 changes: 7 additions & 2 deletions internal/cli/kraft/cloud/service/remove/remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,18 @@ func Remove(ctx context.Context, opts *RemoveOptions, args ...string) error {
return fmt.Errorf("listing service: %w", err)
}

if len(sgListResp.Data.Entries) == 0 {
sgList, err := sgListResp.AllOrErr()
if err != nil {
return fmt.Errorf("listing service: %w", err)
}

if len(sgList) == 0 {
log.G(ctx).Info("no service found")
return nil
}

args = []string{}
for _, sgItem := range sgListResp.Data.Entries {
for _, sgItem := range sgList {
args = append(args, sgItem.Name)
}
}
Expand Down
7 changes: 5 additions & 2 deletions internal/cli/kraft/cloud/volume/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ type CreateOptions struct {
Auth *config.AuthConfig `noattribute:"true"`
Client kcvolumes.VolumesService `noattribute:"true"`
Metro string `noattribute:"true"`
Name string `local:"true" size:"name" short:"n"`
Size string `local:"true" long:"size" short:"s" usage:"Size (MiB increments)"`
Name string `local:"true" size:"name" short:"n" usage:"Name of the volume"`
Size string `local:"true" long:"size" short:"s" usage:"Size (MiB increments or suffixes like Mi, Gi, etc.)"`
Token string `noattribute:"true"`
}

Expand Down Expand Up @@ -93,6 +93,9 @@ func NewCmd() *cobra.Command {
Example: heredoc.Doc(`
# Create a new persistent 100MiB volume named "my-volume"
$ kraft cloud volume create --size 100 --name my-volume
# Create a new persistent 10MiB volume with a random name
$ kraft cloud volume create --size 10Mi
`),
Annotations: map[string]string{
cmdfactory.AnnotationHelpGroup: "kraftcloud-vol",
Expand Down
Loading

0 comments on commit 207e5ec

Please sign in to comment.