From 7fa5d2afc5a0b598f02d6dde047b66d517ccda79 Mon Sep 17 00:00:00 2001 From: Venkatreddy KP Date: Mon, 13 Nov 2023 00:40:11 +0530 Subject: [PATCH] add crossplane resource synch job handlers --- .../crossplane/crossplane_cluster_claims.go | 4 +-- .../pkg/crossplane/crossplane_providers.go | 7 ++--- .../pkg/job/crossplane_resources_sync.go | 31 ++++++++++++------- 3 files changed, 24 insertions(+), 18 deletions(-) diff --git a/capten/agent/pkg/crossplane/crossplane_cluster_claims.go b/capten/agent/pkg/crossplane/crossplane_cluster_claims.go index fa046a96..854e7807 100644 --- a/capten/agent/pkg/crossplane/crossplane_cluster_claims.go +++ b/capten/agent/pkg/crossplane/crossplane_cluster_claims.go @@ -35,8 +35,8 @@ type ClusterClaimSyncHandler struct { clusters map[string]*captenpluginspb.ManagedCluster } -func NewClusterClaimSyncHandler(log logging.Logger, dbStore *captenstore.Store) (*ClusterClaimSyncHandler, error) { - return &ClusterClaimSyncHandler{log: log, dbStore: dbStore, clusters: map[string]*captenpluginspb.ManagedCluster{}}, nil +func NewClusterClaimSyncHandler(log logging.Logger, dbStore *captenstore.Store) *ClusterClaimSyncHandler { + return &ClusterClaimSyncHandler{log: log, dbStore: dbStore, clusters: map[string]*captenpluginspb.ManagedCluster{}} } func (h *ClusterClaimSyncHandler) Sync() error { diff --git a/capten/agent/pkg/crossplane/crossplane_providers.go b/capten/agent/pkg/crossplane/crossplane_providers.go index 593f2620..1f7f21b6 100644 --- a/capten/agent/pkg/crossplane/crossplane_providers.go +++ b/capten/agent/pkg/crossplane/crossplane_providers.go @@ -5,7 +5,6 @@ import ( "encoding/json" "fmt" - "github.com/intelops/go-common/credentials" "github.com/intelops/go-common/logging" captenstore "github.com/kube-tarian/kad/capten/agent/pkg/capten-store" @@ -21,13 +20,11 @@ const ( type ProvidersSyncHandler struct { log logging.Logger - client *k8s.K8SClient dbStore *captenstore.Store - creds credentials.CredentialAdmin } -func NewProvidersSyncHandler(log logging.Logger, dbStore *captenstore.Store) (*ProvidersSyncHandler, error) { - return &ProvidersSyncHandler{log: log, dbStore: dbStore}, nil +func NewProvidersSyncHandler(log logging.Logger, dbStore *captenstore.Store) *ProvidersSyncHandler { + return &ProvidersSyncHandler{log: log, dbStore: dbStore} } func (h *ProvidersSyncHandler) Sync() error { diff --git a/capten/agent/pkg/job/crossplane_resources_sync.go b/capten/agent/pkg/job/crossplane_resources_sync.go index 533f6da5..f02ab664 100644 --- a/capten/agent/pkg/job/crossplane_resources_sync.go +++ b/capten/agent/pkg/job/crossplane_resources_sync.go @@ -3,28 +3,37 @@ package job import ( "github.com/intelops/go-common/logging" captenstore "github.com/kube-tarian/kad/capten/agent/pkg/capten-store" + "github.com/kube-tarian/kad/capten/agent/pkg/crossplane" ) type CrossplaneResourcesSync struct { - dbStore *captenstore.Store - log logging.Logger - frequency string + log logging.Logger + frequency string + clusterHandler *crossplane.ClusterClaimSyncHandler + providerHandler *crossplane.ProvidersSyncHandler } func NewCrossplaneResourcesSync(log logging.Logger, frequency string, dbStore *captenstore.Store) (*CrossplaneResourcesSync, error) { return &CrossplaneResourcesSync{ - log: log, - frequency: frequency, - dbStore: dbStore, + log: log, + frequency: frequency, + clusterHandler: crossplane.NewClusterClaimSyncHandler(log, dbStore), + providerHandler: crossplane.NewProvidersSyncHandler(log, dbStore), }, nil } -func (v *CrossplaneResourcesSync) CronSpec() string { - return v.frequency +func (s *CrossplaneResourcesSync) CronSpec() string { + return s.frequency } -func (v *CrossplaneResourcesSync) Run() { - v.log.Debug("started crossplane resource sync job") +func (s *CrossplaneResourcesSync) Run() { + s.log.Debug("started crossplane resource sync job") + if err := s.providerHandler.Sync(); err != nil { + s.log.Errorf("failed to synch providers, %v", err) + } - v.log.Debug("crossplane resource sync job completed") + if err := s.clusterHandler.Sync(); err != nil { + s.log.Errorf("failed to synch managed clusters, %v", err) + } + s.log.Debug("crossplane resource sync job completed") }