Skip to content

Commit 71236f0

Browse files
committed
1
1 parent fac5f0a commit 71236f0

File tree

12 files changed

+48
-55
lines changed

12 files changed

+48
-55
lines changed

components/registry-facade/pkg/registry/manifest.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"io"
1313
"mime"
1414
"net/http"
15+
"strconv"
1516
"strings"
1617
"time"
1718

@@ -185,15 +186,23 @@ func (mh *manifestHandler) getManifest(w http.ResponseWriter, r *http.Request) {
185186
return err
186187
}
187188

189+
originImageSize := 0
190+
for _, layer := range manifest.Layers {
191+
originImageSize += int(layer.Size)
192+
}
193+
188194
// modify config
189195
addonLayer, err := mh.ConfigModifier(ctx, mh.Spec, cfg)
190196
if err != nil {
191197
log.WithError(err).WithFields(logFields).Error("cannot modify config")
192198
return err
193199
}
194200
manifest.Layers = append(manifest.Layers, addonLayer...)
195-
cfg.Config.Labels = make(map[string]string)
196-
cfg.Config.Labels["test"] = "we can write workspace image ref and size here"
201+
if manifest.Annotations == nil {
202+
manifest.Annotations = make(map[string]string)
203+
}
204+
manifest.Annotations["io.gitpod.workspace-image.size"] = strconv.Itoa(originImageSize)
205+
manifest.Annotations["io.gitpod.workspace-image.ref"] = mh.Spec.BaseRef
197206

198207
// place config in store
199208
rawCfg, err := json.Marshal(cfg)

