diff --git a/capten/agent/internal/crossplane/cluster_claims.go b/capten/agent/internal/crossplane/cluster_claims.go index 9fb0cbcc..ec42124e 100644 --- a/capten/agent/internal/crossplane/cluster_claims.go +++ b/capten/agent/internal/crossplane/cluster_claims.go @@ -53,20 +53,15 @@ func NewClusterClaimSyncHandler(log logging.Logger, dbStore *captenstore.Store) return &ClusterClaimSyncHandler{log: log, dbStore: dbStore, tc: tc}, nil } -func registerK8SClusterClaimWatcher(log logging.Logger, dbStore *captenstore.Store, k8sClient *k8s.K8SClient) error { - obj, err := NewClusterClaimSyncHandler(log, dbStore) - if err != nil { - return err - } - +func registerK8SClusterClaimWatcher(log logging.Logger, handler *ClusterClaimSyncHandler, k8sClient *k8s.K8SClient) error { log.Debugf("Registering resource %s wather", cgvk.String()) - _, err = k8sClient.Clientset.Discovery().ServerResourcesForGroupVersion(cgvk.GroupVersion().String()) + _, err := k8sClient.Clientset.Discovery().ServerResourcesForGroupVersion(cgvk.GroupVersion().String()) if err != nil { log.Debugf("Resource %s not found: %v", cgvk.String(), err) return fmt.Errorf("resource not found") } - err = k8s.RegisterDynamicInformers(obj, k8sClient.DynamicClientInterface, cgvk) + err = k8s.RegisterDynamicInformers(handler, k8sClient.DynamicClientInterface, cgvk) if err != nil { return err } diff --git a/capten/agent/internal/crossplane/package_providers.go b/capten/agent/internal/crossplane/package_providers.go index 53077e82..ead27ff5 100644 --- a/capten/agent/internal/crossplane/package_providers.go +++ b/capten/agent/internal/crossplane/package_providers.go @@ -35,18 +35,12 @@ func NewProvidersSyncHandler(log logging.Logger, dbStore *captenstore.Store) (*P if err != nil { return nil, err } - return &ProvidersSyncHandler{log: log, dbStore: dbStore, tc: tc, activeProviders: map[string]bool{}}, nil } -func registerK8SProviderWatcher(log logging.Logger, dbStore *captenstore.Store, k8sClient *k8s.K8SClient) error { - provider, err := NewProvidersSyncHandler(log, dbStore) - if err != nil { - return err - } - +func registerK8SProviderWatcher(log logging.Logger, provider *ProvidersSyncHandler, k8sClient *k8s.K8SClient) error { log.Debugf("Registering resource %s wather", pgvk.String()) - _, err = k8sClient.Clientset.Discovery().ServerResourcesForGroupVersion(pgvk.GroupVersion().String()) + _, err := k8sClient.Clientset.Discovery().ServerResourcesForGroupVersion(pgvk.GroupVersion().String()) if err != nil { log.Debugf("Resource %s not found: %v\n", pgvk.String(), err) return fmt.Errorf("resource not found") diff --git a/capten/agent/internal/crossplane/watchers.go b/capten/agent/internal/crossplane/watchers.go index 444ec9a6..af2885a9 100644 --- a/capten/agent/internal/crossplane/watchers.go +++ b/capten/agent/internal/crossplane/watchers.go @@ -15,8 +15,18 @@ func RegisterK8SWatcher(log logging.Logger, dbStore *captenstore.Store) error { return fmt.Errorf("failed to initalize k8s client: %v", err) } + clusterHandler, err := NewClusterClaimSyncHandler(log, dbStore) + if err != nil { + return err + } + + provider, err := NewProvidersSyncHandler(log, dbStore) + if err != nil { + return err + } + go retryForEver(60*time.Second, func() (err error) { - err = registerK8SClusterClaimWatcher(log, dbStore, k8sclient) + err = registerK8SClusterClaimWatcher(log, clusterHandler, k8sclient) if err != nil { return fmt.Errorf("failed to RegisterK8SClusterClaimWatcher: %v", err) } @@ -24,7 +34,7 @@ func RegisterK8SWatcher(log logging.Logger, dbStore *captenstore.Store) error { }) go retryForEver(60*time.Second, func() (err error) { - err = registerK8SProviderWatcher(log, dbStore, k8sclient) + err = registerK8SProviderWatcher(log, provider, k8sclient) if err != nil { return fmt.Errorf("failed to RegisterK8SProviderWatcher: %v", err) } diff --git a/capten/agent/internal/temporalclient/client.go b/capten/agent/internal/temporalclient/client.go index 386eba4e..4a0c934a 100644 --- a/capten/agent/internal/temporalclient/client.go +++ b/capten/agent/internal/temporalclient/client.go @@ -2,7 +2,6 @@ package temporalclient import ( "context" - "log" "time" "github.com/intelops/go-common/logging" @@ -50,7 +49,7 @@ func (c *Client) newTemporalClient() (err error) { Logger: c.log, } - if err := createNamespace(opts); err != nil { + if err := createNamespace(opts, c.log); err != nil { return err } @@ -68,21 +67,21 @@ func (c *Client) newTemporalClient() (err error) { return } -func createNamespace(opts client.Options) error { +func createNamespace(opts client.Options, log logging.Logger) error { namespaceClient, err := client.NewNamespaceClient(opts) if err != nil { - log.Println("failed to create the namespace client", err) + log.Errorf("failed to create the namespace client", err) return err } response, err := namespaceClient.Describe(context.Background(), "default") if err != nil { - log.Println("failed to get the namespace", err) + log.Errorf("failed to get the namespace", err) return err } if response.NamespaceInfo.Name == opts.Namespace { - log.Printf("namespace %s exists, skipping namespace creation", opts.Namespace) + log.Debugf("namespace %s exists, skipping namespace creation", opts.Namespace) return nil } @@ -93,10 +92,9 @@ func createNamespace(opts client.Options) error { }) if err != nil { - log.Println("failed to create the namespace", err) + log.Errorf("failed to create the namespace", err) return err } - return nil }