func onDependentCreateFunc()

in kubernetes/controllers/expectation.go [43:86]


func onDependentCreateFunc(r reconcile.Reconciler) func(event.CreateEvent) bool {
	return func(e event.CreateEvent) bool {
		ejr, ok := r.(*ElasticJobReconciler)
		if !ok {
			return true
		}

		// Reconcile any ElasticJob create Event
		if _, ok := e.Object.(*v1alpha1.ElasticJob); ok {
			return true
		}

		// Predicates are provided to filter events before they are given to the EventHandler.
		// Events will be passed to the EventHandler iff all provided Predicates evaluate to true.
		// In this case, it won't filter out pods/services whose owner are not TorchElasticJob,
		// we need to check group label to filter them out.
		value := e.Meta.GetLabels()[v1.GroupNameLabel]
		if value == "" || value != ejr.GetAPIGroupVersion().Group {
			return false
		}

		ejr.Log.Info(fmt.Sprintf("Update on create function: %s create object %s", ejr.ControllerName(), e.Meta.GetName()))
		rtype := e.Meta.GetLabels()[v1.ReplicaTypeLabel]
		if len(rtype) == 0 {
			return false
		}

		if controllerRef := metav1.GetControllerOf(e.Meta); controllerRef != nil {
			var expectKey string
			if _, ok := e.Object.(*corev1.Pod); ok {
				expectKey = common.GenExpectationPodsKey(e.Meta.GetNamespace()+"/"+controllerRef.Name, rtype)
			}

			if _, ok := e.Object.(*corev1.Service); ok {
				expectKey = common.GenExpectationServicesKey(e.Meta.GetNamespace()+"/"+controllerRef.Name, rtype)
			}

			ejr.jobController.Expectations.CreationObserved(expectKey)
			return true
		}

		return true
	}
}