func (r *ServiceTraitReconciler) cleanupResources(ctx context.Context,
	service *corev1alpha2.ServiceTrait, svcUID *types.UID) error {
	log := r.Log.WithValues("gc service", service.Name)
	var svc corev1.Service
	for _, res := range service.Status.Resources {
		uid := res.UID
		if res.Kind == KindService && res.APIVersion == corev1.SchemeGroupVersion.String() {
			if uid != *svcUID {
				log.Info("Found an orphaned service", "orphaned UID", uid)
				sn := client.ObjectKey{Name: res.Name, Namespace: service.Namespace}
				if err := r.Get(ctx, sn, &svc); err != nil {
					if apierrors.IsNotFound(err) {
						continue
					}
					return err
				}
				if err := r.Delete(ctx, &svc); err != nil {
					return err
				}
				log.Info("Removed an orphaned service", "orphaned UID", uid)
			}
		}
	}
	return nil
}
// delete services that are not the same as the existing
delete services that are not the same as the existing
// delete services that are not the same as the existing
func (r *ServiceTraitReconciler) cleanupResources(ctx context.Context,
	service *corev1alpha2.ServiceTrait, svcUID *types.UID) error {
	log := r.Log.WithValues("gc service", service.Name)
	var svc corev1.Service
	for _, res := range service.Status.Resources {
		uid := res.UID
		if res.Kind == KindService && res.APIVersion == corev1.SchemeGroupVersion.String() {
			if uid != *svcUID {
				log.Info("Found an orphaned service", "orphaned UID", uid)
				sn := client.ObjectKey{Name: res.Name, Namespace: service.Namespace}
				if err := r.Get(ctx, sn, &svc); err != nil {
					if apierrors.IsNotFound(err) {
						continue
					}
					return err
				}
				if err := r.Delete(ctx, &svc); err != nil {
					return err
				}
				log.Info("Removed an orphaned service", "orphaned UID", uid)
			}
		}
	}
	return nil
}
func ( r * ServiceTraitReconciler ) cleanupResources ( ctx context . Context , service * corev1alpha2 . ServiceTrait , svcUID * types . UID ) error { log := r . Log . WithValues ( " " , service . Name ) var svc corev1 . Service for _ , res := range service . Status . Resources { uid := res . UID if res . Kind == KindService && res . APIVersion == corev1 . SchemeGroupVersion . String ( ) { if uid != * svcUID { log . Info ( " " , " " , uid ) sn := client . ObjectKey { Name : res . Name , Namespace : service . Namespace } if err := r . Get ( ctx , sn , & svc ) ; err != nil { if apierrors . IsNotFound ( err ) { continue } return err } if err := r . Delete ( ctx , & svc ) ; err != nil { return err } log . Info ( " " , " " , uid ) } } } return nil }
delete services that are not the same as the existing
delete services that are not the same as the existing