Skip to content

Commit 49dfe18

Browse files
hhBobyMCbobs
authored andcommitted
Add initial support for kubevirt
1 parent e9542d8 commit 49dfe18

File tree

13 files changed

+1177
-0
lines changed

13 files changed

+1177
-0
lines changed

.sharing.io/destroy

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/env bash
2+
set -x
3+
kubectl delete -f .sharingio/ingress.yaml
4+
helm delete coder --namespace coder
5+
helm delete postgres --namespace coder
6+
kubectl delete namespace coder
7+
# TODO : populate ii or pair as an admin user without logging in
8+
# TODO : upload / update the kubernetes template

.sharing.io/ingress.template.yaml

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
apiVersion: networking.k8s.io/v1
2+
kind: Ingress
3+
metadata:
4+
annotations:
5+
kubernetes.io/ingress.class: contour-external
6+
name: coder
7+
namespace: coder
8+
spec:
9+
rules:
10+
- host: coder.${SHARINGIO_PAIR_BASE_DNS_NAME}
11+
http:
12+
paths:
13+
- backend:
14+
service:
15+
name: coder
16+
port:
17+
number: 80
18+
path: /
19+
pathType: ImplementationSpecific
20+
tls:
21+
- hosts:
22+
- coder.${SHARINGIO_PAIR_BASE_DNS_NAME}
23+
secretName: letsencrypt-prod
24+
status:
25+
loadBalancer: {}

