Created
January 5, 2022 15:07
-
-
Save timebertt/e123f71f3ecc672a736577266a292968 to your computer and use it in GitHub Desktop.
Example metadata-only client usage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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