Skip to content

Commit db8b7b7

Browse files
Pothulapatiroboquat
authored andcommitted
Add new `workspace-rollout-job to components
Basic rollout works, but without metric analysis Signed-off-by: Tarun Pothulapati <tarun@gitpod.io>
1 parent 17e83b9 commit db8b7b7

File tree

11 files changed

+450
-0
lines changed

11 files changed

+450
-0
lines changed

.github/CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
/components/supervisor @gitpod-io/engineering-ide
8383
/components/usage @gitpod-io/engineering-webapp
8484
/components/usage-api @gitpod-io/engineering-webapp
85+
/components/workspace-rollout-job @gitpod-io/engineering-delivery-operations-experience @gitpod-io/engineering-workspace
8586
/components/workspacekit @gitpod-io/engineering-workspace
8687
/components/ws-daemon-api @aledbf @Furisto
8788
/components/ws-daemon @gitpod-io/engineering-workspace

components/BUILD.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ packages:
8989
- components/toxic-config:docker
9090
- components/installation-telemetry:docker
9191
- components/workspacekit:docker
92+
- components/workspace-rollout-job:docker
9293
- components/ws-daemon:docker
9394
- components/ws-daemon/seccomp-profile-installer:docker
9495
- components/ws-manager-bridge:docker
@@ -143,6 +144,7 @@ packages:
143144
- components/toxic-config:app
144145
- components/installation-telemetry:app
145146
- components/workspacekit:app
147+
- components/workspace-rollout-job:app
146148
- components/ws-daemon:app
147149
- components/ws-manager-bridge:app
148150
- components/ws-manager:app
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
packages:
2+
- name: app
3+
type: go
4+
srcs:
5+
- "**/*.go"
6+
- "go.mod"
7+
- "go.sum"
8+
deps:
9+
- components/common-go:lib
10+
- components/ws-manager-bridge-api/go:lib
11+
env:
12+
- CGO_ENABLED=0
13+
- GOOS=linux
14+
config:
15+
packaging: app
16+
buildCommand: ["go", "build", "-trimpath", "-ldflags", "-buildid= -w -s -X 'github.com/gitpod-io/gitpod/workspace-rollout-job/cmd.Version=commit-${__git_commit}'"]
17+
- name: docker
18+
type: docker
19+
deps:
20+
- :app
21+
argdeps:
22+
- imageRepoBase
23+
config:
24+
dockerfile: leeway.Dockerfile
25+
metadata:
26+
helm-component: workspaceRolloutJob
27+
image:
28+
- ${imageRepoBase}/workspace-rollout-job:${version}
29+
- ${imageRepoBase}/workspace-rollout-job:commit-${__git_commit}
30+
- name: lib
31+
type: go
32+
srcs:
33+
- "**/*.go"
34+
- "go.mod"
35+
- "go.sum"
36+
config:
37+
packaging: library
38+
deps:
39+
- components/common-go:lib
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# workspace-rollout-job
2+
3+
`workspace-rollout-job` performs a rollout from one workspace cluster to another while monitoring
4+
metrics.
5+
6+
## Running Locally
7+
8+
First, Connect to your `meta` cluster and make sure both the new cluster is registered with
9+
a score of `0`.
10+
11+
Then, Make `ws-manager-bridge` accessible:
12+
13+
```bash
14+
kubectl port-forward deployment/ws-manager-bridge 8080
15+
```
16+
17+
Also, Make prometheus accessible:
18+
19+
```bash
20+
kubectl -n monitoring-satellite port-forward prometheus-k8s-0 9090
21+
```
22+
23+
Now, Run the job:
24+
25+
```bash
26+
OLD_CLUSTER="<xyz>" NEW_CLUSTER="<abc>" go run .
27+
```
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// Copyright (c) 2022 Gitpod GmbH. All rights reserved.
2+
// Licensed under the GNU Affero General Public License (AGPL).
3+
// See License-AGPL.txt in the project root for license information.
4+
5+
package cmd
6+
7+
import (
8+
"fmt"
9+
"os"
10+
11+
"github.com/gitpod-io/gitpod/common-go/log"
12+
"github.com/gitpod-io/gitpod/workspace-rollout-job/pkg/rollout"
13+
"github.com/gitpod-io/gitpod/workspace-rollout-job/pkg/wsbridge"
14+
"github.com/spf13/cobra"
15+
)
16+
17+
var rootCmd = &cobra.Command{
18+
Use: "workspace-rollout-job",
19+
Short: "Rollout from old to a new cluster while monitoring metrics",
20+
Run: func(cmd *cobra.Command, args []string) {
21+
log.Info("Starting workspace-rollout-job")
22+
var err error
23+
old, presence := os.LookupEnv("OLD_CLUSTER")
24+
if !presence {
25+
log.WithError(err).Fatal("cannot get old cluster")
26+
}
27+
28+
new, presence := os.LookupEnv("NEW_CLUSTER")
29+
if !presence {
30+
log.WithError(err).Fatal("cannot get new cluster")
31+
}
32+
33+
// Check if the old cluster has a 100 score.
34+
if err = wsbridge.CheckScore(old, 100); err != nil {
35+
log.WithError(err).Fatal("init condition does not satisfy")
36+
}
37+
38+
// Check if the new cluster has a 0 zero score.
39+
// TODO: Check if the new cluster has no constraints.
40+
if err = wsbridge.CheckScore(new, 0); err != nil {
41+
log.WithError(err).Fatal("init condition does not satisfy")
42+
}
43+
44+
// Start the rollout process.
45+
job := rollout.New(old, new, "http://prometheus:9090")
46+
job.Start()
47+
},
48+
}
49+
50+
// Execute adds all child commands to the root command and sets flags appropriately.
51+
// This is called by main.main(). It only needs to happen once to the rootCmd.
52+
func Execute() {
53+
if err := rootCmd.Execute(); err != nil {
54+
fmt.Println(err)
55+
os.Exit(1)
56+
}
57+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
module github.com/gitpod-io/gitpod/workspace-rollout-job
2+
3+
go 1.19
4+
5+
require (
6+
github.com/gitpod-io/gitpod/common-go v0.0.0-00010101000000-000000000000
7+
github.com/gitpod-io/gitpod/ws-manager-bridge/api v0.0.0-00010101000000-000000000000
8+
github.com/spf13/cobra v1.4.0
9+
google.golang.org/grpc v1.49.0
10+
)
11+
12+
require (
13+
github.com/golang/protobuf v1.5.2 // indirect
14+
github.com/inconshreveable/mousetrap v1.0.0 // indirect
15+
github.com/sirupsen/logrus v1.8.1 // indirect
16+
github.com/spf13/pflag v1.0.5 // indirect
17+
golang.org/x/net v0.0.0-20220225172249-27dd8689420f // indirect
18+
golang.org/x/sys v0.0.0-20220825204002-c680a09ffe64 // indirect
19+
golang.org/x/text v0.3.7 // indirect
20+
google.golang.org/genproto v0.0.0-20201019141844-1ed22bb0c154 // indirect
21+
google.golang.org/protobuf v1.28.1 // indirect
22+
)
23+
24+
replace github.com/gitpod-io/gitpod/ws-manager-bridge/api => ../ws-manager-bridge-api/go // leeway
25+
26+
replace github.com/gitpod-io/gitpod/common-go => ../common-go // leeway
27+
28+
replace k8s.io/api => k8s.io/api v0.24.4 // leeway indirect from components/common-go:lib
29+
30+
replace k8s.io/apimachinery => k8s.io/apimachinery v0.24.4 // leeway indirect from components/common-go:lib
31+
32+
replace k8s.io/client-go => k8s.io/client-go v0.24.4 // leeway indirect from components/common-go:lib

components/workspace-rollout-job/go.sum

Lines changed: 99 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Copyright (c) 2022 Gitpod GmbH. All rights reserved.
2+
# Licensed under the GNU Affero General Public License (AGPL).
3+
# See License-AGPL.txt in the project root for license information.
4+
5+
FROM alpine:3.16
6+
7+
# Ensure latest packages are present, like security updates.
8+
RUN apk upgrade --no-cache \
9+
&& apk add --no-cache ca-certificates
10+
11+
RUN adduser -S -D -H -h /app -u 31001 appuser
12+
COPY components-workspace-rollout-job--app/workspace-rollout-job /app/workspace-rollout-job
13+
RUN chown -R appuser /app
14+
15+
USER appuser
16+
ENTRYPOINT [ "/app/workspace-rollout-job" ]
17+
CMD [ "-v", "help" ]
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Copyright (c) 2022 Gitpod GmbH. All rights reserved.
2+
// Licensed under the GNU Affero General Public License (AGPL).
3+
// See License-AGPL.txt in the project root for license information.
4+
5+
package main
6+
7+
import "github.com/gitpod-io/gitpod/workspace-rollout-job/cmd"
8+
9+
func main() {
10+
cmd.Execute()
11+
}

0 commit comments

Comments
 (0)