@@ -897,8 +897,15 @@ func (o *Operator) handleCatSrcDeletion(obj interface{}) {
897897}
898898
899899func validateSourceType (logger * logrus.Entry , in * v1alpha1.CatalogSource ) (out * v1alpha1.CatalogSource , continueSync bool , _ error ) {
900+ defer func () {
901+ logger .WithFields (logrus.Fields {
902+ "continueSync" : continueSync ,
903+ }).Info ("source type validated" )
904+ }()
905+
900906 out = in
901907 var err error
908+
902909 switch sourceType := out .Spec .SourceType ; sourceType {
903910 case v1alpha1 .SourceTypeInternal , v1alpha1 .SourceTypeConfigmap :
904911 if out .Spec .ConfigMap == "" {
@@ -912,6 +919,7 @@ func validateSourceType(logger *logrus.Entry, in *v1alpha1.CatalogSource) (out *
912919 err = fmt .Errorf ("unknown sourcetype: %s" , sourceType )
913920 }
914921 if err != nil {
922+ logger .WithError (err ).Error ("error validating catalog source type" )
915923 out .SetError (v1alpha1 .CatalogSourceSpecInvalidError , err )
916924 return
917925 }
@@ -923,7 +931,6 @@ func validateSourceType(logger *logrus.Entry, in *v1alpha1.CatalogSource) (out *
923931 }
924932 }
925933 continueSync = true
926-
927934 return
928935}
929936
@@ -936,17 +943,22 @@ func (o *Operator) syncConfigMap(logger *logrus.Entry, in *v1alpha1.CatalogSourc
936943
937944 out = in .DeepCopy ()
938945
946+ logger = logger .WithField ("step" , "syncConfigMap" )
939947 logger = logger .WithFields (logrus.Fields {
940948 "configmap.namespace" : in .Namespace ,
941949 "configmap.name" : in .Spec .ConfigMap ,
942950 })
943- logger .Info ("checking catsrc configmap state" )
951+
952+ defer func () {
953+ logger .WithError (syncError ).WithField ("continueSync" , continueSync ).Info ("config map sync'ed" )
954+ }()
944955
945956 var updateLabel bool
946957 // Get the catalog source's config map
947958 configMap , err := o .lister .CoreV1 ().ConfigMapLister ().ConfigMaps (in .GetNamespace ()).Get (in .Spec .ConfigMap )
948959 // Attempt to look up the CM via api call if there is a cache miss
949960 if apierrors .IsNotFound (err ) {
961+ // TODO: Don't reach out via live client if its not found in the cache (https://github.com/operator-framework/operator-lifecycle-manager/issues/3415)
950962 configMap , err = o .opClient .KubernetesInterface ().CoreV1 ().ConfigMaps (in .GetNamespace ()).Get (context .TODO (), in .Spec .ConfigMap , metav1.GetOptions {})
951963 // Found cm in the cluster, add managed label to configmap
952964 if err == nil {
@@ -973,12 +985,9 @@ func (o *Operator) syncConfigMap(logger *logrus.Entry, in *v1alpha1.CatalogSourc
973985 out .SetError (v1alpha1 .CatalogSourceConfigMapError , syncError )
974986 return
975987 }
976-
977- logger .Info ("adopted configmap" )
978988 }
979989
980990 if in .Status .ConfigMapResource == nil || ! in .Status .ConfigMapResource .IsAMatch (& configMap .ObjectMeta ) {
981- logger .Info ("updating catsrc configmap state" )
982991 // configmap ref nonexistent or updated, write out the new configmap ref to status and exit
983992 out .Status .ConfigMapResource = & v1alpha1.ConfigMapResourceReference {
984993 Name : configMap .GetName (),
@@ -998,11 +1007,22 @@ func (o *Operator) syncConfigMap(logger *logrus.Entry, in *v1alpha1.CatalogSourc
9981007func (o * Operator ) syncRegistryServer (logger * logrus.Entry , in * v1alpha1.CatalogSource ) (out * v1alpha1.CatalogSource , continueSync bool , syncError error ) {
9991008 out = in .DeepCopy ()
10001009
1001- logger .Info ("synchronizing registry server" )
1010+ // extraLogContext is used when logging before exiting to provide
1011+ // additional context in cases where we exit early without an error
1012+ extraLogContext := "none"
1013+ defer func () {
1014+ logger .WithFields (logrus.Fields {
1015+ "continueSync" : continueSync ,
1016+ "syncError" : syncError ,
1017+ "extra" : extraLogContext ,
1018+ }).Info ("registry server sync'ed" )
1019+ }()
1020+
10021021 sourceKey := registry.CatalogKey {Name : in .GetName (), Namespace : in .GetNamespace ()}
1022+
10031023 srcReconciler := o .reconciler .ReconcilerForSource (in )
10041024 if srcReconciler == nil {
1005- // TODO: Add failure status on catalogsource and remove from sources
1025+ // TODO: Add failure status on catalogsource and remove from sources )
10061026 syncError = fmt .Errorf ("no reconciler for source type %s" , in .Spec .SourceType )
10071027 out .SetError (v1alpha1 .CatalogSourceRegistryServerError , syncError )
10081028 return
@@ -1015,24 +1035,23 @@ func (o *Operator) syncRegistryServer(logger *logrus.Entry, in *v1alpha1.Catalog
10151035 return
10161036 }
10171037
1018- logger .WithField ("health" , healthy ).Infof ("checked registry server health" )
1038+ logger = logger .WithField ("health" , healthy )
1039+ logger .Info ("checked registry server health" )
10191040
10201041 if healthy && in .Status .RegistryServiceStatus != nil {
1021- logger .Info ("registry state good" )
10221042 continueSync = true
10231043 // return here if catalog does not have polling enabled
10241044 if ! out .Poll () {
1025- logger . Info ( "polling not enabled, nothing more to do" )
1045+ extraLogContext = "catalog does not have polling enabled"
10261046 return
10271047 }
10281048 }
10291049
10301050 // Registry pod hasn't been created or hasn't been updated since the last configmap update, recreate it
1031- logger .Info ("ensuring registry server" )
1032-
10331051 err = srcReconciler .EnsureRegistryServer (logger , out )
10341052 if err != nil {
10351053 if _ , ok := err .(reconciler.UpdateNotReadyErr ); ok {
1054+ extraLogContext = "update pod is not ready yet"
10361055 logger .Info ("requeueing registry server for catalog update check: update pod not yet ready" )
10371056 o .catsrcQueueSet .RequeueAfter (out .GetNamespace (), out .GetName (), reconciler .CatalogPollingRequeuePeriod )
10381057 return
@@ -1042,8 +1061,6 @@ func (o *Operator) syncRegistryServer(logger *logrus.Entry, in *v1alpha1.Catalog
10421061 return
10431062 }
10441063
1045- logger .Info ("ensured registry server" )
1046-
10471064 // requeue the catalog sync based on the polling interval, for accurate syncs of catalogs with polling enabled
10481065 if out .Spec .UpdateStrategy != nil && out .Spec .UpdateStrategy .RegistryPoll != nil {
10491066 if out .Spec .UpdateStrategy .Interval == nil {
@@ -1052,22 +1069,30 @@ func (o *Operator) syncRegistryServer(logger *logrus.Entry, in *v1alpha1.Catalog
10521069 return
10531070 }
10541071 if out .Spec .UpdateStrategy .RegistryPoll .ParsingError != "" && out .Status .Reason != v1alpha1 .CatalogSourceIntervalInvalidError {
1055- out .SetError (v1alpha1 .CatalogSourceIntervalInvalidError , errors .New (out .Spec .UpdateStrategy .RegistryPoll .ParsingError ))
1072+ err := errors .New (out .Spec .UpdateStrategy .RegistryPoll .ParsingError )
1073+ logger .WithError (err ).Error ("registry server sync error: failed to parse registry poll interval" )
1074+ out .SetError (v1alpha1 .CatalogSourceIntervalInvalidError , err )
10561075 }
1057- logger . Infof ("requeuing registry server sync based on polling interval %s" , out .Spec .UpdateStrategy .Interval .Duration .String ())
1076+ extraLogContext = fmt . Sprintf ("requeuing registry server sync based on polling interval %s" , out .Spec .UpdateStrategy .Interval .Duration .String ())
10581077 resyncPeriod := reconciler .SyncRegistryUpdateInterval (out , time .Now ())
10591078 o .catsrcQueueSet .RequeueAfter (out .GetNamespace (), out .GetName (), queueinformer .ResyncWithJitter (resyncPeriod , 0.1 )())
10601079 return
10611080 }
10621081
10631082 if err := o .sources .Remove (sourceKey ); err != nil {
1064- o .logger .WithError (err ).Debug ( " error closing client connection" )
1083+ o .logger .WithError (err ).Error ( "registry server sync error: error closing client connection" )
10651084 }
10661085
10671086 return
10681087}
10691088
10701089func (o * Operator ) syncConnection (logger * logrus.Entry , in * v1alpha1.CatalogSource ) (out * v1alpha1.CatalogSource , continueSync bool , syncError error ) {
1090+ defer func () {
1091+ logger .WithFields (logrus.Fields {
1092+ "continueSync" : continueSync ,
1093+ "syncError" : syncError ,
1094+ }).Info ("registry server connection sync'ed" )
1095+ }()
10711096 out = in .DeepCopy ()
10721097
10731098 sourceKey := registry.CatalogKey {Name : in .GetName (), Namespace : in .GetNamespace ()}
@@ -1152,7 +1177,11 @@ func (o *Operator) syncCatalogSources(obj interface{}) (syncError error) {
11521177 "catalogsource.name" : catsrc .Name ,
11531178 "id" : queueinformer .NewLoopID (),
11541179 })
1155- logger .Info ("syncing catalog source" )
1180+ defer func () {
1181+ logger .WithFields (logrus.Fields {
1182+ "syncError" : syncError ,
1183+ }).Info ("catalog source sync'ed" )
1184+ }()
11561185
11571186 syncFunc := func (in * v1alpha1.CatalogSource , chain []CatalogSourceSyncFunc ) (out * v1alpha1.CatalogSource , syncErr error ) {
11581187 out = in
0 commit comments