Skip to content

Commit

Permalink
Merge pull request #329 from kube-tarian/cluster-claims-sync
Browse files Browse the repository at this point in the history
update cluster cliams sync jobs
  • Loading branch information
vramk23 authored Nov 21, 2023
2 parents 3ac9bfd + 5139b6d commit 731ef21
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 21 deletions.
22 changes: 2 additions & 20 deletions capten/agent/internal/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"github.com/kube-tarian/kad/capten/agent/internal/util"
dbinit "github.com/kube-tarian/kad/capten/common-pkg/cassandra/db-init"
dbmigrate "github.com/kube-tarian/kad/capten/common-pkg/cassandra/db-migrate"
"github.com/kube-tarian/kad/capten/common-pkg/k8s"
"github.com/pkg/errors"
"google.golang.org/grpc/reflection"
)
Expand Down Expand Up @@ -133,25 +132,8 @@ func initializeJobScheduler(cfg *config.SericeConfig, as *captenstore.Store) (*j
}

func registerK8SWatcher(dbStore *captenstore.Store) error {
k8sclient, err := k8s.NewK8SClient(log)
if err != nil {
return fmt.Errorf("failed to initalize k8s client: %v", err)
if err := crossplane.RegisterK8SWatcher(log, dbStore); err != nil {
return err
}

err = crossplane.RegisterK8SClusterClaimWatcher(log, dbStore, k8sclient.DynamicClientInterface)
if err != nil {
return fmt.Errorf("failed to RegisterK8SClusterClaimWatcher: %v", err)
}

err = crossplane.RegisterK8SProviderWatcher(log, dbStore, k8sclient.DynamicClientInterface)
if err != nil {
return fmt.Errorf("failed to RegisterK8SProviderWatcher: %v", err)
}

cc := crossplane.NewClusterClaimSyncHandler(log, dbStore)
go cc.Sync()
ps := crossplane.NewProvidersSyncHandler(log, dbStore)
go ps.Sync()

return nil
}
2 changes: 1 addition & 1 deletion capten/agent/internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ type SericeConfig struct {
Mode string `envconfig:"MODE" default:"production"`
AuthEnabled bool `envconfig:"AUTH_ENABLED" default:"false"`
CrossplaneSyncJobEnabled bool `envconfig:"CROSSPLANE_SYNC_JOB_ENABLED" default:"true"`
CrossplaneSyncJobInterval string `envconfig:"CROSSPLANE_SYNC_JOB_INTERVAL" default:"@every 1m"`
CrossplaneSyncJobInterval string `envconfig:"CROSSPLANE_SYNC_JOB_INTERVAL" default:"@every 1h"`
}

func GetServiceConfig() (*SericeConfig, error) {
Expand Down
32 changes: 32 additions & 0 deletions capten/agent/internal/crossplane/watchers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package crossplane

import (
"fmt"

"github.com/intelops/go-common/logging"
captenstore "github.com/kube-tarian/kad/capten/agent/internal/capten-store"
"github.com/kube-tarian/kad/capten/common-pkg/k8s"
)

func RegisterK8SWatcher(log logging.Logger, dbStore *captenstore.Store) error {
k8sclient, err := k8s.NewK8SClient(log)
if err != nil {
return fmt.Errorf("failed to initalize k8s client: %v", err)
}

err = RegisterK8SClusterClaimWatcher(log, dbStore, k8sclient.DynamicClientInterface)
if err != nil {
return fmt.Errorf("failed to RegisterK8SClusterClaimWatcher: %v", err)
}

err = RegisterK8SProviderWatcher(log, dbStore, k8sclient.DynamicClientInterface)
if err != nil {
return fmt.Errorf("failed to RegisterK8SProviderWatcher: %v", err)
}

cc := NewClusterClaimSyncHandler(log, dbStore)
go cc.Sync()
ps := NewProvidersSyncHandler(log, dbStore)
go ps.Sync()
return nil
}

0 comments on commit 731ef21

Please sign in to comment.