GoogleContainerTools / skaffold

Easy and Repeatable Kubernetes Development
https://skaffold.dev/
Apache License 2.0
14.9k stars 1.62k forks source link

default-repo config set for kube context is ignored #7451

Open chris13524 opened 2 years ago

chris13524 commented 2 years ago

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

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

Dockerfile:

FROM nginx

deployment.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

I think the reason for this is that the default repo is only used from the command line options here. I think if this 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 . <nil> {0xc0002f9ad0 <nil> <nil> <nil> <nil> <nil> <nil>} [] {[] []} []} 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
chris13524 commented 1 year ago

If I rename the created context to not have the k3d- prefix in the name, then the configured default-repo works as expected:

kubectl config rename-context k3d-k3s-default k3s-default
tejal29 commented 1 year ago

Thanks for posting the workaround. We would appreciate community contributions to fix this issue.