Skip to content

Commit 14b345c

Browse files
committed
feat: deploy-flux command
1 parent 4c2644d commit 14b345c

File tree

14 files changed

+816
-21
lines changed

14 files changed

+816
-21
lines changed

cmd/deploy_flux.go

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
package cmd
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/openmcp-project/controller-utils/pkg/clusters"
7+
"github.com/spf13/cobra"
8+
9+
"github.com/openmcp-project/bootstrapper/internal/flux_deployer"
10+
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"
18+
)
19+
20+
// deployFluxCmd represents the "deploy flux" command
21+
var 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),
26+
ArgAliases: []string{
27+
"component-location",
28+
"deployment-templates",
29+
"deployment-repository",
30+
"deployment-repository-branch",
31+
"deployment-repository-path",
32+
},
33+
RunE: func(cmd *cobra.Command, args []string) error {
34+
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])
38+
39+
platformKubeconfig := cmd.Flag(flagKubeconfig).Value.String()
40+
platformCluster := clusters.New("platform").WithConfigPath(platformKubeconfig)
41+
if err := platformCluster.InitializeRESTConfig(); err != nil {
42+
return fmt.Errorf("error initializing REST config for platform cluster: %w", err)
43+
}
44+
if err := platformCluster.InitializeClient(nil); err != nil {
45+
return fmt.Errorf("error initializing client for platform cluster: %w", err)
46+
}
47+
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,
53+
platformCluster, log)
54+
err := d.Deploy(cmd.Context())
55+
if err != nil {
56+
log.Errorf("Flux deployment failed: %v", err)
57+
return err
58+
}
59+
60+
log.Info("Flux deployment completed")
61+
return nil
62+
},
63+
}
64+
65+
func init() {
66+
RootCmd.AddCommand(deployFluxCmd)
67+
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'.")
72+
}

go.mod

Lines changed: 52 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,37 +4,84 @@ go 1.25.0
44

55
require (
66
github.com/go-git/go-git/v5 v5.16.2
7+
github.com/openmcp-project/controller-utils v0.17.0
78
github.com/sirupsen/logrus v1.9.3
89
github.com/spf13/cobra v1.9.1
910
github.com/stretchr/testify v1.11.0
11+
k8s.io/api v0.33.3
12+
k8s.io/apimachinery v0.33.3
1013
k8s.io/utils v0.0.0-20250820121507-0af2bda4dd1d
14+
sigs.k8s.io/controller-runtime v0.21.0
1115
sigs.k8s.io/yaml v1.6.0
1216
)
1317

1418
require (
1519
dario.cat/mergo v1.0.0 // indirect
1620
github.com/Microsoft/go-winio v0.6.2 // indirect
1721
github.com/ProtonMail/go-crypto v1.1.6 // indirect
22+
github.com/beorn7/perks v1.0.1 // indirect
23+
github.com/cespare/xxhash/v2 v2.3.0 // indirect
1824
github.com/cloudflare/circl v1.6.1 // indirect
1925
github.com/cyphar/filepath-securejoin v0.4.1 // indirect
20-
github.com/davecgh/go-spew v1.1.1 // indirect
26+
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
27+
github.com/emicklei/go-restful/v3 v3.12.1 // indirect
2128
github.com/emirpasic/gods v1.18.1 // indirect
29+
github.com/evanphx/json-patch/v5 v5.9.11 // indirect
30+
github.com/fsnotify/fsnotify v1.8.0 // indirect
31+
github.com/fxamacker/cbor/v2 v2.7.0 // indirect
2232
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
2333
github.com/go-git/go-billy/v5 v5.6.2 // indirect
34+
github.com/go-logr/logr v1.4.3 // indirect
35+
github.com/go-openapi/jsonpointer v0.21.0 // indirect
36+
github.com/go-openapi/jsonreference v0.21.0 // indirect
37+
github.com/go-openapi/swag v0.23.0 // indirect
38+
github.com/gogo/protobuf v1.3.2 // indirect
2439
github.com/golang/groupcache v0.0.0-20241129210726-2c02b8208cf8 // indirect
40+
github.com/google/btree v1.1.3 // indirect
41+
github.com/google/gnostic-models v0.6.9 // indirect
42+
github.com/google/go-cmp v0.7.0 // indirect
43+
github.com/google/uuid v1.6.0 // indirect
2544
github.com/inconshreveable/mousetrap v1.1.0 // indirect
2645
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
46+
github.com/josharian/intern v1.0.0 // indirect
47+
github.com/json-iterator/go v1.1.12 // indirect
2748
github.com/kevinburke/ssh_config v1.2.0 // indirect
49+
github.com/mailru/easyjson v0.9.0 // indirect
50+
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
51+
github.com/modern-go/reflect2 v1.0.2 // indirect
52+
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
2853
github.com/pjbgf/sha1cd v0.3.2 // indirect
29-
github.com/pmezard/go-difflib v1.0.0 // indirect
54+
github.com/pkg/errors v0.9.1 // indirect
55+
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
56+
github.com/prometheus/client_golang v1.22.0 // indirect
57+
github.com/prometheus/client_model v0.6.1 // indirect
58+
github.com/prometheus/common v0.62.0 // indirect
59+
github.com/prometheus/procfs v0.15.1 // indirect
3060
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 // indirect
3161
github.com/skeema/knownhosts v1.3.1 // indirect
3262
github.com/spf13/pflag v1.0.7 // indirect
63+
github.com/x448/float16 v0.8.4 // indirect
3364
github.com/xanzy/ssh-agent v0.3.3 // indirect
3465
go.yaml.in/yaml/v2 v2.4.2 // indirect
35-
golang.org/x/crypto v0.37.0 // indirect
36-
golang.org/x/net v0.39.0 // indirect
37-
golang.org/x/sys v0.32.0 // indirect
66+
golang.org/x/crypto v0.41.0 // indirect
67+
golang.org/x/net v0.43.0 // indirect
68+
golang.org/x/oauth2 v0.27.0 // indirect
69+
golang.org/x/sync v0.16.0 // indirect
70+
golang.org/x/sys v0.35.0 // indirect
71+
golang.org/x/term v0.34.0 // indirect
72+
golang.org/x/text v0.28.0 // indirect
73+
golang.org/x/time v0.10.0 // indirect
74+
gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect
75+
google.golang.org/protobuf v1.36.6 // indirect
76+
gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect
77+
gopkg.in/inf.v0 v0.9.1 // indirect
3878
gopkg.in/warnings.v0 v0.1.2 // indirect
3979
gopkg.in/yaml.v3 v3.0.1 // indirect
80+
k8s.io/apiextensions-apiserver v0.33.3 // indirect
81+
k8s.io/client-go v0.33.3 // indirect
82+
k8s.io/klog/v2 v2.130.1 // indirect
83+
k8s.io/kube-openapi v0.0.0-20250318190949-c8a335a9a2ff // indirect
84+
sigs.k8s.io/json v0.0.0-20241014173422-cfa47c3a1cc8 // indirect
85+
sigs.k8s.io/randfill v1.0.0 // indirect
86+
sigs.k8s.io/structured-merge-diff/v4 v4.7.0 // indirect
4087
)

0 commit comments

Comments
 (0)