Skip to content

Instantly share code, notes, and snippets.

@timebertt
Created January 5, 2022 15:07
Show Gist options
  • Save timebertt/e123f71f3ecc672a736577266a292968 to your computer and use it in GitHub Desktop.
Save timebertt/e123f71f3ecc672a736577266a292968 to your computer and use it in GitHub Desktop.
Example metadata-only client usage
var (
ctx context.Context
c client.Client // "sigs.k8s.io/controller-runtime/pkg/client"
podList = &metav1.PartialObjectMetadataList{} // "k8s.io/apimachinery/pkg/apis/meta/v1"
)
podList.SetGroupVersionKind(corev1.SchemeGroupVersion.WithKind("PodList")) // "k8s.io/api/core/v1"
if err := c.List(ctx, podList, client.InNamespace("my-namespace"), client.Limit(1)); err != nil {
return err
}
if len(podList.Items) > 0 {
// namespace contains at least one pod
} else {
// namespace doesn't contain any pods
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment