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
3 changes: 0 additions & 3 deletions .github/workflows/e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ jobs:
run: |
export CLUSTER_NAME=vcluster-k3s
export CLUSTER_NAMESPACE=vcluster-k3s
export CHART_VERSION=0.22.1
export VCLUSTER_YAML=$(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 -
Expand All @@ -139,7 +138,6 @@ jobs:
run: |
export CLUSTER_NAME=vcluster-k0s
export CLUSTER_NAMESPACE=vcluster-k0s
export CHART_VERSION=0.22.1
export CHART_NAME=vcluster
export VCLUSTER_YAML=$(cat ./test/e2e/k0s-values.yaml | sed -z 's/\n/\\n/g')
kubectl create namespace ${CLUSTER_NAMESPACE}
Expand All @@ -161,7 +159,6 @@ jobs:
run: |
export CLUSTER_NAME=vcluster-k8s
export CLUSTER_NAMESPACE=vcluster-k8s
export CHART_VERSION=0.22.1
export CHART_NAME=vcluster
export VCLUSTER_YAML=$(cat ./test/e2e/k8s-values.yaml | sed -z 's/\n/\\n/g')
kubectl create namespace ${CLUSTER_NAMESPACE}
Expand Down
11 changes: 4 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ clusterctl init --infrastructure vcluster

Next you will generate a manifest file for a vcluster instance and create it in the management cluster.
Cluster instance is configured using clusterctl parameters and environment variables - CHART_NAME, CHART_REPO, CHART_VERSION, VCLUSTER_HOST and VCLUSTER_PORT.
In the example commands below, the VCLUSTER_YAML variable will be populated with the contents of the `values.yaml` file.
In the example commands below will install the latest vcluster chart (because CHART_VERSION was omitted) and the VCLUSTER_YAML variable will be populated with the contents of the `values.yaml` file.
```shell
export CLUSTER_NAME=vcluster
export CLUSTER_NAMESPACE=vcluster
Expand Down Expand Up @@ -105,13 +105,11 @@ spec:
# vcluster, and the "/charts/k3s" folder in the vcluster GitHub repo.
# Other available options currently are: "vcluster-k8s", "vcluster-k0s" and "vcluster-eks".
name: ${CHART_NAME:=vcluster}
# By default, a particular vcluster version is used in a given CAPVC release. You may find
# it out from the source code, e.g.:
# https://github.com/loft-sh/cluster-api-provider-vcluster/blob/v0.1.3/pkg/constants/constants.go#L7
# By default the latest stable vcluster version is used.
#
# Please refer to the vcluster Releases page for the list of the available versions:
# https://github.com/loft-sh/vcluster/releases
version: ${CHART_VERSION:=0.22.1}
version: ${CHART_VERSION:=""}

# controlPlaneEndpoint represents the endpoint used to communicate with the control plane.
# You may leave this field empty, and then CAPVC will try to fill in this information based
Expand Down Expand Up @@ -160,12 +158,11 @@ go run -mod vendor main.go
```

Next, in a separate terminal you will generate a manifest file for a vcluster instance.
Cluster instance is configured from a template file using environment variables - CLUSTER_NAME, CHART_NAME, CHART_REPO, CHART_VERSION, VCLUSTER_HOST and VCLUSTER_PORT. Only the CHART_VERSION and CLUSTER_NAME variables are mandatory.
Cluster instance is configured from a template file using environment variables - CLUSTER_NAME, CHART_NAME, CHART_REPO, CHART_VERSION, VCLUSTER_HOST and VCLUSTER_PORT. Only the CLUSTER_NAME variable is mandatory.
In the example commands below, the VCLUSTER_YAML variable will be populated with the contents of the `devvalues.yaml` file, don't forget to re-run the `export VCLUSTER_YAML...` command when the `devvalues.yaml` changes.
```shell
export CLUSTER_NAME=test
export CLUSTER_NAMESPACE=test
export CHART_VERSION=0.22.1
export CHART_NAME=vcluster
export VCLUSTER_YAML=$(cat devvalues.yaml | awk '{printf "%s\\n", $0}')
kubectl create namespace ${CLUSTER_NAMESPACE}
Expand Down
60 changes: 33 additions & 27 deletions controllers/vcluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,51 +270,57 @@ func (r *VClusterReconciler) redeployIfNeeded(_ context.Context, vCluster *v1alp

logger := r.Log

chartRepo := constants.DefaultVClusterRepo
if vCluster.Spec.HelmRelease != nil && vCluster.Spec.HelmRelease.Chart.Repo != "" {
chartRepo = vCluster.Spec.HelmRelease.Chart.Repo
}

chartName := constants.DefaultVClusterChartName
if vCluster.Spec.HelmRelease != nil && vCluster.Spec.HelmRelease.Chart.Name != "" {
chartName = vCluster.Spec.HelmRelease.Chart.Name
}

var chartVersion string
if vCluster.Spec.HelmRelease != nil && vCluster.Spec.HelmRelease.Chart.Version != "" {
chartVersion = vCluster.Spec.HelmRelease.Chart.Version
// Remove 'v' prefix if present
if len(chartVersion) > 0 && chartVersion[0] == 'v' {
chartVersion = chartVersion[1:]
}
}

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

if !conditions.IsTrue(vCluster, v1alpha1.HelmChartDeployedCondition) {
logger.Info("deploying vcluster",
"namespace", vCluster.Namespace,
"clusterName", vCluster.Name,
"chartRepo", chartRepo,
"chartName", chartName,
"chartVersion", chartVersion,
"values", values,
)
} else {
logger.V(1).Info("upgrading vcluster",
"namespace", vCluster.Namespace,
"clusterName", vCluster.Name,
"chartRepo", chartRepo,
"chartName", chartName,
"chartVersion", chartVersion,
"values", values,
)
}

var chartRepo string
if vCluster.Spec.HelmRelease != nil {
chartRepo = vCluster.Spec.HelmRelease.Chart.Repo
}
if chartRepo == "" {
chartRepo = constants.DefaultVClusterRepo
}

// chart name
var chartName string
if vCluster.Spec.HelmRelease != nil {
chartName = vCluster.Spec.HelmRelease.Chart.Name
}
if chartName == "" {
chartName = constants.DefaultVClusterChartName
}

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.HelmRelease.Chart.Version

if len(chartVersion) > 0 && chartVersion[0] == 'v' {
chartVersion = chartVersion[1:]
var chartPath string
if chartVersion != "" {
chartPath = fmt.Sprintf("./%s-%s.tgz", chartName, chartVersion)
} else {
chartPath = fmt.Sprintf("./%s-latest.tgz", chartName)
}

chartPath := "./" + chartName + "-" + chartVersion + ".tgz"
_, err := os.Stat(chartPath)
if err != nil {
// we have to upgrade / install the chart
Expand Down
2 changes: 1 addition & 1 deletion templates/cluster-template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ spec:
chart:
name: ${CHART_NAME:=vcluster}
repo: ${CHART_REPO:=https://charts.loft.sh}
version: ${CHART_VERSION:=0.22.1}
version: ${CHART_VERSION:=""}
controlPlaneEndpoint:
host: ${VCLUSTER_HOST:=""}
port: ${VCLUSTER_PORT:=0}