Skip to content

Commit e2df77f

Browse files
iQQBotroboquat
authored andcommitted
[werft] change routeros to kubectl port-forward
1 parent 424152c commit e2df77f

File tree

2 files changed

+29
-58
lines changed

2 files changed

+29
-58
lines changed

.werft/jobs/build/prepare.ts

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,12 @@ function issueCertificate(werft: Werft, config: JobConfig) {
8585
function decideHarvesterVMCreation(werft: Werft, config: JobConfig) {
8686
if (shouldCreateVM(config)) {
8787
createVM(werft, config)
88-
applyLoadBalancer({ name: config.previewEnvironment.destname })
8988
} else {
9089
werft.currentPhaseSpan.setAttribute("werft.harvester.created_vm", false)
9190
}
91+
if (config.withVM) {
92+
applyLoadBalancer({ name: config.previewEnvironment.destname })
93+
}
9294
werft.done(prepareSlices.BOOT_VM)
9395
}
9496

@@ -121,20 +123,6 @@ ${manifest}
121123
EOF
122124
`);
123125
}
124-
function getVMServiceIP() {
125-
let ip = exec(
126-
`kubectl --kubeconfig ${HARVESTER_KUBECONFIG_PATH} -n ${namespace} get service proxy -o=jsonpath='{.spec.clusterIP}'`,
127-
{ silent: true },
128-
);
129-
if (ip.length > 4) {
130-
return ip;
131-
}
132-
return null;
133-
}
134-
let forwardIP = getVMServiceIP();
135-
if (forwardIP == null) {
136-
throw new Error("Failed to get VM IP");
137-
}
138-
kubectlApplyManifest(Manifests.LBDeployManifest({ name: option.name, destIP: forwardIP }));
126+
kubectlApplyManifest(Manifests.LBDeployManifest({ name: option.name }));
139127
kubectlApplyManifest(Manifests.LBServiceManifest({ name: option.name }));
140128
}

.werft/vm/manifests.ts

Lines changed: 25 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -156,11 +156,11 @@ spec:
156156
- name: ssh-gateway
157157
protocol: TCP
158158
port: 22
159-
targetPort: 22
159+
targetPort: 2200
160160
- name: https
161161
protocol: TCP
162162
port: 443
163-
targetPort: 443
163+
targetPort: 4430
164164
selector:
165165
gitpod.io/lbName: ${name}
166166
type: LoadBalancer
@@ -169,10 +169,9 @@ spec:
169169

170170
type LBDeployManifestOptions = {
171171
name: string
172-
destIP: string
173172
}
174173

175-
export function LBDeployManifest({ name, destIP }: LBDeployManifestOptions) {
174+
export function LBDeployManifest({ name }: LBDeployManifestOptions) {
176175
return `
177176
apiVersion: apps/v1
178177
kind: Deployment
@@ -192,45 +191,29 @@ spec:
192191
labels:
193192
gitpod.io/lbName: ${name}
194193
spec:
194+
volumes:
195+
- name: kubeconfig
196+
secret:
197+
secretName: harvester-kubeconfig
195198
containers:
196-
- name: lb-port-22
197-
image: rancher/klipper-lb:v0.3.4
198-
ports:
199-
- name: lb-port-22
200-
containerPort: 22
201-
protocol: TCP
202-
env:
203-
- name: SRC_PORT
204-
value: '22'
205-
- name: DEST_PROTO
206-
value: TCP
207-
- name: DEST_PORT
208-
value: '22'
209-
- name: DEST_IPS
210-
value: ${destIP}
211-
securityContext:
212-
capabilities:
213-
add:
214-
- NET_ADMIN
215-
- name: lb-port-443
216-
image: rancher/klipper-lb:v0.3.4
217-
ports:
218-
- name: lb-port-443
219-
containerPort: 443
220-
protocol: TCP
221-
env:
222-
- name: SRC_PORT
223-
value: '443'
224-
- name: DEST_PROTO
225-
value: TCP
226-
- name: DEST_PORT
227-
value: '443'
228-
- name: DEST_IPS
229-
value: ${destIP}
230-
securityContext:
231-
capabilities:
232-
add:
233-
- NET_ADMIN
199+
- name: kubectl
200+
image: bitnami/kubectl:1.23.5
201+
args:
202+
- port-forward
203+
- '--kubeconfig'
204+
- /mnt/kubeconfig/harvester-kubeconfig.yml
205+
- '-n'
206+
- preview-${name}
207+
- --address=0.0.0.0
208+
- --pod-running-timeout=2m
209+
- svc/proxy
210+
- '4430:443'
211+
- '2200:22'
212+
resources: {}
213+
volumeMounts:
214+
- name: kubeconfig
215+
readOnly: true
216+
mountPath: /mnt/kubeconfig/
234217
serviceAccount: proxy
235218
enableServiceLinks: false
236219
`

0 commit comments

Comments
 (0)