Skip to content

Commit d7f28d1

Browse files
committed
remove env variable for k8s version and replace lachlanevenson/k8s-kubectl image with rancher/kubectl. Use k8sVersion parameter from config as kubectl version when it is not explicitly specified.
1 parent ebd5584 commit d7f28d1

3 files changed

Lines changed: 15 additions & 17 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10-
11-
## [0.3.0](https://github.com/cloudogu/gitops-build-lib/releases/tag/0.3.0) - 2023-XX-YY
12-
1310
### Added
14-
- Specify version for `helm template` through the `k8sVersion` parameter
11+
- Specify version for `helm template` and kubectl image through the `k8sVersion` parameter
12+
13+
### Changed
14+
- Changed kubectl image from `lachlanevenson/k8s-kubectl` to `rancher/kubectl`, because it is available for every k8s version out there
1515

1616
### Fixed
1717
- Don't fail when no `values-shared.yaml` is provided

README.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ gitops-folder in git. For production it will open a PR with the changes.
130130

131131
```groovy
132132
def gitopsConfig = [
133-
k8sVersion: '1.24.8', /* Default: '1.24.8' if env-Variable GITOPS_BUILD_LIB_K8S_VERSION not specified */
133+
k8sVersion: '1.24.8', /* Default: '1.24.8' */
134134
scm: [
135135
provider: 'SCMManager',
136136
credentialsId: 'scmm-user',
@@ -338,6 +338,8 @@ First of all there are some mandatory properties e.g. the information about your
338338
* `cesBuildLibRepo: 'https://github.com/cloudogu/ces-build-lib'`
339339
* `cesBuildLibVersion: '1.62.0'`
340340
* `mainBranch: 'main'`
341+
* Optional: `k8sVersion: '1.24.8'` Is used for target k8s version in helm template in Argo CD deployments with helm. Is also used to determine the kubectl version, when no specific buildImage is specified.
342+
It is recommended to use an Jenkins environment variable to specify the version, so that you don't have to bump every pipeline after a k8s version upgrade in your cluster.
341343
342344
---
343345
@@ -349,12 +351,13 @@ All of these have set default images, but you can change them if you wish to.
349351
def gitopsConfig = [
350352
buildImages: [
351353
// These are used to run helm and kubectl commands in the core logic
352-
helm: 'ghcr.io/cloudogu/helm:3.5.4-1',
353-
kubectl: 'lachlanevenson/k8s-kubectl:v1.19.3',
354+
helm: 'ghcr.io/cloudogu/helm:3.11.1-2',
355+
// if you specify k8sVersion parameter, then by default rancher/kubectl:v${k8sVersion} will be used
356+
kubectl: 'rancher/kubectl:v1.24.8',
354357
// These are used for each specific validator via an imageRef property inside the validators config. See [Validators] for examples.
355358
kubeval: 'ghcr.io/cloudogu/helm:3.5.4-1',
356359
helmKubeval: 'ghcr.io/cloudogu/helm:3.5.4-1',
357-
yamllint: 'cytopia/yamllint:1.25-0.7'
360+
yamllint: 'cytopia/yamllint:1.25-0.9'
358361
]
359362
]
360363
```
@@ -614,9 +617,7 @@ We decided to generate plain k8s Resources from Helm applications before we push
614617

615618
- With ArgoCD you can only set one source for your application. In case of helm it is common to have a source Repository for your chart and a scource Repository for your configuration files (values.yaml). In order to use two different sources for your helm application you will need some sort of workaround (e.g. Helm dependencies in `Chart.yaml`).
616619
- ArgoCD itself uses `helm template` to apply plain k8s Resources to the cluster. By templating the helm application before pushing to the gitops repository, we have the same resources in our repository as in our cluster. Which leads to increased transparency.
617-
618620
The parameter `k8sVersion` from the gitops config is used as a parameter with `--kube-version` in order to template version-specific manifests such as changed api versions.
619-
`k8sVersion` can also be specified through an env-variable called `GITOPS_BUILD_LIB_K8S_VERSION`.
620621

621622
---
622623

vars/deployViaGitops.groovy

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,9 @@ List getMandatoryFields() {
1818
]
1919
}
2020

21-
Map createDefaultConfig() {
21+
Map createDefaultConfig(String k8sVersion) {
2222

23-
def k8sVersion = ""
24-
if (env.GITOPS_BUILD_LIB_K8S_VERSION){
25-
k8sVersion = env.GITOPS_BUILD_LIB_K8S_VERSION
26-
} else{
23+
if (k8sVersion == null || k8sVersion == ""){
2724
k8sVersion = "1.24.8"
2825
}
2926

@@ -40,7 +37,7 @@ Map createDefaultConfig() {
4037
],
4138
kubectl: [
4239
credentialsId: '',
43-
image: 'lachlanevenson/k8s-kubectl:v1.24.8'
40+
image: "rancher/kubectl:v${k8sVersion}"
4441
],
4542
// We use the helm image (that also contains kubeval plugin) to speed up builds by allowing to reuse image
4643
kubeval: [
@@ -99,7 +96,7 @@ Map createDefaultConfig() {
9996

10097
void call(Map gitopsConfig) {
10198
// Merge default config with the one passed as parameter
102-
gitopsConfig = mergeMaps(createDefaultConfig(), gitopsConfig)
99+
gitopsConfig = mergeMaps(createDefaultConfig(gitopsConfig.k8sVersion as String), gitopsConfig)
103100
if (validateConfig(gitopsConfig)) {
104101
cesBuildLib = initCesBuildLib(gitopsConfig.cesBuildLibRepo, gitopsConfig.cesBuildLibVersion, gitopsConfig.cesBuildLibCredentialsId)
105102
deploy(gitopsConfig)

0 commit comments

Comments
 (0)