Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 65 additions & 19 deletions .github/workflows/e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,6 @@ concurrency:
group: e2e-${{ github.head_ref || github.ref_name }}
cancel-in-progress: true

env:
KUBERNETES_VERSION: 1.29.2
VCLUSTER_VERSION: 0.19
VCLUSTER_NAME: vcluster
VCLUSTER_NAMESPACE: vcluster

jobs:
unit-test:
runs-on: ubuntu-latest
Expand All @@ -39,7 +33,8 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version-file: go.mod
go-version-file: "go.mod"
cache: false

- name: Run Unit Tests
run: go test ./test/controllerstest
Expand All @@ -56,7 +51,8 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version-file: go.mod
go-version-file: "go.mod"
cache: false

- name: Install Prerequisites
run: |
Expand All @@ -75,7 +71,7 @@ jobs:
GOBIN="$(pwd)/bin" go install -tags tools github.com/drone/envsubst/v2/cmd/[email protected]

# Install kubectl
curl -LO "https://dl.k8s.io/release/v${{ env.KUBERNETES_VERSION }}/bin/linux/amd64/kubectl"
curl -LO "https://dl.k8s.io/release/v1.29.2/bin/linux/amd64/kubectl"
chmod +x ./kubectl
sudo mv ./kubectl /usr/local/bin/kubectl

Expand Down Expand Up @@ -113,19 +109,69 @@ jobs:
echo "=== Test get crd ==="
kubectl get crd

- name: Create Vcluster Custom Resource
- name: Create Vcluster Custom Resource K3S
run: |
export CLUSTER_NAME=vcluster-k3s
export CLUSTER_NAMESPACE=vcluster-k3s
export CHART_VERSION=0.19.0
export HELM_VALUES=$(cat ./test/e2e/k3s-values.yaml | sed -z 's/\n/\\n/g')
kubectl create namespace ${CLUSTER_NAMESPACE}
cat templates/cluster-template.yaml | ./bin/envsubst | kubectl apply -n ${CLUSTER_NAMESPACE} -f -

- name: Validate Resource Ready K3S
run: |
kubectl wait --for=condition=ready vcluster -n vcluster-k3s vcluster-k3s --timeout=100s

- name: Run E2E Tests K3S
run: NAMESPACE=vcluster-k3s LOCAL_PORT=14550 go test -mod=vendor ./test/e2e -v

- name: Create Vcluster Custom Resource K0S
run: |
export CLUSTER_NAME=vcluster-k0s
export CLUSTER_NAMESPACE=vcluster-k0s
export CHART_VERSION=0.19.0
export CHART_NAME=vcluster-k0s
export HELM_VALUES=$(cat ./test/e2e/k0s-values.yaml | sed -z 's/\n/\\n/g')
kubectl create namespace ${CLUSTER_NAMESPACE}
cat templates/cluster-template.yaml | ./bin/envsubst | kubectl apply -n ${CLUSTER_NAMESPACE} -f -

- name: Validate Resource Ready K0S
run: |
kubectl wait --for=condition=ready vcluster -n vcluster-k0s vcluster-k0s --timeout=100s

- name: Run E2E Tests K0S
run: NAMESPACE=vcluster-k0s LOCAL_PORT=14551 go test -mod=vendor ./test/e2e -v

- name: Create Vcluster Custom Resource K8S
run: |
export CLUSTER_NAME=vcluster-k8s
export CLUSTER_NAMESPACE=vcluster-k8s
export CHART_VERSION=0.19.0
export CHART_NAME=vcluster-k8s
export HELM_VALUES=$(cat ./test/e2e/k8s-values.yaml | sed -z 's/\n/\\n/g')
kubectl create namespace ${CLUSTER_NAMESPACE}
cat templates/cluster-template.yaml | ./bin/envsubst | kubectl apply -n ${CLUSTER_NAMESPACE} -f -

- name: Validate Resource Ready K8S
run: |
kubectl wait --for=condition=ready vcluster -n vcluster-k8s vcluster-k8s --timeout=100s

- name: Run E2E Tests K8S
run: NAMESPACE=vcluster-k8s LOCAL_PORT=14552 go test -mod=vendor ./test/e2e -v

