@@ -885,11 +885,34 @@ func toggleFeatureGates(deployment *appsv1.Deployment, toToggle ...featuregate.F
885885 awaitPredicates (deadline , w , deploymentReplicas (2 ), deploymentAvailable , deploymentReplicas (1 ))
886886}
887887
888+ var gvks = map [reflect.Type ]schema.GroupVersionKind {
889+ reflect .TypeOf (& v1alpha1.ClusterServiceVersion {}): schema.GroupVersionKind {
890+ Group : v1alpha1 .GroupName ,
891+ Version : v1alpha1 .GroupVersion ,
892+ Kind : v1alpha1 .ClusterServiceVersionKind ,
893+ },
894+ reflect .TypeOf (& v1alpha1.InstallPlan {}): schema.GroupVersionKind {
895+ Group : v1alpha1 .GroupName ,
896+ Version : v1alpha1 .GroupVersion ,
897+ Kind : v1alpha1 .InstallPlanKind ,
898+ },
899+ }
900+
888901type Object interface {
889902 runtime.Object
890903 metav1.Object
891904}
892905
906+ func SetDefaultGroupVersionKind (o Object ) {
907+ gvk := o .GetObjectKind ().GroupVersionKind ()
908+ if ! gvk .Empty () {
909+ return
910+ }
911+ if gvk , ok := gvks [reflect .TypeOf (o )]; ok {
912+ o .GetObjectKind ().SetGroupVersionKind (gvk )
913+ }
914+ }
915+
893916// Apply returns a function that invokes a change func on an object and performs a server-side apply patch with the result and its status subresource.
894917// The given resource must be a pointer to a struct that specifies its Name, Namespace, APIVersion, and Kind at minimum.
895918// The given change function must be aunary, matching the signature: "func(<obj type>) error".
@@ -948,7 +971,7 @@ func Apply(obj Object, changeFunc interface{}) func() error {
948971 if err := client .Get (bg , key , cp ); err != nil {
949972 return err
950973 }
951- cp . GetObjectKind (). SetGroupVersionKind ( obj . GetObjectKind (). GroupVersionKind () )
974+ SetDefaultGroupVersionKind ( cp )
952975 cp .SetManagedFields (nil )
953976
954977 var (
@@ -970,7 +993,7 @@ func Apply(obj Object, changeFunc interface{}) func() error {
970993 if err := client .Get (bg , key , cp ); err != nil {
971994 return err
972995 }
973- cp . GetObjectKind (). SetGroupVersionKind ( obj . GetObjectKind (). GroupVersionKind () )
996+ SetDefaultGroupVersionKind ( cp )
974997 cp .SetManagedFields (nil )
975998
976999 if len (out ) != 1 {
0 commit comments