-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9937 from chrischdi/pr-prowjob-generator
🌱 hack: implement generator for prowjobs
- Loading branch information
Showing
13 changed files
with
552 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
# prowjob-gen | ||
|
||
Prowjob-gen is a tool which helps generating prowjob configuration. | ||
|
||
## Usage | ||
|
||
Flags: | ||
|
||
```txt | ||
-config string | ||
Path to the config file | ||
-output-dir string | ||
Path to the directory to create the files in | ||
-templates-dir string | ||
Path to the directory containing the template files referenced inside the config file | ||
``` | ||
|
||
When running prowjob-gen, all flags need to be provided. | ||
The tool then will iterate over all templates defined in the config file and execute them per configured branch. | ||
|
||
The configuration file is supposed to be in yaml format and to be stored inside the [test-infra](https://github.com/kubernetes/test-infra) | ||
repository, we have to make sure it is not getting parsed as configuration for prow. | ||
Because of that the top-level key for the configuration file is `prow-ignored:`. | ||
|
||
A sample configuration looks as follows: | ||
|
||
<!-- test/test-configuration.yaml --> | ||
```yaml | ||
prow_ignored: | ||
branches: | ||
main: # values below the branch here are available in the template | ||
testImage: "gcr.io/k8s-staging-test-infra/kubekins-e2e:v20231208-8b9fd88e88-1.29" | ||
interval: "2h" | ||
upgradesInterval: "2h" | ||
kubernetesVersionManagement: "v1.26.6@sha256:6e2d8b28a5b601defe327b98bd1c2d1930b49e5d8c512e1895099e4504007adb" | ||
kubebuilderEnvtestKubernetesVersion: "1.26.1" | ||
upgrades: | ||
- from: "1.29" | ||
to: "1.30" | ||
|
||
templates: | ||
- name: "test.yaml.tpl" | ||
template: "test-{{ .branch }}.yaml.tmp" | ||
|
||
versions: | ||
"1.29": | ||
etcd: "3.5.10-0" | ||
coreDNS: "v1.11.1" | ||
k8sRelease: "stable-1.29" | ||
"1.30": | ||
etcd: "3.5.10-0" | ||
coreDNS: "v1.11.1" | ||
k8sRelease: "ci/latest-1.30" | ||
``` | ||
<!-- test/test-configuration.yaml --> | ||
|
||
With this configuration, the template `cluster-api-periodics.yaml.tpl` would get executed for each branch. | ||
In this example we only configure the `main` branch which results in the output file `cluster-api-periodics-main.yaml`. | ||
|
||
When executing a template, the following functions are available as addition to the standard functions in go templates: | ||
|
||
- `TrimPrefix`: [strings.TrimPrefix](https://pkg.go.dev/strings#TrimPrefix) | ||
- `TrimSuffix`: [strings.TrimSuffix](https://pkg.go.dev/strings#TrimSuffix) | ||
- `ReplaceAll`: [strings.ReplaceAll](https://pkg.go.dev/strings#ReplaceAll) | ||
- `last`: `func(any) any`: returns the last element of an array or slice. | ||
|
||
When executing a template, the following variables are available: | ||
|
||
- `branch`: The branch name the file gets templated for (The key in `.prow_ignored.branches`). | ||
- `config`: The branch's configuration from `.prow_ignored.branches.<branch>`. | ||
- `versions`: The versions mapper from `.prow_ignored.versions`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
Copyright 2024 The Kubernetes Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package main | ||
|
||
// ProwIgnoredConfig is the top-level configuration struct. Because we want to | ||
// store the configuration in test-infra as yaml file, we have to prevent prow | ||
// from trying to parse our configuration as prow configuration. Prow provides | ||
// the well-known `prow_ignored` key which is not parsed further by Prow. | ||
type ProwIgnoredConfig struct { | ||
ProwIgnored Config `json:"prow_ignored"` | ||
} | ||
|
||
// Config is the configuration file struct. | ||
type Config struct { | ||
Branches map[string]BranchConfig `json:"branches"` | ||
Templates []Template `json:"templates"` | ||
Versions VersionsMapper `json:"versions"` | ||
} | ||
|
||
// BranchConfig is the branch-based configuration struct. | ||
type BranchConfig struct { | ||
Interval string `json:"interval"` | ||
UpgradesInterval string `json:"upgradesInterval"` | ||
TestImage string `json:"testImage"` | ||
KubernetesVersionManagement string `json:"kubernetesVersionManagement"` | ||
KubebuilderEnvtestKubernetesVersion string `json:"kubebuilderEnvtestKubernetesVersion"` | ||
Upgrades []*Upgrade `json:"upgrades"` | ||
} | ||
|
||
// Template refers a template file and defines the target file name template. | ||
type Template struct { | ||
Template string `json:"template"` | ||
Name string `json:"name"` | ||
} | ||
|
||
// Upgrade describes a kubernetes upgrade. | ||
type Upgrade struct { | ||
From string `json:"from"` | ||
To string `json:"to"` | ||
} | ||
|
||
// VersionsMapper provides key value pairs for a parent key. | ||
type VersionsMapper map[string]map[string]string |
Oops, something went wrong.