- name: Create Vcluster Custom Resource EKS
run: |
export CLUSTER_NAME=${{ env.VCLUSTER_NAME }}
export CLUSTER_NAMESPACE=${{ env.VCLUSTER_NAMESPACE }}
export KUBERNETES_VERSION=${{ env.KUBERNETES_VERSION }}
export VCLUSTER_VERSION=${{ env.VCLUSTER_VERSION }}
export HELM_VALUES=$(cat ./test/e2e/values.yaml | sed -z 's/\n/\\n/g')
export CLUSTER_NAME=vcluster-eks
export CLUSTER_NAMESPACE=vcluster-eks
export CHART_VERSION=0.19.0
export CHART_NAME=vcluster-eks
export HELM_VALUES=$(cat ./test/e2e/eks-values.yaml | sed -z 's/\n/\\n/g')
kubectl create namespace ${CLUSTER_NAMESPACE}
cat templates/cluster-template.yaml | ./bin/envsubst | kubectl apply -n ${CLUSTER_NAMESPACE} -f -

- name: Validate Resource Ready
- name: Validate Resource Ready EKS
run: |
kubectl wait --for=condition=ready vcluster -n ${{ env.VCLUSTER_NAMESPACE }} ${{ env.VCLUSTER_NAME }} --timeout=100s
kubectl wait --for=condition=ready vcluster -n vcluster-eks vcluster-eks --timeout=100s

- name: Run E2E Tests
run: go test -mod=vendor ./test/e2e -v
- name: Run E2E Tests EKS
run: NAMESPACE=vcluster-eks LOCAL_PORT=14553 go test -mod=vendor ./test/e2e -v
11 changes: 0 additions & 11 deletions api/v1alpha1/vcluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,6 @@ type VClusterSpec struct {
// when filled, specified chart will be deployed.
// +optional
HelmRelease *VirtualClusterHelmRelease `json:"helmRelease,omitempty"`

// Kubernetes version that should be used in this vcluster instance, e.g. "1.23".
// Versions out of the supported range will be ignored, and earliest/latest supported
// version will be used instead.
// +optional
KubernetesVersion *string `json:"kubernetesVersion,omitempty"`

// +optional
KubernetesImage *string `json:"kubernetesImage,omitempty"`
// +optional
VirtualClusterVersion *string `json:"virtualClusterVersion,omitempty"`
}

// VClusterStatus defines the observed state of VCluster
Expand Down
15 changes: 0 additions & 15 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 0 additions & 10 deletions config/crd/bases/infrastructure.cluster.x-k8s.io_vclusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,6 @@ spec:
description: the values for the given chart
type: string
type: object
kubernetesImage:
type: string
kubernetesVersion:
description: |-
Kubernetes version that should be used in this vcluster instance, e.g. "1.23".
Versions out of the supported range will be ignored, and earliest/latest supported
version will be used instead.
type: string
virtualClusterVersion:
type: string
type: object
status:
description: VClusterStatus defines the observed state of VCluster
Expand Down
43 changes: 5 additions & 38 deletions controllers/vcluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
"time"

"github.com/go-logr/logr"
vclusterhelm "github.com/loft-sh/utils/pkg/helm"
"github.com/loft-sh/vcluster/pkg/util"
"github.com/loft-sh/vcluster/pkg/util/kubeconfig"
corev1 "k8s.io/api/core/v1"
Expand All @@ -51,7 +50,6 @@ import (
"github.com/loft-sh/cluster-api-provider-vcluster/pkg/util/conditions"
"github.com/loft-sh/cluster-api-provider-vcluster/pkg/util/kubeconfighelper"
"github.com/loft-sh/cluster-api-provider-vcluster/pkg/util/patch"
"github.com/loft-sh/cluster-api-provider-vcluster/pkg/util/vclustervalues"
)

