@@ -22,6 +22,7 @@ import (
2222 "time"
2323
2424 "github.com/GoogleContainerTools/config-sync/pkg/api/configsync"
25+ kptv1alpha1 "github.com/GoogleContainerTools/config-sync/pkg/api/kpt.dev/v1alpha1"
2526 "github.com/GoogleContainerTools/config-sync/pkg/applier/stats"
2627 "github.com/GoogleContainerTools/config-sync/pkg/core"
2728 "github.com/GoogleContainerTools/config-sync/pkg/declared"
@@ -186,21 +187,23 @@ func NewSupervisor(cs *ClientSet, scope declared.Scope, syncName string, reconci
186187// trying to add any new resources from source.
187188func (s * supervisor ) UpdateStatusMode (ctx context.Context ) error {
188189 return retry .RetryOnConflict (retry .DefaultRetry , func () error {
189- u := newInventoryUnstructured (s .syncName , s .syncNamespace )
190- key := client .ObjectKeyFromObject (u )
191- err := s .clientSet .Client .Get (ctx , key , u )
190+ var rg kptv1alpha1.ResourceGroup
191+ rg .SetGroupVersionKind (kinds .ResourceGroup ())
192+ key := resourcegroup .ObjectKey (s .syncName , s .syncNamespace )
193+ err := s .clientSet .Client .Get (ctx , key , & rg )
194+
192195 if err != nil {
193196 // RG doesn't exist, it will be created by applier with appropriate status mode
194197 if apierrors .IsNotFound (err ) {
195198 return nil
196199 }
197- return status .APIServerErrorf (err , "failed to get %s : %s" , u . GetKind (), key )
200+ return status .APIServerErrorf (err , "failed to get %v : %s" , rg . GetObjectKind (). GroupVersionKind (), key )
198201 }
199- if core .SetAnnotation (u , metadata .StatusModeAnnotationKey , s .clientSet .StatusMode .String ()) {
200- klog .V (3 ).Infof ("Updating %s annotation: %s: %s" , u . GetKind (), metadata .StatusModeAnnotationKey , s .clientSet .StatusMode )
201- err := s .clientSet .Client .Update (ctx , u , client .FieldOwner (configsync .FieldManager ))
202+ if core .SetAnnotation (& rg , metadata .StatusModeAnnotationKey , s .clientSet .StatusMode .String ()) {
203+ klog .V (3 ).Infof ("Updating %v annotation: %s: %s" , rg . GetObjectKind (). GroupVersionKind (), metadata .StatusModeAnnotationKey , s .clientSet .StatusMode )
204+ err := s .clientSet .Client .Update (ctx , & rg , client .FieldOwner (configsync .FieldManager ))
202205 if err != nil {
203- return status .APIServerErrorf (err , "failed to update %s : %s" , u . GetKind (), key )
206+ return status .APIServerErrorf (err , "failed to update %v : %s" , rg . GetObjectKind (). GroupVersionKind (), key )
204207 }
205208 }
206209 return nil
@@ -511,10 +514,13 @@ func handleMetrics(ctx context.Context, operation string, err error) {
511514// checkInventoryObjectSize checks the inventory object size limit.
512515// If it is close to the size limit 1M, log a warning.
513516func (s * supervisor ) checkInventoryObjectSize (ctx context.Context , c client.Client ) {
514- u := newInventoryUnstructured (s .syncName , s .syncNamespace )
515- err := c .Get (ctx , client.ObjectKey {Namespace : s .syncNamespace , Name : s .syncName }, u )
517+ var rg kptv1alpha1.ResourceGroup
518+ rg .SetGroupVersionKind (kinds .ResourceGroup ())
519+ key := resourcegroup .ObjectKey (s .syncName , s .syncNamespace )
520+ err := c .Get (ctx , key , & rg )
521+
516522 if err == nil {
517- size , err := getObjectSize (u )
523+ size , err := getObjectSize (& rg )
518524 if err != nil {
519525 klog .Warningf ("Failed to marshal ResourceGroup %s/%s to get its size: %s" , s .syncNamespace , s .syncName , err )
520526 }
@@ -746,13 +752,6 @@ func (s *supervisor) Destroy(ctx context.Context, eventHandler func(Event)) (Obj
746752 return s .destroyInner (ctx , eventHandler )
747753}
748754
749- // newInventoryUnstructured creates an inventory object as an unstructured.
750- func newInventoryUnstructured (name , namespace string ) * unstructured.Unstructured {
751- id := InventoryID (name , namespace )
752- u := resourcegroup .Unstructured (name , namespace , id )
753- return u
754- }
755-
756755// InventoryID returns the inventory id of an inventory object.
757756// The inventory object generated by ConfigSync is in the same namespace as RootSync or RepoSync.
758757// The inventory ID is assigned as <NAMESPACE>_<NAME>.
0 commit comments