.sharing.io/init

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#!/bin/env bash
2+
set -x
3+
4+
# upgrade go to 1.19.1
5+
go version | grep 1.19.1 || curl -L https://dl.google.com/go/go1.19.1.linux-amd64.tar.gz | sudo tar --directory /usr/local --extract --ungzip
6+
# shfmt needed for make
7+
which shfmt || sudo apt-get install shfmt
8+
# for converting k8s yaml to HCL
9+
go install github.com/jrhouston/tfk8s@latest
10+
# TODO: Make still failing, possible dependencies still missing.
11+
12+
# install coder binary until we can build from src
13+
which coder || (
14+
curl -OL https://github.com/coder/coder/releases/download/v0.9.1/coder_0.9.1_linux_amd64.deb
15+
sudo dpkg -i coder_0.9.1_linux_amd64.deb
16+
# Add completion
17+
echo '. <(coder completion bash)' >>~/.bashrc
18+
)
19+
20+
# Deploying coder (from helm for now)
21+
kubectl create namespace coder
22+
# ensure ingress works / certs secrets get copied
23+
kubectl label ns coder cert-manager-tls=sync
24+
# needs a postgres db
25+
helm repo add bitnami https://charts.bitnami.com/bitnami
26+
helm install postgres bitnami/postgresql \
27+
--namespace coder \
28+
--set auth.username=coder \
29+
--set auth.password=coder \
30+
--set auth.database=coder \
31+
--set persistence.size=10Gi
32+
# deploy via helm for now
33+
envsubst <.sharing.io/values.template.yaml >.sharing.io/values.yaml
34+
helm install coder ./helm/ \
35+
--namespace coder \
36+
--values .sharing.io/values.yaml
37+
# setup ingress
38+
envsubst <.sharing.io/ingress.template.yaml >.sharing.io/ingress.yaml
39+
kubectl apply -f .sharing.io/ingress.yaml
40+
# Wait for coder to deploy
41+
kubectl rollout status deployment coder -n coder
42+
kubectl wait -n coder --for=condition=ready pod -l app.kubernetes.io/name=coder
43+
44+
# create the initial user
45+
# populate ii or pair as an admin user without logging in
46+
CODER_EMAIL=ii@ii.coop
47+
CODER_PASSWORD=ii
48+
CODER_USERNAME=ii
49+
CODER_URL=https://coder.${SHARINGIO_PAIR_BASE_DNS_NAME}
50+
# export vars to we can emulate a tty with a short expect script
51+
export CODER_EMAIL CODER_PASSWORD CODER_USERNAME
52+
coder login $CODER_URL -u $CODER_USERNAME -p $CODER_PASSWORD -e $CODER_EMAIL
53+
export HELM_VALUES="service:\n type: NodePort\nsyncer:\n extraArgs:\n - --tls-san=${SHARINGIO_PAIR_BASE_DNS_NAME}"
54+
export EXP_CLUSTER_RESOURCE_SET=true
55+
# Install kubevirt
56+
export RELEASE=$(curl https://storage.googleapis.com/kubevirt-prow/release/kubevirt/kubevirt/stable.txt)
57+
# Deploy the KubeVirt operator
58+
kubectl apply -f https://github.com/kubevirt/kubevirt/releases/download/${RELEASE}/kubevirt-operator.yaml
59+
# Create the KubeVirt CR (instance deployment request) which triggers the actual installation
60+
kubectl apply -f https://github.com/kubevirt/kubevirt/releases/download/${RELEASE}/kubevirt-cr.yaml
61+
# wait until all KubeVirt components are up
62+
kubectl -n kubevirt wait kv kubevirt --for condition=Available
63+
64+
clusterctl init --infrastructure vcluster
65+
clusterctl init --infrastructure kubevirt
66+
clusterctl init --infrastructure=packet
67+
68+
kubectl create ns coder-workspaces
69+
70+
#TODO : upload / update the kubernetes template

.sharing.io/values.template.yaml

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
coder:
2+
# You can specify any environment variables you'd like to pass to Coder
3+
# here. Coder consumes environment variables listed in
4+
# `coder server --help`, and these environment variables are also passed
5+
# to the workspace provisioner (so you can consume them in your Terraform
6+
# templates for auth keys etc.).
7+
#
8+
# Please keep in mind that you should not set `CODER_ADDRESS`,
9+
# `CODER_TLS_ENABLE`, `CODER_TLS_CERT_FILE` or `CODER_TLS_KEY_FILE` as
10+
# they are already set by the Helm chart and will cause conflicts.
11+
image:
12+
tag: "v0.9.0"
13+
env:
14+
- name: CODER_ACCESS_URL
15+
value: "https://coder.${SHARINGIO_PAIR_BASE_DNS_NAME}"
16+
- name: CODER_PG_CONNECTION_URL
17+
value: "postgres://coder:coder@postgres-postgresql.coder.svc.cluster.local:5432/coder?sslmode=disable"
18+
# This env variable controls whether or not to auto-import the "kubernetes"
19+
# template on first startup. This will not work unless
20+
# coder.serviceAccount.workspacePerms is true.
21+
- name: CODER_TEMPLATE_AUTOIMPORT
22+
value: "kubernetes"
23+
- name: CODER_VERBOSE
24+
value: "true"
25+
- name: CODER_AUDIT_LOGGING
26+
value: "false"
27+
- name: CODER_TELEMETRY
28+
value: "false"
29+
- name: CODER_TELEMETRY_TRACE
30+
value: "false"
31+
- name: CODER_WILDCARD_ACCESS_URL
32+
value: "*.coder.${SHARINGIO_PAIR_BASE_DNS_NAME}"
33+
tls:
34+
secretName: null

.sharing.io/vcluster/cluster.tf

+89
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
resource "kubernetes_namespace" "work-namespace" {
2+
metadata {
3+
annotations = {
4+
name = "ii-annotation"
5+
}
6+
7+
labels = {
8+
cert-manager-tls = "sync"
9+
}
10+
11+
name = var.namespace
12+
}
13+
}
14+
resource "kubernetes_manifest" "cluster_vclusters_vcluster1" {
15+
manifest = {
16+
"apiVersion" = "cluster.x-k8s.io/v1beta1"
17+
"kind" = "Cluster"
18+
"metadata" = {
19+
"name" = "vcluster1"
20+
"namespace" = var.namespace
21+
}
22+
"spec" = {
23+
"controlPlaneRef" = {
24+
"apiVersion" = "infrastructure.cluster.x-k8s.io/v1alpha1"
25+
"kind" = "VCluster"
26+
"name" = "vcluster1"
27+
}
28+
"infrastructureRef" = {
29+
"apiVersion" = "infrastructure.cluster.x-k8s.io/v1alpha1"
30+
"kind" = "VCluster"
31+
"name" = "vcluster1"
32+
}
33+
}
34+
}
35+
}
36+
37+
resource "kubernetes_manifest" "vcluster_vclusters_vcluster1" {
38+
provisioner "local-exec" {
39+
command = "kubectl wait --for=condition=Ready --timeout=30s -n ${var.namespace} cluster vcluster1"
40+
}
41+
provisioner "local-exec" {
42+
command = "kubectl get secrets -n ${var.namespace} vcluster1-kubeconfig -o jsonpath={.data.value} | base64 -d > kubeconfig"
43+
}
44+
manifest = {
45+
"apiVersion" = "infrastructure.cluster.x-k8s.io/v1alpha1"
46+
"kind" = "VCluster"
47+
"metadata" = {
48+
"name" = "vcluster1"
49+
"namespace" = var.namespace
50+
}
51+
"spec" = {
52+
"controlPlaneEndpoint" = {
53+
"host" = ""
54+
"port" = 0
55+
}
56+
"helmRelease" = {
57+
"chart" = {
58+
"name" = null
59+
"repo" = null
60+
"version" = null
61+
}
62+
"values" = <<-EOT
63+
service:
64+
type: NodePort
65+
syncer:
66+
extraArgs:
67+
- --tls-san=${var.tls-san}
68+
EOT
69+
}
70+
"kubernetesVersion" = var.k8s-version
71+
}
72+
}
73+
}
74+
75+
# This is generated from the vcluster...
76+
# Need to find a way for it to wait before running, so that the secret exists
77+
data "kubernetes_resource" "kubeconfig" {
78+
api_version = "v1"
79+
kind = "Secret"
80+
depends_on = [
81+
kubernetes_manifest.vcluster_vclusters_vcluster1
82+
]
83+
metadata {
84+
name = "vcluster-kubeconfig"
85+
namespace = var.namespace
86+
}
87+
}
88+
89+
# We'll need to use the kubeconfig from above to provision the coder/pair environment

.sharing.io/vcluster/input.tf

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
variable "namespace" {
2+
description = "namespace that will contain the workspace"
3+
type = string
4+
default = "coder-ws"
5+
}
6+
7+
variable "k8s-version" {
8+
description = "Version of Kubernetes to Depoy as a Cluster"
9+
type = string
10+
default = "1.23.4"
11+
}
12+
13+
variable "tls-san" {
14+
description = "Helm Chart Extra Args --tls-san=X"
15+
type = string
16+
default = "sanskar.pair.sharing.io"
17+
}

.sharing.io/vcluster/output.tf

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# output "kubeconfig" {
2+
# value = base64decode(data.kubernetes_resource.kubeconfig.object.data.value)
3+
# }
+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#+title: Readme
2+
3+
* kubevirt workspace
4+
** create template and cluster
5+
#+nobegin_src shell :dir "../../.."
6+
#+begin_src tmate :dir "../../.." :window kubevirt
7+
cd ~/sharingio/coder
8+
export CRI_PATH=/var/run/containerd/containerd.sock
9+
export IMAGE_REPO=k8s.gcr.io
10+
export NODE_VM_IMAGE_TEMPLATE=quay.io/capk/ubuntu-2004-container-disk:v1.22.0
11+
coder template create kubevirt -d examples/templates/kubevirt --yes --parameter-file examples/templates/kubevirt/kubevirt.param.yaml
12+
coder create kv1 --template kubevirt --parameter-file examples/templates/kubevirt/kubevirt.param.yaml --yes
13+
#+end_src
14+
** update template and new cluster
15+
#+nobegin_src shell :dir "../../.."
16+
#+begin_src tmate :dir "../../.." :window kubevirt
17+
export WORKSPACE=kv1
18+
coder template push kubevirt -d examples/templates/kubevirt --yes --parameter-file examples/templates/kubevirt/kubevirt.param.yaml
19+
coder create $WORKSPACE --template kubevirt --parameter-file examples/templates/kubevirt/kubevirt.param.yaml --yes
20+
unset KUBECONFIG
21+
TMPFILE=$(mktemp -t kubeconfig-XXXXX)
22+
kubectl get secrets -n $WORKSPACE ${WORKSPACE}-kubeconfig -o jsonpath={.data.value} | base64 -d > $TMPFILE
23+
export KUBECONFIG=$TMPFILE
24+
kubectl get ns
25+
#+end_src
26+
27+
#+RESULTS:
28+
#+begin_example
29+
#+end_example

0 commit comments

Comments
 (0)