type ClientConfigGetter interface {
Expand Down Expand Up @@ -280,60 +278,29 @@ func (r *VClusterReconciler) redeployIfNeeded(_ context.Context, vCluster *v1alp
chartName = constants.DefaultVClusterChartName
}

if vCluster.Spec.VirtualClusterVersion == nil || *vCluster.Spec.VirtualClusterVersion == "" {
return fmt.Errorf("empty value of the .spec.virtualClusterVersion field")
if vCluster.Spec.HelmRelease == nil || vCluster.Spec.HelmRelease.Chart.Version == "" {
return fmt.Errorf("empty value of the .spec.HelmRelease.Version field")
}
// chart version
chartVersion := *vCluster.Spec.VirtualClusterVersion
chartVersion := vCluster.Spec.HelmRelease.Chart.Version

if len(chartVersion) > 0 && chartVersion[0] == 'v' {
chartVersion = chartVersion[1:]
}

if vCluster.Spec.KubernetesVersion == nil || *vCluster.Spec.KubernetesVersion == "" {
return fmt.Errorf("empty value of the .spec.kubernetesVersion field")
}
kubernetesVersionStr := strings.Split(*vCluster.Spec.KubernetesVersion, ".")
if len(kubernetesVersionStr) < 2 || len(kubernetesVersionStr) > 3 {
return fmt.Errorf("invalid value of the .spec.kubernetesVersion field: %s", *vCluster.Spec.KubernetesVersion)
}
if len(kubernetesVersionStr) == 3 {
r.Log.Info("kubernetes patch version defined in .spec.kubernetesVersion field will be ignored, latest supported patch version will be used",
"namespace", vCluster.Namespace,
"clusterName", vCluster.Name,
)
}
kubernetesVersion := vclusterhelm.Version{
Major: kubernetesVersionStr[0],
Minor: kubernetesVersionStr[1],
}

// determine values
var values string
if vCluster.Spec.HelmRelease != nil {
if vCluster.Spec.HelmRelease != nil || vCluster.Spec.HelmRelease.Values == "" {
values = vCluster.Spec.HelmRelease.Values
}

//TODO: if .spec.controlPlaneEndpoint.Host is set it would be nice to pass it as --tls-san flag of syncer
values, err := vclustervalues.NewValuesMerger(
kubernetesVersion,
).Merge(&v1alpha1.VirtualClusterHelmRelease{
Chart: v1alpha1.VirtualClusterHelmChart{
Name: chartName,
},
Values: values,
}, r.Log)
if err != nil {
return fmt.Errorf("merge values: %w", err)
}

r.Log.Info("Deploy virtual cluster",
"namespace", vCluster.Namespace,
"clusterName", vCluster.Name,
"values", values,
)
chartPath := "./" + chartName + "-" + chartVersion + ".tgz"
_, err = os.Stat(chartPath)
_, err := os.Stat(chartPath)
if err != nil {
// we have to upgrade / install the chart
err = r.HelmClient.Upgrade(vCluster.Name, vCluster.Namespace, helm.UpgradeOptions{
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ go 1.22.0
require (
github.com/golangci/golangci-lint v1.56.2
github.com/loft-sh/log v0.0.0-20240219160058-26d83ffb46ac
github.com/loft-sh/utils v0.0.29
github.com/onsi/ginkgo/v2 v2.15.0
github.com/onsi/gomega v1.31.1
github.com/stretchr/testify v1.8.4
Expand Down Expand Up @@ -168,6 +167,7 @@ require (
github.com/loft-sh/apiserver v0.0.0-20240125143607-a106e2f2e0f1 // indirect
github.com/loft-sh/jspolicy v0.2.2 // indirect
github.com/loft-sh/loftctl/v3 v3.0.0-20240207094551-f600825cc6f5 // indirect
github.com/loft-sh/utils v0.0.29 // indirect
github.com/loft-sh/vcluster-values v0.0.0-20240207093538-4bbb24e9f699 // indirect
github.com/lufeee/execinquery v1.2.1 // indirect
github.com/macabu/inamedparam v0.1.3 // indirect
Expand Down Expand Up @@ -327,7 +327,7 @@ require (
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/protobuf v1.33.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v2 v2.4.0
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/api v0.29.3
k8s.io/apiextensions-apiserver v0.29.1 // indirect
Expand Down
88 changes: 0 additions & 88 deletions pkg/util/vclustervalues/values.go

This file was deleted.

4 changes: 1 addition & 3 deletions templates/cluster-template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,12 @@ kind: VCluster
metadata:
name: ${CLUSTER_NAME}
spec:
kubernetesVersion: "${KUBERNETES_VERSION:=}"
kubernetesImage: "${KUBERNETES_IMAGE:=null}"
virtualClusterVersion: "${VCLUSTER_VERSION:=}"
helmRelease:
values: "${HELM_VALUES:=}"
chart:
name: ${CHART_NAME:=null}
repo: ${CHART_REPO:=null}
version: ${CHART_VERSION:=null}
controlPlaneEndpoint:
host: ${VCLUSTER_HOST:=""}
port: ${VCLUSTER_PORT:=0}
Loading