components/ws-daemon/go.mod

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ require (
8282
github.com/containerd/continuity v0.4.2 // indirect
8383
github.com/containerd/fifo v1.1.0 // indirect
8484
github.com/containerd/log v0.1.0 // indirect
85+
github.com/containerd/platforms v0.2.1 // indirect
8586
github.com/containerd/ttrpc v1.2.2 // indirect
8687
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
8788
github.com/cyphar/filepath-securejoin v0.2.3 // indirect
@@ -144,7 +145,7 @@ require (
144145
github.com/modern-go/reflect2 v1.0.2 // indirect
145146
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
146147
github.com/opencontainers/go-digest v1.0.0 // indirect
147-
github.com/opencontainers/image-spec v1.1.0-rc2.0.20221005185240-3a7f492d3f1b // indirect
148+
github.com/opencontainers/image-spec v1.1.0-rc5 // indirect
148149
github.com/opencontainers/selinux v1.11.0 // indirect
149150
github.com/pkg/errors v0.9.1 // indirect
150151
github.com/pmezard/go-difflib v1.0.0 // indirect

components/ws-daemon/go.sum

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

components/ws-daemon/pkg/container/containerd.go

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"fmt"
1111
"path/filepath"
1212
"regexp"
13+
"strconv"
1314
"strings"
1415
"sync"
1516
"time"
@@ -20,6 +21,8 @@ import (
2021
"github.com/containerd/containerd/api/types"
2122
"github.com/containerd/containerd/containers"
2223
"github.com/containerd/containerd/errdefs"
24+
"github.com/containerd/containerd/images"
25+
"github.com/containerd/platforms"
2326
"github.com/containerd/typeurl/v2"
2427
ocispecs "github.com/opencontainers/runtime-spec/specs-go"
2528
"github.com/opentracing/opentracing-go"
@@ -502,13 +505,18 @@ func (s *Containerd) GetContainerImageInfo(ctx context.Context, id ID) (*workspa
502505
TotalSize: size,
503506
}
504507

505-
sp, err := image.Spec(ctx)
508+
// Fetch the manifest
509+
manifest, err := images.Manifest(ctx, s.Client.ContentStore(), image.Target(), platforms.Default())
506510
if err != nil {
507-
log.WithError(err).Error("cannot get image spec")
508-
} else {
509-
log.WithField("labels", log.TrustedValueWrap{Value: sp.Config.Labels}).Info("image spec ---------- ")
511+
log.WithError(err).WithField("image", info.ImageRef).Error("Failed to get manifest")
512+
return wsImageInfo, nil
513+
}
514+
if manifest.Annotations != nil {
515+
wsImageInfo.WorkspaceImageRef = manifest.Annotations["io.gitpod.workspace-image.ref"]
516+
if size, err := strconv.Atoi(manifest.Annotations["io.gitpod.workspace-image.size"]); err == nil {
517+
wsImageInfo.WorkspaceImageSize = int64(size)
518+
}
510519
}
511-
512520
return wsImageInfo, nil
513521
}
514522

components/ws-daemon/pkg/controller/workspace_controller.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,6 @@ func (wsc *WorkspaceController) handleWorkspaceRunning(ctx context.Context, ws *
230230
if err != nil {
231231
return ctrl.Result{}, fmt.Errorf("failed to get container image info: %w", err)
232232
}
233-
glog.WithFields(ws.OWI()).WithField("workspace", req.NamespacedName).WithField("info", glog.TrustedValueWrap{Value: info}).WithField("phase", ws.Status.Phase).Info("handle workspace running ===============")
234233

235234
err = retry.RetryOnConflict(retryParams, func() error {
236235
if err := wsc.Get(ctx, req.NamespacedName, ws); err != nil {

components/ws-manager-api/go/crd/v1/workspace_types.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -173,14 +173,10 @@ type WorkspaceImageInfo struct {
173173
TotalSize int64 `json:"totalSize"`
174174

175175
// +kubebuilder:validation:Optional
176-
Details []ImageInfo `json:"details"`
177-
}
176+
WorkspaceImageSize int64 `json:"workspaceImageSize,omitempty"`
178177

179-
type ImageInfo struct {
180-
// +kubebuilder:validation:Required
181-
Size int64 `json:"size"`
182-
// +kubebuilder:validation:Required
183-
Ref string `json:"ref"`
178+
// +kubebuilder:validation:Optional
179+
WorkspaceImageRef string `json:"workspaceImageRef,omitempty"`
184180
}
185181

186182
// WorkspaceStatus defines the observed state of Workspace

components/ws-manager-api/go/crd/v1/zz_generated.deepcopy.go

Lines changed: 1 addition & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

components/ws-manager-mk2/config/crd/bases/workspace.gitpod.io_snapshots.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2024 Gitpod GmbH. All rights reserved.
1+
# Copyright (c) 2023 Gitpod GmbH. All rights reserved.
22
# Licensed under the GNU Affero General Public License (AGPL).
33
# See License.AGPL.txt in the project root for license information.
44

components/ws-manager-mk2/config/crd/bases/workspace.gitpod.io_workspaces.yaml

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2024 Gitpod GmbH. All rights reserved.
1+
# Copyright (c) 2023 Gitpod GmbH. All rights reserved.
22
# Licensed under the GNU Affero General Public License (AGPL).
33
# See License.AGPL.txt in the project root for license information.
44

@@ -520,22 +520,14 @@ spec:
520520
type: object
521521
imageInfo:
522522
properties:
523-
details:
524-
items:
525-
properties:
526-
ref:
527-
type: string
528-
size:
529-
format: int64
530-
type: integer
531-
required:
532-
- ref
533-
- size
534-
type: object
535-
type: array
536523
totalSize:
537524
format: int64
538525
type: integer
526+
workspaceImageRef:
527+
type: string
528+
workspaceImageSize:
529+
format: int64
530+
type: integer
539531
required:
540532
- totalSize
541533
type: object

components/ws-manager-mk2/config/webhook/manifests.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2024 Gitpod GmbH. All rights reserved.
1+
# Copyright (c) 2023 Gitpod GmbH. All rights reserved.
22
# Licensed under the GNU Affero General Public License (AGPL).
33
# See License.AGPL.txt in the project root for license information.
44

0 commit comments

Comments
 (0)