Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kubectl wait --for=create doesn't work with selectors #1675

Open
aaronmondal opened this issue Nov 3, 2024 · 4 comments · May be fixed by kubernetes/kubernetes#128662
Open

kubectl wait --for=create doesn't work with selectors #1675

aaronmondal opened this issue Nov 3, 2024 · 4 comments · May be fixed by kubernetes/kubernetes#128662
Assignees
Labels
kind/bug Categorizes issue or PR as related to a bug. priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. triage/accepted Indicates an issue or PR is ready to be actively worked on.

Comments

@aaronmondal
Copy link

What happened?

This works:

kubectl wait --for=create someresourcetype/resource

But for generated resources where we need to filter, this immediately exits with error: no matching resources found:

kubectl wait --for=create someresourcetype -l somelabel

What did you expect to happen?

I'd expect kubectl wait --for=create to still wait when used with -l. Otherwise we're back to hacky sleeps and bash loops in cases where resource names are unknown (i.e. generated).

How can we reproduce it (as minimally and precisely as possible)?

#!/bin/bash
set -xeuo pipefail

# This works as expected.
(
sleep 1 && cat <<EOF | kubectl create -f - >/dev/null 2>&1
apiVersion: v1
kind: ConfigMap
metadata:
  name: unlabeled-cm
data:
  key: value
EOF
) & pid=$!

kubectl wait --for=create configmap/unlabeled-cm --timeout=10s || true

wait $pid

# This fails, since the filter failure seems to cause an early exit.
(
sleep 1 && cat <<EOF | kubectl create -f - >/dev/null 2>&1
apiVersion: v1
kind: ConfigMap
metadata:
  name: labeled-cm
  labels:
    hello: world
data:
  key: value
EOF
) & pid=$!

kubectl wait --for=create configmap -l hello=world --timeout=10s || true

wait $pid

# This works again, since the configmap now exists.
kubectl wait --for=create configmap -l hello=world --timeout=10s || true

kubectl delete configmap unlabeled-cm labeled-cm

Anything else we need to know?

I didn't test anything other than -l, but other filtering mechanisms might be broken with --for=create as well.

This issue is especially noticeable when working with generated resources. For instance, you might have some trigger after a while to invoke e.g. a Tekton PipelineRun. These PipelineRuns have predictable labels but unpredictable names, making name-based waiting impossible.

Kubernetes version

$ kubectl version
Client Version: v1.31.0
Kustomize Version: v5.4.2
Server Version: v1.31.0

Cloud provider

Local kind cluster, v0.24.0

OS version

# On Linux:
$ cat /etc/os-release
NAME=Gentoo
ID=gentoo
PRETTY_NAME="Gentoo Linux"
ANSI_COLOR="1;32"
HOME_URL="https://www.gentoo.org/"
SUPPORT_URL="https://www.gentoo.org/support/"
BUG_REPORT_URL="https://bugs.gentoo.org/"
VERSION_ID="2.15"
$ uname -a
Linux 6.9.2-gentoo #1 SMP PREEMPT_DYNAMIC Mon May 27 01:25:56 CEST 2024 x86_64 GNU/Linux

# On Windows:
C:\> wmic os get Caption, Version, BuildNumber, OSArchitecture
# paste output here

Install tools

Container runtime (CRI) and version (if applicable)

Related plugins (CNI, CSI, ...) and versions (if applicable)

@aaronmondal aaronmondal added the kind/bug Categorizes issue or PR as related to a bug. label Nov 3, 2024
@k8s-ci-robot k8s-ci-robot added the needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. label Nov 3, 2024
@ardaguclu
Copy link
Member

Yes, you are right and this is a bug. ResourceFinder seems to be returning error nil when no resource has been found with the given label selector.
/triage accepted
/priority important-soon

/cc @soltysh

@k8s-ci-robot k8s-ci-robot added triage/accepted Indicates an issue or PR is ready to be actively worked on. priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. and removed needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Nov 4, 2024
@omerap12
Copy link
Member

omerap12 commented Nov 4, 2024

Yes, you are right and this is a bug. ResourceFinder seems to be returning error nil when no resource has been found with the given label selector. /triage accepted /priority important-soon

/cc @soltysh

I'm glad to take a look at that bug if that's alright with you.

@ardaguclu
Copy link
Member

@omerap12 sounds good. Thank you.

@omerap12
Copy link
Member

omerap12 commented Nov 4, 2024

/assign

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Categorizes issue or PR as related to a bug. priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants