@@ -3,55 +3,65 @@ package cmd
33import (
44 "fmt"
55
6- "github.com/openmcp-project/controller-utils/pkg/clusters"
76 "github.com/spf13/cobra"
7+ v1 "k8s.io/api/core/v1"
8+ "k8s.io/apimachinery/pkg/runtime"
89
10+ cfg "github.com/openmcp-project/bootstrapper/internal/config"
911 "github.com/openmcp-project/bootstrapper/internal/flux_deployer"
1012 logging "github.com/openmcp-project/bootstrapper/internal/log"
11- )
12-
13- const (
14- flagOCMConfig = "ocm-config"
15- flagGitCredentials = "git-credentials"
16- flagKubeconfig = "kubeconfig"
17- flagFluxCDNamespace = "fluxcd-namespace"
13+ "github.com/openmcp-project/bootstrapper/internal/util"
1814)
1915
2016// deployFluxCmd represents the "deploy flux" command
2117var deployFluxCmd = & cobra.Command {
22- Use : "deploy-flux source target " ,
23- Short : "Transfer an OCM component from a source to a target location " ,
24- Long : `Transfers the specified OCM component version from the source location to the target location .` ,
25- Args : cobra .ExactArgs (5 ),
18+ Use : "deploy-flux" ,
19+ Short : "Deploys Flux controllers on the platform cluster, and establishes synchronization with a Git repository " ,
20+ Long : `Deploys Flux controllers on the platform cluster, and establishes synchronization with a Git repository .` ,
21+ Args : cobra .ExactArgs (1 ),
2622 ArgAliases : []string {
27- "component-location" ,
28- "deployment-templates" ,
29- "deployment-repository" ,
30- "deployment-repository-branch" ,
31- "deployment-repository-path" ,
23+ "configFile" ,
3224 },
3325 RunE : func (cmd * cobra.Command , args []string ) error {
26+ configFilePath := args [0 ]
27+
3428 log := logging .GetLogger ()
35- log .Infof ("Starting flux deployment with component-location: %s, deployment-templates: %s, " +
36- "deployment-repository: %s, deployment-repository-branch: %s, deployment-repository-path: %s" ,
37- args [0 ], args [1 ], args [2 ], args [3 ], args [4 ])
29+ log .Infof ("Starting deployment of Flux controllers with config file: %s." , configFilePath )
30+
31+ // Configuration
32+ config := & cfg.BootstrapperConfig {}
33+ err := config .ReadFromFile (configFilePath )
34+ if err != nil {
35+ return fmt .Errorf ("failed to read config file: %w" , err )
36+ }
37+ config .SetDefaults ()
38+ err = config .Validate ()
39+ if err != nil {
40+ return fmt .Errorf ("invalid config file: %w" , err )
41+ }
42+
43+ // Platform cluster
44+ scheme := runtime .NewScheme ()
45+ if err := v1 .AddToScheme (scheme ); err != nil {
46+ return fmt .Errorf ("error adding corev1 to scheme: %w" , err )
47+ }
3848
39- platformKubeconfig := cmd .Flag (flagKubeconfig ).Value .String ()
40- platformCluster := clusters .New ("platform" ).WithConfigPath (platformKubeconfig )
49+ platformCluster , err := util .GetCluster (cmd .Flag (FlagKubeConfig ).Value .String (), "platform" , scheme )
50+ if err != nil {
51+ return fmt .Errorf ("failed to get platform cluster: %w" , err )
52+ }
4153 if err := platformCluster .InitializeRESTConfig (); err != nil {
4254 return fmt .Errorf ("error initializing REST config for platform cluster: %w" , err )
4355 }
4456 if err := platformCluster .InitializeClient (nil ); err != nil {
4557 return fmt .Errorf ("error initializing client for platform cluster: %w" , err )
4658 }
4759
48- d := flux_deployer .NewFluxDeployer (args [0 ], args [1 ], args [2 ], args [3 ], args [4 ],
49- cmd .Flag (flagOCMConfig ).Value .String (),
50- cmd .Flag (flagGitCredentials ).Value .String (),
51- cmd .Flag (flagFluxCDNamespace ).Value .String (),
52- platformKubeconfig ,
60+ d := flux_deployer .NewFluxDeployer (config ,
61+ cmd .Flag (FlagGitConfig ).Value .String (),
62+ cmd .Flag (FlagOcmConfig ).Value .String (),
5363 platformCluster , log )
54- err : = d .Deploy (cmd .Context ())
64+ err = d .Deploy (cmd .Context ())
5565 if err != nil {
5666 log .Errorf ("Flux deployment failed: %v" , err )
5767 return err
@@ -64,9 +74,12 @@ var deployFluxCmd = &cobra.Command{
6474
6575func init () {
6676 RootCmd .AddCommand (deployFluxCmd )
77+ deployFluxCmd .Flags ().SortFlags = false
78+ deployFluxCmd .Flags ().String (FlagOcmConfig , "" , "OCM configuration file" )
79+ deployFluxCmd .Flags ().String (FlagGitConfig , "" , "Git credentials configuration file that configures basic auth or ssh private key. This will be used in the fluxcd GitSource for spec.secretRef to authenticate against the deploymentRepository. If not set, no authentication will be configured." )
80+ deployFluxCmd .Flags ().String (FlagKubeConfig , "" , "Kubernetes configuration file" )
6781
68- deployFluxCmd .Flags ().StringP (flagOCMConfig , "c" , "" , "ocm configuration file" )
69- deployFluxCmd .Flags ().StringP (flagGitCredentials , "g" , "" , "git credentials configuration file that configures basic auth, personal access token, ssh private key. This will be used in the fluxcd GitSource for spec.secretRef to authenticate against the deploymentRepository. If not set, no authentication will be configured." )
70- deployFluxCmd .Flags ().StringP (flagKubeconfig , "k" , "" , "kubeconfig of the Kubernetes cluster on which the flux deployment will be created/updated. If not set, the current context will be used." )
71- deployFluxCmd .Flags ().StringP (flagFluxCDNamespace , "n" , "" , "namespace on the Kubernetes cluster in which the namespaced fluxcd resources will be deployed. Default 'flux-system'." )
82+ if err := deployFluxCmd .MarkFlagRequired (FlagGitConfig ); err != nil {
83+ panic (err )
84+ }
7285}
0 commit comments