Skip to content

List and find deployment created #3158

Closed Answered by camilamacedo86
Tomelin asked this question in Support
Discussion options

You must be logged in to vote

Hi @Tomelin,

To determine the kind of workload (e.g., Deployment, StatefulSet, or DaemonSet) you might can do by inspecting the ownerReferences field in the Pod's metadata. The ownerReferences field will typically provide information about the parent object that "owns" this resource.

Following some example:

package controllers

import (
	corev1 "k8s.io/api/core/v1"
	"k8s.io/apimachinery/pkg/types"
	ctrl "sigs.k8s.io/controller-runtime"
	"sigs.k8s.io/controller-runtime/pkg/client"
)

func (r *YourReconciler) GetPodController(pod *corev1.Pod) (string, error) {
	for _, ownerReference := range pod.OwnerReferences {
		if ownerReference.Kind == "Deployment" {
			return "Deployment", nil
		} else 

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by camilamacedo86
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Support
Labels
None yet
2 participants