Skip to content

Commit 93f2bad

Browse files
committed
use previewctl get-creds
1 parent dbdecc3 commit 93f2bad

File tree

6 files changed

+48
-21
lines changed

6 files changed

+48
-21
lines changed

.werft/jobs/build/const.ts

Lines changed: 1 addition & 0 deletions
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"

.werft/jobs/build/prepare.ts

Lines changed: 17 additions & 3 deletions
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,14 @@ function configureDocker() {
5360
}
5461
}
5562

63+
function configureGlobalKubernetesContext() {
64+
const rc = exec(`previewctl get-credentials --gcp-service-account=${GCLOUD_SERVICE_ACCOUNT_PATH} --kube-save-path=${GLOBAL_KUBECONFIG_PATH}`, { slice: prepareSlices.CONFIGURE_K8S }).code;
65+
66+
if (rc != 0) {
67+
throw new Error("Failed to configure global kubernetes context.");
68+
}
69+
}
70+
5671
function configureStaticClustersAccess() {
5772
const rcCoreDev = exec(
5873
`KUBECONFIG=${CORE_DEV_KUBECONFIG_PATH} gcloud container clusters get-credentials core-dev --zone europe-west1-b --project gitpod-core-dev`,
@@ -90,8 +105,7 @@ async function createVM(werft: Werft, config: JobConfig) {
90105
// We pass the GCP credentials explicitly, otherwise for some reason TF doesn't pick them up
91106
const commonVars = `GOOGLE_BACKEND_CREDENTIALS=${GCLOUD_SERVICE_ACCOUNT_PATH} \
92107
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} \
108+
TF_VAR_kubeconfig_path=${GLOBAL_KUBECONFIG_PATH} \
95109
TF_VAR_preview_name=${config.previewEnvironment.destname} \
96110
TF_VAR_vm_cpu=${cpu} \
97111
TF_VAR_vm_memory=${memory}Gi \

.werft/util/certs.ts

Lines changed: 6 additions & 3 deletions
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 \

.werft/vm/vm.ts

Lines changed: 2 additions & 3 deletions
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."})

dev/preview/infrastructure/harvester/provider.tf

Lines changed: 10 additions & 7 deletions
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" {

dev/preview/infrastructure/harvester/variables.tf

Lines changed: 12 additions & 5 deletions
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" {

0 commit comments

Comments
 (0)