GoogleContainerTools / GoogleContainerTools/skaffold

Using K8s generateName is not possible with Skaffold

Open
#7,622 2 comments 1 reaction 0 assignees View on GitHub
kind/enhancement kind/friction priority/p2
Dominant language
Go
Stars
15.9k
Forks
1.7k
Avg merge
3d 9h
Merged PRs (30d)
10

Description

### Expected behavior

Create resource(s) with autogenerated names as seen [here](https://kubernetes.io/docs/reference/using-api/api-concepts/#generated-values).

### Actual behavior

Using `generateName` for names under `metadata` doesn't work since Skaffold seems to run `kubectl apply` underneath and `generateName` only works with `kubectl create`.

### Information

- Skaffold version: v1.38.0
- Operating system: macOS 12.4
- Installed via: skaffold.dev
- Contents of skaffold.yaml:

```yaml
apiVersion: skaffold/v2beta28
kind: Config
build:
artifacts:
- image:
deploy:
kubectl:
manifests:
- k8s-*
```

### Steps to reproduce the behavior

1. Create a simple `Pod` YAML definition:
```yaml
apiVersion: v1
kind: Pod
metadata:
generateName: simple-example-
labels:
app.kubernetes.io/name: simple-example
spec:
containers:
- name: simple-example
image:
ports:
- containerPort: 80
name: http-web-svc
```
2. Run `skaffold dev`
3. Deployment will fail:

```
WARN[0018] deployer cleanup:kubectl create: running [kubectl --context create --dry-run=client -oyaml -f /Users//k8s-pod.yaml]
- stdout: ""
- stderr: "error: error validating \"/Users//k8s-pod.yaml\": error validating data: [ValidationError(Pod.spec.containers[0]): unknown field \"generateName\" in io.k8s.api.core.v1.Container, ValidationError(Pod.spec.containers[0]): missing required field \"name\" in io.k8s.api.core.v1.Container]; if you choose to ignore these errors, turn validation off with --validate=false\n"
- cause: exit status 1 subtask=-1 task=DevLoop
kubectl create: running [kubectl --context create --dry-run=client -oyaml -f /Users//k8s-pod.yaml]
- stdout: ""
- stderr: "error: error validating \"/Users//k8s-pod.yaml\": error validating data: [ValidationError(Pod.spec.containers[0]): unknown field \"generateName\" in io.k8s.api.core.v1.Container, ValidationError(Pod.spec.containers[0]): missing required field \"name\" in io.k8s.api.core.v1.Container]; if you choose to ignore these errors, turn validation off with --validate=false\n"
- cause: exit status 1
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.