Skip to content

Commit 9557ca6

Browse files
authored
Merge pull request #2477 from neogopher/feat-custom-kaniko-pod-names
feat: custom kaniko pod names
2 parents 4ea6bc6 + 3a00719 commit 9557ca6

5 files changed

Lines changed: 48 additions & 2 deletions

File tree

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
<details className="config-field" data-expandable="false" open>
3+
<summary>
4+
5+
#### `generateName` <span className="config-field-required" data-required="false">required</span> <span className="config-field-type">string</span> <span className="config-field-default"></span> <span className="config-field-enum"></span> {#images-kaniko-generateName}
6+
7+
GenerateName will be used as the generateName field of the build pod
8+
9+
</summary>
10+
11+
12+
13+
</details>

docs/pages/configuration/_partials/v2beta1/images/kaniko_reference.mdx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import PartialSkipPullSecretMount from "./kaniko/skipPullSecretMount.mdx"
1212
import PartialNodeSelector from "./kaniko/nodeSelector.mdx"
1313
import PartialTolerationsreference from "./kaniko/tolerations_reference.mdx"
1414
import PartialServiceAccount from "./kaniko/serviceAccount.mdx"
15+
import PartialGenerateName from "./kaniko/generateName.mdx"
1516
import PartialAnnotations from "./kaniko/annotations.mdx"
1617
import PartialLabels from "./kaniko/labels.mdx"
1718
import PartialInitEnv from "./kaniko/initEnv.mdx"
@@ -72,6 +73,9 @@ Tolerations is a tolerations list to use for the kaniko pod
7273
<PartialServiceAccount />
7374

7475

76+
<PartialGenerateName />
77+
78+
7579
<PartialAnnotations />
7680

7781

docs/pages/configuration/images/build-engines/kaniko.mdx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,23 @@ images:
151151

152152
## Build Pod Configuration
153153

154+
### `generateName`
155+
The `generateName` option expects a string that will be used as the generateName field of the build pod
156+
157+
#### Default value for `generateName`
158+
```yaml
159+
generateName: devspace-build-kaniko-
160+
```
161+
162+
#### Example: Add generateName to kaniko build pods
163+
```yaml
164+
images:
165+
backend:
166+
image: 123.456.789.0:5000/john/appbackend
167+
kaniko:
168+
generateName: devspace-build-kaniko-backend-
169+
```
170+
154171
### `annotations`
155172
The `annotations` option expects a key/value map of extra annotations that will be added to the build pod
156173

pkg/devspace/build/builder/kaniko/build_pod.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
package kaniko
22

33
import (
4+
"path/filepath"
5+
46
"github.com/loft-sh/devspace/pkg/devspace/build/builder/kaniko/util"
57
devspacecontext "github.com/loft-sh/devspace/pkg/devspace/context"
6-
"path/filepath"
78

89
"github.com/docker/distribution/reference"
910
jsonyaml "github.com/ghodss/yaml"
@@ -38,6 +39,9 @@ const devspaceQuota = "devspace-quota"
3839
// DevspaceLimitRange is the limit range name of the space limit range in the devspace cloud
3940
const devspaceLimitRange = "devspace-limit-range"
4041

42+
// The generateName string for the kaniko pod that we use by default
43+
const podGenerateName = "devspace-build-kaniko-"
44+
4145
type availableResources struct {
4246
CPU resource.Quantity
4347
Memory resource.Quantity
@@ -74,6 +78,11 @@ func (b *Builder) getBuildPod(ctx devspacecontext.Context, buildID string, optio
7478
kanikoInitImage = kanikoOptions.InitImage
7579
}
7680

81+
kanikoPodGenerateName := podGenerateName
82+
if kanikoOptions.GenerateName != "" {
83+
kanikoPodGenerateName = kanikoOptions.GenerateName
84+
}
85+
7786
// additional options to pass to kaniko
7887
kanikoArgs := []string{
7988
"--dockerfile=" + kanikoContextPath + "/" + filepath.Base(dockerfilePath),
@@ -213,7 +222,7 @@ func (b *Builder) getBuildPod(ctx devspacecontext.Context, buildID string, optio
213222
// create the build pod
214223
pod := &k8sv1.Pod{
215224
ObjectMeta: metav1.ObjectMeta{
216-
GenerateName: "devspace-build-kaniko-",
225+
GenerateName: kanikoPodGenerateName,
217226
Annotations: map[string]string{},
218227
Labels: map[string]string{
219228
"devspace-build": "true",

pkg/devspace/config/versions/latest/schema.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,9 @@ type KanikoConfig struct {
432432
// ServiceAccount the service account to use for the kaniko pod
433433
ServiceAccount string `yaml:"serviceAccount,omitempty" json:"serviceAccount,omitempty"`
434434

435+
// GenerateName is the optional prefix that will be set to the generateName field of the build pod
436+
GenerateName string `yaml:"generateName,omitempty" json:"generateName,omitempty"`
437+
435438
// Annotations are extra annotations that will be added to the build pod
436439
Annotations map[string]string `yaml:"annotations,omitempty" json:"annotations,omitempty"`
437440

0 commit comments

Comments
 (0)