diff --git a/cli/cmd/add_cluster_admin.go b/cli/cmd/add_cluster_admin.go index 8623cfc77..7b8d17f70 100644 --- a/cli/cmd/add_cluster_admin.go +++ b/cli/cmd/add_cluster_admin.go @@ -7,8 +7,9 @@ import ( "fmt" packageio "github.com/codesphere-cloud/cs-go/pkg/io" + "github.com/codesphere-cloud/oms/cli/cmd/util" "github.com/codesphere-cloud/oms/internal/clusteradmin" - "github.com/codesphere-cloud/oms/internal/util" + intutil "github.com/codesphere-cloud/oms/internal/util" "github.com/spf13/cobra" ) @@ -18,12 +19,12 @@ type AddClusterAdminCmd struct { } type AddClusterAdminOpts struct { - *GlobalOptions + *util.GlobalOptions clusteradmin.Opts } func (c *AddClusterAdminCmd) RunE(_ *cobra.Command, _ []string) error { - clientset, _, err := util.NewClients() + clientset, _, err := intutil.NewClients() if err != nil { return fmt.Errorf("failed to create kubernetes client: %w", err) } @@ -31,7 +32,7 @@ func (c *AddClusterAdminCmd) RunE(_ *cobra.Command, _ []string) error { return clusteradmin.AddClusterAdmin(c.cmd.Context(), clientset, c.Opts.Opts) } -func AddAddClusterAdminCmd(parent *cobra.Command, opts *GlobalOptions) { +func AddAddClusterAdminCmd(parent *cobra.Command, opts *util.GlobalOptions) { c := AddClusterAdminCmd{ cmd: &cobra.Command{ Use: "add-cluster-admin", @@ -43,7 +44,7 @@ func AddAddClusterAdminCmd(parent *cobra.Command, opts *GlobalOptions) { The target cluster is determined by the current kubeconfig context. Set the KUBECONFIG environment variable to target a different kubeconfig.`), - Example: formatExamples("add-cluster-admin", []packageio.Example{ + Example: util.FormatExamples("add-cluster-admin", []packageio.Example{ {Cmd: "--email niklas@codesphere.com", Desc: "Set the cluster admin email using the default secret and namespace"}, {Cmd: "--email admin@codesphere.com --namespace kube-system --secret-name cluster-admin-email", Desc: "Set the cluster admin email in a custom namespace"}, }), @@ -59,5 +60,5 @@ func AddAddClusterAdminCmd(parent *cobra.Command, opts *GlobalOptions) { util.MarkFlagRequired(c.cmd, "email") - AddCmd(parent, c.cmd) + util.AddCmd(parent, c.cmd) } diff --git a/cli/cmd/argocd.go b/cli/cmd/argocd.go index 59601d165..7664197c3 100644 --- a/cli/cmd/argocd.go +++ b/cli/cmd/argocd.go @@ -8,6 +8,7 @@ import ( "os" packageio "github.com/codesphere-cloud/cs-go/pkg/io" + "github.com/codesphere-cloud/oms/cli/cmd/util" argocdinstaller "github.com/codesphere-cloud/oms/internal/installer/argocd" "github.com/spf13/cobra" "golang.org/x/term" @@ -20,7 +21,7 @@ type InstallArgoCDCmd struct { } type InstallArgoCDOpts struct { - *GlobalOptions + *util.GlobalOptions Version string DatacenterId string RegistryURL string @@ -87,7 +88,7 @@ func resolveOCIPassword() (string, error) { return string(pw), nil } -func AddArgoCDCmd(parentCmd *cobra.Command, opts *GlobalOptions) { +func AddArgoCDCmd(parentCmd *cobra.Command, opts *util.GlobalOptions) { argocd := InstallArgoCDCmd{ cmd: &cobra.Command{ Use: "argocd", @@ -106,7 +107,7 @@ func AddArgoCDCmd(parentCmd *cobra.Command, opts *GlobalOptions) { Environment variables: OMS_REGISTRY_PASSWORD Password/token for the Helm OCI registry (required for --deploy-dc-config) OMS_GIT_PASSWORD Password/token for git repo access (optional)`), - Example: formatExamples("beta install argocd", []packageio.Example{ + Example: util.FormatExamples("beta install argocd", []packageio.Example{ {Cmd: "", Desc: "Install ArgoCD helm chart only"}, {Cmd: "--version 7.8.0", Desc: "Install a specific chart version"}, {Cmd: "--deploy-dc-config", Desc: "Install chart and apply Codesphere resources (prompts for OCI password)"}, @@ -123,5 +124,5 @@ func AddArgoCDCmd(parentCmd *cobra.Command, opts *GlobalOptions) { argocd.cmd.Flags().StringVar(&argocd.Opts.RepoURL, "repo", "", "Helm chart repository URL; supports HTTP (default: https://argoproj.github.io/argo-helm) and OCI (e.g. oci://ghcr.io/argoproj/argo-helm)") argocd.cmd.RunE = argocd.RunE - AddCmd(parentCmd, argocd.cmd) + util.AddCmd(parentCmd, argocd.cmd) } diff --git a/cli/cmd/beta.go b/cli/cmd/beta.go index 7bdd594cb..5fed327b2 100644 --- a/cli/cmd/beta.go +++ b/cli/cmd/beta.go @@ -5,6 +5,7 @@ package cmd import ( "github.com/codesphere-cloud/cs-go/pkg/io" + "github.com/codesphere-cloud/oms/cli/cmd/util" "github.com/spf13/cobra" ) @@ -12,7 +13,7 @@ type BetaCmd struct { cmd *cobra.Command } -func AddBetaCmd(rootCmd *cobra.Command, opts *GlobalOptions) { +func AddBetaCmd(rootCmd *cobra.Command, opts *util.GlobalOptions) { beta := BetaCmd{ cmd: &cobra.Command{ Use: "beta", @@ -21,7 +22,7 @@ func AddBetaCmd(rootCmd *cobra.Command, opts *GlobalOptions) { Be aware that that usage and behavior may change as the features are developed.`), }, } - AddCmd(rootCmd, beta.cmd) + util.AddCmd(rootCmd, beta.cmd) AddExtendCmd(beta.cmd, opts) AddBootstrapGcpCmd(beta.cmd, opts) diff --git a/cli/cmd/beta_install.go b/cli/cmd/beta_install.go index d9c56e201..f8e42521a 100644 --- a/cli/cmd/beta_install.go +++ b/cli/cmd/beta_install.go @@ -4,6 +4,7 @@ package cmd import ( + "github.com/codesphere-cloud/oms/cli/cmd/util" "github.com/spf13/cobra" ) @@ -12,14 +13,14 @@ type BetaInstallCmd struct { cmd *cobra.Command } -func AddBetaInstallCmd(rootCmd *cobra.Command, opts *GlobalOptions) { +func AddBetaInstallCmd(rootCmd *cobra.Command, opts *util.GlobalOptions) { install := BetaInstallCmd{ cmd: &cobra.Command{ Use: "install", Short: "Install beta components", }, } - AddCmd(rootCmd, install.cmd) + util.AddCmd(rootCmd, install.cmd) AddArgoCDCmd(install.cmd, opts) AddPCAppsCmd(install.cmd, opts) } diff --git a/cli/cmd/beta_vault_secret.go b/cli/cmd/beta_vault_secret.go index a51155013..2a5d8dd75 100644 --- a/cli/cmd/beta_vault_secret.go +++ b/cli/cmd/beta_vault_secret.go @@ -7,8 +7,8 @@ import ( "fmt" packageio "github.com/codesphere-cloud/cs-go/pkg/io" + "github.com/codesphere-cloud/oms/cli/cmd/util" "github.com/codesphere-cloud/oms/internal/installer/vault" - "github.com/codesphere-cloud/oms/internal/util" "github.com/spf13/cobra" "k8s.io/apimachinery/pkg/runtime" clientgoscheme "k8s.io/client-go/kubernetes/scheme" @@ -22,7 +22,7 @@ type BetaVaultSecretCmd struct { } type BetaVaultSecretOpts struct { - *GlobalOptions + *util.GlobalOptions VaultFile string AgeKeyPath string Namespace string @@ -50,7 +50,7 @@ func (c *BetaVaultSecretCmd) RunE(_ *cobra.Command, _ []string) error { return creator.CreateSecretFromFile(c.cmd.Context(), c.Opts.VaultFile, c.Opts.AgeKeyPath, c.Opts.Namespace, c.Opts.SecretName) } -func AddBetaVaultSecretCmd(parentCmd *cobra.Command, opts *GlobalOptions) { +func AddBetaVaultSecretCmd(parentCmd *cobra.Command, opts *util.GlobalOptions) { cmd := BetaVaultSecretCmd{ cmd: &cobra.Command{ Use: "vault-secret", @@ -58,7 +58,7 @@ func AddBetaVaultSecretCmd(parentCmd *cobra.Command, opts *GlobalOptions) { Long: packageio.Long(`Create a Kubernetes secret from a SOPS-encrypted prod.vault.yaml file. Reads the encrypted vault file, decrypts it using the age key, and creates a Kubernetes secret with all the vault entries as key-value pairs in the target cluster.`), - Example: formatExamples("vault-secret", []packageio.Example{ + Example: util.FormatExamples("vault-secret", []packageio.Example{ {Cmd: "--vault-file prod.vault.yaml --namespace default --secret-name vault-secrets", Desc: "Create secret using default age key location"}, {Cmd: "--vault-file prod.vault.yaml --age-key /path/to/age_key.txt --namespace kube-system --secret-name cluster-secrets", Desc: "Create secret with explicit age key path"}, }), @@ -74,5 +74,5 @@ func AddBetaVaultSecretCmd(parentCmd *cobra.Command, opts *GlobalOptions) { util.MarkFlagRequired(cmd.cmd, "vault-file") cmd.cmd.RunE = cmd.RunE - AddCmd(parentCmd, cmd.cmd) + util.AddCmd(parentCmd, cmd.cmd) } diff --git a/cli/cmd/bootstrap_gcp.go b/cli/cmd/bootstrap_gcp.go index 366bad908..8f87eae55 100644 --- a/cli/cmd/bootstrap_gcp.go +++ b/cli/cmd/bootstrap_gcp.go @@ -11,6 +11,7 @@ import ( "github.com/spf13/cobra" "github.com/codesphere-cloud/cs-go/pkg/io" + "github.com/codesphere-cloud/oms/cli/cmd/util" "github.com/codesphere-cloud/oms/internal/bootstrap" "github.com/codesphere-cloud/oms/internal/bootstrap/gcp" "github.com/codesphere-cloud/oms/internal/env" @@ -18,12 +19,12 @@ import ( "github.com/codesphere-cloud/oms/internal/installer" "github.com/codesphere-cloud/oms/internal/installer/node" "github.com/codesphere-cloud/oms/internal/portal" - "github.com/codesphere-cloud/oms/internal/util" + intutil "github.com/codesphere-cloud/oms/internal/util" ) type BootstrapGcpCmd struct { cmd *cobra.Command - Opts *GlobalOptions + Opts *util.GlobalOptions Env env.Env CodesphereEnv *gcp.CodesphereEnvironment InputRegistryType string @@ -42,7 +43,7 @@ func (c *BootstrapGcpCmd) RunE(_ *cobra.Command, args []string) error { return nil } -func AddBootstrapGcpCmd(parent *cobra.Command, opts *GlobalOptions) { +func AddBootstrapGcpCmd(parent *cobra.Command, opts *util.GlobalOptions) { bootstrapGcpCmd := BootstrapGcpCmd{ cmd: &cobra.Command{ Use: "bootstrap-gcp", @@ -139,7 +140,7 @@ func AddBootstrapGcpCmd(parent *cobra.Command, opts *GlobalOptions) { util.MarkFlagRequired(bootstrapGcpCmd.cmd, "billing-account") util.MarkFlagRequired(bootstrapGcpCmd.cmd, "base-domain") - AddCmd(parent, bootstrapGcpCmd.cmd) + util.AddCmd(parent, bootstrapGcpCmd.cmd) AddBootstrapGcpPostconfigCmd(bootstrapGcpCmd.cmd, opts) AddBootstrapGcpCleanupCmd(bootstrapGcpCmd.cmd, opts) AddBootstrapGcpRestartVMsCmd(bootstrapGcpCmd.cmd, opts) @@ -150,7 +151,7 @@ func (c *BootstrapGcpCmd) BootstrapGcp() error { stlog := bootstrap.NewStepLogger(false) icg := installer.NewInstallConfigManager() gcpClient := gcp.NewGCPClient(ctx, stlog, os.Getenv("GOOGLE_APPLICATION_CREDENTIALS")) - fw := util.NewFilesystemWriter() + fw := intutil.NewFilesystemWriter() portalClient := portal.NewPortalClient() githubClient := github.NewGitHubClient(ctx, c.CodesphereEnv.GitHubPAT) @@ -164,7 +165,7 @@ func (c *BootstrapGcpCmd) BootstrapGcp() error { fw, node.NewSSHNodeClient(c.SSHQuiet), portalClient, - util.NewTime(), + intutil.NewTime(), githubClient, ) if err != nil { diff --git a/cli/cmd/bootstrap_gcp_cleanup.go b/cli/cmd/bootstrap_gcp_cleanup.go index ee71c0e0c..0c73f600c 100644 --- a/cli/cmd/bootstrap_gcp_cleanup.go +++ b/cli/cmd/bootstrap_gcp_cleanup.go @@ -9,9 +9,10 @@ import ( "os" csio "github.com/codesphere-cloud/cs-go/pkg/io" + "github.com/codesphere-cloud/oms/cli/cmd/util" "github.com/codesphere-cloud/oms/internal/bootstrap" "github.com/codesphere-cloud/oms/internal/bootstrap/gcp" - "github.com/codesphere-cloud/oms/internal/util" + intutil "github.com/codesphere-cloud/oms/internal/util" "github.com/spf13/cobra" ) @@ -21,7 +22,7 @@ type BootstrapGcpCleanupCmd struct { } type BootstrapGcpCleanupOpts struct { - *GlobalOptions + *util.GlobalOptions ProjectID string Force bool SkipDNSCleanup bool @@ -34,7 +35,7 @@ func (c *BootstrapGcpCleanupCmd) RunE(_ *cobra.Command, args []string) error { ctx := c.cmd.Context() stlog := bootstrap.NewStepLogger(false) gcpClient := gcp.NewGCPClient(ctx, stlog, os.Getenv("GOOGLE_APPLICATION_CREDENTIALS")) - fw := util.NewFilesystemWriter() + fw := intutil.NewFilesystemWriter() deps := &gcp.CleanupDeps{ GCPClient: gcpClient, @@ -88,13 +89,13 @@ func (c *BootstrapGcpCleanupCmd) ExecuteCleanup(deps *gcp.CleanupDeps) error { return nil } -func AddBootstrapGcpCleanupCmd(bootstrapGcp *cobra.Command, opts *GlobalOptions) { +func AddBootstrapGcpCleanupCmd(bootstrapGcp *cobra.Command, opts *util.GlobalOptions) { cleanup := BootstrapGcpCleanupCmd{ cmd: &cobra.Command{ Use: "cleanup", Short: "Clean up GCP infrastructure created by bootstrap-gcp", Long: csio.Long(`Deletes a GCP project that was previously created using the bootstrap-gcp command.`), - Example: formatExamples("beta bootstrap-gcp cleanup", []csio.Example{ + Example: util.FormatExamples("beta bootstrap-gcp cleanup", []csio.Example{ {Desc: "Clean up using project ID from the local infra file"}, {Cmd: "--project-id my-project-abc123", Desc: "Clean up a specific project"}, {Cmd: "--project-id my-project-abc123 --force", Desc: "Force cleanup without confirmation (skips OMS-managed check)"}, @@ -116,5 +117,5 @@ func AddBootstrapGcpCleanupCmd(bootstrapGcp *cobra.Command, opts *GlobalOptions) flags.StringVar(&cleanup.Opts.DNSProjectID, "dns-project-id", "", "GCP Project ID for DNS zone (optional, will use infra file if not provided)") cleanup.cmd.RunE = cleanup.RunE - AddCmd(bootstrapGcp, cleanup.cmd) + util.AddCmd(bootstrapGcp, cleanup.cmd) } diff --git a/cli/cmd/bootstrap_gcp_cleanup_test.go b/cli/cmd/bootstrap_gcp_cleanup_test.go index 9ad3e0070..3337fd4ca 100644 --- a/cli/cmd/bootstrap_gcp_cleanup_test.go +++ b/cli/cmd/bootstrap_gcp_cleanup_test.go @@ -14,19 +14,20 @@ import ( "github.com/spf13/cobra" "github.com/codesphere-cloud/oms/cli/cmd" + "github.com/codesphere-cloud/oms/cli/cmd/util" "github.com/codesphere-cloud/oms/internal/bootstrap" "github.com/codesphere-cloud/oms/internal/bootstrap/gcp" - "github.com/codesphere-cloud/oms/internal/util" + intutil "github.com/codesphere-cloud/oms/internal/util" ) var _ = Describe("BootstrapGcpCleanupCmd", func() { var ( opts *cmd.BootstrapGcpCleanupOpts - globalOpts *cmd.GlobalOptions + globalOpts *util.GlobalOptions ) BeforeEach(func() { - globalOpts = &cmd.GlobalOptions{} + globalOpts = &util.GlobalOptions{} opts = &cmd.BootstrapGcpCleanupOpts{ GlobalOptions: globalOpts, ProjectID: "", @@ -142,7 +143,7 @@ var _ = Describe("BootstrapGcpCleanupCmd", func() { Context("when created", func() { It("should hold all required dependencies", func() { mockGCPClient := gcp.NewMockGCPClientManager(GinkgoT()) - mockFileIO := util.NewMockFileIO(GinkgoT()) + mockFileIO := intutil.NewMockFileIO(GinkgoT()) stlog := bootstrap.NewStepLogger(false) confirmReader := bytes.NewBufferString("test-project\n") @@ -167,13 +168,13 @@ var _ = Describe("BootstrapGcpCleanupCmd", func() { var ( cleanupCmd *cmd.BootstrapGcpCleanupCmd mockGCPClient *gcp.MockGCPClientManager - mockFileIO *util.MockFileIO + mockFileIO *intutil.MockFileIO deps *gcp.CleanupDeps ) BeforeEach(func() { mockGCPClient = gcp.NewMockGCPClientManager(GinkgoT()) - mockFileIO = util.NewMockFileIO(GinkgoT()) + mockFileIO = intutil.NewMockFileIO(GinkgoT()) cleanupCmd = &cmd.BootstrapGcpCleanupCmd{ Opts: &cmd.BootstrapGcpCleanupOpts{ diff --git a/cli/cmd/bootstrap_gcp_postconfig.go b/cli/cmd/bootstrap_gcp_postconfig.go index 961e2baf9..d0eb064b9 100644 --- a/cli/cmd/bootstrap_gcp_postconfig.go +++ b/cli/cmd/bootstrap_gcp_postconfig.go @@ -8,9 +8,10 @@ import ( "log" "github.com/codesphere-cloud/cs-go/pkg/io" + "github.com/codesphere-cloud/oms/cli/cmd/util" "github.com/codesphere-cloud/oms/internal/bootstrap/gcp" "github.com/codesphere-cloud/oms/internal/installer" - "github.com/codesphere-cloud/oms/internal/util" + intutil "github.com/codesphere-cloud/oms/internal/util" "github.com/spf13/cobra" ) @@ -22,7 +23,7 @@ type BootstrapGcpPostconfigCmd struct { } type BootstrapGcpPostconfigOpts struct { - *GlobalOptions + *util.GlobalOptions InstallConfigPath string PrivateKeyPath string } @@ -31,7 +32,7 @@ func (c *BootstrapGcpPostconfigCmd) RunE(_ *cobra.Command, args []string) error log.Printf("running post-configuration steps...") icg := installer.NewInstallConfigManager() - fw := util.NewFilesystemWriter() + fw := intutil.NewFilesystemWriter() infraFilePath := gcp.GetInfraFilePath() codesphereEnv, exists, err := gcp.LoadInfraFile(fw, infraFilePath) @@ -51,7 +52,7 @@ func (c *BootstrapGcpPostconfigCmd) RunE(_ *cobra.Command, args []string) error return fmt.Errorf("not implemented: run config script on k0s-1 node to install GCP CCM") } -func AddBootstrapGcpPostconfigCmd(bootstrapGcp *cobra.Command, opts *GlobalOptions) { +func AddBootstrapGcpPostconfigCmd(bootstrapGcp *cobra.Command, opts *util.GlobalOptions) { postconfig := BootstrapGcpPostconfigCmd{ cmd: &cobra.Command{ Use: "postconfig", @@ -70,6 +71,6 @@ func AddBootstrapGcpPostconfigCmd(bootstrapGcp *cobra.Command, opts *GlobalOptio flags.StringVar(&postconfig.Opts.InstallConfigPath, "install-config-path", "config.yaml", "Path to the installation configuration file") flags.StringVar(&postconfig.Opts.PrivateKeyPath, "private-key-path", "", "Path to the GCP service account private key file (optional)") - AddCmd(bootstrapGcp, postconfig.cmd) + util.AddCmd(bootstrapGcp, postconfig.cmd) postconfig.cmd.RunE = postconfig.RunE } diff --git a/cli/cmd/bootstrap_gcp_restart_vms.go b/cli/cmd/bootstrap_gcp_restart_vms.go index 68f349338..900b93535 100644 --- a/cli/cmd/bootstrap_gcp_restart_vms.go +++ b/cli/cmd/bootstrap_gcp_restart_vms.go @@ -9,9 +9,10 @@ import ( "os" csio "github.com/codesphere-cloud/cs-go/pkg/io" + "github.com/codesphere-cloud/oms/cli/cmd/util" "github.com/codesphere-cloud/oms/internal/bootstrap" "github.com/codesphere-cloud/oms/internal/bootstrap/gcp" - "github.com/codesphere-cloud/oms/internal/util" + intutil "github.com/codesphere-cloud/oms/internal/util" "github.com/spf13/cobra" ) @@ -21,7 +22,7 @@ type BootstrapGcpRestartVMsCmd struct { } type BootstrapGcpRestartVMsOpts struct { - *GlobalOptions + *util.GlobalOptions ProjectID string Zone string Name string @@ -30,7 +31,7 @@ type BootstrapGcpRestartVMsOpts struct { // resolveProjectAndZone returns the project ID and zone from flags or the infra file. // If both flags are set they are used directly; if neither is set, the infra file is read. // Providing only one of --project-id / --zone is an error. -func (c *BootstrapGcpRestartVMsCmd) resolveProjectAndZone(fw util.FileIO) (string, string, error) { +func (c *BootstrapGcpRestartVMsCmd) resolveProjectAndZone(fw intutil.FileIO) (string, string, error) { projectID := c.Opts.ProjectID zone := c.Opts.Zone @@ -58,7 +59,7 @@ func (c *BootstrapGcpRestartVMsCmd) resolveProjectAndZone(fw util.FileIO) (strin func (c *BootstrapGcpRestartVMsCmd) RunE(_ *cobra.Command, _ []string) error { ctx := c.cmd.Context() stlog := bootstrap.NewStepLogger(false) - fw := util.NewFilesystemWriter() + fw := intutil.NewFilesystemWriter() projectID, zone, err := c.resolveProjectAndZone(fw) if err != nil { @@ -74,7 +75,7 @@ func (c *BootstrapGcpRestartVMsCmd) RunE(_ *cobra.Command, _ []string) error { bs, err := gcp.NewGCPBootstrapper( ctx, - nil, stlog, csEnv, nil, gcpClient, fw, nil, nil, util.NewTime(), nil, + nil, stlog, csEnv, nil, gcpClient, fw, nil, nil, intutil.NewTime(), nil, ) if err != nil { return fmt.Errorf("failed to create bootstrapper: %w", err) @@ -97,7 +98,7 @@ func (c *BootstrapGcpRestartVMsCmd) RunE(_ *cobra.Command, _ []string) error { return nil } -func AddBootstrapGcpRestartVMsCmd(bootstrapGcp *cobra.Command, opts *GlobalOptions) { +func AddBootstrapGcpRestartVMsCmd(bootstrapGcp *cobra.Command, opts *util.GlobalOptions) { restartVMs := BootstrapGcpRestartVMsCmd{ cmd: &cobra.Command{ Use: "restart-vms", @@ -107,7 +108,7 @@ func AddBootstrapGcpRestartVMsCmd(bootstrapGcp *cobra.Command, opts *GlobalOptio By default, restarts all VMs defined in the infrastructure. Use --name to restart a single VM. Project ID and zone are read from the local infra file if available`), - Example: formatExamples("beta bootstrap-gcp restart-vms", []csio.Example{ + Example: util.FormatExamples("beta bootstrap-gcp restart-vms", []csio.Example{ {Desc: "Restart all VMs using project info from the local infra file"}, {Cmd: "--name jumpbox", Desc: "Restart only the jumpbox VM"}, {Cmd: "--name k0s-1", Desc: "Restart a specific k0s node"}, diff --git a/cli/cmd/bootstrap_gcp_restart_vms_test.go b/cli/cmd/bootstrap_gcp_restart_vms_test.go index 7d7007730..7a9be24d2 100644 --- a/cli/cmd/bootstrap_gcp_restart_vms_test.go +++ b/cli/cmd/bootstrap_gcp_restart_vms_test.go @@ -9,16 +9,17 @@ import ( "github.com/spf13/cobra" "github.com/codesphere-cloud/oms/cli/cmd" + "github.com/codesphere-cloud/oms/cli/cmd/util" ) var _ = Describe("BootstrapGcpRestartVMsCmd", func() { var ( - globalOpts *cmd.GlobalOptions + globalOpts *util.GlobalOptions parentCmd *cobra.Command ) BeforeEach(func() { - globalOpts = &cmd.GlobalOptions{} + globalOpts = &util.GlobalOptions{} parentCmd = &cobra.Command{Use: "bootstrap-gcp"} cmd.AddBootstrapGcpRestartVMsCmd(parentCmd, globalOpts) }) diff --git a/cli/cmd/bootstrap_local.go b/cli/cmd/bootstrap_local.go index d3c2add1f..42202cd41 100644 --- a/cli/cmd/bootstrap_local.go +++ b/cli/cmd/bootstrap_local.go @@ -19,11 +19,12 @@ import ( cnpgv1 "github.com/cloudnative-pg/cloudnative-pg/api/v1" csio "github.com/codesphere-cloud/cs-go/pkg/io" + "github.com/codesphere-cloud/oms/cli/cmd/util" "github.com/codesphere-cloud/oms/internal/bootstrap" "github.com/codesphere-cloud/oms/internal/bootstrap/gcp" "github.com/codesphere-cloud/oms/internal/bootstrap/local" "github.com/codesphere-cloud/oms/internal/installer" - "github.com/codesphere-cloud/oms/internal/util" + intutil "github.com/codesphere-cloud/oms/internal/util" rookcephv1 "github.com/rook/rook/pkg/apis/ceph.rook.io/v1" "github.com/spf13/cobra" "golang.org/x/mod/semver" @@ -100,7 +101,7 @@ func AddBootstrapLocalCmd(parent *cobra.Command) { util.MarkFlagRequired(bootstrapLocalCmd.cmd, "registry-user") - AddCmd(parent, bootstrapLocalCmd.cmd) + util.AddCmd(parent, bootstrapLocalCmd.cmd) } func (c *BootstrapLocalCmd) BootstrapLocal() error { @@ -140,7 +141,7 @@ func (c *BootstrapLocalCmd) BootstrapLocal() error { stlog := bootstrap.NewStepLogger(false) icg := installer.NewInstallConfigManager() - fw := util.NewFilesystemWriter() + fw := intutil.NewFilesystemWriter() kubeClient, restConfig, err := c.GetKubeClient(ctx) if err != nil { return fmt.Errorf("failed to initialize Kubernetes client: %w", err) diff --git a/cli/cmd/build.go b/cli/cmd/build.go index d432d0ed7..8f8444aae 100644 --- a/cli/cmd/build.go +++ b/cli/cmd/build.go @@ -5,6 +5,7 @@ package cmd import ( "github.com/codesphere-cloud/cs-go/pkg/io" + "github.com/codesphere-cloud/oms/cli/cmd/util" "github.com/spf13/cobra" ) @@ -13,7 +14,7 @@ type BuildCmd struct { cmd *cobra.Command } -func AddBuildCmd(rootCmd *cobra.Command, opts *GlobalOptions) { +func AddBuildCmd(rootCmd *cobra.Command, opts *util.GlobalOptions) { build := BuildCmd{ cmd: &cobra.Command{ Use: "build", @@ -24,5 +25,5 @@ func AddBuildCmd(rootCmd *cobra.Command, opts *GlobalOptions) { AddBuildImagesCmd(build.cmd, opts) AddBuildImageCmd(build.cmd, opts) - AddCmd(rootCmd, build.cmd) + util.AddCmd(rootCmd, build.cmd) } diff --git a/cli/cmd/build_image.go b/cli/cmd/build_image.go index 04575c6ff..b7be16acf 100644 --- a/cli/cmd/build_image.go +++ b/cli/cmd/build_image.go @@ -9,10 +9,10 @@ import ( "log" "github.com/codesphere-cloud/cs-go/pkg/io" + "github.com/codesphere-cloud/oms/cli/cmd/util" "github.com/codesphere-cloud/oms/internal/env" "github.com/codesphere-cloud/oms/internal/installer" "github.com/codesphere-cloud/oms/internal/system" - "github.com/codesphere-cloud/oms/internal/util" "github.com/spf13/cobra" ) @@ -24,7 +24,7 @@ type BuildImageCmd struct { } type BuildImageOpts struct { - *GlobalOptions + *util.GlobalOptions Dockerfile string Package string Registry string @@ -38,13 +38,13 @@ func (c *BuildImageCmd) RunE(cmd *cobra.Command, args []string) error { return c.BuildImage(pm, im) } -func AddBuildImageCmd(parentCmd *cobra.Command, opts *GlobalOptions) { +func AddBuildImageCmd(parentCmd *cobra.Command, opts *util.GlobalOptions) { imageCmd := &BuildImageCmd{ cmd: &cobra.Command{ Use: "image", Short: "Build and push Docker image using Dockerfile and Codesphere package version", Long: `Build a Docker image from a Dockerfile and push it to a registry, tagged with the Codesphere version from the package.`, - Example: formatExamples("build image", []io.Example{ + Example: util.FormatExamples("build image", []io.Example{ {Cmd: "--dockerfile baseimage/Dockerfile --package codesphere-v1.68.0.tar.gz --registry my-registry.com/my-image", Desc: "Build image for Codesphere version 1.68.0 and push to specified registry"}, }), Args: cobra.ExactArgs(0), @@ -62,7 +62,7 @@ func AddBuildImageCmd(parentCmd *cobra.Command, opts *GlobalOptions) { util.MarkFlagRequired(imageCmd.cmd, "package") util.MarkFlagRequired(imageCmd.cmd, "registry") - AddCmd(parentCmd, imageCmd.cmd) + util.AddCmd(parentCmd, imageCmd.cmd) imageCmd.cmd.RunE = imageCmd.RunE } diff --git a/cli/cmd/build_image_test.go b/cli/cmd/build_image_test.go index ad84ca9ac..cce1499ec 100644 --- a/cli/cmd/build_image_test.go +++ b/cli/cmd/build_image_test.go @@ -11,6 +11,7 @@ import ( "github.com/spf13/cobra" "github.com/codesphere-cloud/oms/cli/cmd" + "github.com/codesphere-cloud/oms/cli/cmd/util" "github.com/codesphere-cloud/oms/internal/env" "github.com/codesphere-cloud/oms/internal/installer" "github.com/codesphere-cloud/oms/internal/system" @@ -20,13 +21,13 @@ var _ = Describe("BuildImageCmd", func() { var ( c cmd.BuildImageCmd opts cmd.BuildImageOpts - globalOpts *cmd.GlobalOptions + globalOpts *util.GlobalOptions mockEnv *env.MockEnv ) BeforeEach(func() { mockEnv = env.NewMockEnv(GinkgoT()) - globalOpts = &cmd.GlobalOptions{} + globalOpts = &util.GlobalOptions{} opts = cmd.BuildImageOpts{ GlobalOptions: globalOpts, Dockerfile: "Dockerfile", @@ -129,12 +130,12 @@ var _ = Describe("BuildImageCmd", func() { var _ = Describe("AddBuildImageCmd", func() { var ( parentCmd *cobra.Command - globalOpts *cmd.GlobalOptions + globalOpts *util.GlobalOptions ) BeforeEach(func() { parentCmd = &cobra.Command{Use: "build"} - globalOpts = &cmd.GlobalOptions{} + globalOpts = &util.GlobalOptions{} }) It("adds the image command with correct properties and flags", func() { diff --git a/cli/cmd/build_images.go b/cli/cmd/build_images.go index 120bebd02..48cd3c4e4 100644 --- a/cli/cmd/build_images.go +++ b/cli/cmd/build_images.go @@ -9,10 +9,10 @@ import ( "log" "github.com/codesphere-cloud/cs-go/pkg/io" + "github.com/codesphere-cloud/oms/cli/cmd/util" "github.com/codesphere-cloud/oms/internal/env" "github.com/codesphere-cloud/oms/internal/installer" "github.com/codesphere-cloud/oms/internal/system" - "github.com/codesphere-cloud/oms/internal/util" "github.com/spf13/cobra" ) @@ -24,7 +24,7 @@ type BuildImagesCmd struct { } type BuildImagesOpts struct { - *GlobalOptions + *util.GlobalOptions Config string Force bool } @@ -42,7 +42,7 @@ func (c *BuildImagesCmd) RunE(_ *cobra.Command, args []string) error { return nil } -func AddBuildImagesCmd(build *cobra.Command, opts *GlobalOptions) { +func AddBuildImagesCmd(build *cobra.Command, opts *util.GlobalOptions) { buildImages := BuildImagesCmd{ cmd: &cobra.Command{ Use: "images", @@ -58,7 +58,7 @@ func AddBuildImagesCmd(build *cobra.Command, opts *GlobalOptions) { util.MarkFlagRequired(buildImages.cmd, "config") - AddCmd(build, buildImages.cmd) + util.AddCmd(build, buildImages.cmd) buildImages.cmd.RunE = buildImages.RunE } diff --git a/cli/cmd/build_images_test.go b/cli/cmd/build_images_test.go index d5afe9adf..9bf2e3b22 100644 --- a/cli/cmd/build_images_test.go +++ b/cli/cmd/build_images_test.go @@ -12,6 +12,7 @@ import ( "github.com/spf13/cobra" "github.com/codesphere-cloud/oms/cli/cmd" + "github.com/codesphere-cloud/oms/cli/cmd/util" "github.com/codesphere-cloud/oms/internal/env" "github.com/codesphere-cloud/oms/internal/installer" "github.com/codesphere-cloud/oms/internal/installer/files" @@ -39,13 +40,13 @@ var _ = Describe("BuildImagesCmd", func() { var ( c cmd.BuildImagesCmd opts *cmd.BuildImagesOpts - globalOpts *cmd.GlobalOptions + globalOpts *util.GlobalOptions mockEnv *env.MockEnv ) BeforeEach(func() { mockEnv = env.NewMockEnv(GinkgoT()) - globalOpts = &cmd.GlobalOptions{} + globalOpts = &util.GlobalOptions{} opts = &cmd.BuildImagesOpts{ GlobalOptions: globalOpts, Config: "", @@ -394,12 +395,12 @@ var _ = Describe("BuildImagesCmd", func() { var _ = Describe("AddBuildImagesCmd", func() { var ( parentCmd *cobra.Command - globalOpts *cmd.GlobalOptions + globalOpts *util.GlobalOptions ) BeforeEach(func() { parentCmd = &cobra.Command{Use: "build"} - globalOpts = &cmd.GlobalOptions{} + globalOpts = &util.GlobalOptions{} }) It("adds the images command with correct properties and flags", func() { diff --git a/cli/cmd/install_codesphere.go b/cli/cmd/codesphere/install_codesphere.go similarity index 96% rename from cli/cmd/install_codesphere.go rename to cli/cmd/codesphere/install_codesphere.go index f55dacc10..141bf27b9 100644 --- a/cli/cmd/install_codesphere.go +++ b/cli/cmd/codesphere/install_codesphere.go @@ -1,7 +1,7 @@ // Copyright (c) Codesphere Inc. // SPDX-License-Identifier: Apache-2.0 -package cmd +package codesphere import ( "fmt" @@ -9,13 +9,14 @@ import ( "path/filepath" "github.com/codesphere-cloud/cs-go/pkg/io" + "github.com/codesphere-cloud/oms/cli/cmd/util" "github.com/codesphere-cloud/oms/internal/configtemplating" "github.com/codesphere-cloud/oms/internal/env" "github.com/codesphere-cloud/oms/internal/installer" "github.com/codesphere-cloud/oms/internal/installer/argocd" "github.com/codesphere-cloud/oms/internal/installer/files" "github.com/codesphere-cloud/oms/internal/installer/vault" - "github.com/codesphere-cloud/oms/internal/util" + intutil "github.com/codesphere-cloud/oms/internal/util" "github.com/spf13/cobra" "go.yaml.in/yaml/v3" ) @@ -33,7 +34,7 @@ type InstallCodesphereCmd struct { } type InstallCodesphereOpts struct { - *GlobalOptions + *util.GlobalOptions Package string Force bool Configs []string @@ -97,14 +98,14 @@ func (c *InstallCodesphereCmd) RunE(cmd *cobra.Command, _ []string) error { return installCodespherePlatform(ctx, effectiveOpts, cfg, c.Env) } -func AddInstallCodesphereCmd(install *cobra.Command, opts *GlobalOptions) { +func AddInstallCmd(install *cobra.Command, opts *util.GlobalOptions) { codesphere := InstallCodesphereCmd{ cmd: &cobra.Command{ Use: "codesphere", Short: "Install a Codesphere instance", Long: io.Long(`Install a Codesphere instance with the provided package, configuration file, and private key. Uses the private-cloud-installer.js script included in the package to perform the installation.`), - Example: formatExamples("install codesphere", []io.Example{ + Example: util.FormatExamples("install codesphere", []io.Example{ { Cmd: "-p codesphere-v1.2.3-installer-lite.tar.gz -k -c config.yaml -s copy-dependencies,extract-dependencies,load-container-images,ceph,postgres,kubernetes,docker", Desc: "Skip most pre-installation steps. E.g. if you only need to re-apply Codesphere's helm charts", @@ -138,7 +139,7 @@ func AddInstallCodesphereCmd(install *cobra.Command, opts *GlobalOptions) { util.MarkPersistentFlagRequired(codesphere.cmd, "config") util.MarkPersistentFlagRequired(codesphere.cmd, "priv-key") - AddCmd(install, codesphere.cmd) + util.AddCmd(install, codesphere.cmd) codesphere.cmd.RunE = codesphere.RunE @@ -202,7 +203,7 @@ func prepareInstallConfig(opts *InstallCodesphereOpts, cm installer.ConfigManage if partial == nil { partial = map[string]any{} } - merged = util.DeepMergeMaps(merged, partial) + merged = intutil.DeepMergeMaps(merged, partial) } mergedBytes, err := yaml.Marshal(merged) diff --git a/cli/cmd/install_codesphere_config_test.go b/cli/cmd/codesphere/install_codesphere_config_test.go similarity index 99% rename from cli/cmd/install_codesphere_config_test.go rename to cli/cmd/codesphere/install_codesphere_config_test.go index 04f73077e..f26872d34 100644 --- a/cli/cmd/install_codesphere_config_test.go +++ b/cli/cmd/codesphere/install_codesphere_config_test.go @@ -1,7 +1,7 @@ // Copyright (c) Codesphere Inc. // SPDX-License-Identifier: Apache-2.0 -package cmd +package codesphere import ( "fmt" diff --git a/cli/cmd/install_codesphere_dependencies.go b/cli/cmd/codesphere/install_codesphere_dependencies.go similarity index 97% rename from cli/cmd/install_codesphere_dependencies.go rename to cli/cmd/codesphere/install_codesphere_dependencies.go index 0ea33164e..be52a0dcc 100644 --- a/cli/cmd/install_codesphere_dependencies.go +++ b/cli/cmd/codesphere/install_codesphere_dependencies.go @@ -1,7 +1,7 @@ // Copyright (c) Codesphere Inc. // SPDX-License-Identifier: Apache-2.0 -package cmd +package codesphere import ( "context" @@ -10,6 +10,7 @@ import ( "runtime" "github.com/codesphere-cloud/cs-go/pkg/io" + "github.com/codesphere-cloud/oms/cli/cmd/util" "github.com/codesphere-cloud/oms/internal/bootstrap" "github.com/codesphere-cloud/oms/internal/env" "github.com/codesphere-cloud/oms/internal/installer" @@ -203,7 +204,7 @@ func AddInstallCodesphereDepenciesCmd(codesphere *cobra.Command, opts *InstallCo Runs ArgoCD install, vault secret sync, and pc-apps deployment first, then steps: set-up-cluster, ms-backends. Requires the infrastructure phase to have completed successfully. Pass --skip-steps argocd or add argocd to operations.skip to skip the ArgoCD pre-step.`), - Example: formatExamples("install codesphere dependencies", []io.Example{ + Example: util.FormatExamples("install codesphere dependencies", []io.Example{ { Cmd: "-p codesphere-v1.2.3-installer-lite.tar.gz -k -c config.yaml", Desc: "Install cluster dependencies (including ArgoCD)", @@ -222,6 +223,6 @@ func AddInstallCodesphereDepenciesCmd(codesphere *cobra.Command, opts *InstallCo Env: env.NewEnv(), } - AddCmd(codesphere, deps.cmd) + util.AddCmd(codesphere, deps.cmd) deps.cmd.RunE = deps.RunE } diff --git a/cli/cmd/install_codesphere_dependencies_test.go b/cli/cmd/codesphere/install_codesphere_dependencies_test.go similarity index 98% rename from cli/cmd/install_codesphere_dependencies_test.go rename to cli/cmd/codesphere/install_codesphere_dependencies_test.go index b0bf8e4d0..1b9e524ae 100644 --- a/cli/cmd/install_codesphere_dependencies_test.go +++ b/cli/cmd/codesphere/install_codesphere_dependencies_test.go @@ -1,7 +1,7 @@ // Copyright (c) Codesphere Inc. // SPDX-License-Identifier: Apache-2.0 -package cmd +package codesphere import ( "os" diff --git a/cli/cmd/install_codesphere_infra.go b/cli/cmd/codesphere/install_codesphere_infra.go similarity index 93% rename from cli/cmd/install_codesphere_infra.go rename to cli/cmd/codesphere/install_codesphere_infra.go index 2fd6c83a0..70274e9bf 100644 --- a/cli/cmd/install_codesphere_infra.go +++ b/cli/cmd/codesphere/install_codesphere_infra.go @@ -1,7 +1,7 @@ // Copyright (c) Codesphere Inc. // SPDX-License-Identifier: Apache-2.0 -package cmd +package codesphere import ( "context" @@ -9,6 +9,7 @@ import ( "runtime" "github.com/codesphere-cloud/cs-go/pkg/io" + "github.com/codesphere-cloud/oms/cli/cmd/util" "github.com/codesphere-cloud/oms/internal/env" "github.com/codesphere-cloud/oms/internal/installer" "github.com/codesphere-cloud/oms/internal/system" @@ -61,7 +62,7 @@ func AddInstallCodesphereInfraCmd(codesphere *cobra.Command, opts *InstallCodesp Short: "Install Codesphere infrastructure (Phase 1)", Long: io.Long(`Install infrastructure dependencies for a Codesphere instance (Phase 1). Runs steps: copy-dependencies, extract-dependencies, load-container-images, sops, docker, postgres, ceph, kubernetes.`), - Example: formatExamples("install codesphere infra", []io.Example{ + Example: util.FormatExamples("install codesphere infra", []io.Example{ { Cmd: "-p codesphere-v1.2.3-installer-lite.tar.gz -k -c config.yaml", Desc: "Install infrastructure components only", @@ -76,6 +77,6 @@ func AddInstallCodesphereInfraCmd(codesphere *cobra.Command, opts *InstallCodesp Env: env.NewEnv(), } - AddCmd(codesphere, infra.cmd) + util.AddCmd(codesphere, infra.cmd) infra.cmd.RunE = infra.RunE } diff --git a/cli/cmd/install_codesphere_platform.go b/cli/cmd/codesphere/install_codesphere_platform.go similarity index 93% rename from cli/cmd/install_codesphere_platform.go rename to cli/cmd/codesphere/install_codesphere_platform.go index 2a178d8e8..7b9a7c3e8 100644 --- a/cli/cmd/install_codesphere_platform.go +++ b/cli/cmd/codesphere/install_codesphere_platform.go @@ -1,7 +1,7 @@ // Copyright (c) Codesphere Inc. // SPDX-License-Identifier: Apache-2.0 -package cmd +package codesphere import ( "context" @@ -9,6 +9,7 @@ import ( "runtime" "github.com/codesphere-cloud/cs-go/pkg/io" + "github.com/codesphere-cloud/oms/cli/cmd/util" "github.com/codesphere-cloud/oms/internal/env" "github.com/codesphere-cloud/oms/internal/installer" "github.com/codesphere-cloud/oms/internal/installer/files" @@ -68,7 +69,7 @@ func AddInstallCodespherePlatformCmd(codesphere *cobra.Command, opts *InstallCod Long: io.Long(`Install the Codesphere platform (Phase 3). Runs step: codesphere. Requires the infrastructure and dependencies phases to have completed successfully.`), - Example: formatExamples("install codesphere platform", []io.Example{ + Example: util.FormatExamples("install codesphere platform", []io.Example{ { Cmd: "-p codesphere-v1.2.3-installer-lite.tar.gz -k -c config.yaml", Desc: "Install Codesphere platform only", @@ -79,6 +80,6 @@ func AddInstallCodespherePlatformCmd(codesphere *cobra.Command, opts *InstallCod Env: env.NewEnv(), } - AddCmd(codesphere, platform.cmd) + util.AddCmd(codesphere, platform.cmd) platform.cmd.RunE = platform.RunE } diff --git a/cli/cmd/install_codesphere_test.go b/cli/cmd/codesphere/install_codesphere_test.go similarity index 87% rename from cli/cmd/install_codesphere_test.go rename to cli/cmd/codesphere/install_codesphere_test.go index 4a5cd14de..2e3623200 100644 --- a/cli/cmd/install_codesphere_test.go +++ b/cli/cmd/codesphere/install_codesphere_test.go @@ -1,7 +1,7 @@ // Copyright (c) Codesphere Inc. // SPDX-License-Identifier: Apache-2.0 -package cmd_test +package codesphere_test import ( "context" @@ -12,27 +12,28 @@ import ( . "github.com/onsi/gomega" "github.com/spf13/cobra" - "github.com/codesphere-cloud/oms/cli/cmd" + "github.com/codesphere-cloud/oms/cli/cmd/codesphere" + "github.com/codesphere-cloud/oms/cli/cmd/util" "github.com/codesphere-cloud/oms/internal/env" ) var _ = Describe("InstallCodesphereCmd", func() { var ( - c cmd.InstallCodesphereCmd - opts *cmd.InstallCodesphereOpts - globalOpts *cmd.GlobalOptions + c codesphere.InstallCodesphereCmd + opts *codesphere.InstallCodesphereOpts + globalOpts *util.GlobalOptions mockEnv *env.MockEnv ) BeforeEach(func() { mockEnv = env.NewMockEnv(GinkgoT()) - globalOpts = &cmd.GlobalOptions{} - opts = &cmd.InstallCodesphereOpts{ + globalOpts = &util.GlobalOptions{} + opts = &codesphere.InstallCodesphereOpts{ GlobalOptions: globalOpts, Package: "codesphere-v1.66.0-installer-lite.tar.gz", Force: false, } - c = cmd.InstallCodesphereCmd{ + c = codesphere.InstallCodesphereCmd{ Opts: opts, Env: mockEnv, } @@ -77,16 +78,16 @@ var _ = Describe("InstallCodesphereCmd", func() { var _ = Describe("AddInstallCodesphereCmd", func() { var ( parentCmd *cobra.Command - globalOpts *cmd.GlobalOptions + globalOpts *util.GlobalOptions ) BeforeEach(func() { parentCmd = &cobra.Command{Use: "install"} - globalOpts = &cmd.GlobalOptions{} + globalOpts = &util.GlobalOptions{} }) It("adds the codesphere command with correct properties and flags", func() { - cmd.AddInstallCodesphereCmd(parentCmd, globalOpts) + codesphere.AddInstallCmd(parentCmd, globalOpts) var codesphereCmd *cobra.Command for _, c := range parentCmd.Commands() { diff --git a/cli/cmd/create.go b/cli/cmd/create.go index 53f45a162..9620bda0a 100644 --- a/cli/cmd/create.go +++ b/cli/cmd/create.go @@ -5,6 +5,7 @@ package cmd import ( "github.com/codesphere-cloud/cs-go/pkg/io" + "github.com/codesphere-cloud/oms/cli/cmd/util" "github.com/spf13/cobra" ) @@ -13,7 +14,7 @@ type CreateCmd struct { cmd *cobra.Command } -func AddCreateCmd(rootCmd *cobra.Command, opts *GlobalOptions) { +func AddCreateCmd(rootCmd *cobra.Command, opts *util.GlobalOptions) { create := CreateCmd{ cmd: &cobra.Command{ Use: "create", @@ -21,7 +22,7 @@ func AddCreateCmd(rootCmd *cobra.Command, opts *GlobalOptions) { Long: io.Long(`Create resources for Codesphere installations, such as test users for automated testing.`), }, } - AddCmd(rootCmd, create.cmd) + util.AddCmd(rootCmd, create.cmd) AddCreateTestUserCmd(create.cmd, opts) } diff --git a/cli/cmd/create_test_user.go b/cli/cmd/create_test_user.go index aa7c861e0..84d275eee 100644 --- a/cli/cmd/create_test_user.go +++ b/cli/cmd/create_test_user.go @@ -9,9 +9,9 @@ import ( "github.com/spf13/cobra" "github.com/codesphere-cloud/cs-go/pkg/io" + "github.com/codesphere-cloud/oms/cli/cmd/util" "github.com/codesphere-cloud/oms/internal/env" "github.com/codesphere-cloud/oms/internal/testuser" - "github.com/codesphere-cloud/oms/internal/util" ) type CreateTestUserCmd struct { @@ -21,7 +21,7 @@ type CreateTestUserCmd struct { } type CreateTestUserOpts struct { - *GlobalOptions + *util.GlobalOptions testuser.CreateTestUserOpts } @@ -36,7 +36,7 @@ func (c *CreateTestUserCmd) RunE(_ *cobra.Command, args []string) error { return nil } -func AddCreateTestUserCmd(parent *cobra.Command, opts *GlobalOptions) { +func AddCreateTestUserCmd(parent *cobra.Command, opts *util.GlobalOptions) { c := CreateTestUserCmd{ cmd: &cobra.Command{ Use: "test-user", @@ -70,5 +70,5 @@ func AddCreateTestUserCmd(parent *cobra.Command, opts *GlobalOptions) { util.MarkFlagRequired(c.cmd, "postgres-host") util.MarkFlagRequired(c.cmd, "postgres-password") - AddCmd(parent, c.cmd) + util.AddCmd(parent, c.cmd) } diff --git a/cli/cmd/create_test_user_test.go b/cli/cmd/create_test_user_test.go index cb74bdffc..577d603a5 100644 --- a/cli/cmd/create_test_user_test.go +++ b/cli/cmd/create_test_user_test.go @@ -9,16 +9,17 @@ import ( "github.com/spf13/cobra" "github.com/codesphere-cloud/oms/cli/cmd" + "github.com/codesphere-cloud/oms/cli/cmd/util" ) var _ = Describe("CreateTestUser", func() { Context("AddCreateTestUserCmd", func() { var createCmd cobra.Command - var opts *cmd.GlobalOptions + var opts *util.GlobalOptions BeforeEach(func() { createCmd = cobra.Command{} - opts = &cmd.GlobalOptions{} + opts = &util.GlobalOptions{} }) It("accepts valid flags with all required flags set", func() { diff --git a/cli/cmd/download.go b/cli/cmd/download.go index 6cf321416..7276735f3 100644 --- a/cli/cmd/download.go +++ b/cli/cmd/download.go @@ -5,6 +5,7 @@ package cmd import ( "github.com/codesphere-cloud/cs-go/pkg/io" + "github.com/codesphere-cloud/oms/cli/cmd/util" "github.com/spf13/cobra" ) @@ -13,7 +14,7 @@ type DownloadCmd struct { cmd *cobra.Command } -func AddDownloadCmd(rootCmd *cobra.Command, opts *GlobalOptions) { +func AddDownloadCmd(rootCmd *cobra.Command, opts *util.GlobalOptions) { download := DownloadCmd{ cmd: &cobra.Command{ Use: "download", @@ -22,7 +23,7 @@ func AddDownloadCmd(rootCmd *cobra.Command, opts *GlobalOptions) { e.g. available Codesphere packages`), }, } - AddCmd(rootCmd, download.cmd) + util.AddCmd(rootCmd, download.cmd) AddDownloadPackageCmd(download.cmd, opts) AddDownloadK0sCmd(download.cmd, opts) diff --git a/cli/cmd/download_k0s.go b/cli/cmd/download_k0s.go index 18c4cba89..c859f8db6 100644 --- a/cli/cmd/download_k0s.go +++ b/cli/cmd/download_k0s.go @@ -10,10 +10,11 @@ import ( packageio "github.com/codesphere-cloud/cs-go/pkg/io" "github.com/spf13/cobra" + "github.com/codesphere-cloud/oms/cli/cmd/util" "github.com/codesphere-cloud/oms/internal/env" "github.com/codesphere-cloud/oms/internal/installer" "github.com/codesphere-cloud/oms/internal/portal" - "github.com/codesphere-cloud/oms/internal/util" + intutil "github.com/codesphere-cloud/oms/internal/util" ) // DownloadK0sCmd represents the k0s download command @@ -21,11 +22,11 @@ type DownloadK0sCmd struct { cmd *cobra.Command Opts DownloadK0sOpts Env env.Env - FileWriter util.FileIO + FileWriter intutil.FileIO } type DownloadK0sOpts struct { - *GlobalOptions + *util.GlobalOptions Version string Force bool Quiet bool @@ -44,14 +45,14 @@ func (c *DownloadK0sCmd) RunE(_ *cobra.Command, args []string) error { return nil } -func AddDownloadK0sCmd(download *cobra.Command, opts *GlobalOptions) { +func AddDownloadK0sCmd(download *cobra.Command, opts *util.GlobalOptions) { k0s := DownloadK0sCmd{ cmd: &cobra.Command{ Use: "k0s", Short: "Download k0s Kubernetes distribution", Long: packageio.Long(`Download a k0s binary directly to the OMS workdir. Will download the latest version if no version is specified.`), - Example: formatExamples("download k0s", []packageio.Example{ + Example: util.FormatExamples("download k0s", []packageio.Example{ {Cmd: "", Desc: "Download k0s using the Go-native implementation"}, {Cmd: "--version 1.22.0", Desc: "Download a specific version of k0s"}, {Cmd: "--quiet", Desc: "Download k0s with minimal output"}, @@ -60,13 +61,13 @@ func AddDownloadK0sCmd(download *cobra.Command, opts *GlobalOptions) { }, Opts: DownloadK0sOpts{GlobalOptions: opts}, Env: env.NewEnv(), - FileWriter: util.NewFilesystemWriter(), + FileWriter: intutil.NewFilesystemWriter(), } k0s.cmd.Flags().StringVarP(&k0s.Opts.Version, "version", "v", "", "Version of k0s to download") k0s.cmd.Flags().BoolVarP(&k0s.Opts.Force, "force", "f", false, "Force download even if k0s binary exists") k0s.cmd.Flags().BoolVarP(&k0s.Opts.Quiet, "quiet", "q", false, "Suppress progress output during download") - AddCmd(download, k0s.cmd) + util.AddCmd(download, k0s.cmd) k0s.cmd.RunE = k0s.RunE } diff --git a/cli/cmd/download_k0s_test.go b/cli/cmd/download_k0s_test.go index fb4dfc7d0..ed20ed402 100644 --- a/cli/cmd/download_k0s_test.go +++ b/cli/cmd/download_k0s_test.go @@ -10,24 +10,25 @@ import ( . "github.com/onsi/gomega" "github.com/codesphere-cloud/oms/cli/cmd" + "github.com/codesphere-cloud/oms/cli/cmd/util" "github.com/codesphere-cloud/oms/internal/env" "github.com/codesphere-cloud/oms/internal/installer" - "github.com/codesphere-cloud/oms/internal/util" + intutil "github.com/codesphere-cloud/oms/internal/util" ) var _ = Describe("DownloadK0sCmd", func() { var ( c cmd.DownloadK0sCmd opts *cmd.DownloadK0sOpts - globalOpts *cmd.GlobalOptions + globalOpts *util.GlobalOptions mockEnv *env.MockEnv - mockFileWriter *util.MockFileIO + mockFileWriter *intutil.MockFileIO ) BeforeEach(func() { mockEnv = env.NewMockEnv(GinkgoT()) - mockFileWriter = util.NewMockFileIO(GinkgoT()) - globalOpts = &cmd.GlobalOptions{} + mockFileWriter = intutil.NewMockFileIO(GinkgoT()) + globalOpts = &util.GlobalOptions{} opts = &cmd.DownloadK0sOpts{ GlobalOptions: globalOpts, Version: "", diff --git a/cli/cmd/download_package.go b/cli/cmd/download_package.go index 38c336950..fa671a2bc 100644 --- a/cli/cmd/download_package.go +++ b/cli/cmd/download_package.go @@ -10,19 +10,20 @@ import ( "github.com/codesphere-cloud/cs-go/pkg/io" "github.com/spf13/cobra" + "github.com/codesphere-cloud/oms/cli/cmd/util" "github.com/codesphere-cloud/oms/internal/portal" - "github.com/codesphere-cloud/oms/internal/util" + intutil "github.com/codesphere-cloud/oms/internal/util" ) // DownloadPackageCmd represents the package command type DownloadPackageCmd struct { cmd *cobra.Command Opts DownloadPackageOpts - FileWriter util.FileIO + FileWriter intutil.FileIO } type DownloadPackageOpts struct { - *GlobalOptions + *util.GlobalOptions Version string Hash string Filename string @@ -54,7 +55,7 @@ func (c *DownloadPackageCmd) RunE(_ *cobra.Command, args []string) error { return nil } -func AddDownloadPackageCmd(download *cobra.Command, opts *GlobalOptions) { +func AddDownloadPackageCmd(download *cobra.Command, opts *util.GlobalOptions) { pkg := DownloadPackageCmd{ cmd: &cobra.Command{ Use: "package [VERSION]", @@ -62,7 +63,7 @@ func AddDownloadPackageCmd(download *cobra.Command, opts *GlobalOptions) { Long: io.Long(`Download a specific version of a Codesphere package To list available packages, run oms list packages.`), Args: cobra.ArbitraryArgs, - Example: formatExamples("download package", []io.Example{ + Example: util.FormatExamples("download package", []io.Example{ {Cmd: "codesphere-v1.55.0", Desc: "Download Codesphere version 1.55.0"}, {Cmd: "--version codesphere-v1.55.0", Desc: "Download Codesphere version 1.55.0"}, {Cmd: "--version codesphere-v1.55.0 --file installer-lite.tar.gz", Desc: "Download lite package of Codesphere version 1.55.0"}, @@ -82,14 +83,14 @@ func AddDownloadPackageCmd(download *cobra.Command, opts *GlobalOptions) { return nil }, }, - FileWriter: util.NewFilesystemWriter(), + FileWriter: intutil.NewFilesystemWriter(), } pkg.cmd.Flags().StringVarP(&pkg.Opts.Version, "version", "V", "", "Codesphere version to download") pkg.cmd.Flags().StringVarP(&pkg.Opts.Hash, "hash", "H", "", "Hash of the version to download if multiple builds exist for the same version") pkg.cmd.Flags().StringVarP(&pkg.Opts.Filename, "file", "f", "installer-lite.tar.gz", "Specify artifact to download") pkg.cmd.Flags().BoolVarP(&pkg.Opts.Quiet, "quiet", "q", false, "Suppress progress output during download") - AddCmd(download, pkg.cmd) + util.AddCmd(download, pkg.cmd) pkg.cmd.RunE = pkg.RunE } @@ -108,7 +109,7 @@ func (c *DownloadPackageCmd) DownloadBuild(p portal.Portal, build portal.Build, return fmt.Errorf("failed to create file %s: %w", fullFilename, err) } } - defer util.CloseFileIgnoreError(out) + defer intutil.CloseFileIgnoreError(out) // get already downloaded file size of fullFilename fileSize := 0 @@ -126,7 +127,7 @@ func (c *DownloadPackageCmd) DownloadBuild(p portal.Portal, build portal.Build, if err != nil { return err } - defer util.CloseFileIgnoreError(verifyFile) + defer intutil.CloseFileIgnoreError(verifyFile) err = p.VerifyBuildArtifactDownload(verifyFile, download) if err != nil { diff --git a/cli/cmd/download_package_test.go b/cli/cmd/download_package_test.go index 6316b43cf..c38fe1dc8 100644 --- a/cli/cmd/download_package_test.go +++ b/cli/cmd/download_package_test.go @@ -12,8 +12,9 @@ import ( "github.com/stretchr/testify/mock" "github.com/codesphere-cloud/oms/cli/cmd" + "github.com/codesphere-cloud/oms/cli/cmd/util" "github.com/codesphere-cloud/oms/internal/portal" - "github.com/codesphere-cloud/oms/internal/util" + intutil "github.com/codesphere-cloud/oms/internal/util" ) var _ = Describe("DownloadPackages", func() { @@ -25,7 +26,7 @@ var _ = Describe("DownloadPackages", func() { hash string build portal.Build mockPortal *portal.MockPortal - mockFileWriter *util.MockFileIO + mockFileWriter *intutil.MockFileIO ) BeforeEach(func() { @@ -33,7 +34,7 @@ var _ = Describe("DownloadPackages", func() { version = "codesphere-1.42.0" hash = "abc1234567" mockPortal = portal.NewMockPortal(GinkgoT()) - mockFileWriter = util.NewMockFileIO(GinkgoT()) + mockFileWriter = intutil.NewMockFileIO(GinkgoT()) }) JustBeforeEach(func() { c = cmd.DownloadPackageCmd{ @@ -60,11 +61,11 @@ var _ = Describe("DownloadPackages", func() { Context("AddDownloadPackageCmd", func() { var downloadCmd cobra.Command - var opts *cmd.GlobalOptions + var opts *util.GlobalOptions BeforeEach(func() { downloadCmd = cobra.Command{} - opts = &cmd.GlobalOptions{} + opts = &util.GlobalOptions{} }) It("valid package with version as flag", func() { diff --git a/cli/cmd/extend.go b/cli/cmd/extend.go index d227ee712..5afadfd0d 100644 --- a/cli/cmd/extend.go +++ b/cli/cmd/extend.go @@ -5,6 +5,7 @@ package cmd import ( "github.com/codesphere-cloud/cs-go/pkg/io" + "github.com/codesphere-cloud/oms/cli/cmd/util" "github.com/spf13/cobra" ) @@ -13,7 +14,7 @@ type ExtendCmd struct { cmd *cobra.Command } -func AddExtendCmd(rootCmd *cobra.Command, opts *GlobalOptions) { +func AddExtendCmd(rootCmd *cobra.Command, opts *util.GlobalOptions) { extend := ExtendCmd{ cmd: &cobra.Command{ Use: "extend", @@ -21,7 +22,7 @@ func AddExtendCmd(rootCmd *cobra.Command, opts *GlobalOptions) { Long: io.Long(`Extend Codesphere ressources such as base images to customize them for your needs.`), }, } - AddCmd(rootCmd, extend.cmd) + util.AddCmd(rootCmd, extend.cmd) AddExtendBaseimageCmd(extend.cmd, opts) } diff --git a/cli/cmd/extend_baseimage.go b/cli/cmd/extend_baseimage.go index 8587608d1..3c2f3a0fc 100644 --- a/cli/cmd/extend_baseimage.go +++ b/cli/cmd/extend_baseimage.go @@ -12,6 +12,7 @@ import ( "github.com/spf13/cobra" "github.com/codesphere-cloud/cs-go/pkg/io" + "github.com/codesphere-cloud/oms/cli/cmd/util" "github.com/codesphere-cloud/oms/internal/env" "github.com/codesphere-cloud/oms/internal/installer" "github.com/codesphere-cloud/oms/internal/system" @@ -26,7 +27,7 @@ type ExtendBaseimageCmd struct { } type ExtendBaseimageOpts struct { - *GlobalOptions + *util.GlobalOptions Package string Dockerfile string Baseimage string @@ -50,7 +51,7 @@ func (c *ExtendBaseimageCmd) RunE(_ *cobra.Command, args []string) error { return nil } -func AddExtendBaseimageCmd(extend *cobra.Command, opts *GlobalOptions) { +func AddExtendBaseimageCmd(extend *cobra.Command, opts *util.GlobalOptions) { baseimage := ExtendBaseimageCmd{ cmd: &cobra.Command{ Use: "baseimage", @@ -69,7 +70,7 @@ func AddExtendBaseimageCmd(extend *cobra.Command, opts *GlobalOptions) { baseimage.cmd.Flags().StringVarP(&baseimage.Opts.Baseimage, "baseimage", "b", "workspace-agent-24.04", "Base image file name inside the package to extend (default: 'workspace-agent-24.04')") baseimage.cmd.Flags().BoolVarP(&baseimage.Opts.Force, "force", "f", false, "Enforce package extraction") - AddCmd(extend, baseimage.cmd) + util.AddCmd(extend, baseimage.cmd) baseimage.cmd.RunE = baseimage.RunE } diff --git a/cli/cmd/extend_baseimage_test.go b/cli/cmd/extend_baseimage_test.go index 46858735f..8ebb274b0 100644 --- a/cli/cmd/extend_baseimage_test.go +++ b/cli/cmd/extend_baseimage_test.go @@ -12,23 +12,24 @@ import ( "github.com/spf13/cobra" "github.com/codesphere-cloud/oms/cli/cmd" + "github.com/codesphere-cloud/oms/cli/cmd/util" "github.com/codesphere-cloud/oms/internal/env" "github.com/codesphere-cloud/oms/internal/installer" "github.com/codesphere-cloud/oms/internal/system" - "github.com/codesphere-cloud/oms/internal/util" + intutil "github.com/codesphere-cloud/oms/internal/util" ) var _ = Describe("ExtendBaseimageCmd", func() { var ( c cmd.ExtendBaseimageCmd opts *cmd.ExtendBaseimageOpts - globalOpts *cmd.GlobalOptions + globalOpts *util.GlobalOptions mockEnv *env.MockEnv ) BeforeEach(func() { mockEnv = env.NewMockEnv(GinkgoT()) - globalOpts = &cmd.GlobalOptions{} + globalOpts = &util.GlobalOptions{} opts = &cmd.ExtendBaseimageOpts{ GlobalOptions: globalOpts, Dockerfile: "Dockerfile", @@ -101,7 +102,7 @@ var _ = Describe("ExtendBaseimageCmd", func() { It("fails when image manager fails to load image", func() { mockPackageManager := installer.NewMockPackageManager(GinkgoT()) mockImageManager := system.NewMockImageManager(GinkgoT()) - mockFileIO := util.NewMockFileIO(GinkgoT()) + mockFileIO := intutil.NewMockFileIO(GinkgoT()) // Create a temporary file for the Dockerfile generation to work with tempFile, err := os.CreateTemp("", "dockerfile-test-*") @@ -137,7 +138,7 @@ var _ = Describe("ExtendBaseimageCmd", func() { It("successfully completes workflow until dockerfile generation", func() { mockPackageManager := installer.NewMockPackageManager(GinkgoT()) mockImageManager := system.NewMockImageManager(GinkgoT()) - mockFileIO := util.NewMockFileIO(GinkgoT()) + mockFileIO := intutil.NewMockFileIO(GinkgoT()) // Create a temporary file for the Dockerfile generation to work with tempFile, err := os.CreateTemp("", "dockerfile-test-*") @@ -161,12 +162,12 @@ var _ = Describe("ExtendBaseimageCmd", func() { var _ = Describe("AddExtendBaseimageCmd", func() { var ( parentCmd *cobra.Command - globalOpts *cmd.GlobalOptions + globalOpts *util.GlobalOptions ) BeforeEach(func() { parentCmd = &cobra.Command{Use: "extend"} - globalOpts = &cmd.GlobalOptions{} + globalOpts = &util.GlobalOptions{} }) It("adds the baseimage command with correct properties and flags", func() { diff --git a/cli/cmd/init.go b/cli/cmd/init.go index ad5e44bdf..02a9e368e 100644 --- a/cli/cmd/init.go +++ b/cli/cmd/init.go @@ -5,6 +5,7 @@ package cmd import ( "github.com/codesphere-cloud/cs-go/pkg/io" + "github.com/codesphere-cloud/oms/cli/cmd/util" "github.com/spf13/cobra" ) @@ -12,7 +13,7 @@ type InitCmd struct { cmd *cobra.Command } -func AddInitCmd(rootCmd *cobra.Command, opts *GlobalOptions) { +func AddInitCmd(rootCmd *cobra.Command, opts *util.GlobalOptions) { init := InitCmd{ cmd: &cobra.Command{ Use: "init", @@ -20,6 +21,6 @@ func AddInitCmd(rootCmd *cobra.Command, opts *GlobalOptions) { Long: io.Long(`Initialize configuration files for Codesphere installation and other components.`), }, } - AddCmd(rootCmd, init.cmd) + util.AddCmd(rootCmd, init.cmd) AddInitInstallConfigCmd(init.cmd, opts) } diff --git a/cli/cmd/init_install_config.go b/cli/cmd/init_install_config.go index 57c8d9a1a..e059cb6c1 100644 --- a/cli/cmd/init_install_config.go +++ b/cli/cmd/init_install_config.go @@ -9,20 +9,21 @@ import ( "strings" csio "github.com/codesphere-cloud/cs-go/pkg/io" + "github.com/codesphere-cloud/oms/cli/cmd/util" "github.com/codesphere-cloud/oms/internal/installer" "github.com/codesphere-cloud/oms/internal/installer/files" - "github.com/codesphere-cloud/oms/internal/util" + intutil "github.com/codesphere-cloud/oms/internal/util" "github.com/spf13/cobra" ) type InitInstallConfigCmd struct { cmd *cobra.Command Opts *InitInstallConfigOpts - FileWriter util.FileIO + FileWriter intutil.FileIO } type InitInstallConfigOpts struct { - *GlobalOptions + *util.GlobalOptions ConfigFile string VaultFile string @@ -104,7 +105,7 @@ func (c *InitInstallConfigCmd) RunE(_ *cobra.Command, args []string) error { return c.InitInstallConfig(icg) } -func AddInitInstallConfigCmd(init *cobra.Command, opts *GlobalOptions) { +func AddInitInstallConfigCmd(init *cobra.Command, opts *util.GlobalOptions) { c := InitInstallConfigCmd{ cmd: &cobra.Command{ Use: "install-config", @@ -127,7 +128,7 @@ func AddInitInstallConfigCmd(init *cobra.Command, opts *GlobalOptions) { - production: HA multi-node setup - minimal: Minimal testing setup `), - Example: formatExamples("init install-config", []csio.Example{ + Example: util.FormatExamples("init install-config", []csio.Example{ {Cmd: "-c config.yaml --vault prod.vault.yaml", Desc: "Create config files interactively"}, {Cmd: "--profile dev -c config.yaml --vault prod.vault.yaml", Desc: "Use dev profile with defaults"}, {Cmd: "--profile production -c config.yaml --vault prod.vault.yaml", Desc: "Use production profile"}, @@ -136,7 +137,7 @@ func AddInitInstallConfigCmd(init *cobra.Command, opts *GlobalOptions) { }), }, Opts: &InitInstallConfigOpts{GlobalOptions: opts}, - FileWriter: util.NewFilesystemWriter(), + FileWriter: intutil.NewFilesystemWriter(), } c.cmd.Flags().StringVarP(&c.Opts.ConfigFile, "config", "c", "config.yaml", "Output file path for config.yaml") @@ -194,7 +195,7 @@ func AddInitInstallConfigCmd(init *cobra.Command, opts *GlobalOptions) { util.MarkFlagRequired(c.cmd, "vault") c.cmd.RunE = c.RunE - AddCmd(init, c.cmd) + util.AddCmd(init, c.cmd) } func (c *InitInstallConfigCmd) InitInstallConfig(icg installer.InstallConfigManager) error { diff --git a/cli/cmd/init_install_config_interactive_test.go b/cli/cmd/init_install_config_interactive_test.go index cff1b025e..61b89bd46 100644 --- a/cli/cmd/init_install_config_interactive_test.go +++ b/cli/cmd/init_install_config_interactive_test.go @@ -9,8 +9,9 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" + "github.com/codesphere-cloud/oms/cli/cmd/util" "github.com/codesphere-cloud/oms/internal/installer" - "github.com/codesphere-cloud/oms/internal/util" + intutil "github.com/codesphere-cloud/oms/internal/util" . "github.com/codesphere-cloud/oms/internal/util/testing" ) @@ -98,13 +99,13 @@ var _ = Describe("Interactive profile usage", func() { c := &InitInstallConfigCmd{ Opts: &InitInstallConfigOpts{ - GlobalOptions: &GlobalOptions{}, + GlobalOptions: &util.GlobalOptions{}, ConfigFile: configFile.Name(), VaultFile: vaultFile.Name(), Profile: "dev", Interactive: false, // Non-interactive to avoid stdin issues }, - FileWriter: util.NewFilesystemWriter(), + FileWriter: intutil.NewFilesystemWriter(), } icg := installer.NewInstallConfigManager() @@ -156,13 +157,13 @@ var _ = Describe("Interactive profile usage", func() { c := &InitInstallConfigCmd{ Opts: &InitInstallConfigOpts{ - GlobalOptions: &GlobalOptions{}, + GlobalOptions: &util.GlobalOptions{}, ConfigFile: "config.yaml", VaultFile: "vault.yaml", Profile: "dev", Interactive: true, }, - FileWriter: util.NewFilesystemWriter(), + FileWriter: intutil.NewFilesystemWriter(), } err := c.InitInstallConfig(mockIcg) @@ -184,14 +185,14 @@ var _ = Describe("Interactive profile usage", func() { c := &InitInstallConfigCmd{ Opts: &InitInstallConfigOpts{ - GlobalOptions: &GlobalOptions{}, + GlobalOptions: &util.GlobalOptions{}, ConfigFile: configFile.Name(), VaultFile: vaultFile.Name(), Profile: "dev", Interactive: false, CodesphereOpenBaoUri: "not-a-valid-url", }, - FileWriter: util.NewFilesystemWriter(), + FileWriter: intutil.NewFilesystemWriter(), } icg := installer.NewInstallConfigManager() diff --git a/cli/cmd/install.go b/cli/cmd/install.go index 7b5d946c0..eb7674d57 100644 --- a/cli/cmd/install.go +++ b/cli/cmd/install.go @@ -5,6 +5,8 @@ package cmd import ( "github.com/codesphere-cloud/cs-go/pkg/io" + "github.com/codesphere-cloud/oms/cli/cmd/codesphere" + "github.com/codesphere-cloud/oms/cli/cmd/util" "github.com/spf13/cobra" ) @@ -13,7 +15,7 @@ type InstallCmd struct { cmd *cobra.Command } -func AddInstallCmd(rootCmd *cobra.Command, opts *GlobalOptions) { +func AddInstallCmd(rootCmd *cobra.Command, opts *util.GlobalOptions) { install := InstallCmd{ cmd: &cobra.Command{ Use: "install", @@ -21,9 +23,9 @@ func AddInstallCmd(rootCmd *cobra.Command, opts *GlobalOptions) { Long: io.Long(`Install Codesphere and other components like Ceph and PostgreSQL.`), }, } - AddCmd(rootCmd, install.cmd) + util.AddCmd(rootCmd, install.cmd) - AddInstallCodesphereCmd(install.cmd, opts) + codesphere.AddInstallCmd(install.cmd, opts) AddInstallK0sCmd(install.cmd, opts) AddInstallOpenBaoCmd(install.cmd, opts) } diff --git a/cli/cmd/install_ceph.go b/cli/cmd/install_ceph.go index ab61f8849..c0e13a282 100644 --- a/cli/cmd/install_ceph.go +++ b/cli/cmd/install_ceph.go @@ -5,6 +5,7 @@ package cmd import ( "github.com/codesphere-cloud/cs-go/pkg/io" + "github.com/codesphere-cloud/oms/cli/cmd/util" "github.com/spf13/cobra" ) @@ -21,5 +22,5 @@ func AddInstallCephCmd(install *cobra.Command) { Long: io.Long(`Coming soon: Install a Ceph cluster`), }, } - AddCmd(install, ceph.cmd) + util.AddCmd(install, ceph.cmd) } diff --git a/cli/cmd/install_k0s.go b/cli/cmd/install_k0s.go index e0e939dec..ecd59d464 100644 --- a/cli/cmd/install_k0s.go +++ b/cli/cmd/install_k0s.go @@ -12,12 +12,13 @@ import ( packageio "github.com/codesphere-cloud/cs-go/pkg/io" "github.com/spf13/cobra" + "github.com/codesphere-cloud/oms/cli/cmd/util" "github.com/codesphere-cloud/oms/internal/env" "github.com/codesphere-cloud/oms/internal/installer" "github.com/codesphere-cloud/oms/internal/installer/files" "github.com/codesphere-cloud/oms/internal/installer/vault" "github.com/codesphere-cloud/oms/internal/portal" - "github.com/codesphere-cloud/oms/internal/util" + intutil "github.com/codesphere-cloud/oms/internal/util" ) // InstallK0sCmd represents the k0s download command @@ -25,11 +26,11 @@ type InstallK0sCmd struct { cmd *cobra.Command Opts InstallK0sOpts Env env.Env - FileWriter util.FileIO + FileWriter intutil.FileIO } type InstallK0sOpts struct { - *GlobalOptions + *util.GlobalOptions Version string K0sctlVersion string Package string @@ -51,7 +52,7 @@ func (c *InstallK0sCmd) RunE(_ *cobra.Command, args []string) error { return c.InstallK0s(pm, k0s, k0sctl) } -func AddInstallK0sCmd(install *cobra.Command, opts *GlobalOptions) { +func AddInstallK0sCmd(install *cobra.Command, opts *util.GlobalOptions) { k0s := InstallK0sCmd{ cmd: &cobra.Command{ Use: "k0s", @@ -63,7 +64,7 @@ func AddInstallK0sCmd(install *cobra.Command, opts *GlobalOptions) { - Generate a k0s configuration from the install-config - Generate a k0sctl configuration for cluster deployment - Deploy k0s to all nodes defined in the install-config using k0sctl`), - Example: formatExamples("install k0s", []packageio.Example{ + Example: util.FormatExamples("install k0s", []packageio.Example{ {Cmd: "--install-config ", Desc: "Path to Codesphere install-config file to generate k0s config from"}, {Cmd: "--version ", Desc: "Version of k0s to install (e.g., v1.30.0+k0s.0)"}, {Cmd: "--k0sctl-version ", Desc: "Version of k0sctl to use (e.g., v0.17.4)"}, @@ -75,7 +76,7 @@ func AddInstallK0sCmd(install *cobra.Command, opts *GlobalOptions) { }, Opts: InstallK0sOpts{GlobalOptions: opts}, Env: env.NewEnv(), - FileWriter: util.NewFilesystemWriter(), + FileWriter: intutil.NewFilesystemWriter(), } k0s.cmd.Flags().StringVarP(&k0s.Opts.Version, "version", "v", "", "Version of k0s to install") k0s.cmd.Flags().StringVar(&k0s.Opts.K0sctlVersion, "k0sctl-version", "", "Version of k0sctl to use") @@ -90,7 +91,7 @@ func AddInstallK0sCmd(install *cobra.Command, opts *GlobalOptions) { _ = k0s.cmd.MarkFlagRequired("install-config") - AddCmd(install, k0s.cmd) + util.AddCmd(install, k0s.cmd) k0s.cmd.RunE = k0s.RunE } diff --git a/cli/cmd/install_k0s_test.go b/cli/cmd/install_k0s_test.go index 118acb76c..3d0e3b4eb 100644 --- a/cli/cmd/install_k0s_test.go +++ b/cli/cmd/install_k0s_test.go @@ -15,11 +15,12 @@ import ( "gopkg.in/yaml.v3" "github.com/codesphere-cloud/oms/cli/cmd" + "github.com/codesphere-cloud/oms/cli/cmd/util" "github.com/codesphere-cloud/oms/internal/env" "github.com/codesphere-cloud/oms/internal/installer" "github.com/codesphere-cloud/oms/internal/installer/files" "github.com/codesphere-cloud/oms/internal/installer/vault" - "github.com/codesphere-cloud/oms/internal/util" + intutil "github.com/codesphere-cloud/oms/internal/util" ) func execCmd(name string, args ...string) ([]byte, error) { @@ -31,15 +32,15 @@ var _ = Describe("InstallK0sCmd", func() { var ( c cmd.InstallK0sCmd opts *cmd.InstallK0sOpts - globalOpts *cmd.GlobalOptions + globalOpts *util.GlobalOptions mockEnv *env.MockEnv - mockFileWriter *util.MockFileIO + mockFileWriter *intutil.MockFileIO ) BeforeEach(func() { mockEnv = env.NewMockEnv(GinkgoT()) - mockFileWriter = util.NewMockFileIO(GinkgoT()) - globalOpts = &cmd.GlobalOptions{} + mockFileWriter = intutil.NewMockFileIO(GinkgoT()) + globalOpts = &util.GlobalOptions{} opts = &cmd.InstallK0sOpts{ GlobalOptions: globalOpts, Version: "", @@ -387,7 +388,7 @@ var _ = Describe("InstallK0sCmd", func() { Skip("sops and age-keygen not available") } - c.FileWriter = util.NewFilesystemWriter() + c.FileWriter = intutil.NewFilesystemWriter() ageKeyPath := filepath.Join(tempDir, "age_key.txt") out, err := execCmd("age-keygen", "-o", ageKeyPath) @@ -454,7 +455,7 @@ var _ = Describe("InstallK0sCmd", func() { Skip("sops and age-keygen not available") } - c.FileWriter = util.NewFilesystemWriter() + c.FileWriter = intutil.NewFilesystemWriter() ageKeyPath := filepath.Join(tempDir, "age_key.txt") out, err := execCmd("age-keygen", "-o", ageKeyPath) @@ -577,6 +578,7 @@ var _ = Describe("InstallK0sCmd", func() { }), mock.Anything, mock.Anything).Return(nil) mockK0sctl.EXPECT().Apply(mock.Anything, "/tmp/k0sctl", false).Return(nil) mockK0sctl.EXPECT().GetKubeconfig(mock.Anything, "/tmp/k0sctl").Return("apiVersion: v1\nkind: Config\n", nil) + mockFileWriter.EXPECT().MkdirAll(mock.Anything, os.FileMode(0755)).Return(nil) // Vault exists and is encrypted. mockFileWriter.EXPECT().Exists(vaultPath).Return(true) diff --git a/cli/cmd/install_openbao.go b/cli/cmd/install_openbao.go index b464fe993..262a22ee7 100644 --- a/cli/cmd/install_openbao.go +++ b/cli/cmd/install_openbao.go @@ -21,9 +21,9 @@ import ( packageio "github.com/codesphere-cloud/cs-go/pkg/io" "github.com/spf13/cobra" + "github.com/codesphere-cloud/oms/cli/cmd/util" "github.com/codesphere-cloud/oms/internal/installer" "github.com/codesphere-cloud/oms/internal/installer/vault" - "github.com/codesphere-cloud/oms/internal/util" ) // InstallOpenBaoCmd wraps the cobra command and options for 'oms install openbao'. @@ -34,7 +34,7 @@ type InstallOpenBaoCmd struct { // InstallOpenBaoOpts holds the CLI flags for the OpenBao installer. type InstallOpenBaoOpts struct { - *GlobalOptions + *util.GlobalOptions Namespace string SecretsEngineName string BaoUsername string @@ -114,7 +114,7 @@ func (c *InstallOpenBaoCmd) RunE(_ *cobra.Command, _ []string) error { } // AddInstallOpenBaoCmd registers the openbao subcommand under install. -func AddInstallOpenBaoCmd(install *cobra.Command, opts *GlobalOptions) { +func AddInstallOpenBaoCmd(install *cobra.Command, opts *util.GlobalOptions) { openbao := InstallOpenBaoCmd{ cmd: &cobra.Command{ Use: "openbao", @@ -130,7 +130,7 @@ func AddInstallOpenBaoCmd(install *cobra.Command, opts *GlobalOptions) { 6. Extract and encrypt unseal keys + password as SOPS DR backup The command is idempotent and safe to re-run.`), - Example: formatExamples("install openbao", []packageio.Example{ + Example: util.FormatExamples("install openbao", []packageio.Example{ {Cmd: "--dr-backup-path ./backups/cluster-1.enc.json", Desc: "Fresh bootstrap with DR backup saved locally"}, {Cmd: "--dr-backup-path ./backups/cluster-1.enc.json --secrets-engine my-engine --bao-user myuser", Desc: "Custom engine and user"}, {Cmd: "--dr-backup-path ./backups/cluster-1.enc.json --timeout 10m", Desc: "Extended timeout for slower clusters"}, @@ -150,7 +150,7 @@ func AddInstallOpenBaoCmd(install *cobra.Command, opts *GlobalOptions) { util.MarkFlagRequired(openbao.cmd, "dr-backup-path") - AddCmd(install, openbao.cmd) + util.AddCmd(install, openbao.cmd) openbao.cmd.RunE = openbao.RunE } diff --git a/cli/cmd/licenses.go b/cli/cmd/licenses.go index b518d058c..531a5348e 100644 --- a/cli/cmd/licenses.go +++ b/cli/cmd/licenses.go @@ -6,6 +6,7 @@ package cmd import ( "log" + "github.com/codesphere-cloud/oms/cli/cmd/util" "github.com/codesphere-cloud/oms/internal/tmpl" "github.com/spf13/cobra" ) @@ -34,6 +35,6 @@ func AddLicensesCmd(rootCmd *cobra.Command) { Long: `Print information about the OMS license and open source licenses of dependencies.`, }, } - AddCmd(rootCmd, licenses.cmd) + util.AddCmd(rootCmd, licenses.cmd) licenses.cmd.RunE = licenses.RunE } diff --git a/cli/cmd/list.go b/cli/cmd/list.go index 37d0f57cd..083f24b9d 100644 --- a/cli/cmd/list.go +++ b/cli/cmd/list.go @@ -5,6 +5,7 @@ package cmd import ( "github.com/codesphere-cloud/cs-go/pkg/io" + "github.com/codesphere-cloud/oms/cli/cmd/util" "github.com/spf13/cobra" ) @@ -12,7 +13,7 @@ type ListCmd struct { cmd *cobra.Command } -func AddListCmd(rootCmd *cobra.Command, opts *GlobalOptions) { +func AddListCmd(rootCmd *cobra.Command, opts *util.GlobalOptions) { list := ListCmd{ cmd: &cobra.Command{ Use: "list", @@ -21,7 +22,7 @@ func AddListCmd(rootCmd *cobra.Command, opts *GlobalOptions) { eg. available Codesphere packages`), }, } - AddCmd(rootCmd, list.cmd) + util.AddCmd(rootCmd, list.cmd) AddListPackagesCmd(list.cmd, opts) AddListAPIKeysCmd(list.cmd, opts) } diff --git a/cli/cmd/list_api_keys.go b/cli/cmd/list_api_keys.go index 7a5d833d4..0a5930b73 100644 --- a/cli/cmd/list_api_keys.go +++ b/cli/cmd/list_api_keys.go @@ -6,8 +6,9 @@ package cmd import ( "fmt" + "github.com/codesphere-cloud/oms/cli/cmd/util" "github.com/codesphere-cloud/oms/internal/portal" - "github.com/codesphere-cloud/oms/internal/util" + intutil "github.com/codesphere-cloud/oms/internal/util" "github.com/codesphere-cloud/cs-go/pkg/io" "github.com/jedib0t/go-pretty/v6/table" @@ -16,7 +17,7 @@ import ( type ListAPIKeysCmd struct { cmd *cobra.Command - TableWriter util.TableWriter + TableWriter intutil.TableWriter } func (c *ListAPIKeysCmd) RunE(_ *cobra.Command, args []string) error { @@ -30,19 +31,19 @@ func (c *ListAPIKeysCmd) RunE(_ *cobra.Command, args []string) error { return nil } -func AddListAPIKeysCmd(list *cobra.Command, opts *GlobalOptions) { +func AddListAPIKeysCmd(list *cobra.Command, opts *util.GlobalOptions) { c := ListAPIKeysCmd{ cmd: &cobra.Command{ Use: "api-keys", Short: "List API keys", Long: io.Long(`List API keys registered in the OMS portal.`), }, - TableWriter: util.GetTableWriter(), + TableWriter: intutil.GetTableWriter(), } c.cmd.RunE = c.RunE - AddCmd(list, c.cmd) + util.AddCmd(list, c.cmd) } func (c *ListAPIKeysCmd) PrintKeysTable(keys []portal.ApiKey) { diff --git a/cli/cmd/list_packages.go b/cli/cmd/list_packages.go index dde6228c4..ad2764761 100644 --- a/cli/cmd/list_packages.go +++ b/cli/cmd/list_packages.go @@ -6,8 +6,9 @@ package cmd import ( "fmt" + "github.com/codesphere-cloud/oms/cli/cmd/util" "github.com/codesphere-cloud/oms/internal/portal" - "github.com/codesphere-cloud/oms/internal/util" + intutil "github.com/codesphere-cloud/oms/internal/util" "github.com/codesphere-cloud/cs-go/pkg/io" "github.com/jedib0t/go-pretty/v6/table" @@ -17,11 +18,11 @@ import ( type ListBuildsCmd struct { cmd *cobra.Command Opts ListBuildsOpts - TableWriter util.TableWriter + TableWriter intutil.TableWriter } type ListBuildsOpts struct { - *GlobalOptions + *util.GlobalOptions Internal bool Sort string } @@ -41,7 +42,7 @@ func (c *ListBuildsCmd) RunE(_ *cobra.Command, args []string) error { return nil } -func AddListPackagesCmd(list *cobra.Command, opts *GlobalOptions) { +func AddListPackagesCmd(list *cobra.Command, opts *util.GlobalOptions) { builds := ListBuildsCmd{ cmd: &cobra.Command{ Use: "packages", @@ -49,7 +50,7 @@ func AddListPackagesCmd(list *cobra.Command, opts *GlobalOptions) { Long: io.Long(`List packages available for download via the OMS portal.`), }, Opts: ListBuildsOpts{GlobalOptions: opts}, - TableWriter: util.GetTableWriter(), + TableWriter: intutil.GetTableWriter(), } builds.cmd.RunE = builds.RunE @@ -57,7 +58,7 @@ func AddListPackagesCmd(list *cobra.Command, opts *GlobalOptions) { _ = builds.cmd.Flags().MarkHidden("list-internal") builds.cmd.Flags().StringVarP(&builds.Opts.Sort, "sort", "s", portal.SortSemver, "Sort order: 'semver' (by semantic version) or 'date' (by build date)") - AddCmd(list, builds.cmd) + util.AddCmd(list, builds.cmd) } func (c *ListBuildsCmd) PrintPackagesTable(packages portal.Builds) { diff --git a/cli/cmd/pc_apps.go b/cli/cmd/pc_apps.go index 2bd94b3b9..a2b67310f 100644 --- a/cli/cmd/pc_apps.go +++ b/cli/cmd/pc_apps.go @@ -7,8 +7,8 @@ import ( "fmt" packageio "github.com/codesphere-cloud/cs-go/pkg/io" + "github.com/codesphere-cloud/oms/cli/cmd/util" "github.com/codesphere-cloud/oms/internal/installer" - "github.com/codesphere-cloud/oms/internal/util" "github.com/spf13/cobra" ctrlclient "sigs.k8s.io/controller-runtime/pkg/client" ctrlconfig "sigs.k8s.io/controller-runtime/pkg/client/config" @@ -21,7 +21,7 @@ type InstallPCAppsCmd struct { } type InstallPCAppsOpts struct { - *GlobalOptions + *util.GlobalOptions Version string Namespace string ValuesFiles []string @@ -58,7 +58,7 @@ func (c *InstallPCAppsCmd) RunE(cmd *cobra.Command, args []string) error { return nil } -func AddPCAppsCmd(parentCmd *cobra.Command, opts *GlobalOptions) { +func AddPCAppsCmd(parentCmd *cobra.Command, opts *util.GlobalOptions) { pcApps := InstallPCAppsCmd{ Opts: InstallPCAppsOpts{ GlobalOptions: opts, @@ -74,7 +74,7 @@ func AddPCAppsCmd(parentCmd *cobra.Command, opts *GlobalOptions) { Registry credentials and chart URL are read automatically from the Kubernetes secret "argocd-codesphere-oci-read" in the argocd namespace. This secret is created by "oms beta install argocd --deploy-dc-config".`), - Example: formatExamples("beta install pc-apps", []packageio.Example{ + Example: util.FormatExamples("beta install pc-apps", []packageio.Example{ {Cmd: "--version 1.0.0", Desc: "Install a specific version"}, {Cmd: "--version 1.0.0 -f base.yaml -f dc-overlay.yaml", Desc: "Install with custom values files"}, {Cmd: "--version 1.0.0 --namespace custom-ns", Desc: "Install into a custom namespace"}, @@ -89,5 +89,5 @@ func AddPCAppsCmd(parentCmd *cobra.Command, opts *GlobalOptions) { util.MarkFlagRequired(pcApps.cmd, "version") - AddCmd(parentCmd, pcApps.cmd) + util.AddCmd(parentCmd, pcApps.cmd) } diff --git a/cli/cmd/register.go b/cli/cmd/register.go index 99a489bb7..e8882d88d 100644 --- a/cli/cmd/register.go +++ b/cli/cmd/register.go @@ -9,8 +9,9 @@ import ( "time" "github.com/codesphere-cloud/cs-go/pkg/io" + "github.com/codesphere-cloud/oms/cli/cmd/util" "github.com/codesphere-cloud/oms/internal/portal" - "github.com/codesphere-cloud/oms/internal/util" + intutil "github.com/codesphere-cloud/oms/internal/util" "github.com/spf13/cobra" ) @@ -26,7 +27,7 @@ type RegisterCmd struct { } type RegisterOpts struct { - *GlobalOptions + *util.GlobalOptions Owner string Organization string Role string @@ -47,7 +48,7 @@ func (c *RegisterCmd) RunE(_ *cobra.Command, args []string) error { return nil } -func AddRegisterCmd(list *cobra.Command, opts *GlobalOptions) { +func AddRegisterCmd(list *cobra.Command, opts *util.GlobalOptions) { c := RegisterCmd{ cmd: &cobra.Command{ Use: "register", @@ -63,7 +64,7 @@ func AddRegisterCmd(list *cobra.Command, opts *GlobalOptions) { c.cmd.RunE = c.RunE - AddCmd(list, c.cmd) + util.AddCmd(list, c.cmd) } func (c *RegisterCmd) Register(p portal.Portal) (*portal.ApiKey, error) { @@ -73,7 +74,7 @@ func (c *RegisterCmd) Register(p portal.Portal) (*portal.ApiKey, error) { var expiresAt time.Time if c.Opts.ValidFor != "" { - validForDuration, err := util.GetDurationFromString(c.Opts.ValidFor) + validForDuration, err := intutil.GetDurationFromString(c.Opts.ValidFor) if err != nil { return nil, err } diff --git a/cli/cmd/register_test.go b/cli/cmd/register_test.go index be46cefdb..438b48320 100644 --- a/cli/cmd/register_test.go +++ b/cli/cmd/register_test.go @@ -13,6 +13,7 @@ import ( "github.com/stretchr/testify/mock" "github.com/codesphere-cloud/oms/cli/cmd" + "github.com/codesphere-cloud/oms/cli/cmd/util" "github.com/codesphere-cloud/oms/internal/portal" ) @@ -130,7 +131,7 @@ var _ = Describe("RegisterCmd", func() { var _ = Describe("AddRegisterCmd", func() { It("adds the register command to the parent", func() { parent := &cobra.Command{} - opts := &cmd.GlobalOptions{} + opts := &util.GlobalOptions{} cmd.AddRegisterCmd(parent, opts) found := false for _, c := range parent.Commands() { diff --git a/cli/cmd/revoke.go b/cli/cmd/revoke.go index 3332913d6..907ac6a81 100644 --- a/cli/cmd/revoke.go +++ b/cli/cmd/revoke.go @@ -5,6 +5,7 @@ package cmd import ( "github.com/codesphere-cloud/cs-go/pkg/io" + "github.com/codesphere-cloud/oms/cli/cmd/util" "github.com/spf13/cobra" ) @@ -12,7 +13,7 @@ type RevokeCmd struct { cmd *cobra.Command } -func AddRevokeCmd(rootCmd *cobra.Command, opts *GlobalOptions) { +func AddRevokeCmd(rootCmd *cobra.Command, opts *util.GlobalOptions) { revoke := RevokeCmd{ cmd: &cobra.Command{ Use: "revoke", @@ -21,6 +22,6 @@ func AddRevokeCmd(rootCmd *cobra.Command, opts *GlobalOptions) { eg. api keys.`), }, } - AddCmd(rootCmd, revoke.cmd) + util.AddCmd(rootCmd, revoke.cmd) AddRevokeAPIKeyCmd(revoke.cmd, opts) } diff --git a/cli/cmd/revoke_api_key.go b/cli/cmd/revoke_api_key.go index e766af724..f01592cf9 100644 --- a/cli/cmd/revoke_api_key.go +++ b/cli/cmd/revoke_api_key.go @@ -7,8 +7,8 @@ import ( "fmt" "github.com/codesphere-cloud/cs-go/pkg/io" + "github.com/codesphere-cloud/oms/cli/cmd/util" "github.com/codesphere-cloud/oms/internal/portal" - "github.com/codesphere-cloud/oms/internal/util" "github.com/spf13/cobra" ) @@ -18,7 +18,7 @@ type RevokeAPIKeyCmd struct { } type RevokeAPIKeyOpts struct { - *GlobalOptions + *util.GlobalOptions ID string } @@ -36,7 +36,7 @@ func (c *RevokeAPIKeyCmd) Revoke(p portal.Portal) error { return nil } -func AddRevokeAPIKeyCmd(list *cobra.Command, opts *GlobalOptions) { +func AddRevokeAPIKeyCmd(list *cobra.Command, opts *util.GlobalOptions) { c := RevokeAPIKeyCmd{ cmd: &cobra.Command{ Use: "api-key", @@ -51,5 +51,5 @@ func AddRevokeAPIKeyCmd(list *cobra.Command, opts *GlobalOptions) { c.cmd.RunE = c.RunE - AddCmd(list, c.cmd) + util.AddCmd(list, c.cmd) } diff --git a/cli/cmd/revoke_api_key_test.go b/cli/cmd/revoke_api_key_test.go index a2ed0c95c..c6e4bedb7 100644 --- a/cli/cmd/revoke_api_key_test.go +++ b/cli/cmd/revoke_api_key_test.go @@ -11,6 +11,7 @@ import ( "github.com/spf13/cobra" "github.com/codesphere-cloud/oms/cli/cmd" + "github.com/codesphere-cloud/oms/cli/cmd/util" "github.com/codesphere-cloud/oms/internal/portal" ) @@ -51,7 +52,7 @@ var _ = Describe("RevokeCmd", func() { var _ = Describe("AddRevokeAPIKeyCmd", func() { It("adds the api-key command to the parent", func() { parent := &cobra.Command{} - opts := &cmd.GlobalOptions{} + opts := &util.GlobalOptions{} cmd.AddRevokeAPIKeyCmd(parent, opts) found := false for _, c := range parent.Commands() { diff --git a/cli/cmd/root.go b/cli/cmd/root.go index 51bbfab82..eb703b7c3 100644 --- a/cli/cmd/root.go +++ b/cli/cmd/root.go @@ -8,26 +8,14 @@ import ( "os" "github.com/codesphere-cloud/cs-go/pkg/io" + "github.com/codesphere-cloud/oms/cli/cmd/util" "github.com/codesphere-cloud/oms/internal/portal" "github.com/spf13/cobra" ) -type GlobalOptions struct { - OmsPortalApiKey string -} - -// AddCmd adds a command, inheriting the parent's Args validator if not explicitly set. -// Individual commands that need different argument rules can override this by setting their own Args validator. -func AddCmd(parent *cobra.Command, cmd *cobra.Command) { - if cmd.Args == nil { - cmd.Args = parent.Args - } - parent.AddCommand(cmd) -} - // GetRootCmd adds all child commands to the root command and sets flags appropriately. func GetRootCmd() *cobra.Command { - opts := &GlobalOptions{} + opts := &util.GlobalOptions{} rootCmd := &cobra.Command{ Use: "oms", Short: "Codesphere Operations Management System (OMS)", diff --git a/cli/cmd/root_test.go b/cli/cmd/root_test.go index 2bc849b98..c780b4629 100644 --- a/cli/cmd/root_test.go +++ b/cli/cmd/root_test.go @@ -8,10 +8,10 @@ import ( . "github.com/onsi/gomega" "github.com/spf13/cobra" - "github.com/codesphere-cloud/oms/cli/cmd" + "github.com/codesphere-cloud/oms/cli/cmd/util" ) -var _ = Describe("AddCmd", func() { +var _ = Describe("util.AddCmd", func() { It("inherits the parent Args validator when the child does not define one", func() { parent := &cobra.Command{ Use: "root", @@ -23,7 +23,7 @@ var _ = Describe("AddCmd", func() { Use: "child", RunE: func(_ *cobra.Command, _ []string) error { return nil }, } - cmd.AddCmd(parent, child) + util.AddCmd(parent, child) parent.SetArgs([]string{"child", "extra"}) err := parent.Execute() @@ -49,7 +49,7 @@ var _ = Describe("AddCmd", func() { return nil }, } - cmd.AddCmd(parent, child) + util.AddCmd(parent, child) parent.SetArgs([]string{"child", "value"}) err := parent.Execute() diff --git a/cli/cmd/smoketest.go b/cli/cmd/smoketest.go index 02f1db468..7585bdadf 100644 --- a/cli/cmd/smoketest.go +++ b/cli/cmd/smoketest.go @@ -5,6 +5,7 @@ package cmd import ( "github.com/codesphere-cloud/cs-go/pkg/io" + "github.com/codesphere-cloud/oms/cli/cmd/util" "github.com/spf13/cobra" ) @@ -13,7 +14,7 @@ type SmoketestCmd struct { cmd *cobra.Command } -func AddSmoketestCmd(rootCmd *cobra.Command, opts *GlobalOptions) { +func AddSmoketestCmd(rootCmd *cobra.Command, opts *util.GlobalOptions) { smoketest := SmoketestCmd{ cmd: &cobra.Command{ Use: "smoketest", @@ -21,7 +22,7 @@ func AddSmoketestCmd(rootCmd *cobra.Command, opts *GlobalOptions) { Long: io.Long(`Run automated smoke tests for Codesphere installations to verify functionality.`), }, } - AddCmd(rootCmd, smoketest.cmd) + util.AddCmd(rootCmd, smoketest.cmd) AddSmoketestCodesphereCmd(smoketest.cmd, opts) } diff --git a/cli/cmd/smoketest_codesphere.go b/cli/cmd/smoketest_codesphere.go index 5f1462d73..501877c59 100644 --- a/cli/cmd/smoketest_codesphere.go +++ b/cli/cmd/smoketest_codesphere.go @@ -12,9 +12,9 @@ import ( "time" "github.com/codesphere-cloud/cs-go/pkg/io" + "github.com/codesphere-cloud/oms/cli/cmd/util" "github.com/codesphere-cloud/oms/internal/codesphere" "github.com/codesphere-cloud/oms/internal/codesphere/teststeps" - "github.com/codesphere-cloud/oms/internal/util" "github.com/spf13/cobra" ) @@ -50,7 +50,7 @@ func (c *SmoketestCodesphereCmd) RunE(_ *cobra.Command, args []string) error { return c.RunSmoketest() } -func AddSmoketestCodesphereCmd(parent *cobra.Command, opts *GlobalOptions) { +func AddSmoketestCodesphereCmd(parent *cobra.Command, opts *util.GlobalOptions) { var stepNames []string for _, s := range availableSteps { stepNames = append(stepNames, s.Name()) @@ -63,7 +63,7 @@ func AddSmoketestCodesphereCmd(parent *cobra.Command, opts *GlobalOptions) { Long: io.Long(`Run automated smoke tests for a Codesphere installation by creating a workspace, setting environment variables, executing commands, syncing landscape, and running a pipeline stage. The workspace is automatically deleted after the test completes.`), - Example: formatExamples("smoketest codesphere", []io.Example{ + Example: util.FormatExamples("smoketest codesphere", []io.Example{ { Cmd: "--baseurl https://codesphere.example.com/api --token YOUR_TOKEN", Desc: "Run smoke tests against a Codesphere installation", @@ -110,7 +110,7 @@ func AddSmoketestCodesphereCmd(parent *cobra.Command, opts *GlobalOptions) { c.cmd.RunE = c.RunE - AddCmd(parent, c.cmd) + util.AddCmd(parent, c.cmd) } func (c *SmoketestCodesphereCmd) RunSmoketest() (err error) { diff --git a/cli/cmd/smoketest_codesphere_test.go b/cli/cmd/smoketest_codesphere_test.go index afa7143d4..177257634 100644 --- a/cli/cmd/smoketest_codesphere_test.go +++ b/cli/cmd/smoketest_codesphere_test.go @@ -16,6 +16,7 @@ import ( "github.com/stretchr/testify/mock" "github.com/codesphere-cloud/oms/cli/cmd" + "github.com/codesphere-cloud/oms/cli/cmd/util" "github.com/codesphere-cloud/oms/internal/codesphere" "github.com/codesphere-cloud/oms/internal/codesphere/teststeps" ) @@ -642,7 +643,7 @@ var _ = Describe("SmoketestCodesphereCmd", func() { var _ = Describe("AddSmoketestCodesphereCmd", func() { It("adds the smoketest codesphere command to the parent", func() { parent := &cobra.Command{} - opts := &cmd.GlobalOptions{} + opts := &util.GlobalOptions{} cmd.AddSmoketestCodesphereCmd(parent, opts) found := false for _, c := range parent.Commands() { diff --git a/cli/cmd/template.go b/cli/cmd/template.go index fc78049de..8ad221250 100644 --- a/cli/cmd/template.go +++ b/cli/cmd/template.go @@ -5,6 +5,7 @@ package cmd import ( "github.com/codesphere-cloud/cs-go/pkg/io" + "github.com/codesphere-cloud/oms/cli/cmd/util" "github.com/spf13/cobra" ) @@ -12,7 +13,7 @@ type TemplateCmd struct { cmd *cobra.Command } -func AddTemplateCmd(rootCmd *cobra.Command, opts *GlobalOptions) { +func AddTemplateCmd(rootCmd *cobra.Command, opts *util.GlobalOptions) { template := TemplateCmd{ cmd: &cobra.Command{ Use: "template", @@ -22,5 +23,5 @@ func AddTemplateCmd(rootCmd *cobra.Command, opts *GlobalOptions) { } AddTemplateConfigCmd(template.cmd, opts) - AddCmd(rootCmd, template.cmd) + util.AddCmd(rootCmd, template.cmd) } diff --git a/cli/cmd/template_config.go b/cli/cmd/template_config.go index a01634806..48d1010c3 100644 --- a/cli/cmd/template_config.go +++ b/cli/cmd/template_config.go @@ -8,9 +8,9 @@ import ( "os" "github.com/codesphere-cloud/cs-go/pkg/io" + "github.com/codesphere-cloud/oms/cli/cmd/util" "github.com/codesphere-cloud/oms/internal/configtemplating" "github.com/codesphere-cloud/oms/internal/installer/vault" - "github.com/codesphere-cloud/oms/internal/util" "github.com/spf13/cobra" ) @@ -20,7 +20,7 @@ type TemplateConfigCmd struct { } type TemplateConfigOpts struct { - *GlobalOptions + *util.GlobalOptions Config string Vault string AgeKey string @@ -43,7 +43,7 @@ func (c *TemplateConfigCmd) RunE(cmd *cobra.Command, _ []string) error { return nil } -func AddTemplateConfigCmd(parentCmd *cobra.Command, opts *GlobalOptions) { +func AddTemplateConfigCmd(parentCmd *cobra.Command, opts *util.GlobalOptions) { configCmd := &TemplateConfigCmd{ cmd: &cobra.Command{ Use: "config", @@ -65,7 +65,7 @@ Template syntax in config.yaml: caCert: "{{ secret "caCert" "file.content" }}" Secret names and selectors must match entries in the prod.vault.yaml file.`), - Example: formatExamples("template config", []io.Example{ + Example: util.FormatExamples("template config", []io.Example{ { Cmd: "--config config.yaml --vault prod.vault.yaml --age-key age_key.txt", Desc: "Render config.yaml with secrets from prod.vault.yaml", @@ -84,7 +84,7 @@ Secret names and selectors must match entries in the prod.vault.yaml file.`), util.MarkFlagRequired(configCmd.cmd, "vault") util.MarkFlagRequired(configCmd.cmd, "age-key") - AddCmd(parentCmd, configCmd.cmd) + util.AddCmd(parentCmd, configCmd.cmd) configCmd.cmd.RunE = configCmd.RunE } diff --git a/cli/cmd/update.go b/cli/cmd/update.go index 45c5614c4..4112b51b4 100644 --- a/cli/cmd/update.go +++ b/cli/cmd/update.go @@ -5,6 +5,7 @@ package cmd import ( "github.com/codesphere-cloud/cs-go/pkg/io" + "github.com/codesphere-cloud/oms/cli/cmd/util" "github.com/spf13/cobra" ) @@ -12,7 +13,7 @@ type UpdateCmd struct { cmd *cobra.Command } -func AddUpdateCmd(rootCmd *cobra.Command, opts *GlobalOptions) { +func AddUpdateCmd(rootCmd *cobra.Command, opts *util.GlobalOptions) { updateCmd := UpdateCmd{ cmd: &cobra.Command{ Use: "update", @@ -26,5 +27,5 @@ func AddUpdateCmd(rootCmd *cobra.Command, opts *GlobalOptions) { AddUpdateDockerfileCmd(updateCmd.cmd, opts) AddUpdateInstallConfigCmd(updateCmd.cmd, opts) - AddCmd(rootCmd, updateCmd.cmd) + util.AddCmd(rootCmd, updateCmd.cmd) } diff --git a/cli/cmd/update_api_key.go b/cli/cmd/update_api_key.go index 4114f54be..b425d3854 100644 --- a/cli/cmd/update_api_key.go +++ b/cli/cmd/update_api_key.go @@ -8,8 +8,9 @@ import ( "log" "time" + "github.com/codesphere-cloud/oms/cli/cmd/util" "github.com/codesphere-cloud/oms/internal/portal" - "github.com/codesphere-cloud/oms/internal/util" + intutil "github.com/codesphere-cloud/oms/internal/util" "github.com/spf13/cobra" ) @@ -18,7 +19,7 @@ type UpdateAPIKeyCmd struct { } type UpdateAPIKeyOpts struct { - *GlobalOptions + *util.GlobalOptions APIKeyID string ValidFor string } @@ -45,11 +46,11 @@ func AddApiKeyUpdateCmd(parentCmd *cobra.Command) { util.MarkFlagRequired(apiKeyCmd, "id") util.MarkFlagRequired(apiKeyCmd, "valid-for") - AddCmd(parentCmd, apiKeyCmd) + util.AddCmd(parentCmd, apiKeyCmd) } func (c *UpdateAPIKeyCmd) UpdateAPIKey(p portal.Portal) error { - validForDuration, err := util.GetDurationFromString(c.Opts.ValidFor) + validForDuration, err := intutil.GetDurationFromString(c.Opts.ValidFor) if err != nil { return err } diff --git a/cli/cmd/update_dockerfile.go b/cli/cmd/update_dockerfile.go index 59a6cd3f9..601362ae7 100644 --- a/cli/cmd/update_dockerfile.go +++ b/cli/cmd/update_dockerfile.go @@ -10,10 +10,11 @@ import ( "log" "github.com/codesphere-cloud/cs-go/pkg/io" + "github.com/codesphere-cloud/oms/cli/cmd/util" "github.com/codesphere-cloud/oms/internal/env" "github.com/codesphere-cloud/oms/internal/installer" "github.com/codesphere-cloud/oms/internal/system" - "github.com/codesphere-cloud/oms/internal/util" + intutil "github.com/codesphere-cloud/oms/internal/util" "github.com/spf13/cobra" ) @@ -24,7 +25,7 @@ type UpdateDockerfileCmd struct { } type UpdateDockerfileOpts struct { - *GlobalOptions + *util.GlobalOptions Package string Dockerfile string Baseimage string @@ -48,7 +49,7 @@ func (c *UpdateDockerfileCmd) RunE(_ *cobra.Command, args []string) error { return nil } -func AddUpdateDockerfileCmd(parentCmd *cobra.Command, opts *GlobalOptions) { +func AddUpdateDockerfileCmd(parentCmd *cobra.Command, opts *util.GlobalOptions) { dockerfileCmd := &UpdateDockerfileCmd{ cmd: &cobra.Command{ Use: "dockerfile", @@ -57,7 +58,7 @@ func AddUpdateDockerfileCmd(parentCmd *cobra.Command, opts *GlobalOptions) { This command extracts the base image from a Codesphere package and updates the FROM statement in the specified Dockerfile to use that base image. The base image is loaded into the local Docker daemon so it can be used for building.`, - Example: formatExamples("update dockerfile", []io.Example{ + Example: util.FormatExamples("update dockerfile", []io.Example{ {Cmd: "--dockerfile baseimage/Dockerfile --package codesphere-v1.68.0.tar.gz", Desc: "Update Dockerfile to use the default base image from the package (workspace-agent-24.04)"}, {Cmd: "--dockerfile baseimage/Dockerfile --package codesphere-v1.68.0.tar.gz --baseimage workspace-agent-20.04.tar", Desc: "Update Dockerfile to use the workspace-agent-20.04 base image from the package"}, }), @@ -75,7 +76,7 @@ in the specified Dockerfile to use that base image. The base image is loaded int util.MarkFlagRequired(dockerfileCmd.cmd, "dockerfile") util.MarkFlagRequired(dockerfileCmd.cmd, "package") - AddCmd(parentCmd, dockerfileCmd.cmd) + util.AddCmd(parentCmd, dockerfileCmd.cmd) dockerfileCmd.cmd.RunE = dockerfileCmd.RunE } @@ -109,9 +110,9 @@ func (c *UpdateDockerfileCmd) UpdateDockerfile(pm installer.PackageManager, im s if err != nil { return fmt.Errorf("failed to open dockerfile %s: %w", c.Opts.Dockerfile, err) } - defer util.CloseFileIgnoreError(dockerfileFile) + defer intutil.CloseFileIgnoreError(dockerfileFile) - dockerfileManager := util.NewDockerfileManager() + dockerfileManager := intutil.NewDockerfileManager() updatedContent, err := dockerfileManager.UpdateFromStatement(dockerfileFile, imageName) if err != nil { return fmt.Errorf("failed to update FROM statement: %w", err) diff --git a/cli/cmd/update_dockerfile_test.go b/cli/cmd/update_dockerfile_test.go index 9c8522239..0505197b3 100644 --- a/cli/cmd/update_dockerfile_test.go +++ b/cli/cmd/update_dockerfile_test.go @@ -12,10 +12,11 @@ import ( "github.com/spf13/cobra" "github.com/codesphere-cloud/oms/cli/cmd" + "github.com/codesphere-cloud/oms/cli/cmd/util" "github.com/codesphere-cloud/oms/internal/env" "github.com/codesphere-cloud/oms/internal/installer" "github.com/codesphere-cloud/oms/internal/system" - "github.com/codesphere-cloud/oms/internal/util" + intutil "github.com/codesphere-cloud/oms/internal/util" ) const sampleDockerfileContent = `FROM workspace-agent:20.04 @@ -28,13 +29,13 @@ var _ = Describe("UpdateDockerfileCmd", func() { var ( c cmd.UpdateDockerfileCmd opts cmd.UpdateDockerfileOpts - globalOpts *cmd.GlobalOptions + globalOpts *util.GlobalOptions mockEnv *env.MockEnv ) BeforeEach(func() { mockEnv = env.NewMockEnv(GinkgoT()) - globalOpts = &cmd.GlobalOptions{} + globalOpts = &util.GlobalOptions{} opts = cmd.UpdateDockerfileOpts{ GlobalOptions: globalOpts, Package: "codesphere-v1.68.0.tar.gz", @@ -98,7 +99,7 @@ var _ = Describe("UpdateDockerfileCmd", func() { It("fails when dockerfile cannot be opened", func() { mockPackageManager := installer.NewMockPackageManager(GinkgoT()) mockImageManager := system.NewMockImageManager(GinkgoT()) - mockFileIO := util.NewMockFileIO(GinkgoT()) + mockFileIO := intutil.NewMockFileIO(GinkgoT()) c.Opts.Dockerfile = "Dockerfile" c.Opts.Baseimage = "" @@ -137,7 +138,7 @@ var _ = Describe("UpdateDockerfileCmd", func() { It("fails when writing updated dockerfile fails", func() { mockPackageManager := installer.NewMockPackageManager(GinkgoT()) mockImageManager := system.NewMockImageManager(GinkgoT()) - mockFileIO := util.NewMockFileIO(GinkgoT()) + mockFileIO := intutil.NewMockFileIO(GinkgoT()) // Create a temporary file for the Dockerfile tempFile, err := os.CreateTemp("", "dockerfile-test-*") @@ -171,7 +172,7 @@ var _ = Describe("UpdateDockerfileCmd", func() { It("successfully updates dockerfile and loads image", func() { mockPackageManager := installer.NewMockPackageManager(GinkgoT()) mockImageManager := system.NewMockImageManager(GinkgoT()) - mockFileIO := util.NewMockFileIO(GinkgoT()) + mockFileIO := intutil.NewMockFileIO(GinkgoT()) // Create a temporary file for the Dockerfile tempFile, err := os.CreateTemp("", "dockerfile-test-*") @@ -204,7 +205,7 @@ var _ = Describe("UpdateDockerfileCmd", func() { It("uses force flag when extracting dependencies", func() { mockPackageManager := installer.NewMockPackageManager(GinkgoT()) mockImageManager := system.NewMockImageManager(GinkgoT()) - mockFileIO := util.NewMockFileIO(GinkgoT()) + mockFileIO := intutil.NewMockFileIO(GinkgoT()) // Create a temporary file for the Dockerfile tempFile, err := os.CreateTemp("", "dockerfile-test-*") @@ -237,7 +238,7 @@ var _ = Describe("UpdateDockerfileCmd", func() { It("handles different base image names correctly", func() { mockPackageManager := installer.NewMockPackageManager(GinkgoT()) mockImageManager := system.NewMockImageManager(GinkgoT()) - mockFileIO := util.NewMockFileIO(GinkgoT()) + mockFileIO := intutil.NewMockFileIO(GinkgoT()) // Create a temporary file for the Dockerfile tempFile, err := os.CreateTemp("", "dockerfile-test-*") @@ -272,12 +273,12 @@ var _ = Describe("UpdateDockerfileCmd", func() { var _ = Describe("AddUpdateDockerfileCmd", func() { var ( parentCmd *cobra.Command - globalOpts *cmd.GlobalOptions + globalOpts *util.GlobalOptions ) BeforeEach(func() { parentCmd = &cobra.Command{Use: "update"} - globalOpts = &cmd.GlobalOptions{} + globalOpts = &util.GlobalOptions{} }) It("adds the dockerfile command with correct properties and flags", func() { diff --git a/cli/cmd/update_install_config.go b/cli/cmd/update_install_config.go index 1ab004220..347ba0aee 100644 --- a/cli/cmd/update_install_config.go +++ b/cli/cmd/update_install_config.go @@ -9,21 +9,22 @@ import ( "strings" csio "github.com/codesphere-cloud/cs-go/pkg/io" + "github.com/codesphere-cloud/oms/cli/cmd/util" "github.com/codesphere-cloud/oms/internal/installer" "github.com/codesphere-cloud/oms/internal/installer/files" "github.com/codesphere-cloud/oms/internal/installer/secrets" - "github.com/codesphere-cloud/oms/internal/util" + intutil "github.com/codesphere-cloud/oms/internal/util" "github.com/spf13/cobra" ) type UpdateInstallConfigCmd struct { cmd *cobra.Command Opts *UpdateInstallConfigOpts - FileWriter util.FileIO + FileWriter intutil.FileIO } type UpdateInstallConfigOpts struct { - *GlobalOptions + *util.GlobalOptions ConfigFile string VaultFile string @@ -69,7 +70,7 @@ func (c *UpdateInstallConfigCmd) RunE(_ *cobra.Command, args []string) error { return c.UpdateInstallConfig(icg) } -func AddUpdateInstallConfigCmd(update *cobra.Command, opts *GlobalOptions) { +func AddUpdateInstallConfigCmd(update *cobra.Command, opts *util.GlobalOptions) { c := UpdateInstallConfigCmd{ cmd: &cobra.Command{ Use: "install-config", @@ -83,14 +84,14 @@ func AddUpdateInstallConfigCmd(update *cobra.Command, opts *GlobalOptions) { For example, updating the PostgreSQL primary IP will trigger regeneration of the PostgreSQL server certificates that include that IP address.`), - Example: formatExamples("update install-config", []csio.Example{ + Example: util.FormatExamples("update install-config", []csio.Example{ {Cmd: "--postgres-primary-ip 10.10.0.4 --config config.yaml --vault prod.vault.yaml", Desc: "Update PostgreSQL primary IP and regenerate certificates"}, {Cmd: "--domain new.example.com --config config.yaml --vault prod.vault.yaml", Desc: "Update Codesphere domain"}, {Cmd: "--k8s-api-server 10.0.0.10 --config config.yaml --vault prod.vault.yaml", Desc: "Update Kubernetes API server host"}, }), }, Opts: &UpdateInstallConfigOpts{GlobalOptions: opts}, - FileWriter: util.NewFilesystemWriter(), + FileWriter: intutil.NewFilesystemWriter(), } c.cmd.Flags().StringVarP(&c.Opts.ConfigFile, "config", "c", "config.yaml", "Path to existing config.yaml file") @@ -139,7 +140,7 @@ func AddUpdateInstallConfigCmd(update *cobra.Command, opts *GlobalOptions) { util.MarkFlagRequired(c.cmd, "vault") c.cmd.RunE = c.RunE - AddCmd(update, c.cmd) + util.AddCmd(update, c.cmd) } func (c *UpdateInstallConfigCmd) UpdateInstallConfig(icg installer.InstallConfigManager) error { diff --git a/cli/cmd/update_install_config_test.go b/cli/cmd/update_install_config_test.go index 5d1848b88..9a067bd4a 100644 --- a/cli/cmd/update_install_config_test.go +++ b/cli/cmd/update_install_config_test.go @@ -13,6 +13,7 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" + "github.com/codesphere-cloud/oms/cli/cmd/util" "github.com/codesphere-cloud/oms/internal/installer" "github.com/codesphere-cloud/oms/internal/installer/files" "github.com/codesphere-cloud/oms/internal/installer/secrets" @@ -206,7 +207,7 @@ codesphere: }) opts = &UpdateInstallConfigOpts{ - GlobalOptions: &GlobalOptions{}, + GlobalOptions: &util.GlobalOptions{}, ConfigFile: configFile.Name(), VaultFile: vaultFile.Name(), } diff --git a/cli/cmd/update_oms.go b/cli/cmd/update_oms.go index 78883e413..e6296ccb7 100644 --- a/cli/cmd/update_oms.go +++ b/cli/cmd/update_oms.go @@ -11,6 +11,7 @@ import ( "github.com/creativeprojects/go-selfupdate" "github.com/spf13/cobra" + "github.com/codesphere-cloud/oms/cli/cmd/util" "github.com/codesphere-cloud/oms/internal/version" ) @@ -66,7 +67,7 @@ func AddOmsUpdateCmd(parentCmd *cobra.Command) { return cmdState.SelfUpdate() }, } - AddCmd(parentCmd, omsCmd) + util.AddCmd(parentCmd, omsCmd) } func (c *UpdateOmsCmd) SelfUpdate() error { diff --git a/cli/cmd/upgrade.go b/cli/cmd/upgrade.go index 17cc50cf5..fcf173a7d 100644 --- a/cli/cmd/upgrade.go +++ b/cli/cmd/upgrade.go @@ -4,6 +4,7 @@ package cmd import ( + "github.com/codesphere-cloud/oms/cli/cmd/util" "github.com/spf13/cobra" ) @@ -21,5 +22,5 @@ func AddUpgradeCmd(rootCmd *cobra.Command) { }, } - AddCmd(rootCmd, upgrade.cmd) + util.AddCmd(rootCmd, upgrade.cmd) } diff --git a/cli/cmd/upgrade_ceph.go b/cli/cmd/upgrade_ceph.go index 30d1ca4eb..341c17b4f 100644 --- a/cli/cmd/upgrade_ceph.go +++ b/cli/cmd/upgrade_ceph.go @@ -5,6 +5,7 @@ package cmd import ( "github.com/codesphere-cloud/cs-go/pkg/io" + "github.com/codesphere-cloud/oms/cli/cmd/util" "github.com/spf13/cobra" ) @@ -21,5 +22,5 @@ func AddUpgradeCephCmd(upgrade *cobra.Command) { Long: io.Long(`Coming soon: Install a Ceph cluster`), }, } - AddCmd(upgrade, ceph.cmd) + util.AddCmd(upgrade, ceph.cmd) } diff --git a/cli/cmd/upgrade_codesphere.go b/cli/cmd/upgrade_codesphere.go index cb35e556b..5e2932fed 100644 --- a/cli/cmd/upgrade_codesphere.go +++ b/cli/cmd/upgrade_codesphere.go @@ -5,6 +5,7 @@ package cmd import ( "github.com/codesphere-cloud/cs-go/pkg/io" + "github.com/codesphere-cloud/oms/cli/cmd/util" "github.com/spf13/cobra" ) @@ -21,5 +22,5 @@ func AddUpgradeCodesphereCmd(upgrade *cobra.Command) { Long: io.Long(`Coming soon: Upgrade Codesphere to the latest or a specific version`), }, } - AddCmd(upgrade, codesphere.cmd) + util.AddCmd(upgrade, codesphere.cmd) } diff --git a/cli/cmd/util/cmd_util.go b/cli/cmd/util/cmd_util.go new file mode 100644 index 000000000..120706bd0 --- /dev/null +++ b/cli/cmd/util/cmd_util.go @@ -0,0 +1,19 @@ +// Copyright (c) Codesphere Inc. +// SPDX-License-Identifier: Apache-2.0 + +package util + +import "github.com/spf13/cobra" + +// AddCmd adds a command, inheriting the parent's Args validator if not explicitly set. +// Individual commands that need different argument rules can override this by setting their own Args validator. +func AddCmd(parent *cobra.Command, cmd *cobra.Command) { + if cmd.Args == nil { + cmd.Args = parent.Args + } + parent.AddCommand(cmd) +} + +type GlobalOptions struct { + OmsPortalApiKey string +} diff --git a/cli/cmd/example_helpers.go b/cli/cmd/util/example_helpers.go similarity index 84% rename from cli/cmd/example_helpers.go rename to cli/cmd/util/example_helpers.go index 04c2f993c..4bead0736 100644 --- a/cli/cmd/example_helpers.go +++ b/cli/cmd/util/example_helpers.go @@ -1,7 +1,7 @@ // Copyright (c) Codesphere Inc. // SPDX-License-Identifier: Apache-2.0 -package cmd +package util import ( "strings" @@ -10,9 +10,9 @@ import ( "github.com/codesphere-cloud/oms/internal/version" ) -// formatExamples builds an Example string similar to io.FormatExampleCommands +// FormatExamples builds an Example string similar to io.FormatExampleCommands // it prefixes commands with a stable binary name (e.g. "oms") instead of temporary go-build paths -func formatExamples(cmdName string, examples []io.Example) string { +func FormatExamples(cmdName string, examples []io.Example) string { var b strings.Builder for i, ex := range examples { if ex.Desc != "" { diff --git a/internal/util/required_flag.go b/cli/cmd/util/required_flag.go similarity index 100% rename from internal/util/required_flag.go rename to cli/cmd/util/required_flag.go diff --git a/cli/cmd/version.go b/cli/cmd/version.go index 03bf92777..25a064518 100644 --- a/cli/cmd/version.go +++ b/cli/cmd/version.go @@ -6,6 +6,7 @@ package cmd import ( "log" + "github.com/codesphere-cloud/oms/cli/cmd/util" v "github.com/codesphere-cloud/oms/internal/version" "github.com/spf13/cobra" ) @@ -33,6 +34,6 @@ func AddVersionCmd(rootCmd *cobra.Command) { Long: `Print current version of OMS.`, }, } - AddCmd(rootCmd, version.cmd) + util.AddCmd(rootCmd, version.cmd) version.cmd.RunE = version.RunE }