Skip to content

Commit

Permalink
Merge pull request #1583 from FabianKramm/main
Browse files Browse the repository at this point in the history
merge vCluster charts & new values.yaml
  • Loading branch information
FabianKramm committed Mar 15, 2024
2 parents 245784c + f1e599e commit 35794ea
Show file tree
Hide file tree
Showing 354 changed files with 16,393 additions and 14,860 deletions.
22 changes: 14 additions & 8 deletions .github/workflows/e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ concurrency:
cancel-in-progress: true

env:
IMAGE_NAME: ghcr.io/${{ github.repository }}-ci:PR${{ github.event.number }}
REPOSITORY_NAME: ghcr.io/${{ github.repository }}-ci
TAG_NAME: PR${{ github.event.number }}
VCLUSTER_SUFFIX: vcluster
VCLUSTER_NAME: vcluster
VCLUSTER_NAMESPACE: vcluster
Expand Down Expand Up @@ -53,8 +54,8 @@ jobs:
run: |
set -x
TELEMETRY_PRIVATE_KEY="" goreleaser build --single-target --snapshot --id vcluster --clean --output ./vcluster
docker build -t ${{ env.IMAGE_NAME }} -f Dockerfile.release --build-arg TARGETARCH=amd64 --build-arg TARGETOS=linux .
docker save -o vcluster_syncer ${{ env.IMAGE_NAME }}
docker build -t "${{ env.REPOSITORY_NAME }}:${{ env.TAG_NAME }}" -f Dockerfile.release --build-arg TARGETARCH=amd64 --build-arg TARGETOS=linux .
docker save -o vcluster_syncer "${{ env.REPOSITORY_NAME }}:${{ env.TAG_NAME }}"
- name: Upload syncer image to artifact
uses: actions/upload-artifact@v4
with:
Expand Down Expand Up @@ -139,6 +140,7 @@ jobs:
name: e2e-binaries
path: ./test/*/*.test
retention-days: 7

download-latest-cli:
name: Execute test suites
runs-on: ubuntu-latest
Expand All @@ -153,7 +155,6 @@ jobs:
path: ./vcluster-current
retention-days: 7


upgrade-test:
name: test if we can upgrade from older version
needs:
Expand Down Expand Up @@ -192,6 +193,7 @@ jobs:
with:
name: vcluster
path: vcluster-dev

- name: Download current cli
uses: actions/download-artifact@v4
with:
Expand All @@ -201,6 +203,7 @@ jobs:
uses: actions/download-artifact@v4
with:
name: vcluster_syncer

- name: install sed
run: |
sudo apt-get install -y sed
Expand All @@ -217,22 +220,24 @@ jobs:
--distro=${{ matrix.distribution }}
kubectl wait --for=condition=ready pod -l app=${{ env.VCLUSTER_SUFFIX }} -n ${{ env.VCLUSTER_NAMESPACE }} --timeout=300s
- name: upgrade with the dev cli
run: |
chmod +x ./vcluster-dev/vcluster
set -x
sed -i "s|REPLACE_IMAGE_NAME|${{ env.IMAGE_NAME }}|g" test/commonValues.yaml
sed -i "s|REPLACE_REPOSITORY_NAME|${{ env.REPOSITORY_NAME }}|g" test/commonValues.yaml
sed -i "s|REPLACE_TAG_NAME|${{ env.TAG_NAME }}|g" test/commonValues.yaml
./vcluster-dev/vcluster create vcluster --distro=${{ matrix.distribution }} \
--connect=false \
--upgrade \
--local-chart-dir ./chart \
-f ./test/commonValues.yaml
sleep 20
kubectl wait --for=condition=ready pod -l app=${{ env.VCLUSTER_SUFFIX }} -n ${{ env.VCLUSTER_NAMESPACE }} --timeout=300s
e2e-tests:
name: Execute test suites
needs:
Expand Down Expand Up @@ -340,7 +345,8 @@ jobs:
sudo apt-get install -y sed
sed -i "s|REPLACE_IMAGE_NAME|${{ env.IMAGE_NAME }}|g" ${{ matrix.test-suite-path }}/../commonValues.yaml
sed -i "s|REPLACE_REPOSITORY_NAME|${{ env.REPOSITORY_NAME }}|g" ${{ matrix.test-suite-path }}/../commonValues.yaml
sed -i "s|REPLACE_TAG_NAME|${{ env.TAG_NAME }}|g" ${{ matrix.test-suite-path }}/../commonValues.yaml
kind load image-archive vcluster_syncer
Expand All @@ -351,7 +357,7 @@ jobs:
--debug \
--connect=false \
--distro=${{ matrix.distribution }} \
--local-chart-dir ./charts/${{ matrix.distribution }} \
--local-chart-dir ./chart \
-f ./test/commonValues.yaml \
$haValues \
-f ${{ matrix.test-suite-path }}/values.yaml \
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
with:
go-version-file: ./go.mod
cache: false
- name: Generate Embedded Helm Charts
- name: Generate Embedded Helm Chart
run: |
go generate ./...
- name: Run golangci-lint
Expand Down
5 changes: 1 addition & 4 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,7 @@ jobs:
RELEASE_VERSION=$(echo $GITHUB_REF | sed -nE 's!refs/tags/v!!p')
helm plugin install https://github.com/chartmuseum/helm-push.git
helm repo add chartmuseum $CHART_MUSEUM_URL --username $CHART_MUSEUM_USER --password $CHART_MUSEUM_PASSWORD
helm cm-push --force --version="$RELEASE_VERSION" --app-version="$RELEASE_VERSION" charts/k3s/ chartmuseum
helm cm-push --force --version="$RELEASE_VERSION" --app-version="$RELEASE_VERSION" charts/k0s/ chartmuseum
helm cm-push --force --version="$RELEASE_VERSION" --app-version="$RELEASE_VERSION" charts/k8s/ chartmuseum
helm cm-push --force --version="$RELEASE_VERSION" --app-version="$RELEASE_VERSION" charts/eks/ chartmuseum
helm cm-push --force --version="$RELEASE_VERSION" --app-version="$RELEASE_VERSION" chart chartmuseum
env:
CHART_MUSEUM_URL: "https://charts.loft.sh/"
CHART_MUSEUM_USER: ${{ secrets.CHART_MUSEUM_USER }}
Expand Down
5 changes: 1 addition & 4 deletions .github/workflows/unit-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,7 @@ jobs:
helm plugin install https://github.com/helm-unittest/helm-unittest
- name: Run Helm Unit Tests
run: |
helm unittest charts/eks -d
helm unittest charts/k3s -d
helm unittest charts/k0s -d
helm unittest charts/k8s -d
helm unittest chart
go-unit-test:
name: Execute all go tests
Expand Down
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ linters:
disable-all: true
enable:
- asasalint
- tagalign
- asciicheck
- bidichk
- decorder
Expand All @@ -31,7 +32,6 @@ linters:
- revive
- staticcheck
- stylecheck
- tagalign
- typecheck
- unconvert
- unused
Expand Down
59 changes: 59 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,65 @@ Run:
./vcluster create v1 # create vcluster
```

### Deploy vCluster from source

#### 1. Check if you have the following software installed:

* A running Kubernetes cluster v1.26 or newer and Kubectl installed, verify Kubernetes version via `kubectl version`
* Docker needs to be installed (e.g. docker-desktop, orbstack, rancher desktop etc.)
* Helm installed and verify via `helm version`
* Golang version 1.22 and verify via `go version`

#### 2. Git clone the repository `git clone https://github.com/loft-sh/vcluster.git`

#### 3. Build vCluster CLI first:
```
sudo go build -mod vendor -o /usr/local/bin/vcluster cmd/vclusterctl/main.go
```

**If you already have vCluster CLI installed, please make sure to uninstall it first.**

#### 4. Verify vCluster CLI was compiled correctly via `vcluster version`:

```
$ vcluster version
vcluster version 0.0.1
```

#### 5. Build vCluster Container Image:

```
docker build . -t my-vcluster:0.0.1
```

#### 5a. Optional: if using kind, you need to import the image into kind

```
kind load docker-image my-vcluster:0.0.1
```

#### 6. Create vCluster with self-compiled vCluster CLI

We can create a new `vcluster.yaml`:
```yaml
controlPlane:
statefulSet:
imagePullPolicy: Never
image:
repository: my-vcluster
tag: 0.0.1
```
Then deploy the vCluster with the provided `vcluster.yaml`:
```
vcluster create my-vcluster -n my-vcluster -f ./vcluster.yaml --local-chart-dir chart
```
Afterwards open a second terminal and use the vCluster:
```
kubectl get ns
```
## Developing the hostpath-mapper component instead of syncer
In case you need to develop the hostpath-mapper daemonset instead of the syncer, you can use the `dev-hostpath-mapper` profile in `devspace.yaml`. You can do this by running the following command:
Expand Down
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ COPY vendor/ vendor/
COPY cmd/vcluster cmd/vcluster
COPY cmd/vclusterctl cmd/vclusterctl
COPY pkg/ pkg/
COPY config/ config/

ENV GO111MODULE on
ENV DEBUG true
Expand Down
3 changes: 2 additions & 1 deletion Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ e2e distribution="k3s" path="./test/e2e" multinamespace="false": create-kind &&

cp test/commonValues.yaml dist/commonValues.yaml

sed -i.bak "s|REPLACE_IMAGE_NAME|vcluster:e2e-latest|g" dist/commonValues.yaml
sed -i.bak "s|REPLACE_REPOSITORY_NAME|vcluster|g" dist/commonValues.yaml
sed -i.bak "s|REPLACE_TAG_NAME|e2e-latest|g" dist/commonValues.yaml
rm dist/commonValues.yaml.bak

sed -i.bak "s|kind-control-plane|vcluster-control-plane|g" dist/commonValues.yaml
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
22 changes: 22 additions & 0 deletions chart/templates/_backingstore.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{{/*
is external etcd enabled?
*/}}
{{- define "vcluster.externalEtcd.enabled" -}}
{{- if and (eq (include "vcluster.distro" .) "k8s") (not .Values.controlPlane.backingStore.embeddedEtcd.enabled) -}}
{{- true -}}
{{- else if and (eq (include "vcluster.distro" .) "eks") (not .Values.controlPlane.backingStore.embeddedEtcd.enabled) -}}
{{- true -}}
{{- else if .Values.controlPlane.backingStore.externalEtcd.enabled -}}
{{- true -}}
{{- end -}}
{{- end -}}

