This repository has been archived by the owner on Oct 9, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 62
/
clusterresource.go
64 lines (55 loc) · 2.13 KB
/
clusterresource.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package entrypoints
import (
"context"
errors2 "github.com/pkg/errors"
"github.com/flyteorg/flytestdlib/promutils"
"github.com/flyteorg/flyteadmin/pkg/clusterresource"
"github.com/flyteorg/flyteadmin/pkg/runtime"
"github.com/flyteorg/flytestdlib/logger"
"github.com/spf13/cobra"
_ "gorm.io/driver/postgres" // Required to import database driver.
)
var parentClusterResourceCmd = &cobra.Command{
Use: "clusterresource",
Short: "This command administers the ClusterResourceController. Please choose a subcommand.",
}
var controllerRunCmd = &cobra.Command{
Use: "run",
Short: "This command will start a cluster resource controller to periodically sync cluster resources",
RunE: func(cmd *cobra.Command, args []string) error {
ctx := context.Background()
configuration := runtime.NewConfigurationProvider()
scope := promutils.NewScope(configuration.ApplicationConfiguration().GetTopLevelConfig().MetricsScope).NewSubScope("clusterresource")
clusterResourceController, err := clusterresource.NewClusterResourceControllerFromConfig(ctx, scope, configuration)
if err != nil {
return err
}
clusterResourceController.Run()
logger.Infof(ctx, "ClusterResourceController started running successfully")
return nil
},
}
var controllerSyncCmd = &cobra.Command{
Use: "sync",
Short: "This command will sync cluster resources",
RunE: func(cmd *cobra.Command, args []string) error {
ctx := context.Background()
configuration := runtime.NewConfigurationProvider()
scope := promutils.NewScope(configuration.ApplicationConfiguration().GetTopLevelConfig().MetricsScope).NewSubScope("clusterresource")
clusterResourceController, err := clusterresource.NewClusterResourceControllerFromConfig(ctx, scope, configuration)
if err != nil {
return err
}
err = clusterResourceController.Sync(ctx)
if err != nil {
return errors2.Wrap(err, "Failed to sync cluster resources ")
}
logger.Infof(ctx, "ClusterResourceController synced successfully")
return nil
},
}
func init() {
RootCmd.AddCommand(parentClusterResourceCmd)
parentClusterResourceCmd.AddCommand(controllerRunCmd)
parentClusterResourceCmd.AddCommand(controllerSyncCmd)
}