Skip to content

Commit bf3d548

Browse files
authored
[ws-manager-mk2] Scrub status fields, add vscode launch.json (#18595)
* [ws-manager-mk2] Scrub status fields, add vscode launch.json * Fix scrubber panic on unexported pointer
1 parent 7b66ab6 commit bf3d548

File tree

7 files changed

+56
-33
lines changed

7 files changed

+56
-33
lines changed

components/scrubber/scrubber.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ Example:
3232
Example
3333
}
3434
35-
func (TrustedExample) isTrustedValue() {}
35+
func (TrustedExample) IsTrustedValue() {}
3636
3737
func scrubExample(e *Example) *TrustedExample {
3838
return &TrustedExample{
@@ -249,6 +249,9 @@ var (
249249

250250
// Pointer implements reflectwalk.PointerValueWalker
251251
func (s *structScrubber) Pointer(val reflect.Value) error {
252+
if !val.CanInterface() {
253+
return nil
254+
}
252255
value := val.Interface()
253256
if _, ok := value.(TrustedValue); ok {
254257
return reflectwalk.SkipEntry

components/scrubber/scrubber_test.go

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"testing"
1010

1111
"github.com/google/go-cmp/cmp"
12+
"github.com/google/go-cmp/cmp/cmpopts"
1213
)
1314

1415
func TestValue(t *testing.T) {
@@ -67,6 +68,11 @@ type TrustedStructToTest struct {
6768
StructToTest
6869
}
6970

71+
type UnexportedStructToTest struct {
72+
Exported string
73+
unexportedPtr *string
74+
}
75+
7076
func (TrustedStructToTest) IsTrustedValue() {}
7177

7278
func scrubStructToTestAsTrustedValue(v *StructToTest) TrustedValue {
@@ -92,6 +98,7 @@ func TestStruct(t *testing.T) {
9298
Name string
9399
Struct any
94100
Expectation Expectation
101+
CmpOpts []cmp.Option
95102
}{
96103
{
97104
Name: "basic happy path",
@@ -193,6 +200,20 @@ func TestStruct(t *testing.T) {
193200
},
194201
},
195202
},
203+
{
204+
Name: "contains unexported pointers",
205+
Struct: UnexportedStructToTest{
206+
Exported: "foo",
207+
unexportedPtr: nil,
208+
},
209+
Expectation: Expectation{
210+
Result: UnexportedStructToTest{
211+
Exported: "foo",
212+
unexportedPtr: nil,
213+
},
214+
},
215+
CmpOpts: []cmp.Option{cmpopts.IgnoreUnexported(UnexportedStructToTest{})},
216+
},
196217
}
197218

198219
for _, test := range tests {
@@ -206,7 +227,7 @@ func TestStruct(t *testing.T) {
206227
act.Result = test.Struct
207228
}
208229

209-
if diff := cmp.Diff(test.Expectation, act); diff != "" {
230+
if diff := cmp.Diff(test.Expectation, act, test.CmpOpts...); diff != "" {
210231
t.Errorf("Struct() mismatch (-want +got):\n%s", diff)
211232
}
212233
})

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ type PortSpec struct {
154154
type WorkspaceStatus struct {
155155
PodStarts int `json:"podStarts"`
156156
URL string `json:"url,omitempty"`
157-
OwnerToken string `json:"ownerToken,omitempty"`
157+
OwnerToken string `json:"ownerToken,omitempty" scrub:"redact"`
158158

159159
// +kubebuilder:default=Unknown
160160
Phase WorkspacePhase `json:"phase,omitempty"`
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"version": "0.2.0",
3+
"configurations": [
4+
{
5+
"name": "Launch Package",
6+
"type": "go",
7+
"request": "launch",
8+
"mode": "auto",
9+
"program": "${workspaceRoot}/main.go",
10+
"args": ["--config", "example-config.json"]
11+
}
12+
]
13+
}

components/ws-manager-mk2/controllers/workspace_controller.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
"sigs.k8s.io/controller-runtime/pkg/log"
2929

3030
wsk8s "github.com/gitpod-io/gitpod/common-go/kubernetes"
31+
"github.com/gitpod-io/gitpod/components/scrubber"
3132
"github.com/gitpod-io/gitpod/ws-manager-mk2/pkg/maintenance"
3233
config "github.com/gitpod-io/gitpod/ws-manager/api/config"
3334
workspacev1 "github.com/gitpod-io/gitpod/ws-manager/api/crd/v1"
@@ -133,11 +134,18 @@ func (r *WorkspaceReconciler) Reconcile(ctx context.Context, req ctrl.Request) (
133134
r.updateMetrics(ctx, &workspace)
134135
r.emitPhaseEvents(ctx, &workspace, oldStatus)
135136

136-
var podStatus *corev1.PodStatus
137+
var scrubbedPodStatus *corev1.PodStatus
137138
if len(workspacePods.Items) > 0 {
138-
podStatus = &workspacePods.Items[0].Status
139+
scrubbedPodStatus = workspacePods.Items[0].Status.DeepCopy()
140+
if err = scrubber.Default.Struct(scrubbedPodStatus); err != nil {
141+
log.Error(err, "failed to scrub pod status")
142+
}
143+
}
144+
scrubbedStatus := workspace.Status.DeepCopy()
145+
if err = scrubber.Default.Struct(scrubbedStatus); err != nil {
146+
log.Error(err, "failed to scrub workspace status")
139147
}
140-
log.Info("updating workspace status", "status", workspace.Status, "podStatus", podStatus)
148+
log.Info("updating workspace status", "status", scrubbedStatus, "podStatus", scrubbedPodStatus)
141149
err = r.Status().Update(ctx, &workspace)
142150
if err != nil {
143151
return errorResultLogConflict(log, fmt.Errorf("failed to update workspace status: %w", err))

components/ws-manager-mk2/example-config.json

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,8 @@
22
"manager": {
33
"namespace": "staging-cw-io-limit-hack",
44
"schedulerName": "",
5+
"secretsNamespace": "workspace-secrets",
56
"seccompProfile": "localhost/workspace_default_cw-ws-manager-mk2.1.json",
6-
"container": {
7-
"workspace": {
8-
"image": "OVERWRITTEN-IN-REQUEST",
9-
"requests": {
10-
"cpu": "1",
11-
"memory": "2Gi",
12-
"ephemeral-storage": ""
13-
},
14-
"limits": {
15-
"cpu": "",
16-
"memory": "",
17-
"ephemeral-storage": ""
18-
}
19-
}
20-
},
217
"timeouts": {
228
"startup": "1h0m0s",
239
"initialization": "30m0s",
@@ -32,7 +18,6 @@
3218
"initProbe": {
3319
"timeout": "1s"
3420
},
35-
"podTemplate": {},
3621
"urlTemplate": "https://{{ .Prefix }}.ws.foo.com",
3722
"portUrlTemplate": "https://{{ .WorkspacePort }}-{{ .Prefix }}.ws.foo.com",
3823
"workspaceHostPath": "/var/gitpod/workspaces",
@@ -57,22 +42,15 @@
5742
"gcloud": {
5843
"credentialsFile": "",
5944
"region": "",
60-
"projectId": "",
61-
"parallelUpload": 0,
62-
"maximumBackupCount": 0
45+
"projectId": ""
6346
},
6447
"minio": {
6548
"endpoint": "minio.default.svc.cluster.local:9000",
6649
"accessKey": "6BYlUKCJraAbBy5U35A4",
6750
"accessKeyFile": "",
6851
"secretKey": "ClclNAidlUwP2ESwEsXt",
6952
"secretKeyFile": "",
70-
"region": "local",
71-
"parallelUpload": 6
72-
},
73-
"backupTrail": {
74-
"enabled": true,
75-
"maxLength": 3
53+
"region": "local"
7654
},
7755
"blobQuota": 5368709120
7856
}
@@ -90,4 +68,4 @@
9068
"prometheus": {
9169
"addr": "127.0.0.1:9500"
9270
}
93-
}
71+
}

components/ws-manager-mk2/ws-manager-mk2.code-workspace

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
"folders": [
33
{ "path": "../common-go" },
44
{ "path": "../ws-daemon" },
5-
{ "path": "../ws-manager" },
65
{ "path": "../ws-manager-api" },
76
{ "path": "../ws-manager-mk2" },
7+
{ "path": "../scrubber" },
88
{ "path": "../server" },
99
{ "path": "../../test" },
1010
{ "path": "../../dev/gpctl" },

0 commit comments

Comments
 (0)