diff --git a/README.md b/README.md index f0cf82e..f356a75 100644 --- a/README.md +++ b/README.md @@ -7,17 +7,22 @@ The openmcp bootstrapper is a command line tool that is able to set up an openmcp landscape initially and to update existing openmcp landscapes with new versions of the openmcp project. Supported commands: -* `ocmTransfer`: Transfers the specified OCM component version from the source location to the target location. +* `ocm-transfer`: Transfers the specified OCM component version from the source location to the target location. +* `deploy-flux`: Deploys the FluxCD components to the specified Kubernetes cluster. +* `manage-deployment-repo`: Templates the openMCP git ops templates and applies them to the specified git repository and all kustomized resources to the specified Kubernetes cluster. -### `ocmTransfer` +Supported global flags: +* `--verbosity`: Sets the verbosity level of the logging output. Supported levels are `trace`, `debug`, `info`, `warn`, `error`. Default is `info`. -The `ocmTransfer` command is used to transfer an OCM component version from a source location to a target location. -The `ocmTransfer` requires the following parameters: +### `ocm-transfer` + +The `ocm-transfer` command is used to transfer an OCM component version from a source location to a target location. +The `ocm-transfer` requires the following parameters: * `source`: The source location of the OCM component version to be transferred. * `target`: The target location where the OCM component version should be transferred to. Optional parameters: -* `--config`: Path to the OCM configuration file. +* `--ocm-config`: Path to the OCM configuration file. ```shell openmcp-bootstrapper ocmTransfer --config @@ -31,11 +36,149 @@ ocm --config transfer componentversion --recursive --copy-r Example: ```shell -openmcp-bootstrapper ocmTransfer ghcr.io/openmcp-project/components//github.com/openmcp-project/openmcp:v0.0.11 ./ctf -openmcp-bootstrapper ocmTransfer ghcr.io/openmcp-project/components//github.com/openmcp-project/openmcp:v0.0.11 ghcr.io/my-github-user +openmcp-bootstrapper ocm-transfer ghcr.io/openmcp-project/components//github.com/openmcp-project/openmcp:v0.0.11 ./ctf +openmcp-bootstrapper ocm-transfer ghcr.io/openmcp-project/components//github.com/openmcp-project/openmcp:v0.0.11 ghcr.io/my-github-user +``` + +## `deploy-flux` + +The `deploy-flux` command is used to deploy the FluxCD components to a Kubernetes cluster. +The `deploy-flux` command requires the following parameters: +* `bootstrapper-config`: Path to the bootstrapper configuration file. + +Optional parameters: +* `--kubeconfig`: Path to the kubeconfig file of the target Kubernetes cluster. If not set, the value of the `KUBECONFIG` environment variable will be used. If the `KUBECONFIG` environment variable is not set, the default kubeconfig file located at `$HOME/.kube/config` will be used. +* `--ocm-config`: Path to the OCM configuration file. +* `--git-config`: Path to the git configuration file containing the credentials for accessing the git repository. If not set, no authentication will be configured. + +### bootstrapper configuration file + +The `deploy-flux` command requires a bootstrapper configuration file in YAML format. The configuration file contains the following sections: +* `component` (required): The OCM component version to be deployed. The location must be in the format `//:`. For example: `ghcr.io/openmcp-project/components//github.com/openmcp-project/openmcp:v0.0.18`. +* `repository` (required): The git repository where the FluxCD components should be deployed to. The `url` field specifies the URL of the git repository and the `branch` field specifies the branch to be used. +* `environment` (required): The name of the openMCP environment that shall be managed by FluxCD. For example: `dev`, `prod`, `dev-eu10`, etc. + +```yaml +component: + location: //: + +repository: + url: + branch: + +environment: + name: +``` + +Example: +```shell +openmcp-bootstrapper deploy-flux ./examples/bootstrapper-config.yaml --kubeconfig ~/.kube/config --ocm-config ./examples/ocm-config.yaml --git-config ./examples/git-config.yaml ./examples/bootstrapper-config.yaml ``` +## `manage-deployment-repo` + +The `manageDeploymentRepo` command is used to template the openMCP git ops templates and apply them to the specified git repository and all kustomized resources to the specified Kubernetes cluster. +The `manageDeploymentRepo` command requires the following parameters: +* `bootstrapper-config`: Path to the bootstrapper configuration file. +* `--git-config`: Path to the git configuration file containing the credentials for accessing the git repository. +Optional parameters: +* `--kubeconfig`: Path to the kubeconfig file of the target Kubernetes cluster. If not set, the value of the `KUBECONFIG` environment variable will be used. If the `KUBECONFIG` environment variable is not set, the default kubeconfig file located at `$HOME/.kube/config` will be used. +* `--ocm-config`: Path to the OCM configuration file. +* `--extra-manifest-dir` (repeatable): Path to an extra manifest directory that should be added to the kustomization. This can be used to add custom resources to the deployment. +* + + +The `manage-deployment-repo` requires a bootstrapper configuration file in YAML format. The configuration file contains the following sections: +* `component` (required): The OCM component version to be deployed. The location must be in the format `//:`. For example: `gh +* `repository` (required): The git repository where the FluxCD components should be deployed to. The `url` field specifies the URL of the git repository and the `branch` field specifies the branch to be used. +* `environment` (required): The name of the openMCP environment that shall be managed by FluxCD. For example: `dev`, `prod`, `dev-eu10`, etc. +* `imagePullSecrets` (optional): A list of image pull secrets that shall be used for all Kubernetes deployments created by the bootstrapper. The secrets must already exist in the target cluster in the namespace `openmcp-system`. +* `providers` (optional): A list of `cluster-providers`, `service-providers`, and `platform-services` that shall be enabled in the deployment. Each provider can have its own configuration. +* `openmcpOperator` (required): Configuration for the openmcp operator. + +```yaml +component: + location: //: + +repository: + url: + branch: + +environment: + name: + +imagePullSecrets: +- + +providers: + clusterProviders: + - name: kind + config: + extraVolumeMounts: + - mountPath: /var/run/docker.sock + name: docker + extraVolumes: + - name: docker + hostPath: + path: /var/run/host-docker.sock + type: Socket + verbosity: debug + serviceProviders: + - name: landscaper + config: + verbosity: debug + + platformServices: [] + + openmcpOperator: + config: + managedControlPlane: + mcpClusterPurpose: mcp-worker + reconcileMCPEveryXDays: 7 + scheduler: + scope: Cluster + purposeMappings: + mcp: + template: + spec: + profile: kind + tenancy: Exclusive + mcp-worker: + template: + spec: + profile: kind + tenancy: Exclusive + platform: + template: + metadata: + labels: + clusters.openmcp.cloud/delete-without-requests: "false" + spec: + profile: kind + tenancy: Shared + onboarding: + template: + metadata: + labels: + clusters.openmcp.cloud/delete-without-requests: "false" + spec: + profile: kind + tenancy: Shared + workload: + tenancyCount: 20 + template: + metadata: + namespace: workload-clusters + spec: + profile: kind + tenancy: Shared +``` + +Example: +```shell +openmcp-bootstrapper manage-deployment-repo --kubeconfig ~/.kube/config --ocm-config ./examples/ocm-config.yaml --git-config ./examples/git-config.yaml --extra-manifest-dir ./my-custom-manifests ./examples/bootstrapper-config.yaml +``` ## Requirements and Setup diff --git a/cmd/constants.go b/cmd/constants.go new file mode 100644 index 0000000..cd5bf4b --- /dev/null +++ b/cmd/constants.go @@ -0,0 +1,7 @@ +package cmd + +const ( + FlagGitConfig = "git-config" + FlagOcmConfig = "ocm-config" + FlagKubeConfig = "kubeconfig" +) diff --git a/cmd/deploy_flux.go b/cmd/deploy_flux.go index e9c75c9..d0c9186 100644 --- a/cmd/deploy_flux.go +++ b/cmd/deploy_flux.go @@ -22,6 +22,7 @@ var deployFluxCmd = &cobra.Command{ ArgAliases: []string{ "configFile", }, + Example: ` openmcp-bootstrapper deploy-flux "./config.yaml"`, RunE: func(cmd *cobra.Command, args []string) error { configFilePath := args[0] diff --git a/cmd/manageDeploymentRepo.go b/cmd/manage_deployment_repo.go similarity index 93% rename from cmd/manageDeploymentRepo.go rename to cmd/manage_deployment_repo.go index 2426f40..bba33f0 100644 --- a/cmd/manageDeploymentRepo.go +++ b/cmd/manage_deployment_repo.go @@ -17,9 +17,6 @@ import ( ) const ( - FlagGitConfig = "git-config" - FlagOcmConfig = "ocm-config" - FlagKubeConfig = "kubeconfig" FlagExtraManifestDir = "extra-manifest-dir" ) @@ -33,16 +30,16 @@ func (w LogWriter) Write(p []byte) (n int, err error) { // manageDeploymentRepoCmd represents the manageDeploymentRepo command var manageDeploymentRepoCmd = &cobra.Command{ - Use: "manageDeploymentRepo", + Use: "manage-deployment-repo", Short: "Updates the openMCP deployment specification in the specified Git repository", Long: `Updates the openMCP deployment specification in the specified Git repository. The update is based on the specified component version. -openmcp-bootstrapper manageDeploymentRepo `, +openmcp-bootstrapper manage-deployment-repo `, Args: cobra.ExactArgs(1), ArgAliases: []string{ "configFile", }, - Example: ` openmcp-bootstrapper manageDeploymentRepo "./config.yaml"`, + Example: ` openmcp-bootstrapper manage-deployment-repo "./config.yaml"`, RunE: func(cmd *cobra.Command, args []string) error { configFilePath := args[0] diff --git a/cmd/ocmTransfer.go b/cmd/ocm_transfer.go similarity index 79% rename from cmd/ocmTransfer.go rename to cmd/ocm_transfer.go index c515a82..9ae2cf4 100644 --- a/cmd/ocmTransfer.go +++ b/cmd/ocm_transfer.go @@ -9,7 +9,7 @@ import ( // ocmTransferCmd represents the "ocm transfer componentversion" command var ocmTransferCmd = &cobra.Command{ - Use: "ocmTransfer source target", + Use: "ocm-transfer 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.`, Aliases: []string{ @@ -23,7 +23,7 @@ var ocmTransferCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) error { log := log.GetLogger() - log.Debugf("Executing ocmTransfer with source: %s, target: %s", args[0], args[1]) + log.Debugf("Executing ocm-transfer with source: %s, target: %s", args[0], args[1]) transferCommands := []string{ "transfer", @@ -38,12 +38,12 @@ var ocmTransferCmd = &cobra.Command{ args[1], // target } - return ocmcli.Execute(cmd.Context(), transferCommands, transferArgs, cmd.Flag("config").Value.String()) + return ocmcli.Execute(cmd.Context(), transferCommands, transferArgs, cmd.Flag(FlagOcmConfig).Value.String()) }, } func init() { RootCmd.AddCommand(ocmTransferCmd) - ocmTransferCmd.PersistentFlags().StringP("config", "c", "", "ocm configuration file") + ocmTransferCmd.PersistentFlags().String(FlagOcmConfig, "", "ocm configuration file") } diff --git a/cmd/ocmTransfer_test.go b/cmd/ocm_transfer_test.go similarity index 97% rename from cmd/ocmTransfer_test.go rename to cmd/ocm_transfer_test.go index c65f1b2..b141df6 100644 --- a/cmd/ocmTransfer_test.go +++ b/cmd/ocm_transfer_test.go @@ -44,7 +44,7 @@ func TestOcmTransfer(t *testing.T) { for _, tc := range testCases { t.Run(tc.desc, func(t *testing.T) { root := cmd.RootCmd - args := []string{"ocmTransfer"} + args := []string{"ocm-transfer"} if len(tc.arguments) > 0 { args = append(args, tc.arguments...) }