{{/*
migrate from external etcd?
*/}}
{{- define "vcluster.externalEtcd.migrate" -}}
{{- if and .Values.controlPlane.backingStore.embeddedEtcd.enabled .Values.controlPlane.backingStore.embeddedEtcd.migrateFromExternalEtcd -}}
{{- true -}}
{{- end -}}
{{- end -}}

22 changes: 10 additions & 12 deletions charts/eks/templates/_coredns.tpl → chart/templates/_coredns.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,38 @@
*/}}
{{- define "vcluster.corefile" -}}
Corefile: |-
{{- if .Values.coredns.config }}
{{ .Values.coredns.config | indent 8 }}
{{- if .Values.controlPlane.coredns.overwriteConfig }}
{{ .Values.controlPlane.coredns.overwriteConfig | indent 8 }}
{{- else }}
.:1053 {
errors
health
ready
rewrite name regex .*\.nodes\.vcluster\.com kubernetes.default.svc.cluster.local
kubernetes cluster.local in-addr.arpa ip6.arpa {
{{- if .Values.pro }}
{{- if .Values.coredns.integrated }}
kubeconfig /pki/admin.conf
{{- end }}
{{- if .Values.controlPlane.coredns.embedded }}
kubeconfig /data/vcluster/admin.conf
{{- end }}
pods insecure
{{- if .Values.fallbackHostDns }}
{{- if or .Values.networking.advanced.fallbackHostCluster (and .Values.controlPlane.coredns.embedded .Values.networking.resolveDNS) }}
fallthrough cluster.local in-addr.arpa ip6.arpa
{{- else }}
fallthrough in-addr.arpa ip6.arpa
{{- end }}
}
{{- if and .Values.coredns.integrated .Values.coredns.plugin.enabled }}
vcluster {{ toYaml .Values.coredns.plugin.config | b64enc }}
{{- if and .Values.controlPlane.coredns.embedded .Values.networking.resolveDNS }}
vcluster
{{- end }}
hosts /etc/NodeHosts {
ttl 60
reload 15s
fallthrough
}
prometheus :9153
{{- if .Values.fallbackHostDns }}
{{- if .Values.networking.advanced.fallbackHostCluster }}
forward . {{`{{.HOST_CLUSTER_DNS}}`}}
{{- else if and .Values.isolation.enabled .Values.isolation.networkPolicy.enabled }}
forward . /etc/resolv.conf {{ .Values.coredns.fallback }} {
{{- else if .Values.policies.networkPolicy.enabled }}
forward . /etc/resolv.conf {{ .Values.policies.networkPolicy.fallbackDns }} {
policy sequential
}
{{- else }}
Expand Down
39 changes: 39 additions & 0 deletions chart/templates/_distro.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{{- define "vcluster.distro.env" -}}
{{- if and (eq (include "vcluster.distro" .) "k3s") .Values.controlPlane.distro.k3s.env -}}
{{ .Values.controlPlane.distro.k3s.env }}
{{- else if and (eq (include "vcluster.distro" .) "k8s") .Values.controlPlane.distro.k8s.env -}}
{{ .Values.controlPlane.distro.k8s.env }}
{{- else if and (eq (include "vcluster.distro" .) "k0s") .Values.controlPlane.distro.k0s.env -}}
{{ .Values.controlPlane.distro.k0s.env }}
{{- else if and (eq (include "vcluster.distro" .) "eks") .Values.controlPlane.distro.eks.env -}}
{{ .Values.controlPlane.distro.eks.env }}
{{- end -}}
{{- end -}}

{{/*
vCluster Distro
*/}}
{{- define "vcluster.distro" -}}
{{- $distros := 0 -}}
{{- if .Values.controlPlane.distro.k3s.enabled -}}
k3s
{{- $distros = add1 $distros -}}
{{- end -}}
{{- if .Values.controlPlane.distro.k0s.enabled -}}
k0s
{{- $distros = add1 $distros -}}
{{- end -}}
{{- if .Values.controlPlane.distro.k8s.enabled -}}
k8s
{{- $distros = add1 $distros -}}
{{- end -}}
{{- if .Values.controlPlane.distro.eks.enabled -}}
eks
{{- $distros = add1 $distros -}}
{{- end -}}
{{- if eq $distros 0 -}}
k3s
{{- else if gt $distros 1 -}}
{{- fail "you can only enable one distro at the same time" -}}
{{- end -}}
{{- end -}}
7 changes: 7 additions & 0 deletions chart/templates/_helper.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{{- define "vcluster.controlPlane.image" -}}
{{- if .Values.controlPlane.statefulSet.image.tag -}}
{{ .Values.controlPlane.advanced.defaultImageRegistry }}{{ .Values.controlPlane.statefulSet.image.repository }}:{{ .Values.controlPlane.statefulSet.image.tag }}
{{- else -}}
{{ .Values.controlPlane.advanced.defaultImageRegistry }}{{ .Values.controlPlane.statefulSet.image.repository }}:{{ .Chart.Version }}-pro
{{- end -}}
{{- end -}}
Loading

0 comments on commit 35794ea

Please sign in to comment.