Skip to content

Commit

Permalink
Merge pull request #455 from kube-tarian/temporal-client-log
Browse files Browse the repository at this point in the history
update logger
  • Loading branch information
vramk23 authored Apr 6, 2024
2 parents 8738fb1 + 0416708 commit 5c7300f
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 26 deletions.
11 changes: 3 additions & 8 deletions capten/agent/internal/crossplane/cluster_claims.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
10 changes: 2 additions & 8 deletions capten/agent/internal/crossplane/package_providers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
14 changes: 12 additions & 2 deletions capten/agent/internal/crossplane/watchers.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,26 @@ 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)
}
return nil
})

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)
}
Expand Down
14 changes: 6 additions & 8 deletions capten/agent/internal/temporalclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package temporalclient

import (
"context"
"log"
"time"

"github.com/intelops/go-common/logging"
Expand Down Expand Up @@ -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
}

Expand All @@ -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
}

Expand All @@ -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
}

Expand Down

0 comments on commit 5c7300f

Please sign in to comment.