// Scan scans for resource references.
Scan scans for resource references.
// Scan scans for resource references .
func (d *Deployment) Scan(ctx context.Context, gvr, fqn string, wait bool) (Refs, error) {
	ns, n := client.Namespaced(fqn)
	oo, err := d.Factory.List(d.GVR(), ns, wait, labels.Everything())
	if err != nil {
		return nil, err
	}
	refs := make(Refs, 0, len(oo))
	for _, o := range oo {
		var dp appsv1.Deployment
		err = runtime.DefaultUnstructuredConverter.FromUnstructured(o.(*unstructured.Unstructured).Object, &dp)
		if err != nil {
			return nil, errors.New("expecting Deployment resource")
		}
		switch gvr {
		case "v1/configmaps":
			if !hasConfigMap(&dp.Spec.Template.Spec, n) {
				continue
			}
			refs = append(refs, Ref{
				GVR: d.GVR(),
				FQN: client.FQN(dp.Namespace, dp.Name),
			})
		case "v1/secrets":
			found, err := hasSecret(d.Factory, &dp.Spec.Template.Spec, dp.Namespace, n, wait)
			if err != nil {
				log.Warn().Err(err).Msgf("scanning secret %q", fqn)
				continue
			}
			if !found {
				continue
			}
			refs = append(refs, Ref{
				GVR: d.GVR(),
				FQN: client.FQN(dp.Namespace, dp.Name),
			})
		case "v1/persistentvolumeclaims":
			if !hasPVC(&dp.Spec.Template.Spec, n) {
				continue
			}
			refs = append(refs, Ref{
				GVR: d.GVR(),
				FQN: client.FQN(dp.Namespace, dp.Name),
			})
		}
	}
	return refs, nil
}
func ( d * Deployment ) Scan ( ctx context . Context , gvr , fqn string , wait bool ) ( Refs , error ) { ns , n := client . Namespaced ( fqn ) oo , err := d . Factory . List ( d . GVR ( ) , ns , wait , labels . Everything ( ) ) if err != nil { return nil , err } refs := make ( Refs , 0 , len ( oo ) ) for _ , o := range oo { var dp appsv1 . Deployment err = runtime . DefaultUnstructuredConverter . FromUnstructured ( o . ( * unstructured . Unstructured ) . Object , & dp ) if err != nil { return nil , errors . New ( " " ) } switch gvr { case " " : if ! hasConfigMap ( & dp . Spec . Template . Spec , n ) { continue } refs = append ( refs , Ref { GVR : d . GVR ( ) , FQN : client . FQN ( dp . Namespace , dp . Name ) , } ) case " " : found , err := hasSecret ( d . Factory , & dp . Spec . Template . Spec , dp . Namespace , n , wait ) if err != nil { log . Warn ( ) . Err ( err ) . Msgf ( " " , fqn ) continue } if ! found { continue } refs = append ( refs , Ref { GVR : d . GVR ( ) , FQN : client . FQN ( dp . Namespace , dp . Name ) , } ) case " " : if ! hasPVC ( & dp . Spec . Template . Spec , n ) { continue } refs = append ( refs , Ref { GVR : d . GVR ( ) , FQN : client . FQN ( dp . Namespace , dp . Name ) , } ) } } return refs , nil }
Scan scans for resource references.
Scan scans for resource references .