Skip to content

Commit 72b840c

Browse files
committed
use previewctl get-creds
1 parent cb83111 commit 72b840c

22 files changed

+68
-45
lines changed

Diff for: .gitpod.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
image: eu.gcr.io/gitpod-core-dev/dev/dev-environment:af-dev-update-image.8
1+
image: eu.gcr.io/gitpod-core-dev/dev/dev-environment:aa-previewctl-fix-rebuild.2
22
workspaceLocation: gitpod/gitpod-ws.code-workspace
33
checkoutLocation: gitpod
44
ports:

Diff for: .werft/aks-installer-tests.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ pod:
6565
secretName: self-hosted-github-oauth
6666
containers:
6767
- name: nightly-test
68-
image: eu.gcr.io/gitpod-core-dev/dev/dev-environment:af-dev-update-image.8
68+
image: eu.gcr.io/gitpod-core-dev/dev/dev-environment:aa-previewctl-fix-rebuild.2
6969
workingDir: /workspace
7070
imagePullPolicy: Always
7171
volumeMounts:

Diff for: .werft/build.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ pod:
7676
- name: MYSQL_TCP_PORT
7777
value: 23306
7878
- name: build
79-
image: eu.gcr.io/gitpod-core-dev/dev/dev-environment:af-dev-update-image.8
79+
image: eu.gcr.io/gitpod-core-dev/dev/dev-environment:aa-previewctl-fix-rebuild.2
8080
workingDir: /workspace
8181
imagePullPolicy: IfNotPresent
8282
resources:

Diff for: .werft/cleanup-installer-tests.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ pod:
2525
secretName: aks-credentials
2626
containers:
2727
- name: nightly-test
28-
image: eu.gcr.io/gitpod-core-dev/dev/dev-environment:af-dev-update-image.8
28+
image: eu.gcr.io/gitpod-core-dev/dev/dev-environment:aa-previewctl-fix-rebuild.2
2929
workingDir: /workspace
3030
imagePullPolicy: Always
3131
volumeMounts:

Diff for: .werft/debug.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ pod:
5454
- name: MYSQL_TCP_PORT
5555
value: 23306
5656
- name: build
57-
image: eu.gcr.io/gitpod-core-dev/dev/dev-environment:af-dev-update-image.8
57+
image: eu.gcr.io/gitpod-core-dev/dev/dev-environment:aa-previewctl-fix-rebuild.2
5858
workingDir: /workspace
5959
imagePullPolicy: IfNotPresent
6060
volumeMounts:

Diff for: .werft/eks-installer-tests.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ pod:
6565
secretName: self-hosted-github-oauth
6666
containers:
6767
- name: nightly-test
68-
image: eu.gcr.io/gitpod-core-dev/dev/dev-environment:af-dev-update-image.8
68+
image: eu.gcr.io/gitpod-core-dev/dev/dev-environment:aa-previewctl-fix-rebuild.2
6969
workingDir: /workspace
7070
imagePullPolicy: Always
7171
volumeMounts:

Diff for: .werft/gke-installer-tests.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ pod:
6565
secretName: self-hosted-github-oauth
6666
containers:
6767
- name: nightly-test
68-
image: eu.gcr.io/gitpod-core-dev/dev/dev-environment:af-dev-update-image.8
68+
image: eu.gcr.io/gitpod-core-dev/dev/dev-environment:aa-previewctl-fix-rebuild.2
6969
workingDir: /workspace
7070
imagePullPolicy: Always
7171
volumeMounts:

Diff for: .werft/ide-integration-tests-startup.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ pod:
1717
secretName: github-token-gitpod-bot
1818
containers:
1919
- name: gcloud
20-
image: eu.gcr.io/gitpod-core-dev/dev/dev-environment:af-dev-update-image.8
20+
image: eu.gcr.io/gitpod-core-dev/dev/dev-environment:aa-previewctl-fix-rebuild.2
2121
workingDir: /workspace
2222
imagePullPolicy: IfNotPresent
2323
env:

Diff for: .werft/jobs/build/const.ts

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ export const GCLOUD_SERVICE_ACCOUNT_PATH = "/mnt/secrets/gcp-sa/service-account.
22
export const CORE_DEV_KUBECONFIG_PATH = "/workspace/gitpod/kubeconfigs/core-dev";
33
export const HARVESTER_KUBECONFIG_PATH = "/workspace/gitpod/kubeconfigs/harvester";
44
export const PREVIEW_K3S_KUBECONFIG_PATH = "/workspace/gitpod/kubeconfigs/k3s";
5+
export const GLOBAL_KUBECONFIG_PATH = process.env.HOME + "/.kube/config"

