Skip to content

Commit c4d6da2

Browse files
committed
chore: use latest if CHART_VERSION is not set
1 parent fddb777 commit c4d6da2

File tree

4 files changed

+38
-38
lines changed

4 files changed

+38
-38
lines changed

.github/workflows/e2e.yaml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@ jobs:
118118
run: |
119119
export CLUSTER_NAME=vcluster-k3s
120120
export CLUSTER_NAMESPACE=vcluster-k3s
121-
export CHART_VERSION=0.22.1
122121
export VCLUSTER_YAML=$(cat ./test/e2e/k3s-values.yaml | sed -z 's/\n/\\n/g')
123122
kubectl create namespace ${CLUSTER_NAMESPACE}
124123
cat templates/cluster-template.yaml | ./bin/envsubst | kubectl apply -n ${CLUSTER_NAMESPACE} -f -
@@ -139,7 +138,6 @@ jobs:
139138
run: |
140139
export CLUSTER_NAME=vcluster-k0s
141140
export CLUSTER_NAMESPACE=vcluster-k0s
142-
export CHART_VERSION=0.22.1
143141
export CHART_NAME=vcluster
144142
export VCLUSTER_YAML=$(cat ./test/e2e/k0s-values.yaml | sed -z 's/\n/\\n/g')
145143
kubectl create namespace ${CLUSTER_NAMESPACE}
@@ -161,7 +159,6 @@ jobs:
161159
run: |
162160
export CLUSTER_NAME=vcluster-k8s
163161
export CLUSTER_NAMESPACE=vcluster-k8s
164-
export CHART_VERSION=0.22.1
165162
export CHART_NAME=vcluster
166163
export VCLUSTER_YAML=$(cat ./test/e2e/k8s-values.yaml | sed -z 's/\n/\\n/g')
167164
kubectl create namespace ${CLUSTER_NAMESPACE}

README.md

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ clusterctl init --infrastructure vcluster
2121

2222
Next you will generate a manifest file for a vcluster instance and create it in the management cluster.
2323
Cluster instance is configured using clusterctl parameters and environment variables - CHART_NAME, CHART_REPO, CHART_VERSION, VCLUSTER_HOST and VCLUSTER_PORT.
24-
In the example commands below, the VCLUSTER_YAML variable will be populated with the contents of the `values.yaml` file.
24+
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.
2525
```shell
2626
export CLUSTER_NAME=vcluster
2727
export CLUSTER_NAMESPACE=vcluster
@@ -105,13 +105,11 @@ spec:
105105
# vcluster, and the "/charts/k3s" folder in the vcluster GitHub repo.
106106
# Other available options currently are: "vcluster-k8s", "vcluster-k0s" and "vcluster-eks".
107107
name: ${CHART_NAME:=vcluster}
108-
# By default, a particular vcluster version is used in a given CAPVC release. You may find
109-
# it out from the source code, e.g.:
110-
# https://github.com/loft-sh/cluster-api-provider-vcluster/blob/v0.1.3/pkg/constants/constants.go#L7
108+
# By default the latest stable vcluster version is used.
111109
#
112110
# Please refer to the vcluster Releases page for the list of the available versions:
113111
# https://github.com/loft-sh/vcluster/releases
114-
version: ${CHART_VERSION:=0.22.1}
112+
version: ${CHART_VERSION:=""}
115113

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

162160
Next, in a separate terminal you will generate a manifest file for a vcluster instance.
163-
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.
161+
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.
164162
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.
165163
```shell
166164
export CLUSTER_NAME=test
167165
export CLUSTER_NAMESPACE=test
168-
export CHART_VERSION=0.22.1
169166
export CHART_NAME=vcluster
170167
export VCLUSTER_YAML=$(cat devvalues.yaml | awk '{printf "%s\\n", $0}')
171168
kubectl create namespace ${CLUSTER_NAMESPACE}

controllers/vcluster_controller.go

