GoogleContainerTools / GoogleContainerTools/skaffold

default-repo config set for kube context is ignored

Open
#7,451 2 comments 2 reactions 0 assignees View on GitHub
bugbash/q4-2022 deploy/kubectl help wanted kind/bug priority/p2
Dominant language
Go
Stars
15.9k
Forks
1.7k
Avg merge
3d 9h
Merged PRs (30d)
10

Description

### Expected behavior

I expect `skaffold config --kube-context set default-repo` to work.

### Actual behavior

Configured `default-repo` for the kube context is ignored and the `local-registry-hosting` value from the cluster is used instead.

### Information

- Skaffold version: 1.38.0
- Operating system: Ubuntu 22.04
- Installed via: skaffold.dev
- Contents of skaffold.yaml:

```yaml
apiVersion: skaffold/v2beta28
kind: Config
build:
artifacts:
- image: nginx
deploy:
kubectl:
manifests:
- deployment.yaml
```

Dockerfile:
```Dockerfile
FROM nginx
```

deployment.yaml:
```yaml
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx
spec:
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx
```

### Steps to reproduce the behavior

1. `k3d cluster create --registry-create=test-registry.localhost -p 5000`
2. `skaffold config --kube-context=k3d-k3s-default set default-repo test-registry.localhost:5000`
3. `skaffold --kube-context=k3d-k3s-default run`

- observe the use of the `localhost:xxxx` repo name in the image tag rather than `test-registry.localhost:5000`
- this is the same as the `host` field from: `kubectl --context=k3d-k3s-default get cm -n kube-public local-registry-hosting -o yaml`

I think the reason for this is that the default repo is only used from the command line options [here](https://github.com/GoogleContainerTools/skaffold/blob/bd82e13a222256a60e686d4300c1d5b5c5cf6962/pkg/skaffold/config/util.go#L258). I think if [this](https://github.com/GoogleContainerTools/skaffold/blob/bd82e13a222256a60e686d4300c1d5b5c5cf6962/pkg/skaffold/config/util.go#L241) code block was duplicated for the default repo option, that might work.

```
% skaffold -vdebug --kube-context=k3d-k3s-default run
INFO[0000] Activated kube-context "k3d-k3s-default" subtask=-1 task=DevLoop
DEBU[0000] skaffold API not starting as it's not requested subtask=-1 task=DevLoop
INFO[0000] Skaffold &{Version:v1.38.0 ConfigVersion:skaffold/v2beta28 GitVersion: GitCommit:89b789ddcfe00d2fe7626fd86ef39a3eb6b455c5 BuildDate:2022-04-06T15:00:45Z GoVersion:go1.17.7 Compiler:gc Platform:linux/amd64 User:} subtask=-1 task=DevLoop
INFO[0000] Loaded Skaffold defaults from "/home/user/.skaffold/config" subtask=-1 task=DevLoop
DEBU[0000] found config for context "k3d-k3s-default" subtask=-1 task=DevLoop
DEBU[0000] parsed 1 configs from configuration file /workspaces/evs-at-risc/skaffold-default-repo-issue/skaffold.yaml subtask=-1 task=DevLoop
DEBU[0000] Defaulting build type to local build subtask=-1 task=DevLoop
INFO[0000] map entry found when executing locate for &{nginx . {0xc0002f9ad0 } [] {[] []} []} of type *v1.Artifact and pointer: 824645608384 subtask=-1 task=DevLoop
INFO[0000] Using kubectl context: k3d-k3s-default subtask=-1 task=DevLoop
DEBU[0000] getting client config for kubeContext: `k3d-k3s-default` subtask=-1 task=DevLoop
INFO[0000] using default-repo=localhost:38163 from cluster configmap subtask=-1 task=DevLoop
DEBU[0000] Running command: [minikube version --output=json] subtask=-1 task=DevLoop
DEBU[0000] setting Docker user agent to skaffold-v1.38.0 subtask=-1 task=DevLoop
DEBU[0000] CLI platforms provided: "" subtask=-1 task=DevLoop
DEBU[0000] getting client config for kubeContext: `k3d-k3s-default` subtask=-1 task=DevLoop
DEBU[0000] platforms detected from active kubernetes cluster nodes: "linux/amd64" subtask=-1 task=DevLoop
DEBU[0000] platforms selected for artifact "nginx": "linux/amd64" subtask=-1 task=DevLoop
DEBU[0000] Using builder: local subtask=-1 task=DevLoop
DEBU[0000] push value not present in NewBuilder, defaulting to true because cluster.PushImages is true subtask=-1 task=DevLoop
INFO[0000] build concurrency first set to 1 parsed from *local.Builder[0] subtask=-1 task=DevLoop
INFO[0000] final build concurrency value is 1 subtask=-1 task=DevLoop
Generating tags...
- nginx -> DEBU[0000] Running command: [git describe --tags --always] subtask=-1 task=Build
DEBU[0000] Command output: [d84d0f4
] subtask=-1 task=Build
DEBU[0000] Running command: [git status . --porcelain] subtask=-1 task=Build
DEBU[0000] Command output: [?? skaffold-default-repo-issue/
] subtask=-1 task=Build
localhost:38163/nginx:d84d0f4-dirty
INFO[0000] Tags generated in 13.715181ms subtask=-1 task=Build
Checking cache...
^C
```

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.