Diff for: .werft/jobs/build/prepare.ts

+18-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
import {exec, execStream} from "../../util/shell";
22
import { Werft } from "../../util/werft";
3-
import { CORE_DEV_KUBECONFIG_PATH, GCLOUD_SERVICE_ACCOUNT_PATH, HARVESTER_KUBECONFIG_PATH } from "./const";
3+
import {
4+
CORE_DEV_KUBECONFIG_PATH,
5+
GCLOUD_SERVICE_ACCOUNT_PATH,
6+
GLOBAL_KUBECONFIG_PATH,
7+
HARVESTER_KUBECONFIG_PATH
8+
} from "./const";
49
import { JobConfig } from "./job-config";
510
import {certReady} from "../../util/certs";
611
import {vmExists} from "../../vm/vm";
712

813
const phaseName = "prepare";
914
const prepareSlices = {
15+
CONFIGURE_K8S: "Configuring k8s access.",
1016
CONFIGURE_CORE_DEV: "Configuring core-dev access.",
1117
BOOT_VM: "Booting VM.",
1218
WAIT_CERTIFICATES: "Waiting for certificates to be ready for the preview.",
@@ -19,6 +25,7 @@ export async function prepare(werft: Werft, config: JobConfig) {
1925
activateCoreDevServiceAccount();
2026
configureDocker();
2127
configureStaticClustersAccess();
28+
configureGlobalKubernetesContext();
2229
werft.done(prepareSlices.CONFIGURE_CORE_DEV);
2330
if (!config.withPreview)
2431
{
@@ -53,6 +60,15 @@ function configureDocker() {
5360
}
5461
}
5562

63+
function configureGlobalKubernetesContext() {
64+
exec(`sleep 1000000000`)
65+
const rc = exec(`previewctl get-credentials --gcp-service-account=${GCLOUD_SERVICE_ACCOUNT_PATH} --kube-save-path=${GLOBAL_KUBECONFIG_PATH}`, { slice: prepareSlices.CONFIGURE_K8S }).code;
66+
67+
if (rc != 0) {
68+
throw new Error("Failed to configure global kubernetes context.");
69+
}
70+
}
71+
5672
function configureStaticClustersAccess() {
5773
const rcCoreDev = exec(
5874
`KUBECONFIG=${CORE_DEV_KUBECONFIG_PATH} gcloud container clusters get-credentials core-dev --zone europe-west1-b --project gitpod-core-dev`,
@@ -90,8 +106,7 @@ async function createVM(werft: Werft, config: JobConfig) {
90106
// We pass the GCP credentials explicitly, otherwise for some reason TF doesn't pick them up
91107
const commonVars = `GOOGLE_BACKEND_CREDENTIALS=${GCLOUD_SERVICE_ACCOUNT_PATH} \
92108
GOOGLE_APPLICATION_CREDENTIALS=${GCLOUD_SERVICE_ACCOUNT_PATH} \
93-
TF_VAR_dev_kube_path=${CORE_DEV_KUBECONFIG_PATH} \
94-
TF_VAR_harvester_kube_path=${HARVESTER_KUBECONFIG_PATH} \
109+
TF_VAR_kubeconfig_path=${GLOBAL_KUBECONFIG_PATH} \
95110
TF_VAR_preview_name=${config.previewEnvironment.destname} \
96111
TF_VAR_vm_cpu=${cpu} \
97112
TF_VAR_vm_memory=${memory}Gi \

Diff for: .werft/k3s-installer-tests.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ pod:
6565
secretName: self-hosted-github-oauth
6666
containers:
6767
- name: nightly-test
68-
image: eu.gcr.io/gitpod-core-dev/dev/dev-environment:af-dev-update-image.8
68+
image: eu.gcr.io/gitpod-core-dev/dev/dev-environment:aa-previewctl-fix-rebuild.2
6969
workingDir: /workspace
7070
imagePullPolicy: Always
7171
volumeMounts:

Diff for: .werft/platform-delete-preview-environment.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ pod:
2525
secretName: harvester-vm-ssh-keys
2626
containers:
2727
- name: build
28-
image: eu.gcr.io/gitpod-core-dev/dev/dev-environment:af-dev-update-image.8
28+
image: eu.gcr.io/gitpod-core-dev/dev/dev-environment:aa-previewctl-fix-rebuild.2
2929
workingDir: /workspace
3030
imagePullPolicy: IfNotPresent
3131
volumeMounts:

Diff for: .werft/platform-delete-preview-environments-cron.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pod:
2929
secretName: github-token-gitpod-bot
3030
containers:
3131
- name: build
32-
image: eu.gcr.io/gitpod-core-dev/dev/dev-environment:af-dev-update-image.8
32+
image: eu.gcr.io/gitpod-core-dev/dev/dev-environment:aa-previewctl-fix-rebuild.2
3333
workingDir: /workspace
3434
imagePullPolicy: IfNotPresent
3535
volumeMounts:

Diff for: .werft/platform-trigger-artificial-job.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ pod:
2424
secretName: github-token-gitpod-bot
2525
containers:
2626
- name: build
27-
image: eu.gcr.io/gitpod-core-dev/dev/dev-environment:aledbf-dl.1
27+
image: eu.gcr.io/gitpod-core-dev/dev/dev-environment:aa-previewctl-fix-rebuild.2
2828
workingDir: /workspace
2929
imagePullPolicy: IfNotPresent
3030
volumeMounts:

Diff for: .werft/platform-trigger-werft-cleanup.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ pod:
2222
secretName: gcp-sa-gitpod-dev-deployer
2323
containers:
2424
- name: build
25-
image: eu.gcr.io/gitpod-core-dev/dev/dev-environment:af-dev-update-image.8
25+
image: eu.gcr.io/gitpod-core-dev/dev/dev-environment:aa-previewctl-fix-rebuild.2
2626
workingDir: /workspace
2727
imagePullPolicy: IfNotPresent
2828
volumeMounts:

Diff for: .werft/util/certs.ts

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import {exec, ExecOptions, execStream} from "./shell";
2-
import {CORE_DEV_KUBECONFIG_PATH, GCLOUD_SERVICE_ACCOUNT_PATH, HARVESTER_KUBECONFIG_PATH} from "../jobs/build/const";
2+
import {
3+
CORE_DEV_KUBECONFIG_PATH,
4+
GCLOUD_SERVICE_ACCOUNT_PATH,
5+
GLOBAL_KUBECONFIG_PATH,
6+
} from "../jobs/build/const";
37
import { Werft } from "./werft";
48
import { reportCertificateError } from "../util/slack";
59
import {JobConfig} from "../jobs/build/job-config";
@@ -21,8 +25,7 @@ export async function certReady(werft: Werft, config: JobConfig, slice: string):
2125
// We pass the GCP credentials explicitly, otherwise for some reason TF doesn't pick them up
2226
const commonVars = `GOOGLE_BACKEND_CREDENTIALS=${GCLOUD_SERVICE_ACCOUNT_PATH} \
2327
GOOGLE_APPLICATION_CREDENTIALS=${GCLOUD_SERVICE_ACCOUNT_PATH} \
24-
TF_VAR_dev_kube_path=${CORE_DEV_KUBECONFIG_PATH} \
25-
TF_VAR_harvester_kube_path=${HARVESTER_KUBECONFIG_PATH} \
28+
TF_VAR_kubeconfig_path=${GLOBAL_KUBECONFIG_PATH} \
2629
TF_VAR_preview_name=${config.previewEnvironment.destname} \
2730
TF_VAR_vm_cpu=${cpu} \
2831
TF_VAR_vm_memory=${memory}Gi \

Diff for: .werft/vm/vm.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {
2-
CORE_DEV_KUBECONFIG_PATH,
32
GCLOUD_SERVICE_ACCOUNT_PATH,
3+
GLOBAL_KUBECONFIG_PATH,
44
HARVESTER_KUBECONFIG_PATH,
55
PREVIEW_K3S_KUBECONFIG_PATH
66
} from "../jobs/build/const";
@@ -19,8 +19,7 @@ export async function deleteVM(options: { name: string }) {
1919
await execStream(`DESTROY=true \
2020
GOOGLE_APPLICATION_CREDENTIALS=${GCLOUD_SERVICE_ACCOUNT_PATH} \
2121
GOOGLE_BACKEND_CREDENTIALS=${GCLOUD_SERVICE_ACCOUNT_PATH} \
22-
TF_VAR_dev_kube_path=${CORE_DEV_KUBECONFIG_PATH} \
23-
TF_VAR_harvester_kube_path=${HARVESTER_KUBECONFIG_PATH} \
22+
TF_VAR_kubeconfig_path=${GLOBAL_KUBECONFIG_PATH} \
2423
TF_VAR_preview_name=${options.name} \
2524
./dev/preview/workflow/preview/deploy-harvester.sh`,
2625
{slice: "Deleting VM."})

Diff for: .werft/workspace-run-integration-tests.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ pod:
2222
secretName: github-token-gitpod-bot
2323
containers:
2424
- name: gcloud
25-
image: eu.gcr.io/gitpod-core-dev/dev/dev-environment:af-dev-update-image.8
25+
image: eu.gcr.io/gitpod-core-dev/dev/dev-environment:aa-previewctl-fix-rebuild.2
2626
workingDir: /workspace
2727
imagePullPolicy: IfNotPresent
2828
env:

Diff for: dev/image/Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
FROM gitpod/workspace-full:2022-10-15-02-50-27
66

7-
ENV TRIGGER_REBUILD 22
7+
ENV TRIGGER_REBUILD 23
88

99
USER root
1010

Diff for: dev/preview/infrastructure/harvester/provider.tf

+10-7
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ terraform {
99
required_providers {
1010
harvester = {
1111
source = "harvester/harvester"
12-
version = ">=0.5.1"
12+
version = ">=0.5.3"
1313
}
1414
k8s = {
1515
source = "hashicorp/kubernetes"
@@ -23,18 +23,21 @@ terraform {
2323
}
2424

2525
provider "harvester" {
26-
alias = "harvester"
27-
kubeconfig = var.harvester_kube_path
26+
alias = "harvester"
27+
kubeconfig = var.kubeconfig_path
28+
kubecontext = "harvester"
2829
}
2930

3031
provider "k8s" {
31-
alias = "dev"
32-
config_path = var.dev_kube_path
32+
alias = "dev"
33+
config_path = var.kubeconfig_path
34+
config_context = var.dev_kube_context
3335
}
3436

3537
provider "k8s" {
36-
alias = "harvester"
37-
config_path = var.harvester_kube_path
38+
alias = "harvester"
39+
config_path = var.kubeconfig_path
40+
config_context = var.harvester_kube_context
3841
}
3942

4043
provider "google" {

Diff for: dev/preview/infrastructure/harvester/variables.tf

+12-5
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,22 @@ variable "preview_name" {
33
description = "The preview environment's name"
44
}
55

6-
variable "harvester_kube_path" {
6+
variable "kubeconfig_path" {
77
type = string
8-
description = "The path to the Harvester Cluster kubeconfig"
8+
default = "/home/gitpod/.kube/config"
9+
description = "The path to the kubernetes config"
910
}
1011

11-
variable "dev_kube_path" {
12+
variable "harvester_kube_context" {
1213
type = string
13-
description = "The path to the Dev Cluster kubeconfig"
14+
default = "harvester"
15+
description = "The name of the harvester kube context"
16+
}
17+
18+
variable "dev_kube_context" {
19+
type = string
20+
default = "dev"
21+
description = "The name of the dev kube context"
1422
}
1523

1624
variable "vm_memory" {
@@ -28,7 +36,6 @@ variable "vm_cpu" {
2836
variable "vm_storage_class" {
2937
type = string
3038
description = "The storage class for the VM"
31-
default = "longhorn-gitpod-k3s-202209251218-onereplica"
3239
}
3340

3441
variable "harvester_ingress_ip" {

Diff for: dev/preview/previewctl/cmd/credentials.go

+4-9
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,6 @@ type getCredentialsOpts struct {
3434
gcpClient *gcloud.Config
3535
logger *logrus.Logger
3636

37-
serviceAccountPath string
38-
kubeConfigSavePath string
39-
4037
getCredentialsMap map[string]func(ctx context.Context) (*api.Config, error)
4138
configMap map[string]*api.Config
4239
}
@@ -46,18 +43,16 @@ func newGetCredentialsCommand(logger *logrus.Logger) *cobra.Command {
4643
var client *gcloud.Config
4744
ctx := context.Background()
4845
opts := &getCredentialsOpts{
49-
logger: logger,
50-
kubeConfigSavePath: kubeConfigSavePath,
51-
serviceAccountPath: serviceAccountPath,
52-
configMap: map[string]*api.Config{},
46+
logger: logger,
47+
configMap: map[string]*api.Config{},
5348
}
5449

5550
cmd := &cobra.Command{
5651
Use: "get-credentials",
5752
Long: `previewctl get-credentials retrieves the kubernetes configs for core-dev and harvester clusters,
5853
merges them with the default config, and outputs them either to stdout or to a file.`,
5954
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
60-
client, err = gcloud.New(ctx, opts.serviceAccountPath)
55+
client, err = gcloud.New(ctx, serviceAccountPath)
6156
if err != nil {
6257
return err
6358
}
@@ -118,7 +113,7 @@ func (o *getCredentialsOpts) mergeContexts() error {
118113
return err
119114
}
120115

121-
if o.kubeConfigSavePath != "" {
116+
if kubeConfigSavePath != "" {
122117
return clientcmd.WriteToFile(*finalConfig, kubeConfigSavePath)
123118
}
124119

0 commit comments

Comments
 (0)