Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions cmd/deploy_flux.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package cmd

import (
"fmt"

"github.com/openmcp-project/controller-utils/pkg/clusters"
"github.com/spf13/cobra"

"github.com/openmcp-project/bootstrapper/internal/flux_deployer"
logging "github.com/openmcp-project/bootstrapper/internal/log"
)

const (
flagOCMConfig = "ocm-config"
flagGitCredentials = "git-credentials"
flagKubeconfig = "kubeconfig"
flagFluxCDNamespace = "fluxcd-namespace"
)

// deployFluxCmd represents the "deploy flux" command
var deployFluxCmd = &cobra.Command{
Use: "deploy-flux source target",
Short: "Transfer an OCM component from a source to a target location",
Long: `Transfers the specified OCM component version from the source location to the target location.`,
Args: cobra.ExactArgs(5),
ArgAliases: []string{
"component-location",
"deployment-templates",
"deployment-repository",
"deployment-repository-branch",
"deployment-repository-path",
},
RunE: func(cmd *cobra.Command, args []string) error {
log := logging.GetLogger()
log.Infof("Starting flux deployment with component-location: %s, deployment-templates: %s, "+
"deployment-repository: %s, deployment-repository-branch: %s, deployment-repository-path: %s",
args[0], args[1], args[2], args[3], args[4])

platformKubeconfig := cmd.Flag(flagKubeconfig).Value.String()
platformCluster := clusters.New("platform").WithConfigPath(platformKubeconfig)
if err := platformCluster.InitializeRESTConfig(); err != nil {
return fmt.Errorf("error initializing REST config for platform cluster: %w", err)
}
if err := platformCluster.InitializeClient(nil); err != nil {
return fmt.Errorf("error initializing client for platform cluster: %w", err)
}

d := flux_deployer.NewFluxDeployer(args[0], args[1], args[2], args[3], args[4],
cmd.Flag(flagOCMConfig).Value.String(),
cmd.Flag(flagGitCredentials).Value.String(),
cmd.Flag(flagFluxCDNamespace).Value.String(),
platformKubeconfig,
platformCluster, log)
err := d.Deploy(cmd.Context())
if err != nil {
log.Errorf("Flux deployment failed: %v", err)
return err
}

log.Info("Flux deployment completed")
return nil
},
}

func init() {
RootCmd.AddCommand(deployFluxCmd)

deployFluxCmd.Flags().StringP(flagOCMConfig, "c", "", "ocm configuration file")
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.")
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.")
deployFluxCmd.Flags().StringP(flagFluxCDNamespace, "n", "", "namespace on the Kubernetes cluster in which the namespaced fluxcd resources will be deployed. Default 'flux-system'.")
}
57 changes: 52 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,84 @@ go 1.25.0

require (
github.com/go-git/go-git/v5 v5.16.2
github.com/openmcp-project/controller-utils v0.17.0
github.com/sirupsen/logrus v1.9.3
github.com/spf13/cobra v1.9.1
github.com/stretchr/testify v1.11.0
k8s.io/api v0.33.3
k8s.io/apimachinery v0.33.3
k8s.io/utils v0.0.0-20250820121507-0af2bda4dd1d
sigs.k8s.io/controller-runtime v0.21.0
sigs.k8s.io/yaml v1.6.0
)

require (
dario.cat/mergo v1.0.0 // indirect
github.com/Microsoft/go-winio v0.6.2 // indirect
github.com/ProtonMail/go-crypto v1.1.6 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/cloudflare/circl v1.6.1 // indirect
github.com/cyphar/filepath-securejoin v0.4.1 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/emicklei/go-restful/v3 v3.12.1 // indirect
github.com/emirpasic/gods v1.18.1 // indirect
github.com/evanphx/json-patch/v5 v5.9.11 // indirect
github.com/fsnotify/fsnotify v1.8.0 // indirect
github.com/fxamacker/cbor/v2 v2.7.0 // indirect
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
github.com/go-git/go-billy/v5 v5.6.2 // indirect
github.com/go-logr/logr v1.4.3 // indirect
github.com/go-openapi/jsonpointer v0.21.0 // indirect
github.com/go-openapi/jsonreference v0.21.0 // indirect
github.com/go-openapi/swag v0.23.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/groupcache v0.0.0-20241129210726-2c02b8208cf8 // indirect
github.com/google/btree v1.1.3 // indirect
github.com/google/gnostic-models v0.6.9 // indirect
github.com/google/go-cmp v0.7.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/kevinburke/ssh_config v1.2.0 // indirect
github.com/mailru/easyjson v0.9.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/pjbgf/sha1cd v0.3.2 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/prometheus/client_golang v1.22.0 // indirect
github.com/prometheus/client_model v0.6.1 // indirect
github.com/prometheus/common v0.62.0 // indirect
github.com/prometheus/procfs v0.15.1 // indirect
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 // indirect
github.com/skeema/knownhosts v1.3.1 // indirect
github.com/spf13/pflag v1.0.7 // indirect
github.com/x448/float16 v0.8.4 // indirect
github.com/xanzy/ssh-agent v0.3.3 // indirect
go.yaml.in/yaml/v2 v2.4.2 // indirect
golang.org/x/crypto v0.37.0 // indirect
golang.org/x/net v0.39.0 // indirect
golang.org/x/sys v0.32.0 // indirect
golang.org/x/crypto v0.41.0 // indirect
golang.org/x/net v0.43.0 // indirect
golang.org/x/oauth2 v0.27.0 // indirect
golang.org/x/sync v0.16.0 // indirect
golang.org/x/sys v0.35.0 // indirect
golang.org/x/term v0.34.0 // indirect
golang.org/x/text v0.28.0 // indirect
golang.org/x/time v0.10.0 // indirect
gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect
google.golang.org/protobuf v1.36.6 // indirect
gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/apiextensions-apiserver v0.33.3 // indirect
k8s.io/client-go v0.33.3 // indirect
k8s.io/klog/v2 v2.130.1 // indirect
k8s.io/kube-openapi v0.0.0-20250318190949-c8a335a9a2ff // indirect
sigs.k8s.io/json v0.0.0-20241014173422-cfa47c3a1cc8 // indirect
sigs.k8s.io/randfill v1.0.0 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.7.0 // indirect
)
Loading