Skip to content

Commit 93c7d69

Browse files
committed
Improve error when trying to install an 'empty' dependency
This could happen if you add a dependency to package metadata with all of the pointer fields unset. Signed-off-by: Nic Cope <[email protected]>
1 parent 4bb41be commit 93c7d69

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

internal/controller/pkg/resolver/reconciler.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -589,16 +589,16 @@ func NewPackage(dep *v1beta1.Dependency, version string, ref name.Reference) (*u
589589
pack.SetAPIVersion(*dep.APIVersion)
590590
pack.SetKind(*dep.Kind)
591591
case ptr.Deref(dep.Type, "") == v1beta1.ConfigurationPackageType:
592-
pack.SetAPIVersion("pkg.crossplane.io/v1")
593-
pack.SetKind("Configuration")
592+
pack.SetAPIVersion(v1.ConfigurationGroupVersionKind.GroupVersion().String())
593+
pack.SetKind(v1.ConfigurationKind)
594594
case ptr.Deref(dep.Type, "") == v1beta1.ProviderPackageType:
595-
pack.SetAPIVersion("pkg.crossplane.io/v1")
596-
pack.SetKind("Provider")
595+
pack.SetAPIVersion(v1.ProviderGroupVersionKind.GroupVersion().String())
596+
pack.SetKind(v1.ProviderKind)
597597
case ptr.Deref(dep.Type, "") == v1beta1.FunctionPackageType:
598-
pack.SetAPIVersion("pkg.crossplane.io/v1")
599-
pack.SetKind("Function")
598+
pack.SetAPIVersion(v1.FunctionGroupVersionKind.GroupVersion().String())
599+
pack.SetKind(v1.FunctionKind)
600600
default:
601-
return nil, errors.Errorf("cannot determine dependency type - you must specify either a valid type, or an explicit apiVersion and kind")
601+
return nil, errors.Errorf("encountered an invalid dependency: package dependencies must specify either a valid type, or an explicit apiVersion, kind, and package")
602602
}
603603

604604
return pack, nil
@@ -613,16 +613,16 @@ func NewPackageList(dep *v1beta1.Dependency) (*unstructured.UnstructuredList, er
613613
l.SetAPIVersion(*dep.APIVersion)
614614
l.SetKind(*dep.Kind + "List")
615615
case ptr.Deref(dep.Type, "") == v1beta1.ConfigurationPackageType:
616-
l.SetAPIVersion("pkg.crossplane.io/v1")
617-
l.SetKind("ConfigurationList")
616+
l.SetAPIVersion(v1.ConfigurationGroupVersionKind.GroupVersion().String())
617+
l.SetKind(v1.ConfigurationKind + "List")
618618
case ptr.Deref(dep.Type, "") == v1beta1.ProviderPackageType:
619-
l.SetAPIVersion("pkg.crossplane.io/v1")
620-
l.SetKind("ProviderList")
619+
l.SetAPIVersion(v1.ProviderGroupVersionKind.GroupVersion().String())
620+
l.SetKind(v1.ProviderKind + "List")
621621
case ptr.Deref(dep.Type, "") == v1beta1.FunctionPackageType:
622-
l.SetAPIVersion("pkg.crossplane.io/v1")
623-
l.SetKind("FunctionList")
622+
l.SetAPIVersion(v1.FunctionGroupVersionKind.GroupVersion().String())
623+
l.SetKind(v1.FunctionKind + "List")
624624
default:
625-
return nil, errors.Errorf("cannot determine dependency type - you must specify either a valid type, or an explicit apiVersion and kind")
625+
return nil, errors.Errorf("encountered an invalid dependency: package dependencies must specify either a valid type, or an explicit apiVersion, kind, and package")
626626
}
627627

628628
return l, nil

internal/controller/pkg/revision/dependency.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ func (m *PackageDependencyManager) Resolve(ctx context.Context, meta pkgmetav1.P
9999
case dep.Function != nil:
100100
pdep.Package = *dep.Function
101101
pdep.Type = ptr.To(v1beta1.FunctionPackageType)
102+
default:
103+
return 0, 0, 0, errors.Errorf("encountered an invalid dependency: package dependencies must specify either a valid type, or an explicit apiVersion, kind, and package")
102104
}
103105
pdep.Constraints = dep.Version
104106
sources[i] = pdep

0 commit comments

Comments
 (0)