Lines changed: 33 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -270,51 +270,57 @@ func (r *VClusterReconciler) redeployIfNeeded(_ context.Context, vCluster *v1alp
270270

271271
logger := r.Log
272272

273+
chartRepo := constants.DefaultVClusterRepo
274+
if vCluster.Spec.HelmRelease != nil && vCluster.Spec.HelmRelease.Chart.Repo != "" {
275+
chartRepo = vCluster.Spec.HelmRelease.Chart.Repo
276+
}
277+
278+
chartName := constants.DefaultVClusterChartName
279+
if vCluster.Spec.HelmRelease != nil && vCluster.Spec.HelmRelease.Chart.Name != "" {
280+
chartName = vCluster.Spec.HelmRelease.Chart.Name
281+
}
282+
283+
var chartVersion string
284+
if vCluster.Spec.HelmRelease != nil && vCluster.Spec.HelmRelease.Chart.Version != "" {
285+
chartVersion = vCluster.Spec.HelmRelease.Chart.Version
286+
// Remove 'v' prefix if present
287+
if len(chartVersion) > 0 && chartVersion[0] == 'v' {
288+
chartVersion = chartVersion[1:]
289+
}
290+
}
291+
273292
var values string
274-
if vCluster.Spec.HelmRelease != nil || vCluster.Spec.HelmRelease.Values == "" {
293+
if vCluster.Spec.HelmRelease != nil && vCluster.Spec.HelmRelease.Values != "" {
275294
values = vCluster.Spec.HelmRelease.Values
276295
}
296+
277297
if !conditions.IsTrue(vCluster, v1alpha1.HelmChartDeployedCondition) {
278298
logger.Info("deploying vcluster",
279299
"namespace", vCluster.Namespace,
280300
"clusterName", vCluster.Name,
301+
"chartRepo", chartRepo,
302+
"chartName", chartName,
303+
"chartVersion", chartVersion,
281304
"values", values,
282305
)
283306
} else {
284307
logger.V(1).Info("upgrading vcluster",
285308
"namespace", vCluster.Namespace,
286309
"clusterName", vCluster.Name,
310+
"chartRepo", chartRepo,
311+
"chartName", chartName,
312+
"chartVersion", chartVersion,
313+
"values", values,
287314
)
288315
}
289316

290-
var chartRepo string
291-
if vCluster.Spec.HelmRelease != nil {
292-
chartRepo = vCluster.Spec.HelmRelease.Chart.Repo
293-
}
294-
if chartRepo == "" {
295-
chartRepo = constants.DefaultVClusterRepo
296-
}
297-
298-
// chart name
299-
var chartName string
300-
if vCluster.Spec.HelmRelease != nil {
301-
chartName = vCluster.Spec.HelmRelease.Chart.Name
302-
}
303-
if chartName == "" {
304-
chartName = constants.DefaultVClusterChartName
305-
}
306-
307-
if vCluster.Spec.HelmRelease == nil || vCluster.Spec.HelmRelease.Chart.Version == "" {
308-
return fmt.Errorf("empty value of the .spec.HelmRelease.Version field")
309-
}
310-
// chart version
311-
chartVersion := vCluster.Spec.HelmRelease.Chart.Version
312-
313-
if len(chartVersion) > 0 && chartVersion[0] == 'v' {
314-
chartVersion = chartVersion[1:]
317+
var chartPath string
318+
if chartVersion != "" {
319+
chartPath = fmt.Sprintf("./%s-%s.tgz", chartName, chartVersion)
320+
} else {
321+
chartPath = fmt.Sprintf("./%s-latest.tgz", chartName)
315322
}
316323

317-
chartPath := "./" + chartName + "-" + chartVersion + ".tgz"
318324
_, err := os.Stat(chartPath)
319325
if err != nil {
320326
// we have to upgrade / install the chart

templates/cluster-template.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ spec:
2222
chart:
2323
name: ${CHART_NAME:=vcluster}
2424
repo: ${CHART_REPO:=https://charts.loft.sh}
25-
version: ${CHART_VERSION:=0.22.1}
25+
version: ${CHART_VERSION:=""}
2626
controlPlaneEndpoint:
2727
host: ${VCLUSTER_HOST:=""}
2828
port: ${VCLUSTER_PORT:=0}

0 commit comments

Comments
 (0)